akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define INF 100000000000000007LL
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;

int n,m;

int u[1000001],v[1000001];
ll d[1000001];

ll dist[2][1000001];
ll cnt[2][1000001];
vector<P> G[1000001];

void dijk(int s,int t,int di){
	for(int i=0;i<n;i++){
		dist[di][i]=INF;
	}
	dist[di][s]=0;
	cnt[di][s]=1;
	priority_queue<P,vector<P>,greater<P> > que;
	que.push(P(0,s));
	while(que.size()){
		P p=que.top();
		que.pop();
		int v=p.second;
		ll c=p.first;
		if(dist[di][v]<c)continue;
		for(int i=0;i<G[v].size();i++){
			if(dist[di][G[v][i].first]>c+G[v][i].second){
				dist[di][G[v][i].first]=c+G[v][i].second;
				cnt[di][G[v][i].first]=cnt[di][v];
				que.push(P(dist[di][G[v][i].first],G[v][i].first));
			}else if(dist[di][G[v][i].first]==c+G[v][i].second){
				cnt[di][G[v][i].first]=(cnt[di][G[v][i].first]+cnt[di][v])%MOD;
			}
		}
	}
}

int main(void){
	int s,t;
	scanf("%d%d",&n,&m);
	scanf("%d%d",&s,&t);
	s--;
	t--;
	for(int i=0;i<m;i++){
		scanf("%d%d%lld",&u[i],&v[i],&d[i]);
		u[i]--;
		v[i]--;
		G[u[i]].push_back(P(v[i],d[i]));
		G[v[i]].push_back(P(u[i],d[i]));
	}
	dijk(s,t,0);
	dijk(t,s,1);
	ll ans=cnt[0][t]*(cnt[1][s])%MOD;
	//printf("%lld\n",ans);
	for(int i=0;i<n;i++){
		if((dist[0][i]+dist[1][i])==dist[0][t]){
			if(dist[0][i]==dist[1][i]){
				ll gi=cnt[0][i]*cnt[1][i]%MOD;
				ans-=gi*gi%MOD;
				ans+=MOD;
				ans%=MOD;
			}
		}
	}
	//printf("%lld\n",ans);
	for(int i=0;i<m;i++){
		if((dist[0][u[i]]+dist[1][v[i]]+d[i])==dist[0][t]){
			ll dif=dist[0][u[i]]-dist[1][v[i]];
			ll gi=dist[0][v[i]]-dist[0][u[i]];
			ll gi2=dist[1][u[i]]-dist[1][v[i]];
			gi=max(gi,-gi);
			gi2=max(gi2,-gi2);
			if(dif<0LL)dif=-dif;
			if(dif==d[i])continue;
			if(gi!=d[i] || gi2!=d[i])continue;
			if(dist[0][u[i]]<=dist[1][v[i]] && dist[1][v[i]]<=dist[0][v[i]]){
				ll gi=cnt[0][u[i]]*cnt[1][v[i]]%MOD;
				ans-=(gi*gi)%MOD;
				ans+=MOD;
				ans%=MOD;
			}else if(dist[1][v[i]]<=dist[0][u[i]] && dist[0][u[i]]<=dist[1][u[i]]){
				ll gi=cnt[0][u[i]]*cnt[1][v[i]]%MOD;
				ans-=(gi*gi)%MOD;
				ans+=MOD;
				ans%=MOD;
			}
		}
		swap(u[i],v[i]);
		if((dist[0][u[i]]+dist[1][v[i]]+d[i])==dist[0][t]){
			ll dif=dist[0][u[i]]-dist[1][v[i]];
			ll gi=dist[0][v[i]]-dist[0][u[i]];
			ll gi2=dist[1][u[i]]-dist[1][v[i]];
			if(dif<0LL)dif=-dif;
			if(dif==d[i])continue;
			gi=max(gi,-gi);
			gi2=max(gi2,-gi2);
			if(gi!=d[i] || gi2!=d[i])continue;
			if(dist[0][u[i]]<=dist[1][v[i]] && dist[1][v[i]]<=dist[0][v[i]]){
				ll gi=cnt[0][u[i]]*cnt[1][v[i]]%MOD;
				ans-=(gi*gi)%MOD;
				ans+=MOD;
				ans%=MOD;
			}else if(dist[1][v[i]]<=dist[0][u[i]] && dist[0][u[i]]<=dist[1][u[i]]){
				ll gi=cnt[0][u[i]]*cnt[1][v[i]]%MOD;
				ans-=(gi*gi)%MOD;
				ans+=MOD;
				ans%=MOD;
			}
		}
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 54228
#include <iostream>
#include <string>
using namespace std;
int main(){
  int k;
  string s;
  cin >> k;
  cin >> s;
  if((int)s.size() <= k){
    cout << s;
  }else{
    string ns="";
    for(int i=0;i<k;i++){
      ns += s[i];
    }
    ns += "...";
    cout << ns;
  }
}
    

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#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 show(x) {for(auto i: x){cout << i << " ";} cout<<endl;}
#define showm(m) {for(auto i: m){cout << m.x << " ";} cout<<endl;}
typedef long long ll;
typedef pair<int, int> P;
ll gcd(int x, int y){ return y?gcd(y, x%y):x;}
ll lcm(ll x, ll y){ return (x*y)/gcd(x,y);}

int mod = 3;
typedef struct mint
{
    ll x;
    mint(ll x = 0) : x(x % mod){} //コンストラクタ
    /* 演算子オーバーロード */
    mint &operator+=(const mint a)
    {
        if ((x += a.x) >= mod)
            x -= mod;
        return *this;
    }
    mint &operator-=(const mint a)
    {
        if ((x += mod - a.x) >= mod)
            x -= mod;
        return *this;
    }
    mint &operator*=(const mint a)
    {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const
    {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint a) const
    {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint a) const
    {
        mint res(*this);
        return res *= a;
    }
    mint pow(ll t) const
    {
        if (!t)
            return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1)
            a *= *this;
        return a;
    }
    // for prime mod
    mint inv() const
    {
        return pow(mod - 2);
    }
    mint &operator/=(const mint a)
    {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const
    {
        mint res(*this);
        return res /= a;
    }
} mint_t;

int main()
{
    int n, p;
    cin >> n >> p;
    vector<int> amaribox(p, 0); //modの数を管理
    string s;
    cin >> s;
    mod = p;

    ll ans = 0;
    if (p != 2 && p != 5){
        mint kurikoshi(0);
        mint keta_mod(1);
        rep(i, n){
            int num = (s[n-1-i] - '0') % p;

            kurikoshi += keta_mod * num ;
            keta_mod *= 10;
 //           cout << kurikoshi.x << ":" << num << ":" << keta_mod.x<< endl;

            if (kurikoshi.x == 0) ans++;
            ans += amaribox[kurikoshi.x];

            amaribox[kurikoshi.x] += 1;
        }

    } else {
        rep(i, n){
            int num = (s[n-1-i] - '0') % p;
            if (num == 0) ans += n-i;
        }
    }

    cout << ans << endl;

}

Measured memory_bytes: 644
/*
 * Author: Anmol Choudhary
 */
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include<bits/stdc++.h>
using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define pb push_back
#define rep0(a,b) for(int a=0;a<b;a++)
#define rep1(a,b) for(int a=1;a<=b;a++)
#define repp(a,b,c) for(int a=b;a<c;a++)
#define in insert
#define len length()
#define si size()
#define lb lower_bound
#define ub upper_bound
#define beg begin()
#define en end()
#define f first
#define s second
#define pr(a) cout<<a
#define pr2(a,b) cout<<a<<" "<<b<<"\n"
#define nx cout<<"\n"
const ll mod = 1000000007;
const ll maxn = 500005;
const ll mm = 1e+18;
void solve()
{
    int n;
    cin>>n;
    bool p=true;
    rep0(i,n){
        int x;
        cin>>x;
        if(x%2==0){
            if(x%3&&x%5){
                p=false;
            }
        }
    }
    if(p) cout<<"APPROVED";
    else cout<<"DENIED";
}
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t=1;
    //cin>>t;
    while(t--){
        solve();
        //nx;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <stack>
#include <algorithm>
#include <vector>
#include <bitset>
#include <map>
#include <utility>
#include <cmath>
#include <list>
#include <set>
#include <map>

# define INF 0x3f3f3f3f 

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a, b; cin>>a>>b;
    cout<<(a*b)<<endl;
    return 0;
}

Measured memory_bytes: 3608
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
using namespace std;
const int MaxN = 1e5;
long long cnt1[MaxN + 5],cnt2[MaxN + 5],a[MaxN + 5],b[MaxN + 5],c[MaxN + 5],n;

bool cmp1(long long x, long long  y){
	return x < y;
}
bool cmp(long long x, long long y){
	return x > y;
}

int main()
{
	scanf("%lld",&n);
	for(int i = 1; i <= n; i++)
		scanf("%lld",&a[i]);
	for(int i = 1; i <= n; i++)
		scanf("%lld",&b[i]);
	for(int i = 1; i <= n; i++)
		scanf("%lld",&c[i]);
	sort(a + 1, a + n + 1,cmp1);
	sort(b + 1, b + n + 1,cmp1);
	sort(c + 1, c + n + 1, cmp);
	long long p = 1;
	int ok = 1;
	for(int i = 1; i <= n; i++){
		if(p == n + 1){ 
			cnt1[i] = p - 1;
			continue;
		}
		ok = 1;
		while(ok && p <= n){
			if(a[p] < b[i]) p++;
			else ok = 0; 
		}
		cnt1[i] = p - 1;
	}
	p = 1, ok = 1;
	for(int i = n; i >= 1; i--){
		if(p == n + 1){
			cnt2[i] = p - 1;
			continue;
		}
		ok = 1;
		while(ok && p <= n){
			if(c[p] > b[i]) p++;
			else ok = 0;
		}
		cnt2[i] = p - 1;
	}	
	long long sum = 0;
	for(int i = 1; i <= n; i++){
		sum += cnt1[i] * cnt2[i];
	}
	printf("%lld\n",sum);
}

Measured memory_bytes: 4096
fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let n: usize = sc.read();
    let mut b: Vec<usize> = sc.read_vec(n);
    let mut ans = vec![];
    for _ in 0..n {
        let mut flag = false;
        for j in (0..b.len()).rev() {
            if b[j] == j+1 {
                ans.push(b[j]);
                b.remove(j);
                flag = true;
                break;
            }
        }
        if !flag {
            println!("{}", -1);
            return;
        }
    }
    ans.reverse();
    for v in ans {
        println!("{}", v);
    }
}

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

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

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
#define f(i,x,n) for(int i=x;i<n;i++)
#define all(c) c.begin(),c.end()
#define int ll
using ll = long long;
using pii = pair<int,int>;
const int MOD = 1e9+7, N = 1e5 + 10; 

int32_t main(){
   ios::sync_with_stdio(false);
   cin.tie(NULL);
   int n;
   cin >> n;
   string s;
   cin >> s;
   f(i,0,s.length()){
      int a = s[i]-'A';
      a += n;
      a = a%26;
      cout << char('A'+a);
   }
   return 0;
}

Measured memory_bytes: 256
def getlist():
	return list(map(int, input().split()))

from collections import defaultdict
import queue

const = 10 ** 9 + 7
INF = float("inf")

class Graph(object):
    def __init__(self):
        self.graph = defaultdict(list)

    def __len__(self):
        return len(self.graph)

    def add_edge(self, a, b):
        self.graph[a].append(b)

    def get_nodes(self):
        return self.graph.keys()

class BFS(object):
	def __init__(self, graph, s, N, K):
		self.ans = 1
		self.g = graph.graph
		self.Q = queue.Queue()
		self.W = [len(self.g[i]) for i in range(N)]
		self.visit = ["No"] * (N + 1) #見たか判定
		self.visit[s] = "Yes"
		#startの処理
		for i in self.g[s]:
			self.Q.put(i)
		if self.W[0] + 1 > K:
			self.ans = 0
		else:
			for i in range(self.W[0] + 1):
				self.ans = (self.ans * (K - i)) % const

		#start以降の処理
		while not self.Q.empty():
			v = self.Q.get()
			for i in self.g[v]:
				if self.visit[i] == "No":
					if self.W[i] + 1 > K:
						self.ans = 0
					else:
						for j in range(self.W[i] - 1):
							self.ans = (self.ans * (K - 2 - j)) % const
					self.Q.put(i)
					self.visit[i] = "Yes"

	def answer(self):
		return self.ans

#受け取り、初期化
N, K = getlist()
G = Graph()
for i in range(N - 1):
	a, b = getlist()
	G.add_edge(a - 1, b - 1)
	G.add_edge(b - 1, a - 1)
s = 0

#幅優先探索
W = BFS(G, 0, N, K)
print(W.answer())


Measured memory_bytes: 40036
using System;

public class Problem
{
  public static void Main(string[] args)
  {
    var inputs = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
    int a = inputs[0], b = inputs[1], x = inputs[2];
    var ans = x - a >= 0 && x - a < b ? "YES" : "NO";
    Console.WriteLine(ans);
  }
}


Measured memory_bytes: 11092
#include<iostream>
#include<vector>
#include<string>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<utility>
#include<set>
#include<map>
#include<stack>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef vector<int> vec;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define stop char nyaa;cin>>nyaa;

void solve() {
	int n;
	cin >> n;
	vector<vector<int>> p(n);
	rep(i, n) {
		int x;
		cin >> x;
		--x;
		p[x].push_back(i+1);
	}
	vector<int> ans(n);
	stack<int> st;
	int cnt = 0;
	int cur = 0;
	while (cnt<n) {
		if (p[cur].size()) {
			int m = p[cur].size();
			rep(i, p[cur].size()) {
				st.push(p[cur][m - i - 1]);
			}
			p[cur].clear();
		}
		if (!ans[cur] && st.size()) {
			ans[cur] = st.top();
			++cnt;
			st.pop();
		}
		cur = (cur + 1) % n;
	}
	rep(i, n)cout << ans[i] << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	solve();
	stop
		return 0;
}


Measured memory_bytes: 7540
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll a[200010];
ll n;
inline ll Check(ll k)
{
	ll low = 0, high = 0, is = 0;
	ll x = k;
	for(ll i = 1; i <= n; ++ i)
	{
		if(a[i] > x)
			++ high;
		else if(a[i] < x)
			++ low;
		else ++ is;
		++ x;
	}
	if(low > high + is)
		return 1;
	else if(high > low + is)
		return -1;
	else
		return 0;
}
int main()
{
	scanf("%lld", &n);
	for(ll i = 1; i <= n; ++ i)
		scanf("%lld", &a[i]);
	ll l = -10000000000, r = 10000000000;
	while(l < r)
	{
		ll Mid = (l + r) >> 1;
		ll s = Check(Mid);
		if(s == 1)
			r = Mid;
		else if(s == -1)
			l = Mid;
		else
		{
			l = Mid;
			break;
		}
	}
	ll s = 0;
	for(ll i = 1; i <= n; ++ i)
	{
		 s += abs(a[i] - l);
		 ++ l;
	}
	printf("%lld", s);
	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define pii pair<int,int>
#define pll pair<lli,lli>
#define vi  vector<int>
#define vii vector<pair<int,int>>
#define vll vector<lli>
#define pb  push_back
#define mp  make_pair
#define ss  second
#define ff  first
#define all(x) sort(x.begin(),x.end())
#define BLACK 0
#define WHITE 1
#define piii pair<int,pii>
const int maxn = 2e5+9;
vector<pii>adj[maxn];
int vis[maxn];
int color[maxn];
void dfs(int curr,int col)
{
    vis[curr]=1;
    color[curr]=col;
    for(pii child:adj[curr])
    {
        if(vis[child.ff]==0)
        {
            int w=child.ss;
            if(w%2==0)dfs(child.ff,col);
            else dfs(child.ff,col^1);
        }
    }
}
void solve()
{
    int n;cin>>n;
    for(int i=1;i<n;i++)
    {
        int a,b,c;cin>>a>>b>>c;
        adj[a].pb(mp(b,c));
        adj[b].pb(mp(a,c));
    }
    dfs(1,BLACK);
    for(int i=1;i<=n;i++)
    {
        cout<<color[i]<<endl;
    }

}

int main()
{
    solve();
}


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


using namespace std;
#define SZ(x) (int)(x.size())
#define REP(i, n) for(int i=0;i<n;++i)
#define FOR(i, a, b) for(int i=a;i<b;++i)
#define RREP(i, n) for(int i=n-1;i>=0;--i)
#define RFOR(i, a, b) for(int i=b-1;i>=a;--i)

#define all(x) begin(x),end(x)
#define dump(x) cerr<<#x<<" = "<<(x)<<endl
#define debug(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<< endl;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;
const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;

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

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


template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> p) {
    os << p.first << ":" << p.second;
    return os;
}

template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "[";
    REP(i, SZ(v)) {
        if (i) os << ", ";
        os << v[i];
    }
    return os << "]";
}

template<class T1, class T2>
ostream &operator<<(ostream &os, const map<T1, T2> &mp) {
    os << "[";
    for (auto it = mp.begin(); it != mp.end(); ++it) {
        if (it != mp.begin()) {
            os << ", ";
        }
        os << *it;
    }
    return os << "]";
}

// edit

void solve() {

    int X, N;
    cin >> X >> N;
    set<int> st;
    REP(i, N) {
        int tmp;
        cin >> tmp;
        st.insert(tmp);
    }

    int ans = -110;
    for (int i = -1; i <= 101; ++i) {
        if (abs(ans - X) > abs(i - X) && !st.count(i)) {
            ans = i;
        }
    }

    cout << ans << endl;

}


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
//    std::ifstream in("input.txt");
//    std::cin.rdbuf(in.rdbuf());

    solve();


    return 0;
}


