akhauriyash/Code-Regression huggingface dataset:
from sys  import stdin,stdout

import bisect

import math

def st():
    return list(stdin.readline().strip())

def inp():
    return int(stdin.readline())

def li():
    return list(map(int,stdin.readline().split()))

def mp():
    return map(int,stdin.readline().split())

def pr(n):
    stdout.write(str(n)+"\n")

def soe(limit):
    l=[1]*(limit+1)
    prime=[]
    for i in range(2,limit+1):
        if l[i]:
            for j in range(i*i,limit+1,i):
                l[j]=0

    for i in range(2,limit+1):
        if l[i]:
            prime.append(i)
    return prime

def segsoe(low,high):
    limit=int(high**0.5)+1
    prime=soe(limit)
    n=high-low+1
    l=[0]*(n+1)
    for i in range(len(prime)):
        lowlimit=(low//prime[i])*prime[i]
        if lowlimit<low:
            lowlimit+=prime[i]
        if lowlimit==prime[i]:
            lowlimit+=prime[i]
        for j in range(lowlimit,high+1,prime[i]):
            l[j-low]=1
    for i in range(low,high+1):
        if not l[i-low]:
            if i!=1:
                print(i)

def power(a,n):
    r=1
    while n:
        if n&1:
            r=(r*a)
        a*=a
        n=n>>1
    return r

l=soe(10**6 +100)

def solve():
    n=inp()
    a=bisect.bisect_left(l,n)
    
    print(l[a])



for _ in range(1):
    solve()
    


Measured memory_bytes: 19804
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = (n) - 1; i >= 0; --i)

typedef long long ll;
typedef vector<ll> vl;

vector<pair<ll, ll>> factorize(ll N) {
  vector<pair<ll, ll>> res;
  ll n = N;
  for (ll p = 2; p*p <= n; p++) {
    if (N%p != 0) continue;
    int count = 0;
    while (N%p == 0) {
      count++; // pで割れる回数をカウント
      N /= p;
    }
    res.push_back(make_pair(p, count));
  }
  if (N != 1) res.push_back(make_pair(N, 1)); // 最終的にNが素数のとき
  return res;
}

vl factors(vector<pair<ll, ll>> f) {
  vl res;
  res.push_back(1);
  REP (i, f.size()) {
    int s = res.size();
    REP (j, s) REP (k, f[i].second) {
      res.push_back(res[j]*pow(f[i].first, k+1));
    }
  }
  sort(res.begin(), res.end());
  return res;
}

int N, M;

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

  vl f = factors(factorize(M));
  REPR (i, f.size()) {
    if (M/f[i] >= N) {
      cout << f[i] << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 512
using System;
using static System.Console;
using static System.Math;
using System.IO;
using System.Collections.Generic;
namespace I_am_the_green_coder{
    class Inonoa{
        // なんか入力用の関数作ったけどまだテストしてないので使う前に確かめて
        static void Main(){
            long a = ILongs()[0];
            Console.WriteLine(3 * a * a);
        }

        static readonly long MOD = 1000000007;

        ///<summary>a_1, a_2, a_3, ...みたいなの</summary>
        static long[] ILongs(){
            string[] s = ReadLine().Split();
            long[] re = new long[s.Length];
            for(long i=0;i<s.Length;i++){
                re[i] = long.Parse(s[i]);
            }
            return re;
        }

        ///<summary>xooxoxoxxoxo...みたいなの</summary>
        static char[] IChars(){
            return ReadLine().ToCharArray();
        }

        ///<summary>n m とかをちょっとはやくかくだけ</summary>
        static string[] IStrings(){
            return ReadLine().Split();
        }

        ///<summary>n行の入力を取ったり</summary>
        static long[][] ILongLongs(long n){
            long[][] re = new long[n][];
            for(long i=0;i<n;i++){
                string[] s = ReadLine().Split();
                re[i] = new long[s.Length];
                for(long j=0;j<s.Length;j++){
                    re[i][j] = long.Parse(s[j]);
                }
            }
            return re;
        }

        ///<summary>n行の文字列を取ったり</summary>
        static char[][] ICharsChars(long n){
            char[][] re = new char[n][];
            for(long i=0;i<n;i++){
                re[i] = ReadLine().ToCharArray();
            }
            return re;
        }
    }
}

Measured memory_bytes: 13140
#include <iostream>
#include <set>

using namespace std;

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

int main() {
  int n;
  cin >> n;
  set<int> memo;
  Rep(i, n) {
    int m;
    cin >> m;
    if (memo.find(m) != memo.end()) {
      cout << "NO" << endl;
      return 0;
    }
    memo.insert(m);
  }
  cout << "YES" << endl;
  return 0;
}


Measured memory_bytes: 9600
import math
n = int(input())
cnt = 0

for i in range(1,int(math.sqrt(n)) + 1):
    if n % i == 0:
        if (n-i) // i > 0 and n // ((n-i) // i) == n % ((n-i) // i):
            cnt += (n-i) // i
print(cnt)

Measured memory_bytes: 3060
#include<vector>
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<map>
#include<functional>
#include<queue>
#include<stack>
#include<string.h>
#define ll long long int
#define MOD 1000000007LL
using namespace std;
int main() {
    int n;
    cin>>n;
    int a[30];
    for(int i=0;i<26;i++){
        a[i]=MOD;
    }
    for(int i=0;i<n;i++){
        int b[30]={};
        string s;
        cin>>s;
        for(int j=0;j<s.length();j++){
            int d=s[j]-'a';
            b[d]++;
        }
        for(int j=0;j<26;j++){
            a[j]=min(b[j],a[j]);
        }
    }
    for(int i=0;i<26;i++){
        for(int j=0;j<a[i];j++){
            char c=i+'a';
            cout<<c;
        }
    }
    cout<<endl;
}


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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

void solve() {
  vector<ll> a, b;
  int n;
  cin >> n;
  a.resize(n);
  b.resize(n);
  for(int i = 0; i < n; i++) cin >> a[i] >> b[i];
  ll ret = 0;
  for(int i = n-1; i >= 0; i--) {
    ll curr = a[i] + ret;
    ll need = curr % b[i];
    need = b[i] - need;
    need %= b[i];
    ret += need;
  }
  cout << ret << endl;
}

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


Measured memory_bytes: 1792
#include <bits/stdc++.h>
typedef long long ll;
const int INF=1e9,MOD=1e9+7,ohara=1e6;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(ll (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(ll i=(a);i<(b);i++)
#define rrrep(i,a,b) for(ll i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl

ll n,cnt,ans[ohara],a,b,c,d,cmp,cmpp,m,h,w,x,y,sum,pos;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

void cal(ll dat){
    rrep(i,2,n+1){
        if(dat<=1)break;
        if(dat%i!=0)continue;
        while(1){
        dat/=i;
        ans[i]++;
        if(dat%i!=0||dat<=1)break;
        }
    }
    return;
}

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

    rep(i,ohara)ans[i]=1;
    cin>>n;
    rrep(i,2,n+1){
        cal(i);
    }
    rep(i,n+1){
        rep(j,n+1){
            rep(k,n+1){
                if(i==j||j==k||i==k)continue;
                if(ans[i]>=5&&ans[j]>=5&&ans[k]>=3)cnt++;
            }
        }
    }
    cnt/=2;
    rep(i,n+1){
        rep(j,n+1){
            if(i==j)continue;
            if(ans[i]>=3&&ans[j]>=25)cnt++;
            if(ans[i]>=5&&ans[j]>=15)cnt++;
        }
    }
    rep(i,n+1){
        if(ans[i]>=75)cnt++;
    }
    Cout(cnt);
    return 0;
}


Measured memory_bytes: 8064
def main():
    from collections import Counter
    import sys
    input = sys.stdin.buffer.readline

    _ = int(input())
    A = [int(i) for i in input().split()]

    ans = 0
    A.sort(reverse=True)
    c = Counter(A)

    for b in A:
        if c[b] == 0:
            continue
        a = (2 ** b.bit_length()) - b
        if a == b:
            cur = c[b]//2
        else:
            cur = min(c[a], c[b])
        ans += cur
        c[b] -= cur
        c[a] -= cur
        # print(a, b, c, ans)

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 105748
#include "bits/stdc++.h"
using namespace std;
const int N = 105;


pair< int, int> a[N], b[N];
vector < int> conn[N];
vector< int> vis;
vector< int> match;


int aug(int x) {
    if (vis[x]) return 0;
    vis[x] = 1;

    for (int y : conn[x]) {
        if (match[y] == -1 or aug(match[y])) {
            match[y] = x;
            return 1;
        }
    }
    return 0;
}

int main() {
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) scanf("%d %d", &a[i].first, &a[i].second);
    for (int i = 0; i < n; ++i) scanf("%d %d", &b[i].first, &b[i].second);

    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            if (a[i].first < b[j].first and a[i].second < b[j].second) {
                conn[i].emplace_back(j + n);
            }
        }
    }

    // for(int i = 0; i < n; ++i) {
    //     for(int J: conn[i]) cout << J << ' ';
    //         cout << endl;
    // }

    int res = 0;
    match.assign(2 * N, -1);
    for (int i = 0; i < n; ++i) {
        vis.assign(2 * N, 0);
        if (aug(i)) res++;
    }

    printf("%d\n", res);

}