Measured memory_bytes: 3084
#include <bits/stdc++.h>
#define rep(i,x,n) for(int i=x; i<(int)(n); i++)
#define rep_eq(i,x,n) for(int i=x; i<=(int)(n); i++)
using namespace std;

int main() {
  int N; cin >>N;
  vector<int> d(N);
  rep(i,0,N) cin >>d[i];
  sort(d.rbegin(),d.rend());
  int ans=1;
  rep(i,0,N-1) {
    if (d[i+1]<d[i]) {ans++;}
  }
  cout <<ans <<endl;
  return 0;
}


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

int main(void)
{
	int a, b, c;
	int ct;
	int n;
	
	cin >> a >> b >> c;
	
	ct = 0;
	for (n = a; n <= b; n++){
		if (c % n == 0){
			ct++;
		}
	}
	
	cout << ct << endl;
	
	return (0);
}

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

int main() {
  int A, B, n = 0;
  cin >> A >> B;
  while (A <= B) {
    if (A / 10000 == A % 10 && 
        (A % 10000) / 1000 == (A / 10) % 10) {
      n++;
    }
    A++;
  }
  cout << n << endl;
}



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

int main() {
    int h;  cin >> h;
    int w;  cin >> w;

    char tile[h][w];
    for (int i = 0; i < h; i++) {
        for(int j=0;j<w;j++){
            cin >> tile[i][j];
        }
    }

    bool row[h]={false};
    bool col[w]={false};
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (tile[i][j] == '#') {
                row[i] = true;
                col[j] = true;
            }
        }
    }

    for (int i = 0; i < h; i++) {
        if (row[i]) {
            for (int j = 0; j < w; j++) {
                if (col[j]) {
                    cout << tile[i][j];
                }
            }
            cout << endl;
        }
    }
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,s,f) for(int i=s;i<f;i++)
#define INF 1000000000000000000
#define MOD 1000000007
#define endl "\n"
#define fcout cout<<fixed<<setprecision(15)
typedef pair<int, int> P;
//struct edge { int to, cost; };

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