Measured memory_bytes: 256
using System;
using System.IO;

// arihon p335
// This solution is O(|T|log^2|T| + Q|P|log|T|) order.
namespace ALDS1_14_D
{
    class SuffixArray
    {
        internal int[] sa, rank, tmp;
        internal string S;
        internal int n, k;
 
        public SuffixArray(string SS)
        {
            S = SS;
            n = S.Length;
            sa = new int[n + 1];
            rank = new int[n << 1 + 1];
            tmp = new int[n + 1];
            Construct_SA();
        }
 
        public int Compare_SA(int i, int j)
        {
            return (rank[i] != rank[j]) ? rank[i] - rank[j] : rank[i + k] - rank[j + k];
        }
 
        public void Construct_SA()
        {
            for (int i = 0; i < n; i++)
            {
                sa[i] = i;
                rank[i] = S[i];
            }
            sa[n] = n;
 
            for (k = 1; k <= n; k <<= 1)
            {
                Array.Sort(sa, Compare_SA);
 
                int d;
                d = tmp[sa[0]] = 0;
 
                for (int i = 1; i <= n; i++)
                {
                    d = tmp[sa[i]] = d + ((Compare_SA(sa[i - 1], sa[i]) < 0) ? 1 : 0);
                }
 
                for (int i = 0; i <= n; i++)
                {
                    rank[i] = tmp[i];
                }
            }
        }
 
        public string Contains(string pattern)
        {
            int l = 1, r = n + 1;
            int pl = pattern.Length;
 
            while (l < r)
            {
                int m = (l + r) >> 1;
 
                string subStr = (sa[m] + pl > n) ? S.Substring(sa[m]) : S.Substring(sa[m], pl);
 
                int comp = subStr.CompareTo(pattern);
                if (comp == 0) return "1";
 
                if (comp < 0) l = m + 1;
                else r = m;
            }
            return "0";
        }
    }
 
 
    class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            var T = Console.ReadLine();
            var SA = new SuffixArray(T);
            var Q = int.Parse(Console.ReadLine());
            for (int i = 0; i < Q; i++)
            {
                var P = Console.ReadLine();
                Console.WriteLine(SA.Contains(P));
            }
            Console.Out.Flush();
        }
    }
}

Measured memory_bytes: 50716
n,m = map(int, input().split())

matrix = list()
for i in range(n):
  matrix.append(list(map(int, input().split())))

vector = list()
for i in range(m):
  vector.append(int(input()))

result = list()
for i in range(n):
  sum = 0
  for j in range(m):
    sum += matrix[i][j] * vector[j]
  result.append(sum)

[print(result[i]) for i in range(n)]