template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

bool prime(int n) {
    for (int i = 2; i <= sqrt(n); i++) {
        if (n % i == 0)return false;
    }
    return n != 1;
}
int gcd(int x, int y) {
    if (y == 0)return x;
    return gcd(y, x % y);
}
int lcm(int x, int y) {
    return x / gcd(x, y) * y;
}
int mod_pow(int n, int p, int m) {
    if (p == 0) return 1;
    if (p % 2 == 0) {
        int t = mod_pow(n, p / 2, m);
        return (t * t) % m;
    }
    return n * mod_pow(n, p - 1, m) % m;
}
int extGCD(int a, int b, int& x, int& y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    long long d = extGCD(b, a % b, y, x);
    y -= a / b * x;
    return d;
}
int modinv(int a, int m) {
    int b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
int modinv2(int a, int mod) {
    return mod_pow(a, mod - 2, mod);
}
int digit(int x) {
    int cnt = 0;
    while (x > 0) {
        cnt += x % 10;
        x /= 10;
    }
    return cnt;
}
int read() {
    int tmp;
    cin >> tmp;
    return tmp;
}
int xor128() {
    static int x = 123456789, y = 362436069, z = 521288629, w = 88675123;
    int t = (x xor (x << 11));
    x = y; y = z; z = w;
    return (w = (w xor (w >> 19)) xor (t xor (t >> 8)));
}
map<int, int> factaring(int x) {
    map<int, int>ans;
    int now = 2;
    while (now * now <= x) {
        if (x % now == 0) {
            x /= now;
            ans[now]++;
        }
        else now++;
    }
    if (x != 1) ans[x]++;
    return ans;
}
int comb(int n, int k, int mod) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    k = min(k, n - k);
    int x = 1, y = 1;
    rep(i, k) {
        y *= i + 1;
        y %= mod;
    }
    for (int i = n - k + 1; i <= n; i++) {
        x *= i;
        x %= mod;
    }
    return x * modinv(y, mod) % mod;
}