Measured memory_bytes: 6020
//----------BHAVIK DIWANI(PICT_COMP)---------------
#include<bits/stdc++.h>
#include<stdlib.h>
#include<stdio.h>
#define test ll t; cin>>t; while(t--)
#define FOR(p,n) for(ll i=p;i<(ll)n;i++)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mod 1000000007
#define ll long long
#define int long long
#define ull unsigned long long
#define MAX 1000005
#define pb push_back
#define mkp make_pair
#define vi vector<int>
#define pii pair<int,int>
#define endl '\n'
#define vs vector<string>
#define mii map<int,int>
#define msi map<string,int>
#define vpii vector< pair<int, int > >
#define vpsi vector< pair< string ,int > >
#define forci(p,q) for(int i=p;i<q;i++)
ll gcd(ll a,ll b){ if(b==0) return a;    return gcd(b,a%b);}
ll lcm(ll a,ll b) { return (a/gcd(a,b)*b);}
ull power(ull a, ull b) {a %= mod;  ull res = 1;  while (b > 0) { if (b & 1) res = res * a % mod;  a = a * a % mod;  b >>= 1; }  return res%mod; }
ll modmul(ll x, ll y){return (x*y)%mod;}
ll modadd(ll x, ll y){return (x+y)%mod;}
ll modsub(ll x, ll y){return (x-y+mod)%mod;}
ll fact[1000007]={0};
void facto() {fact[0]=1;fact[1]=1;for(int i=2;i<100007;i++)fact[i]=(fact[i-1]*i)%mod;}
ll ncr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[r],mod-2)))%mod; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
ll npr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
inline long long toint(const std::string &s) {std::stringstream ss; ss << s; long long x; ss >> x; return x;}
inline std::string tostring(long long number) {std::stringstream ss; ss << number; return ss.str();}
inline std::string tobin(long long x) {return std::bitset<63>(x).to_string();}
/*bool prime[MAX];
ull sieve(){memset(prime,true,sizeof(prime));for(ull p=2;p*p<MAX;p++){if(prime[p]==true){for(ull i=2*p;i<MAX;i+=p){prime[i]=false;}}}prime[0]=0;prime[1]=0;
}*/
using namespace std;
signed main()
{
	fastio;
	int n,k;
	cin>>n>>k;
	mii mp1;
	for(int i=0;i<k;i++)
	{
		int d;
		cin>>d;
		for(int i=0;i<d;i++)
		{
			int x;
			cin>>x;
			mp1[x]++;
		}
	}
	cout<<n-mp1.size()<<endl;
}












Measured memory_bytes: 3648
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        a: i64,
        b: i64
    }
    if a > 0 {
        println!("Positive");
    } else if a * b <= 0 {
        println!("Zero");
    } else if (min(0, b + 1) - a) % 2 == 0 {
        println!("Positive");
    } else {
        println!("Negative");
    }
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){

double n;
cin>>n;

double l=n/1.08;
double r=(n+1)/1.08;

if(ceil(l)==l){
	cout<<l;
}
else if(r>ceil(l)){
	cout<<ceil(l);
}
else
	cout<<":(";



}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <bitset>
#include <map>
#include <set>
#include <string>
#include <cmath>
#include <sstream>
using namespace std;
#define MOD 1000000007
#define MAX 510000
#define INF 1<<30
#define LINF (ll)1<<62
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(), (x).rend()
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;

ll h,w;

bool in(ll y, ll x){
    return 1 <= y && y <= h && 1 <= x && x <= w;
}

int main(){
    ll n; cin >> h >> w >> n;
    set<P> se;
    rep(i,n){
        ll a,b; cin >> a >> b;
        se.insert(make_pair(a,b));
    }
    vl ans(10,0);
    for(auto i : se){
        ll y = i.first;
        ll x = i.second;
        for(ll sy=y-2; sy<=y; sy++){
            for(ll sx=x-2; sx<=x; sx++){
                if(!in(sy,sx) || !in(sy+2,sx+2)) continue;
                ll cnt = 0;
                rep(i,3){
                    rep(j,3){
                        if(se.find(make_pair(sy+i,sx+j)) != se.end()){
                            //cout << sy << sx << sy+i << sx+j << y << x << endl;
                            cnt++;
                        }
                    }
                }
                ans[cnt]++;
            }
        }
    }
    ll sum = 0;
    REP(i,1,10){
        ans[i] /= i;
        sum += ans[i];
    }
    ans[0] = (h-2)*(w-2) - sum;
    rep(i,10) cout << ans[i] << endl;
}


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

int main()
{
  int K;
  int a[3];
  int res=0;
  rep(i,3) cin >> a[i];
  cin >> K;

  sort(a,a+3);
  res=a[0]+a[1];

  int num=a[2];
  rep(i,K){
    num*=2;
  }
  res+= num;
  cout << res << endl;
}

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

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)

const int MAX_N=1e6;
const int MAX_M=180;

int dp[MAX_N];
int dp2[MAX_N];

int main(){
	REP(i,MAX_N){
		dp[i]=dp2[i]=i;
	}
	FOR(i,2,MAX_M+1){
		int p=i*(i+1)*(i+2)/6;
		FOR(j,p,MAX_N){
			dp[j]=min(dp[j],dp[j-p]+1);
			if (p&1){
				dp2[j]=min(dp2[j],dp2[j-p]+1);
			}
		}
	}
	int N;
	do{
		scanf("%d",&N);
		if (N){
			printf("%d %d\n",dp[N],dp2[N]);
		}
	}while(N);
	return 0;
}

Measured memory_bytes: 9000
n = int(input())
A = list(map(int,input().split()))
ave = sum(A)/n 
diff = []  
for a in A:
	diff.append(abs(a-ave))
tmp = 0   
d = 10**9
for i in range(n):
	if diff[i] < d:
		d = diff[i]
		tmp = i
print(tmp)

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

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

    if(s == "ARC") cout << "ABC" << endl;
    else cout << "ARC" << endl;

    return 0;
}

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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i,k,n) for(int i = k; i < n; i++)
//#define sum(start, end) accumulate(start, end, 0)
#define mmax(start, end) *max_element(start, end)
#define mmin(start, end) *min_element(start, end)
#define pb push_back
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef string str;

using namespace std;
template <class T = ll> T in() { T _in; cin >> _in; return (_in); }


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

    ll a=in(), b=in();
    cout << (a+b) / 2 + (a+b) % 2 << endl;

    return 0;
}


Measured memory_bytes: 256
/**
*　　　　　　　　┏┓　　 　┏┓
* 　　　　　　　┏┛┗━━━━━━━┛┗━━━┓
* 　　　　　　　┃　　　　　　　┃ 　
* 　　　　　　　┃　　　━　　 　┃
* 　　　　　　　┃　＞　　　＜　┃
* 　　　　　　　┃　　　　　　　┃
* 　　　　　　　┃...　⌒　... 　┃
* 　　　　　　　┃　　　　　　　┃
* 　　　　　　　┗━┓　　　┏━┛
* 　　　　　　　　　┃　　　┃　　　　　　　　　　
* 　　　　　　　　　┃　　　┃
* 　　　　　　　　　┃　　　┃　　　　　　　　　　　
* 　　　　　　　　　┃　　　┃  　　　　　　
* 　　　　　　　　　┃　　　┃
* 　　　　　　　　　┃　　　┃　　　　　　　　　　　
* 　　　　　　　　　┃　　　┗━━━┓
* 　　　　　　　　　┃　　　　　　　┣┓
* 　　　　　　　　　┃　　　　　　　┏┛
* 　　　　　　　　　┗┓┓┏━┳┓┏┛
* 　　　　　　　　　　┃┫┫　┃┫┫
* 　　　　　　　　　　┗┻┛　┗┻┛
*/
#include<iostream>  
#include<cstdio>  
#include<fstream>  
#include<iomanip>
#include<algorithm>  
#include<cmath>  
#include<deque>  
#include<vector>
#include<bitset>
#include<queue>  
#include<string>  
#include<cstring>  
#include<map>  
#include<stack>  
#include<set>
#include<cassert>
#include<functional>