signed main() {
    //srand((unsigned)time(NULL));

    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    string s;
    cin >> s;
    cout << s.substr(0, 3) << endl;

    return 0;
}


Measured memory_bytes: 3656
import java.util.*;
import java.util.stream.Collectors;
import java.io.*;
import java.math.BigDecimal;
import java.nio.charset.StandardCharsets;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		Main ins = new Main(in);
		ins.calc();
		ins.showResult();
	}

	int N, K, Q;
	int[] x, y;
	Node[] nodes;

	static class Node {
		int id;
		long dist;
		Map<Integer, Long> conns;

		Node(int id) {
			this.id = id;
			this.dist = 0L;
			this.conns = new HashMap<>();
		}
	}

	Main(BufferedReader in) throws IOException {
		N = Integer.parseInt(in.readLine());
		this.nodes = new Node[N];
		for (int i = 0; i < N; ++i) {
			nodes[i] = new Node(i);
		}
		for (int i = 0; i < N - 1; ++i) {
			String[] tokens = in.readLine().split(" ");
			int a = Integer.parseInt(tokens[0]) - 1;
			int b = Integer.parseInt(tokens[1]) - 1;
			long c = Long.parseLong(tokens[2]);
			nodes[a].conns.put(b, c);
			nodes[b].conns.put(a, c);
		}
		String[] tokens = in.readLine().split(" ");
		Q = Integer.parseInt(tokens[0]);
		K = Integer.parseInt(tokens[1]) - 1;
		x = new int[Q];
		y = new int[Q];
		for (int i = 0; i < Q; ++i) {
			tokens = in.readLine().split(" ");
			x[i] = Integer.parseInt(tokens[0]) - 1;
			y[i] = Integer.parseInt(tokens[1]) - 1;
		}
	}

	void calcDist(int current, int parent) {
		if (parent < 0) {
			nodes[current].dist = 0L;
		} else {
			nodes[current].dist = nodes[parent].dist + nodes[parent].conns.get(current);
		}
		for (Integer next : nodes[current].conns.keySet()) {
			int n = next;
			if (n != parent) {
				calcDist(n, current);
			}
		}
	}

	void calc() {
		calcDist(K, -1);
		for (int i = 0; i < Q; ++i) {
			long dist = nodes[x[i]].dist + nodes[y[i]].dist;
			System.out.println(dist);
		}
	}

	void showResult() {
	}
}