#define pii pair<int, int>
#define mod 1000000007
#define mp make_pair
#define pi acos(-1)
#define eps 0.000000001
#define mst(a,i) memset(a,i,sizeof(a))
#define all(n) n.begin(),n.end()
#define lson(x) ((x<<1))  
#define rson(x) ((x<<1)|1) 
#define inf 0x3f3f3f3f
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
const int maxn = 1e5 + 5;

vector<int>prime;
int isprime[maxn];

void getprimelist(int t)
{
	mst(isprime, 1);
	isprime[1] = 0;
	for (int i = 2; i <= t; ++i)
	{
		if (isprime[i])prime.push_back(i);
		for (int j = 0; j < prime.size() && prime[j] * i <= t; ++j)
		{
			isprime[prime[j] * i] = 0;
			if (i%prime[j] == 0)break;
		}
	}
}
int ok[maxn];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
#ifdef DEBUG
	freopen("old_data.json", "r", stdin);
	freopen("1.out", "w", stdout);
#endif // DEBUG clang++ checker.cpp --target=i686-pc-mingw32 -o checker.exe
	int n;
	getprimelist(100000);
	for (int i = 1; i <= 100000; ++i) {
		if (isprime[i] && isprime[(i + 1) / 2])ok[i] = 1;
	}
	for (int i = 1; i <= 100000; ++i)ok[i] += ok[i - 1];
	cin >> n;
	int l, r;
	for (int i = 1; i <= n; ++i) {
		cin >> l >> r;
		cout << ok[r] - ok[l - 1] << endl;
	}
	return 0;
}

Measured memory_bytes: 1536
#-*-coding:utf-8-*-

def research_zero(cards:list):
    return [i for i, x in enumerate(cards) if x == 0]


def main():
    n = int(input())
    S_cards=[0]*13
    C_cards=[0]*13
    D_cards=[0]*13
    H_cards=[0]*13

    for i in range(n):
        t,n=input().split()
        if t=="S":
            S_cards[int(n)-1]=1
        elif t=="H":
            H_cards[int(n)-1]=1
        elif t=="C":
            C_cards[int(n)-1]=1
        elif t=="D":
            D_cards[int(n)-1]=1


    S_zero_list=research_zero(S_cards)
    H_zero_list=research_zero(H_cards)
    C_zero_list=research_zero(C_cards)
    D_zero_list=research_zero(D_cards)

    if len(S_zero_list):
        for i in S_zero_list:
            print("S {}".format(i+1))
    if len(H_zero_list):
        for i in H_zero_list:
            print("H {}".format(i+1))
    if len(C_zero_list):
        for i in C_zero_list:
            print("C {}".format(i+1))
    if len(D_zero_list):
        for i in D_zero_list:
            print("D {}".format(i+1))

if __name__=="__main__":
    main()


Measured memory_bytes: 5616
package main

import "fmt"

func main() {
	var x, k, d int64
	fmt.Scan(&x, &k, &d)
	if x < 0 {
		x = -x
	}

	var ans int64
	if x/d > k {
		ans = (x - k*d)
	} else {
		k -= x / d
		r := x % d
		if k%2 == 0 {
			ans = r
		} else {
			ans = r - d
		}
	}
	if ans < 0 {
		ans = -ans
	}
	fmt.Println(ans)
}


Measured memory_bytes: 1772
/*************************************************\
           In the name of almighty ALLAH
                 MD.Faysal Hasan
                Comilla Univesity
\*************************************************/

#include<bits/stdc++.h>
using namespace std;

#define     ikarus_101  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef     long long             ll;
typedef     long double           ld;
typedef     unsigned long long    ull;
typedef     vector<ll>            vcl;
typedef     pair<ll,ll>           pll;
typedef     vector<pll>           vpl;
typedef     map<ll,ll>            mll;
typedef     multiset<ll>          msl;
typedef     multimap<ll,ll>       Mll;
using pqboro=priority_queue<ll,vcl,less<ll>>;
using pqchoto=priority_queue<ll,vcl,greater<ll>>;

#define    all(str)       str.begin(),str.end()
#define    sajo(str)      sort(str.begin(),str.end())
#define    rev(str)       reverse(str.begin(),str.end())
#define    usajo(str)     sort(str.rbegin(),str.rend())
#define    vin(a)         for(auto &it : a) cin>>it
#define    vout(a)        for(auto it:a) cout<<it<<' ';cout<<nn
#define    pb             push_back
#define    eb             emplace_back
#define    mkp(x,y)       make_pair(x,y)
#define    F              first
#define    S              second
#define    yes            cout<<"YES"<<nn
#define    no             cout<<"NO"<<nn
#define    nn             "\n" ///endl
#define    rep(i,n)       for (i=0;i<n;++i )
#define    rep1(i,n)      for (i=1;i<=n;++i )

#define    min3(a,b,c)    min(a,min(b,c))
#define    max3(a,b,c)    max(a,max(b,c))
#define    sqr(x)         ((x)*(x))
#define    pi             2*acos(0.0)
#define    gcd(a,b)       __gcd(a,b)
#define    lcm(a,b)       (a/gcd(a,b))*b
#define    mem(a,b)       memset(a,b,sizeof (a))
#define    dec(x)         cout<<fixed<<setprecision(x)
#define    none(n)         __builtin_popcountll(n)
#define    strl(a)        atoi(a.c_str())
string lstr(ll n){stringstream ss;ss<<n;return ss.str();}

const   int  N   =   2e5+7;
const   int  M   =   1e9+7;
const   ll  inf  =   0x7f7f7f7f7f7f7f7f;

int main() {ikarus_101

    ll n,m,i,j,k,x;

    cin >> n;
    cout << ((n+999)/1000)*1000-n << nn;
















}


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

const int N = 2e5 + 5;
int n, a[N], b[N];
long long k;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n >> k;
	for(int i = 1; i <= n; ++i) {
		cin >> a[i];
	}
	int dg = 1, di = 1, cz = 1;
	b[1] = di;
	while(k) {
		dg = a[dg], --k;
		if(b[dg]) {
			cz = di - b[dg] + 1;
			break;
		}
		++di;
		b[dg] = di;
	}
	k %= cz;
	for(int i = 1; i <= k; ++i) {
		dg = a[dg];
	}
	cout << dg << endl;
	return 0;
}


Measured memory_bytes: 5168
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define pdi pair<db,int>
#define mp make_pair
#define pb push_back
#define enter putchar('\n')
#define space putchar(' ')
#define eps 1e-8
#define mo 974711
#define MAXN 5005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;char c = getchar();T f = 1;
    while(c < '0' || c > '9') {
	if(c == '-') f = -1;
	c = getchar();
    }
    while(c >= '0' && c <= '9') {
	res = res * 10 + c - '0';
	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
	out(x / 10);
    }
    putchar('0' + x % 10);
}
vector<int> v[1500];
int N = 1407;
int K = 38;
int a[45][45];
void Solve() {
    for(int i = 1 ; i <= K ; ++i) v[1].pb(i);
    int t = 0;
    for(int i = 2 ; i <= N ; i += (K - 1)) {
	++t;
	for(int j = i ; j <= i + (K - 1) - 1 ; ++j) v[j].pb(t);
    }
    t = K;
    for(int i = 0 ; i < K - 1 ; ++i) {
	for(int j = 0 ; j < K - 1 ; ++j) {
	    a[i][j] = ++t;
	    v[i + 2].pb(t);
	}
    }
    t = 0;
    for(int i = K + 1 ; i <= N ; i += (K - 1)) {
	for(int j = 0 ; j < K - 1 ; ++j) {
	    int p = j;
	    for(int h = 0 ; h < K - 1 ; ++h) {
		v[i + j].pb(a[h][p]);
		p = (p + t) % (K - 1);
	    }
	}
	++t;
    }
    out(N);space;out(K);enter;
    for(int i = 1 ; i <= N ; ++i) {
	for(auto b : v[i]) {
	    out(b);space;
	}
	enter;
    }
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
    return 0;
}


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

// why am I so weak

int n;
int a[100055];

int main() {
	scanf("%d", &n);

	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}

	int res = 1;

	// sigma(2 * a[0...i - 1]) >= a[i]

	sort(a, a + n);

	long long sum = 0ll;

	for (int i = 0; i < n; i++) sum += a[i];

	sum -= a[n - 1];

	for (int i = n - 2; i >= 0; i--) {
		if (2ll * sum < a[i + 1]) break;

		sum -= a[i];
		res++;
	}

	printf("%d\n", res);

	return 0;
}


Measured memory_bytes: 1148
import java.io.InputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.Comparator;
import java.util.Deque;
import java.util.HashMap;
import java.util.HashSet;
import java.util.InputMismatchException;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.PriorityQueue;
import java.util.TreeMap;
import java.math.BigDecimal;
import java.math.BigInteger;
    
public class Main{
 
static final InputStream in=System.in;
static final PrintWriter out=new PrintWriter(System.out);
static final int INF=Integer.MAX_VALUE;
static final long LINF=Long.MAX_VALUE;
 
public static void main(String[] args) throws IOException{
InputReader ir=new InputReader(in);
int[] a=ir.nextIntArray(3);
Arrays.sort(a);
out.println(a[0]+" "+a[1]+" "+a[2]);
out.flush();
}

static class InputReader {
 private InputStream in;
 private byte[] buffer=new byte[1024];
 private int curbuf;
 private int lenbuf;
 
 public InputReader(InputStream in) {this.in=in; this.curbuf=this.lenbuf=0;}
  
 public boolean hasNextByte() {
  if(curbuf>=lenbuf){
   curbuf= 0;
   try{
    lenbuf=in.read(buffer);
   }catch(IOException e) {
    throw new InputMismatchException();
   }
   if(lenbuf<=0) return false;
  }
  return true;
 }
 
 private int readByte(){if(hasNextByte()) return buffer[curbuf++]; else return -1;}

 private boolean isSpaceChar(int c){return !(c>=33&&c<=126);}
 
 private void skip(){while(hasNextByte()&&isSpaceChar(buffer[curbuf])) curbuf++;}

 public boolean hasNext(){skip(); return hasNextByte();}
 
 public String next(){
  if(!hasNext()) throw new NoSuchElementException();
  StringBuilder sb=new StringBuilder();
  int b=readByte();
  while(!isSpaceChar(b)){
   sb.appendCodePoint(b);
   b=readByte();
  }
  return sb.toString();
 }
 
 public int nextInt() {
  if(!hasNext()) throw new NoSuchElementException();
  int c=readByte();
  while (isSpaceChar(c)) c=readByte();
  boolean minus=false;
  if (c=='-') {
   minus=true;
   c=readByte();
  }
  int res=0;
  do{
   if(c<'0'||c>'9') throw new InputMismatchException();
   res=res*10+c-'0';
   c=readByte();
  }while(!isSpaceChar(c));
  return (minus)?-res:res;
 }
 
 public long nextLong() {
  if(!hasNext()) throw new NoSuchElementException();
  int c=readByte();
  while (isSpaceChar(c)) c=readByte();
  boolean minus=false;
  if (c=='-') {
   minus=true;
   c=readByte();
  }
  long res = 0;
  do{
   if(c<'0'||c>'9') throw new InputMismatchException();
   res=res*10+c-'0';
   c=readByte();
  }while(!isSpaceChar(c));
  return (minus)?-res:res;
 }
 
 public double nextDouble(){return Double.parseDouble(next());}
 
 public BigInteger nextBigInteger(){return new BigInteger(next());}
 
 public int[] nextIntArray(int n){
  int[] a=new int[n];
  for(int i=0;i<n;i++) a[i]=nextInt();
  return a;
 }
 
 public char[][] nextCharMap(int n,int m){
  char[][] map=new char[n][m];
  for(int i=0;i<n;i++) map[i]=next().toCharArray();
  return map;
 }
}
}