Measured memory_bytes: 102840
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back

int n;
int main(){
    int n;
    while(cin>>n&&n){
        int dp[256][256][4];
        rep(i,256)rep(j,256)rep(k,4)dp[i][j][k] = 0;

        vector<string> data(n);
        rep(i,n)cin>>data[i];
        
        int maxi = 0;
        rep(i,n){
            rep(j,n){
                if(data[i][j]=='1'){
                    dp[i][j][0] = ( j-1>=0          )*dp[i  ][j-1][0] +1;
                    dp[i][j][1] = ( i-1>=0          )*dp[i-1][j  ][1] +1;
                    dp[i][j][2] = ( i-1>=0&&j-1>=0  )*dp[i-1][j-1][2] +1;
                    dp[i][j][3] = ( i-1>=0&&j+1<n   )*dp[i-1][j+1][3] +1;

                    rep(k,4) maxi = max(maxi,dp[i][j][k]);
                }
            }
        }
        cout<<maxi<<endl;
    }
}

Measured memory_bytes: 2312
def main():
    s = input()
    while s:
        if s[-5:] == 'dream' or s[-5:] == 'erase':
            s = s[:-5]
        elif s[-6:] == 'eraser':
            s = s[:-6]
        elif s[-7:] == 'dreamer':
            s = s[:-7]
        else:
            break

    if s:
        print('NO')
    else:
        print('YES')


if __name__ == '__main__':
    main()


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

typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define DECIM8  fixed<<setprecision(8) 
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())

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

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

using namespace std;
// dx,cost
int main(void)
{
  int n;
  cin >> n;
  vector<pair<int,int> > adj[131072];
  REP(i,n){
    int tmp;
    cin >> tmp;
    if(tmp) adj[i].push_back(make_pair(tmp,0));
    else REP(j,6) adj[i].push_back(make_pair(j+1,1));
  }
  int answer;
  set<int> already;
  priority_queue<pair<int,int> >dijk;
  dijk.push(make_pair(-0,0));
  while(!dijk.empty()){
    int ncos,x;
    tie(ncos,x)=dijk.top();
    dijk.pop();
    if(!already.insert(x).second) continue;
    if(x==n-1){
      cout << -ncos << endl;
      return 0;
    }
    REP(i,adj[x].size()){
      int dx,cost;
      tie(dx,cost)=adj[x][i];
      dijk.push(make_pair(ncos-cost,x+dx));
    }
  }
  return 0;
}

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

#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define rep(i, n) FOR(i, 0, n - 1)
typedef long long ll;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }

const string YES = "YES";
const string NO = "NO";

void solve(long long N, vector<long long> A){
    vector<ll> A_orig;
    A_orig = A;

    std::sort(A.begin(), A.end());
    A.erase(std::unique(A.begin(), A.end()), A.end());

    if (A.size() == A_orig.size()) {
        cout << YES << endl;
    } else {
        cout << NO << endl;
    }
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    cin >> N;
    vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        cin >> A[i];
    }
    solve(N, move(A));
}


Measured memory_bytes: 3328
from collections import deque
n = int(input())
r = deque(map(int, input().split()))
i=0
while True:
    if max(len(r),i)==i:
        break
    if r[i]!=i+1:
        r.popleft()
    else:
        i+=1
print('-1' if len(r)==0 else n-len(r))

Measured memory_bytes: 25244
package main

import (
	"fmt"
	"math"
)