Measured memory_bytes: 24332
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 
  int X, Y;
  cin >> X >> Y;
  int ans = 0;
  
  for(int i=0;i<X+1;i++){
  	if(  Y - 4*i == 2*(X-i)){
  	ans = 1;
  	break;
  	}
  }
  
  if(ans == 1){
  cout << "Yes" << endl;
  }
  
  else{
  cout << "No" << endl;
  }
 
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define uLL unsigned long long
using namespace std;
#define LL long long
#define N 100005
struct xx {
	int ed,last;
} w[N<<1];
int cot = 0,head[N];
void Link(int s,int e) {
	w[++cot].ed = e,w[cot].last = head[s],head[s] = cot;
	return ;
}
const int mo = 1e9+7;
void Add(LL &res,int x) {
	res *= x;
	res %= mo;
	return ;
}
int n,k,sz[N],fa[N];
LL ans = 1;
void dfs(int now,int pre) {
	fa[now] = pre;
	int sx = k - sz[pre];
	if(pre) sx --;
	if(fa[pre]) sx --;
	Add(ans,sx);
	for(int i=head[now]; i; i=w[i].last) {
		int e = w[i].ed;
		if(e == pre) continue;
		dfs(e,now),sz[now] ++;
	}
	return ;
}
int main() {
	cin >> n >> k;
	for(int i=1,a,b; i<n; i++) {
		scanf("%d%d",&a,&b);
		Link(a,b),Link(b,a);
	}
	dfs(1,0);
	cout << ans;
	return 0;
}

Measured memory_bytes: 6528
import java.util.*;
import static java.lang.Math.*;
public class Main {
	final Scanner sc=new Scanner(System.in);
	public static void main(String[] args) {
		new Main().init();
	}
	void init(){
		final long STACK_SIZE=8*1024*1024;
		new Thread(null, new AOJ1320(), "RUN", STACK_SIZE).start();
	}
	
	class AOJ1320 implements Runnable{
		AOJ1320(){}
		@Override public void run(){
			while(sc.hasNext()){
				N=sc.nextInt();
				if(N==0)	break;
				solve();
			}
		}
		
		int N,N2;
		final int INF=1<<29;
		
		void solve(){
			String[] str=new String[N];
			for(int i=0; i<N; ++i)	str[i]=sc.next();
			
			boolean[] eq=new boolean[N];
			for(int i=0; i<N; ++i){
				if(eq[i])	continue;
				for(int j=0; j<N; ++j){
					if(i!=j && !eq[j] && str[i].matches(".*?"+str[j]+".*?"))	eq[j]=true;
				}
			}
			ArrayList<String> str2=new ArrayList<String>();
			for(int i=0; i<N; ++i)if(!eq[i])	str2.add(str[i]);
			N2=str2.size();
			
			int[][] len=new int[N2][N2];
			for(int i=0; i<N2; ++i){
				for(int j=0; j<N2; ++j){
					if(i==j)	continue;
					int offset=0, l=str2.get(i).length();
					for( ; offset<l; ++offset){
						if( str2.get(j).startsWith( str2.get(i).substring(offset) ) )	break;
					}
					len[i][j]=str2.get(j).length()-(l-offset);
				}
			}
			
			int[][] dp=new int[1<<N2][N2];
			for(int i=0; i<(1<<N2); ++i)for(int j=0; j<N2; ++j)dp[i][j]=INF;
			for(int i=0; i<N2; ++i)	dp[1<<i][i]=str2.get(i).length();
			for(int i=0; i<(1<<N2); ++i){
				for(int j=0; j<N2; ++j){
					if(dp[i][j]>=INF)	continue;
					for(int k=0; k<N2; ++k){
						if( (i&(1<<k)) > 0 )	continue;
						int newIdx=i|(1<<k);
						dp[newIdx][k]=min(dp[newIdx][k], dp[i][j]+len[j][k]);
					}
				}
			}
			
			int ans=INF, tmp=(1<<N2)-1;
			for(int i=0; i<N2; ++i)	ans=min(ans,dp[tmp][i]);
			System.out.println(ans);
		}
	}
}

Measured memory_bytes: 17000
s=input()
x,y=map(int,input().split())
xx,yy=[],[]
w=[0,0]
ans=chk=f=0
for i in s:
    if f==1 and i=='F':
        chk+=1
    elif f==1 and i=='T':
        yy.append(chk)
        f=0
    elif f==0 and i=='F':
        chk+=1
    elif f==0 and i=='T':
        xx.append(chk)
        f=1
    if i=='T': chk=0
if chk and f==1:
    yy.append(chk)
elif chk and f==0:
    xx.append(chk)
if s[0]=='F':
    w[0]+=xx[0]
    xx[0]=0
xx.sort()
yy.sort()
for i in xx[::-1]:
    if w[0]<x:
        w[0]+=i
    else:
        w[0]-=i
for i in yy[::-1]:
    if w[1]<y:
        w[1]+=i
    else:
        w[1]-=i
print("Yes" if w[0]==x and w[1]==y else "No")

Measured memory_bytes: 40176
#include<cstdio>
#include<algorithm>
#include<cmath>
#define ll long long
#define mod 1000000007
using namespace std;
ll n, m;
int main()
{
	ll dap = 1;
	scanf("%lld %lld", &n, &m);
	if (abs(m - n) >= 2)
	{
		puts("0");
		return 0;
	}
	for (int i = 1; i <= n; i++)
	{
		dap *= i;
		dap %= mod;
	}
	for (int i = 1; i <= m; i++)
	{
		dap *= i;
		dap %= mod;
	}
	if (n == m)
	{
		dap *= 2;
		dap %= mod;
	}
	printf("%lld", dap);
}

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

using namespace std;

#undef LOCAL
string to_string(string s) { return '"' + s + '"'; }
string to_string(bool x) { return (x ? "T" : "F"); }
string to_string(const char* s) { return to_string((string)s); }
template <typename A, typename B>
string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename V>
string to_string(V v) {
    bool f = true; string res = "[";
    for (const auto& x: v) {
        if (!f) res += ", ";
        f = false;
        res += to_string(x); } res += "]";
    return res;
}
void debug() { cerr << endl; }
template <typename H, typename... T>
void debug(H h, T... t) { cerr << " " << to_string(h); debug(t...); }
#ifdef LOCAL
#define dbg(args...) cerr<<"("<<#args<<") =", debug(args)
#else
#define dbg(args...) 2019
#endif

const int INF = 0x3f3f3f3f;

void solve() {
    int n; cin >> n;
    vector<vector<int>> g(n);
    for (int i = 1; i < n; i++) {
        int x; cin >> x; x--;
        g[x].emplace_back(i);
    }
    vector<int> a(n);
    for (auto& x: a) {
        cin >> x;
    }
//    // anti-chain width <= 2. 
//    // but not for this problem. since X_v is sum of subtree(s). 
//    // so necessary but not sufficient
//    vector<pair<int, int>> bak(n);
//    bak[0] = {a[0], 1<<30};
//    function<bool(int)> dfs = [&](int u){
//        for (int v: g[u]) {
//            bak[v] = bak[u];
//            if (a[v] <= bak[u].first) {
//                bak[v].first = a[v];
//            } else if (a[v] <= bak[u].second) {
//                bak[v].second = a[v];
//            } else return false;
//            if (!dfs(v)) return false;
//        }
//        return true;
//    };
//    auto res = dfs(0)?"POSSIBLE":"IMPOSSIBLE";

#define rep(i) for(int i=0;i<2;i++)
    vector<array<int,2>> sub(n);
    function<bool(int)> dfs = [&](int u){
        for (int v: g[u])
            if (!dfs(v)) return false;
        if (g[u].empty()) return true;
        rep(b){
            int w = b^1;
            vector<vector<int>> dp(2, vector<int>(a[u] + 1, INF));
            int crt = 0;
            dp[crt][0] = 0;
            for (int v: g[u]) {
                int nxt = crt^1;
                for (int i = 0; i <= a[u]; i++) {
                    dp[nxt][i] = INF;
                    if (a[v] <= i) {
                        dp[nxt][i] = min(dp[nxt][i], dp[crt][i-a[v]] + sub[v][w]);
                    }
                    if (sub[v][b] <= i) {
                        dp[nxt][i] = min(dp[nxt][i], dp[crt][i-sub[v][b]] + a[v]);
                    }
                }
                crt ^= 1;
                dbg(dp);
            }
            int mi = INF;
            for (int i = 0; i <= a[u]; i++) {
                mi = min(mi, dp[crt][i]);
            }
            dbg(u, dp, mi);
            sub[u][w] = mi;
        }
        return sub[u][0] < INF || sub[u][1] < INF;
    };
    auto res = dfs(0)?"POSSIBLE":"IMPOSSIBLE";
    dbg(sub);
    cout << res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


Measured memory_bytes: 384
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<int, int> P;
static const double EPS = 1e-5;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
int getnum(string str){
  stringstream ss;
  ss<<str.substr(0,str.find_first_of(","));
  int ret;
  ss>>ret;
  return ret;
}
int ti[100000];
int main(void){
  string line;
  set<int> s1,s2;
  while(getline(cin,line)){
    if(line.size()==0) break;
    s1.insert(getnum(line)); 
    ti[getnum(line)]++;
  }
  while(getline(cin,line)){
    if(line.size()==0) break;
    s2.insert(getnum(line));
    ti[getnum(line)]++;
  }
  set<int>::iterator it = s1.begin();
  while(it!=s1.end()){
    if(s2.find(*it)!=s2.end()){
      printf("%d %d\n",*it,ti[*it]);
    }
    it++;
  }
  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define rep(i,a,b) for (int i=(a); i<=(b); i++)
#define per(i,a,b) for (int i=(a); i>=(b); i--)
using namespace std;
typedef long long LL;

inline LL read() {
    LL x=0,f=1; char ch=getchar();
    while (!(ch>='0'&&ch<='9')) {if (ch=='-')f=-1;ch=getchar();}
    while (ch>='0'&&ch<='9') {x=x*10+(ch-'0'); ch=getchar();}
    return x*f;
}

const int L = 105;

int n; LL k;
char s[L];

int main() {

	#ifndef ONLINE_JUDGE
	//	freopen("data.in","r",stdin);
	//	freopen("data.out","w",stdout);
	#endif

	scanf("%s",s+1); n=strlen(s+1); k=read();
	rep(i,1,k) if (s[i]!='1') {putchar(s[i]); return 0;}
	puts("1");

	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++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)

int main() {
  int H, W; cin >> H >> W;
  vector<vector<char>> mp(H, vector<char>(W));
  vector<vector<bool>> flag(H, vector<bool>(W, false));
  rep(i, H) {
    rep(j, W) {
      cin >> mp.at(i).at(j);
    }
  }
  rep(i, H) {
    int count =  0;
    rep(j, W) {
      if (mp.at(i).at(j) == '.') {
        count++;
      }
    }
    if (count == W) {
      rep(j, W) {
        flag.at(i).at(j) = true;
      }
    }
  }
  rep(i, W) {
    int count =  0;
    rep(j, H) {
      if (mp.at(j).at(i) == '.') {
        count++;
      }
    }
    if (count == H) {
      rep(j, H) {
        flag.at(j).at(i) = true;
      }
    }
  }
  
  rep(i, H) {
    int cnt = 0;
    rep(j, W) {
      if (flag.at(i).at(j) == false) {
        cout << mp.at(i).at(j);
        cnt++;
      }
      if (j == W-1) {
        if (cnt != 0) {
          cout << endl;
        }
      }
    }
  }
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define SZ(x) ((int)x.size())
#define ALL(x) x.begin(),x.end()
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=(a); i<=(b); i++)
#define per(i,a,b) for (register int i=(a); i>=(b); i--)
using namespace std;
typedef long double ld;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
typedef vector<int> Vi;
template<class T> inline void read(T &x){
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
template<class T> T gcd(T a, T b){return !b?a:gcd(b,a%b);}
template<class T> inline void umin(T &x, T y){x=x<y?x:y;}
template<class T> inline void umax(T &x, T y){x=x>y?x:y;}
mt19937 R(chrono::system_clock().now().time_since_epoch().count());

const int N = 1<<18|3, B = 11;
struct node{int id,u,l;};
int n,v[N],w[N],q,ans[N],sz,len,a[N];vector<node>que[N];Pii b[N];

void dfs2(int id, int dep, int x, int y){
	if(x<0)return;
	if(dep>sz){
		umax(ans[id],y);
		return;
	}
	dfs2(id,dep+1,x,y);
	dfs2(id,dep+1,x-w[a[dep]],y+v[a[dep]]);
}
void dfs1(int id, int dep, int x, int y){
	if(x<b[1].fi)return;
	if(dep>sz){
		umax(ans[id],y+b[upper_bound(b+1,b+len+1,mp(x,0x3f3f3f3f))-b-1].se);
		return;
	}
	dfs1(id,dep+1,x,y);
	dfs1(id,dep+1,x-w[a[dep]],y+v[a[dep]]);
}
void dfs(int dep, int x, int y){
	if(dep>sz){
		b[++len]=mp(x,y);
		return;
	}
	dfs(dep+1,x,y);
	dfs(dep+1,x+w[a[dep]],y+v[a[dep]]);
}
int main()
{
	cin>>n;
	for(int i=1; i<=n; ++i)
	{
		cin>>v[i]>>w[i];
	}
	cin>>q;
	for(int i=1; i<=q; ++i)
	{
		int u, l;
		cin>>u>>l;
		if(u<(1<<B))
		{
			sz=0;
			for(; u; u>>=1)
			{
				a[++sz]=u;
				//dfs2(i, 1, l, 0);
			}
			dfs2(i, 1, l, 0);
		}
		else
		{
			int x=u;
			while(x>=(1<<B))
			{
				x>>=1;
				//que[x].pb((node){i,u,l});
			}
			que[x].pb((node){i,u,l});
		}
	}
	for(int i=1; i<=n; ++i)
	{
		if(SZ(que[i]))
		{
			sz=len=0;
			for(int u=i; u; u>>=1)
			{
				a[++sz]=u;
				//dfs(1, 0, 0);
				//sort(b+1,b+len+1);
			}
			dfs(1, 0, 0);
			sort(b+1,b+len+1);
			for(int j=2; j<=len; ++j)
			{
				umax(b[j].se,b[j-1].se);
			}
			for(auto q:que[i])
			{
				sz=0;
				for(int u=q.u; u>i; u>>=1)
				{
					a[++sz]=u;
					//dfs1(q.id, 1, q.l, 0);
				}
				dfs1(q.id, 1, q.l, 0);
			}
		}
	}
	for(int i=1; i<=q; ++i)
	{
		printf("%d\n",ans[i]);
	}
	return 0;
}


Measured memory_bytes: 14020
#include <iostream>

int main(){
	int h, w;
	while(1){
		std::cin >> h >> w;
		if(!h && !w)
			break;
		for(int j = 0; j < h; j++){
			for(int i = 0; i < w; i++){
				if((i - j) % 2)
					std::cout << '.';
				else
					std::cout << '#';
			}
			std::cout << std::endl;
		}
		std::cout << std::endl;
	}
	return 0;
}

Measured memory_bytes: 1152
//be name khoda
//Pedram Sadeghian
// :)
#include <bits/stdc++.h>
using namespace std;

const int maxN = 1e5;
int nam[maxN][3], ans, n, m, k1, k2, k3;
pair <int, pair <int, int> > P[maxN];
bool issame(int a, int b){
	return nam[a][0] == nam[b][0];
}
void merrge(int a, int b){
	if (nam[a][2] < nam[b][2])
		swap(a, b);
	int S = nam[a][2] + nam[b][2], k = a;
	bool plp = 1;
	while (k != a || plp){
		plp = 0;
		nam[k][2] = S;
		nam[k][0] = nam[b][0];
		k = nam[k][1];
	}
	k = b; plp = 1;
	while (k != b || plp){
		plp = 0;
		nam[k][2] = S;
		k = nam[k][1];
	}
	S = nam[a][1];
	nam[a][1] = nam[b][1];
	nam[b][1] = S;
	return ;
}
int main(){
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n >> m;
	for (int i = 0 ; i < m ; i++){
		cin >> k1 >> k2 >> P[i].first;
		P[i].second.first = k1;
		P[i].second.second = k2;
	}
	sort(P, P + m);
	for (int i = 0 ; i < n ; i++){
		nam[i][0] = i + 1;
		nam[i][1] = i;
		nam[i][2] = 1;
	}
	for (int i = 0 ; i < m ; i++){
		if (not issame(P[i].second.first, P[i].second.second)){
			ans += P[i].first;
			merrge(P[i].second.first, P[i].second.second);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 4508
#include<cstdio>
#include<cmath>
#include<string>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<map>
#include<set>
#include<limits>
#include<bitset>
#include<array>
#include<numeric>
#include<iomanip>
#include<functional>

using namespace std;
typedef long long int ll;

#define C(I) cout<<(I)<<endl

ll n,m,a,b,c,x,y,aa[100010],ba[100010];
bool r,br,ar;
string sa,sb,sc;
char ca,cb;


int main(){
    
    cin>>a>>b>>c;
    C(b-a==c-b ? "YES":"NO");
    
    
    
}


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

int main(){
    int K, N;
    cin >> K >> N;
    int A[N];
    for(int i =0; i < N; i++){
        cin >> A[i];
    }
    int max = A[0] + (K - A[N - 1]);
    for(int i =0; i < N-1; i++){
        if(A[i + 1] - A[i] > max) max = A[i + 1] - A[i];
    }
    cout << K - max << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
 
int main(){
 
  int n;
  cin>>n;
  
  string g;
  cin>>g;
  
  int r=0,w=0;
  
  for(auto x:g)
    r+=(x=='R');
  
  for(int i=0;i<r;i++)
    w+=(g[i]=='W');
  
  cout<<w<<endl;
  
}

Measured memory_bytes: 3732
#include <iostream>
#include <set>
#include <vector>
#include <algorithm>
using namespace std;

typedef unsigned long long int ulint;
typedef long long int lint;

int main(){
  ulint K, X;
  cin >> K >> X;

  if (K * 500 >= X) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

}


Measured memory_bytes: 888
import sys
import math
import heapq
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, m=DVSR): return pow(x, m - 2, m)
def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())
def FLIST(n):
    res = [1]
    for i in range(1, n+1): res.append(res[i-1]*i%DVSR)
    return res
def gcd(x, y):
    if x < y: x, y = y, x
    div = x % y
    while div != 0:
        x, y = y, div
        div = x % y
    return y

N=II()
AB = [LI() for _ in range(N-1)]

graph = [[] for _ in range(N+1)]
for a,b in AB:
    graph[a].append(b)
    graph[b].append(a)

root = 1
parent = [0] * (N+1)
order = []
stack = [root]
while stack:
    x = stack.pop()
    order.append(x)
    for y in graph[x]:
        if y == parent[x]: continue
        parent[y] = x
        stack.append(y)

x = (DVSR + 1) // 2
PWR=[1]*(N+1)
RWP=[1]*(N+1)

for i in range(1,N+1):
    PWR[i] = PWR[i-1] * 2 % DVSR
    RWP[i] = RWP[i-1] * x % DVSR

answer = 0
size = [1] * (N+1)
for v in order[::-1]:
    p = parent[v]
    size[p] += size[v]
    A = [size[w] for w in graph[v] if w != p]
    if v != root: A.append(N - 1 - sum(A))
    if len(A) == 1: continue
    prod = 1
    coef = 1
    for x in A:
        prod *= RWP[x]
        prod %= DVSR
        coef += (PWR[x] - 1)
    E = 1 - prod * coef % DVSR
    answer += E

answer *= RWP[1]
answer %= DVSR
print(answer)

Measured memory_bytes: 90952