func main() {
	var n int
	fmt.Scan(&n)

	ls := make([]int, 0, n)
	for i := 0; i < n; i++ {
		var nn int
		fmt.Scan(&nn)
		ls = append(ls, nn)
	}

	m := Max(ls...)

	var exs bool
	var mm int
	for _, item := range ls {
		if item != m {
			mm += item
		} else {
			if exs {
				mm += item
			}
			exs = true
		}
	}

	if mm > m {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

func Max(nums ...int) int {
	if len(nums) == 0 {
		panic("function max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Max(float64(res), float64(nums[i])))
	}
	return res
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//------------------------------------------------------------------------------
class UnionFind
{
public:
    UnionFind(int size) : m_Nodes(size)
    {
        Init();
    }
 
    void Init()
    {
        for (int i = 0, size = m_Nodes.size(); i < size; ++i)
        {
            m_Nodes[i].Init(i);
        }
    }
 
    int Root(int x)
    {
        const int parent = m_Nodes[x].m_Parent;
        if (parent == x)
        {
            return x;
        }
        else
        {
            return m_Nodes[x].m_Parent = Root(parent);
        }
    }
 
    bool Same(int x, int y)
    {
        return Root(x) == Root(y);
    }
 
    bool Unite(int x, int y)
    {
        x = Root(x);
        y = Root(y);
 
        if (x == y) return false;
 
        if (m_Nodes[x].m_Rank < m_Nodes[y].m_Rank)
        {
            m_Nodes[x].m_Parent = y;
            m_Nodes[y].m_Size += m_Nodes[x].m_Size;
        }
        else
        {
            m_Nodes[y].m_Parent = x;
            m_Nodes[x].m_Size += m_Nodes[y].m_Size;
            if (m_Nodes[x].m_Rank == m_Nodes[y].m_Rank) ++m_Nodes[x].m_Rank;
        }
 
        return true;
    }
 
    int Size(int x)
    {
        return m_Nodes[Root(x)].m_Size;
    }
 
private:
    struct Node
    {
    public:
        void Init(int index)
        {
            m_Parent = index;
            m_Rank = 0;
            m_Size = 1;
        }
 
        int m_Parent = -1;
        int m_Rank = -1;
        int m_Size = -1;
    };
 
    vector<Node> m_Nodes;
};
//------------------------------------------------------------------------------
void _main()
{
    int N;
    cin >> N;
    vector<pair<int, int>> x(N), y(N);
    rep(i, 0, N)
    {
        cin >> x[i].first >> y[i].first;
        x[i].second = y[i].second = i;
    }
    sort(x.begin(), x.end());
    sort(y.begin(), y.end());

    vector<tuple<int, int, int>> v;
    rep(i, 0, N - 1)
    {
        v.push_back(make_tuple(x[i + 1].first - x[i].first, x[i].second, x[i + 1].second));
        v.push_back(make_tuple(y[i + 1].first - y[i].first, y[i].second, y[i + 1].second));
    }
    sort(v.begin(), v.end());

    UnionFind uf(N);

    ll ans = 0;
    int roadNum = 0;
    for (const auto& t : v)
    {
        int cost, a, b;
        tie(cost, a, b) = t;

        if (uf.Same(a, b)) continue;

        ans += cost;

        uf.Unite(a, b);

        ++roadNum;

        if (roadNum == N - 1)
        {
            break;
        }
    }
    cout << ans << endl;
}


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

using namespace std;

int main(){
  int N, M;
  cin >> N >> M;
  
  vector<int> A(N);
  for(int i=0; i<N; i++) cin >> A[i];
  sort(A.begin(), A.end(), greater<int>());
  int sum = accumulate(A.begin(), A.end(), 0);
  double thr = ((double)sum) / (4.0 * M);
  
  string ret = ((double)A[M-1] >= thr) ? "Yes" : "No";
  cout << ret;
  
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype

template <class T>
int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define popcount __builtin_popcount

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

template <class T> void max_swap(T& a, const T b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T b) { a = min(a, b); }

const double EPS = 1e-10;
typedef long long ll;
typedef pair<int, int> pint;


int main()
{
	int n, m, s;
	while (scanf("%d%d%d", &n, &m, &s), n | m | s)
	{
		int nn = n * n;

		// dp[iÈºðgÁ½][j(a_jÜÅ)][s] = sum|k=[1..i-1](dp[k][j-1][s-k])
		static int dp[2][50][3001];
		const int mod = 100000;

		rep (i, nn + 1)
			rep (j, s + 1)
				dp[0][i][j] = dp[1][i][j] = 0;

		dp[0][0][0] = 1;
		for (int i = 1; i <= m; ++i)
		{
			int (*prev)[3001] = dp[(i + 1) & 1];
			int (*cur)[3001] = dp[i & 1];

			rep (j, nn + 1)
				rep (k, s + 1)
					cur[j][k] = prev[j][k];

			for (int j = nn; j > 0; --j)
				for (int k = s; k >= i; --k)
					(cur[j][k] += prev[j - 1][k - i]) %= mod;
		}

		printf("%d\n", dp[m & 1][nn][s]);
	}
}

Measured memory_bytes: 2044
#include <bits/stdc++.h>
#include<iostream>
using namespace std;
#define CMAX 1000000

int main(void)
{
    int s;
    cin >> s;
    int c[CMAX];
    for(auto i = 0; i < CMAX ; i++) c[i] = 0;

    int m = 2;
    int a = s;
    c[a]++;
    while(true) {
        if (a % 2 == 0) {
            a = a / 2;
        } else {
            a = a * 3 + 1;
        }
        //cerr << a << endl;
        c[a]++;
        if (c[a] ==2) {
            break;
        }
        m++;
    }

    cout << m << endl;
    
}

Measured memory_bytes: 4096
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define pye cout << "yes" << endl;
#define pno cout << "no" << endl;
#define pYe cout << "Yes" << endl;
#define pNo cout << "No" << endl;
#define pYE cout << "YES" << endl;
#define pNO cout << "NO" << endl;
#define prin(num) cout << num << endl;
#define REP(i, n) for(i=0; i<n; i++)
#define REPR(i, n) for(i=n; i>=0; i--)
#define FOR(i, m, n) for(i=m; i<n; i++)
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define INF 1000000000
#define MOD 1000000007LL
#define MAX 100005
#define NIL -1
#define WHITE 0
#define GRAY 1
#define BLACK 2
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> doup;
typedef map<ll, ll> Map;

int main(void) {
    ll n, i;
    ll L[200];
    ll ans=0;
    cin >> n;
    for(i=0; i<2*n; i++)
        cin >> L[i];
    sort(L, L+2*n);
    
    for(i=0; i<2*n; i+=2)
        ans+=L[i];
    prin(ans)
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int N,P;
	int t[2];
	int D=0;
	
	int i,j,k;
	
	cin>>N>>P;
	cin>>t[0];
	for(i=1;i<N;i++){
		cin>>t[1];
		if(t[1]-t[0]<P){
			D=D+t[1]-t[0];
		}else{
			D=D+P;
		}
		t[0]=t[1];
	}
	D=D+P;
	cout<<D;
}
	

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

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

int main(void) {
	string s;
	ll k;
	cin >> s >> k;
	
	ll cnt = 0LL;
	int ans = 0;
	for(int i = 0; i < s.size(); ++i) {
		if( s[i] - '0' == 1 ) cnt++;
		else cnt += (s[i] - '0') * 1e18;
		
		if( cnt >= k ) { 
			ans = s[i] - '0';
			break;
		}
	}
	
	cout << ans << endl;
	
	return 0;
}


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

#define loop(i,n) for(int i = 0;i < int(n);i++)
#define rloop(i,n) for(int i = int(n);i >= 0;i--)
#define range(i,a,b) for(int i = int(a);i <= int(b);i++)
#define SZ(c) int(c.size())
#define ALL(c) c.begin(), c.end()
#define RALL(c) c.rbegin(), c.rend()
#define PI acos(-1)
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define sfi1(v) scanf("%d",&v)
#define sfi2(v1,v2) scanf("%d %d",&v1,&v2)
#define sfi3(v1,v2,v3) scanf("%d %d %d",&v1,&v2,&v3)
#define sfll1(v) scanf("%I64d",&v);
#define sfll2(v1,v2) scanf("%I64d %I64d",&v1,&v2)
#define sfll3(v1,v2,v3) scanf("%I64d %I64d %I64d",&v1,&v2,&v3)
#define endl '\n'

typedef vector<int> vi;
typedef vector<pair<int,int> > vii;
typedef long long ll;
typedef pair<int, int> pii;



int main()
{

#ifndef ONLINE_JUDGE
	//freopen("in.in", "r", stdin);
	//freopen("out.in", "w", stdout);
#endif
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);


    int a , b;
    cin >> a >> b;
    if((a+b)&1)cout << "IMPOSSIBLE" << endl;
    else cout << (a+b) / 2 << endl;
    return 0;
}


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

// #define int long long
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

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

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n; cin>>n;
  map<ll,ll> m;
  rep(i,n){
    string s; cin>>s;
    if(s[0]=='M') m[0]++;
    if(s[0]=='A') m[1]++;
    if(s[0]=='R') m[2]++;
    if(s[0]=='C') m[3]++;
    if(s[0]=='H') m[4]++;
  }
  
  // for(auto e: m){
  //   cout<<e.second<<endl;
  // }
  
  ll ans=0;
  rep(i,5){
    irep(j,i+1,5){
      irep(k,j+1,5){
        ans+=m[i]*m[j]*m[k];
      }
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

a, b, c = list(map(int, input().split()))
k = int(input())

i = 0

while True:
    if a >= b:
        b *= 2
    elif b >= c:
        c *= 2
    
    i += 1
    if i == k:
        break

if a < b < c:
    print("Yes")
else:
    print("No")

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

int main()
{
	int a, b,i,j;
	while (1)
	{
		cin >> a >> b;
		if (a == 0 && b == 0)break;
		for(i = 1;i <= a;i++)
		{
			for (j = 1; j <= b; j++)
			{
				if ((i + j) % 2 == 0)
				{
					cout << '#';
				}
				else
				{
					cout << '.';
				}
			}
			cout << endl;
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 1152
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(){
    int     n, l;
    char    pool[100+1][100+1]={0};

    scanf("%d%d", &n, &l);
    for(int i=0; i<n; i++){ scanf("%s", pool[i]); }
    qsort( pool, n, 101, strcmp );
    for(int i=0; i<n; i++){ printf("%s", pool[i]); }
    return 0;
}

Measured memory_bytes: 1732
H,W=map(int,input().split())
S=[list(map(str,input().split())) for i in range(H)]
ans=[[0 for i in range(W+2)]for j in range(H+2)]
inf=10
for i in range(H):
    S[i]=list(S[i][0])
for i in range(W):
    for j in range(H):
        if S[j][i]=='#':
            ans[j+1][i+1]=inf

for i in range(W):
    for j in range(H):
        if S[j][i]=='#':
            ans[j][i+1]+=1
            ans[j][i+2]+=1
            ans[j][i]+=1
            ans[j+2][i+1]+=1
            ans[j+1][i]+=1
            ans[j+1][i+2]+=1
            ans[j+2][i+2]+=1
            ans[j+2][i]+=1
del(ans[-1])
del(ans[0])
for i in range(len(ans)):
    del(ans[i][-1])
    del(ans[i][0])
for i in range(W):
    for j in range(H):
        if ans[j][i]>=inf:
            ans[j][i]='#'
        else:
            ans[j][i]=str(ans[j][i])

for i in range(H):
    print("".join(ans[i]))
       

Measured memory_bytes: 9216
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using ld = long double;
#define ALL(x) x.begin(),x.end()
#define P pair<ll,ll>
#define mod 1000000007

int main() {
  int h, n, a, b;
  cin >> h >> n;
  vector<P> magic;
  vector<ll> cost(h + 1, pow(10, 17));
  rep(i, n) {
    cin >> a >> b;
    magic.push_back(P(a, b));
  }
  for (int i = 1; i <= h; i++) {
    for (int j = 0; j < n; j++) {
      if (magic[j].first >= i) {
        cost[i] = min(cost[i], magic[j].second);
      } else {
        cost[i] = min(cost[i], magic[j].second + cost[i - magic[j].first]);
      }
    }
  }
  cout << cost[h] << endl;

  return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
int main() {
int K;
cin>>K;
string S;
cin>>S;
if(S.size()<=K){
    cout<<S;
}
else{
    for(int i=0;i<K;i++){
        cout<<S[i];}
    for(int i=0;i<=K;i++){

        if(i==K)

            cout<<"...";
    }
}

	return 0;
}


Measured memory_bytes: 3640
import Control.Applicative ((<$>))
import Control.Monad
import Data.Complex
import Text.Printf

type Vector = Complex Double

dot :: Vector -> Vector -> Double
dot a b = realPart $ conjugate a * b

normalize :: Vector -> Vector
normalize = signum

readWords :: Read a => IO [a]
readWords = map read . words <$> getLine

main :: IO ()
main = do
  [x1,y1,x2,y2] <- readWords :: IO [Double]
  let
    p1 = x1:+y1
    p2 = x2:+y2
    d = normalize (p2-p1)

  q <- readLn

  ps <- replicateM q $ do
    [x,y] <- readWords :: IO [Double]
    return $ x:+y

  forM_ ps $ \p -> do
    let x:+y = p+(p1+((p-p1)`dot`d:+0)*d-p)*(2:+0)
    printf "%.10f %.10f\n" x y

Measured memory_bytes: 4872
n,m=map(int,input().split())
mat=[]

for i in range(n):
    mat.append([int(i) for i in input().split()])
move=[]
for i in range(n):
    for j in range(m):
        if mat[i][j]&1: 
            if j+1<m: 
                move.append([i,j,i,j+1])
                mat[i][j]-=1 
                mat[i][j+1]+=1 
            elif i+1<n:
                move.append([i,j,i+1,j])
                mat[i][j]-=1 
                mat[i+1][j]+=1 
print(len(move))
#print(mat)
for a,b,c,d in move:
    print(a+1,b+1,c+1,d+1)

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

const int maxn = 1e6;
int dp[maxn];

int solve(int a[], int i, int n){
	// reach a last
	if(i==(n-1)) return 0;
	// not reachable
	if(i>=n) return INT_MAX;
	
	if(dp[i] != -1)
		return dp[i];
	
	int left=INT_MAX, right=INT_MAX;
	left = abs(a[i]-a[i+1])+solve(a, i+1, n);
	
	if(i+2 < n){
		right=abs(a[i]-a[i+2]) + solve(a, i+2, n);
	}
	
	return dp[i] = min(right, left);
}

int solve(int a[], int n){
	if(n==0)
		return 0;
	
	if(n<0)
		return INT_MAX;
	
	if(dp[n]!=-1)
		return dp[n];
			
	int one = INT_MAX, two = INT_MAX;
	
	if(n-1 >= 0)
		one = abs(a[n]-a[n-1]) + solve(a, n-1);
	
	if(n-2 >= 0)
		two = abs(a[n]-a[n-2]) + solve(a, n-2);
	
	return dp[n] = min(one, two);
}

void solve(){
	int n; cin >> n;
	int a[n]={};
	for(int i=0; i<n; i++)
		cin >> a[i];
	memset(dp, -1, sizeof(dp));			
	cout << solve(a, n-1) << "\n";	
}

int main(){
	solve();
}

Measured memory_bytes: 12288
// template {{{

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

#define loop(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) loop(i, 0, n)
#define rloop(i, a, b) for (int i = (int)(b) - 1; i >= (int)(a); i--)
#define rrep(i, n) rloop(i, 0, n)
#define pb push_back
#define pf push_front
#define eb emplace_back
#define ef emplace_front
#define mp std::make_pair
#define mt std::make_tuple
#define fi first
#define se second

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

template<typename T, size_t H, size_t W>
using matrix = std::array<std::array<T, W>, H>;

const int MOD = 1e9 + 7;
const int INF = 1e9 + 10;
const ll LLINF = 1e18 + 10;

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

template<typename T>
inline T sq(T x){ return x * x; }

template<typename T, typename U>
inline void chmax(T &x, U y){ x = std::max<T>(x, y); }

template<typename T, typename U>
inline void chmin(T &x, U y){ x = std::min<T>(x, y); }

template<typename T>
inline void sort(T &c){ std::sort(std::begin(c), std::end(c)); }

template<typename T>
inline void reverse(T &c){ std::reverse(std::begin(c), std::end(c)); }

template<typename T>
inline void unique(T &c){ std::sort(c); c.erase(std::unique(std::begin(c), std::end(c))); }

// }}}

using tp3 = tuple<int, int, int>;
using tp4 = tuple<int, int, int, int>;

int N, M, H, K;
int a[1000], b[1000], c[1000], h[1000], r[1000];
int S, T;
int P;
int dp[256];
int dp2[25][100][256];

int main()
{
	while (cin >> N >> M >> H >> K, N){
		rep(i, M){
			cin >> a[i] >> b[i] >> c[i] >> h[i] >> r[i], a[i]--, b[i]--, r[i]--;
			a[i + M] = b[i]; b[i + M] = a[i]; c[i + M] = c[i];
			h[i + M] = h[i]; r[i + M] = r[i];
		}
		M *= 2;
		cin >> S >> T >> P, S--, T--;
		fill_n(dp, 256, INF);
		dp[0] = 0;
		rep(i, P){
			int l, d, k, b = 0;
			cin >> l >> d;
			rep(j, l){
				cin >> k, k--;
				b |= 1 << k;
			}
			rep(j, 256) chmin(dp[j | b], dp[j] + d);
		}
		rep(i, 256) rep(j, 256) chmin(dp[i], dp[i | j]);
		
		fill_n(**dp2, 25 * 100 * 256, INF);
		dp2[0][S][0] = 0;
		rep(i, H) rep(j, 256) rep(k, M){
			if (i + h[k] > H) continue;
			chmin(dp2[i + h[k]][b[k]][j], dp2[i][a[k]][j] + c[k]);
			chmin(dp2[i + h[k]][b[k]][j | (1 << r[k])], dp2[i][a[k]][j]);
		}

		int res = INF;
		rep(i, H + 1) rep(j, 256) chmin(res, dp[j] + dp2[i][T][j]);
		cout << (res >= INF ? -1 : res) << endl;
	}
}

Measured memory_bytes: 5580
#include <bits/stdc++.h>
using namespace std;
const int N=1e5+7;
#define ll long long
char s[20];
int main(){
	scanf("%s",s+1);
	int len=strlen(s+1);
	if(s[1]!='A'){
		printf("WA\n");
		return 0;
	}
	if(len<2){
		printf("WA\n");
		return 0;
	}
	if((s[2]>='A'&&s[2]<='Z')||(s[2]=='C')){
			printf("WA\n");
			return 0;
	}
	int tmp=0;
	for(int i = 3;i<len;i++){
		if(s[i]=='C') tmp++;
		if(s[i]>='A'&&s[i]<='Z'&&s[i]!='C'){
			printf("WA\n");
			return 0;
		}
	}
	if((s[len]>='A'&&s[len]<='Z')||(s[len]=='C')){
			printf("WA\n");
			return 0;
	}
	if(tmp!=1){
		printf("WA\n");
		return 0;
	}
	printf("AC\n");
}

Measured memory_bytes: 256