akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(x,y) (x=min(x,y))
#define chmax(x,y) (x=max(x,y))
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}
#define N 100010
int c[N];
int main(){
	int n;
  cin>>n;
  rep(i, n){
    int x;
    cin>>x;
    c[x]++;
  }
  int res = 0;
  rep(i, N) res += max(0, c[i]-1);
  cout<<n-(res+1)/2*2<<endl;
	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <cmath>
#include <numeric>
#include <string>

#define debug(s) cout << s << endl
#define debug1(s, t) cout << s << " " << t << endl

using namespace std;
using i64 = long long;

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

    int ans;
    ans = (n + 1) >> 1;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <complex>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstring>

#define REP(i,x) for(int i=0 ; i<(int)(x) ; i++)
#define ALL(x) (x).begin(),(x).end()
#define LL long long

using namespace std;

LL solve(){
    int N;
    cin >> N;
    vector<vector<LL> > D(N, vector<LL>(N));
    vector<vector<int> > nouse(N, vector<int>(N));
    REP(i, N)REP(j, N)cin >> D[i][j];
    LL res = 0;
    REP(k, N)REP(i, N)REP(j, N){
        if(D[i][j] > D[i][k]+D[k][j])return -1;
        if(i==k || j==k)continue;
        if(D[i][j] == D[i][k]+D[k][j])nouse[i][j] = nouse[j][i] = 1;

    }
    REP(i, N)REP(j, i){
        if(nouse[i][j])continue;
        res += D[i][j];
    }
    return res;
}

int main(){
    cout << solve() << endl;
    return 0;
}


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

int main() {
int n,ans=0;
cin>>n;
for(int i=1;i<=n;i++){
int x;
cin>>x;
if(x%2&&i%2)
ans++;
}
cout<<ans;
	return 0;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
int main(){
int a, b, c;
cin >> a >> b >>c;
for(int i = 0; i< 3; i++){
if(a>b){
swap(a, b);
}
if(b>c){
swap(b, c);
}
if(a > c){
swap(a, c);
}
}
cout << a << ' ' << b << ' '<< c << endl;
}



Measured memory_bytes: 3096
#include <cstdio>
#include <cmath>

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

    
    double diff[n];
    for(int i = 0; i < n; i++){
        diff[i] = fabs(a - (t - h[i] * 0.006));
    }


    int a_hi = 0;
    double b = diff[0];
    for(int i = 0; i < n; i++){
        if(diff[i] < b){
            b = diff[i];
            a_hi = i;
        }
    }

    printf("%d",a_hi + 1);
    
    return 0;
}

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

int main(){
    int n, s=0;
    ll x;
    cin >> n;
    rep(i, n){
        cin >> x;
        if(x == 1){continue;}
        ll y = (int)pow(x, 0.5);
        bool flag = true;
        repc(j, 2, y+1){
            if(x % j == 0){
                flag = false;
                break;
            }
        }
        if(flag){
            s++;
        }
    }
    cout << s << endl;
    return 0;
}


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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int main(){
	string s;
	cin >> s;
	int n=s.length();
	vector<int> cnt[26];
	for(int i=0; i<n; i++) cnt[s[i]-'a'].push_back(i);

	ll ans=1;
	for(int i=0; i<n; i++){
		for(int j=0; j<26; j++){
			if(s[i]-'a'==j) continue;
			ans+=cnt[j].end()-lower_bound(cnt[j].begin(), cnt[j].end(), i);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1908
import java.util.Scanner;

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

        int a, b;  boolean flag = false;
        a = scan.nextInt();
        b = scan.nextInt();

        if(a%3 == 0 || b%3 == 0 || (a+b)%3 == 0){
            flag = true;
        }

        if(flag){
            System.out.println("Possible");
        }else{
            System.out.println("Impossible");
        }
    }
}


Measured memory_bytes: 21584
#include <iostream>
#include <vector>
#include <queue>

#define INF 1000000000

using namespace std;
class Edge {
public:
    Edge(){};
    Edge(int s, int t, int w) : s {s}, t {t}, w {w} {};
    int s;
    int t;
    int w;
};

class Graph {
public:
    Graph(int v, int e, vector<Edge> es) : vn {v}, en {e}, es {es} {};
    vector<int> bellmanFord(int st){
        auto ds = vector<int>(vn, INF);
        ds[st] = 0;
        int cnt = 0;
        while(cnt <= en){
            bool update = false;
            for(auto e : es){
                if(ds[e.s] != INF && ds[e.s] + e.w < ds[e.t]){
                    update = true;
                    ds[e.t] = ds[e.s] + e.w;
                }
            }
            if(!update){
                break;
            } else {
                ++cnt;
            }
        }
        return cnt <= en ? ds : vector<int>();
    };
private:
    int vn;
    int en;
    vector<Edge> es;
};
int main(){
    ios_base::sync_with_stdio(false);
    int v, e, r;
    cin >> v >> e >> r;
    auto es = vector<Edge>();
    int s, t, w;
    for(int i = 0; i < e; ++i){
        cin >> s >> t >> w;
        es.push_back(Edge(s, t, w));
    }
    auto gs = Graph(v, e, es);
    auto ds = gs.bellmanFord(r);
    if(ds.size() != v){
        cout << "NEGATIVE CYCLE" << endl;
    } else {
        for(auto x : ds){
            if(x == INF){
                cout << "INF" << endl;
            } else {
                cout << x << endl;
            }
        }
    }
}

Measured memory_bytes: 1288
#include<bits/stdc++.h>
using namespace std;
int i,f,p,k,t,a[66666];
int main()
{
    
    cin>>k>>t;
    for(i=0;i<t;i++)
	{
		i++;
		i--;
		cin>>a[i];
		f+=a[i];
		i++;
		i--;
	}
    for(i=0;i<t;i++)
	{
		i++;
		i--;
        p=a[i]*2-f-1;
        if(p>=0)
		{
            cout<<p<<endl;
            return 0;
        i--;    i++;
		i--;i++;
		i--;i++;
		i--;i++;
		i--;i++;
		i--;i++;
		i--;i++;
		i--;i++;
		i--;i++;
		i--;i++;
		i--;i++;
		i--;i++;
		i--;i++;
		i--;i++;
		i--;i++;
		i--;i++;
		i--;
        }
        i++;
		i--;
    }
    cout<<"0"<<endl;
    return 0;
}

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

using namespace std;

int main(){
	int n;
	while(cin >> n, n){
		int res = 0;
		int target = 2;
		int state = 0;
		for(int i=0;i<n;i++){
			string s; cin >> s;
			if(s[1] == 'u') state++;
			else            state--;
			if(state == target){
				res++;
				target = 2-target;
			}
		}
		cout << res << endl;
	}
}

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

using namespace std;
int main()

{
 int n,a,b ;
 cin>>n>>a>>b;
 if(n==1){
    cout<<"Hello World"<<endl;
 }
 else if(n==2){
    cout<<a+b<<endl;
 }

  return 0;
}

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



int main(){
	int cnt=0;
	set<int> se;
	string s;
	cin >> s;
	for(int i=1;i<s.size();i++){
		if(s[i]==s[i-1]){
			cnt++;
			se.insert(s[i]);
		}
	}
	
	if(cnt>=2&&se.size()==1) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
// WeirdBugsButOkay

#include <bits/stdc++.h>
 
#define ll long long
#define ld long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
 
using namespace std;

ll pow3(ll a,ll b,ll m=1000000007)
{
    ll res=1;
    while(b>0)
    {
        if(b&1)
            res=(res*a)%m;
        a=(a*a)%m;
        b>>=1;
    }
    return res;
}

void solve()
{
    ll n,m;
    cin>>n>>m;
    ll sum=0;
    ll a[n];
    for(ll i=0;i<n;i++)
    {
        cin>>a[i];
        sum+=a[i];
    }
    ll cnt=0;
    ld nd=sum/(4.0*m);
    for(ll i=0;i<n;i++)
        if(a[i]>=nd)
            cnt++;
    if(cnt>=m)
        cout<<"Yes";
    else cout<<"No";
}
 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll q=1;
    //cin>>q;
    for(ll i=0;i<q;i++)
    {
        solve();
    }
    return 0;
}

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

#define REP(i,n) for(int i = 0;i < n;i++)
#define REPR(i,n) for(int i = n-1;i >= 0;i--)
#define FOR(i,m,n) for(int i = m;i < n;i++)
#define INF 2e9
#define ALL(v) v.begin(),v.end()
#define ll long long
#define GREATER greater<int>()

using namespace std;

string pop_back(string s){
    string t = s.substr(0,s.size()-1);
    return t;
}

int gcd(int max,int min){
    
    if(max<min){
        int tmp=max;
        max=min;
        min=tmp;
    }

    if(max%min==0)return min;
    else return gcd(min,max%min);

}

int main(void){

    string s,t;
    cin>>s>>t;
    for(int i=0;i<s.size();i++){
        if(s==t){
            puts("Yes");
            return 0;
        }
        s=s.back()+s.substr(0,s.size()-1);
    }

    puts("No");

    return 0;
}




Measured memory_bytes: 256
import java.io.IOException;
import java.util.NoSuchElementException;

import java.io.InputStream;

@SuppressWarnings("unchecked")
public class Main {
    public static void main(String[] args) throws IOException {
        FastScanner fs = new FastScanner();

        final int A = fs.nextInt();
        final int B = fs.nextInt();
        final int C = fs.nextInt();
        final int X = fs.nextInt();
        final int Y = fs.nextInt();

        int ans;

        if (A + B < 2 * C) ans = A * X + B * Y;
        else {
            int tmp1 = X <= Y ?
                2 * C * X + B * (Y - X)
                : A * (X - Y) + 2 * C * Y;

            int tmp2 = X <= Y ?
                2 * C * Y
                : 2 * C * X;

            ans = Math.min(tmp1, tmp2);
        }

        System.out.println(ans);
    }
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() {
        if (hasNextByte()) return buffer[ptr++];
        else return -1;
    }
    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }
    public boolean hasNext() {
        while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;
        return hasNextByte();
    }
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if(b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() {
        return Double.parseDouble(next());
    }
}


Measured memory_bytes: 22484
#include <iostream>
#include <vector>
#include <algorithm>

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

	std::vector<int> v(N);
	for (int i = 0; i < N; ++i) std::cin >> v[i];
	sort(v.begin(), v.end());

	int ini = v[0], fin = K - v[N - 1];
	int max = v[0];
	for (int i = 1; i < N; ++i) {
		if (v[i] - v[i - 1] > max) max = v[i] - v[i - 1];
	}
	if (K - v[N - 1] > max) max = K - v[N - 1];
	if (ini + fin > max) max = ini + fin;

	std::cout << K - max << '\n';
return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
 
int main(void){
  long long a,b,c,d,max;
  scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
   max=a*c;
  if(max<b*d) max=b*d;
 
  if(max<a*d) max=a*d;
  if(max<c*b) max=c*b;
  printf("%lld\n",max);
 
 
  return 0;
}

Measured memory_bytes: 1732
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>
#include <random>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
//#define int long long

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;
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; }


void solve() {
    VI x(5);
    REP(i,0,5) cin >> x[i];
    REP(i,0,5) if (x[i] == 0) {
        cout << i + 1 << endl;
        return;
    }
}

signed main() {
    solve();
    
    return 0;
}

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

int ara[1000007];

int dp[10000];


int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>ara[i];
    }
    dp[0]=0;
    for(int i=1;i<n;i++)
    {
        dp[i]=dp[i-1]+abs(ara[i]-ara[i-1]);
        if(i > 1)
        {
            dp[i] = min(dp[i],dp[i-2]+abs(ara[i]-ara[i-2]));
        }
    }
    cout << dp[n-1] << endl;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;



int main() {
	ios::sync_with_stdio(false); cin.tie(0);
	int n;
	cin >> n;
	if (n % 2 == 0) {
		cout << 0.5 << endl;
	} else {
		cout << double((int)n/2+1)/double(n) << endl;
	}
}

Measured memory_bytes: 256
import java.io.PrintWriter

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = nextList().map(String::toInt)
fun nextLongList() = nextList().map(String::toLong)
fun nextDoubleList() = nextList().map(String::toDouble)

val pw = PrintWriter(System.out)
fun print(s: Any = "") = pw.print(s)
fun println(s: Any = "") = pw.println(s)

fun <T> Iterable<T>.join(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "") = joinToString(separator, prefix, postfix)
fun <T> Array<T>.join(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "") = joinToString(separator, prefix, postfix)

fun main(args: Array<String>) {
    main()
    pw.flush()
}

fun main() {
    val (N, A, B) = nextIntList()
    val X = nextLongList()
    val D = (1 until N).map { (X[it] - X[it - 1]) * A }.map { it.coerceAtMost(B.toLong()) }
    println(D.sum())
}

Measured memory_bytes: 59892
import numpy as np
a_list=[]
for i in range(3):
  tmp=list(map(int,input().split()))
  a_list.append(tmp)
a_list=np.array(a_list)
num=int(input())
for i in range(num):
  tmp=int(input())
  a_list[a_list==tmp]=-1
  
yes_no=False
for i in range(3):
  if sum(a_list[i])==-3:
    yes_no=True
    break
  tmp=0
  for j in range(3):
    tmp+=a_list[j][i]
  if tmp==-3:
    yes_no=True
    break
else:
  yes_no=False
tmp=0
tmp2=0
for i in range(3):
  tmp+=a_list[i][i]
  tmp2+=a_list[i][2-i]
if tmp==-3 or tmp2==-3:
  yes_no=True

if yes_no:
  print("Yes")
else:
  print("No")

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

int main() {
  vector<int> A(3);
  for(int i=0;i<3;i++){
    cin >>A.at(i);
  }
  
  sort(A.begin(),A.end());
  int ans=A.at(0)+A.at(1)+A.at(2)*10;
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
void solve(int n){
	vector<pair<int,int> >v;
	for(int i;i<n;i++){
		int id;cin>>id;
		int cnt=0;
		for(int j=0;j<4;j++){int a,b;cin>>a>>b;cnt+=a*60+b;}
		v.push_back(make_pair(cnt,id));
	}
	sort(v.begin(),v.end());
	cout<<v[0].second<<endl;
	cout<<v[1].second<<endl;
	cout<<v[n-2].second<<endl;
	return;
}
int main() {
	int n;while(cin>>n){
		if(!n)return 0;
		solve(n);
	}
	return 0;
}

Measured memory_bytes: 3176
var
        a,b:array[0..200005] of int64;
        i:longint;
        n,h,res:int64;
        check:real;
begin
        read(n,h);
        res:=0;
        for i:=1 to n do read(a[i],b[i]);
        for i:=1 to n do
        begin
                check:=0;
                check:=sqrt(sqr(a[i])+sqr(b[i]));
                if check<=h then inc(res);
        end;
        write(res);
end.


Measured memory_bytes: 3340
import java.util.*;

public class Main {

    /**
     * @param args
     */
    public static void main(String[] args) throws java.io.IOException {
        // TODO 自動生成されたメソッド・スタブ
        Scanner sc = new Scanner(System.in);
        char bor[][] = new char[3][3];

        while (sc.hasNext()) {
            char[] tmps = sc.nextLine().toCharArray();
            for (int i = 0; i < 3; i++) {
                for (int j = 0; j < 3; j++) {
                    bor[i][j] = tmps[i * 3 + j];
                }
            }

            char ans = 'u';
            for (int i = 0; i < 3; i++) {
                if (bor[i][0] == bor[i][1] && bor[i][0] == bor[i][2]) {
                    if (bor[i][0] == 'o') {
                        ans = 'o';
                        break;
                    } else if (bor[i][0] == 'x') {
                        ans = 'x';
                        break;
                    } else
                        continue;
                }
            }
            if (ans != 'u') {
                System.out.println(ans);
                continue;
            }

            for (int i = 0; i < 3; i++) {
                if (bor[0][i] == bor[1][i] && bor[0][i] == bor[2][i]) {
                    if (bor[0][i] == 'o') {
                        ans = 'o';
                        break;
                    } else if (bor[0][i] == 'x') {
                        ans = 'x';
                        break;
                    } else
                        continue;
                }
            }
            if (ans != 'u') {
                System.out.println(ans);
                continue;
            }
            if (bor[0][0] == bor[1][1] && bor[0][0] == bor[2][2]) {
                char j = bor[0][0];
                if (j == 'o')
                    ans = 'o';
                else if (j == 'x')
                    ans = 'x';
            }

            if (ans != 'u') {
                System.out.println(ans);
                continue;
            }

            if (bor[0][2] == bor[1][1] && bor[0][2] == bor[2][0]) {
                char j = bor[1][1];
                if (j == 'o')
                    ans = 'o';
                else if (j == 'x')
                    ans = 'x';
            }

            if (ans != 'u') {
                System.out.println(ans);
            } else
                System.out.println("d");

        }
    }
}

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

typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
#define MP make_pair
#define PB push_back
#define X first
#define Y second

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define ITER(it, a) for(__typeof(a.begin()) it = a.begin(); it != a.end(); ++it)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())
#define FILL(a, value) memset(a, value, sizeof(a))
#define debug(a) cout << #a << " = " << a << endl;

const double PI = acos(-1.0);
const LL INF = 1e9;
const LL LINF = INF * INF;

const int MAX = 1 << 18;
int n, m, k;
PII a[MAX];
vector<int> blocked[MAX];

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//freopen("In.txt", "r", stdin);
	//freopen("Out.txt", "w", stdout);
	
	cin >> n >> m >> k;
	if (m < n)
	{
		FOR(i, 1, n + 1)
			blocked[i].PB(m + 1);
		m = n;
	}
	
	FOR(i, 1, n + 2)
		blocked[n + 1].PB(i);
	
	set<PII> b;
	FOR(i, 0, k)
	{
		cin >> a[i].X >> a[i].Y;
		blocked[a[i].X].PB(a[i].Y);
	}
	
	FOR(i, 1, n + 2)
		for(auto j: blocked[i])
			b.insert({i, j});
	
	FOR(i, 1, n + 1)
		sort(ALL(blocked[i]));
	
	if (n == 1 || b.count({2, 1}))
	{
		cout << 1 << endl;
		return 0;
	}
	
	int ans = INF;
	bool bula = 0;
	if (SZ(blocked[2]) && blocked[2][0] == 2)
		bula = 1;
	
	int prev_mx = 2;
	if (bula)
		--prev_mx;
	int mx;
	
	FOR(i, 3, n + 2)
	{		
		mx = prev_mx + 1;
		if (b.count({i, mx}))
			--mx;
		if (SZ(blocked[i]) && blocked[i][0] <= mx)
		{
			ans = i - 1;
			break;
		}
		
		prev_mx = mx;
	}
	
	ans = min(ans, n);	
	cout << ans << endl;
	cerr << "Time elapsed: " << clock() / (double)CLOCKS_PER_SEC << endl;
	return 0;
}



Measured memory_bytes: 43640
#include <stdio.h>

int main() {
	int S, h = 0, m = 0, s = 0;

	scanf("%d",&S);

	while(S >= 3600){
		S -= 3600;
		h++;
	}

	while(S >= 60){
		S -= 60;
		m++;
	}

	s = S;

	printf("%d:%d:%d\n",h,m,s);

	return 0;
}

Measured memory_bytes: 1816
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll a7=1000000007;
ll inf=100000000000000000;

ll min(ll a,ll b){
    if(a<b)return a;
    return b;
}
ll max(ll a,ll b){
    if(a>b)return a;
    return b;
}

ll node[1000000];
ll cc;

void update(ll i){
    node[cc]=i;
    ll j=cc;
    ll a;
    while(j>0 && node[((j-1)-(j-1)%2)/2]<node[j]){
        a=node[((j-1)-(j-1)%2)/2];
        node[((j-1)-(j-1)%2)/2]=node[j];
        node[j]=a;
        j=((j-1)-(j-1)%2)/2;
    }
    cc++;
}

ll find(){
    if(cc==0)return 0;
    if(cc==1){
        ll a=node[0];
        node[0]=0;
        cc=0;
        return a;
    }
    ll a=node[0];
    node[0]=node[cc-1];
    node[cc-1]=0;
    cc--;
    ll j=0;
    ll b;
    while((node[2*j+1]!=0 || node[2*j+2]!=0) && (node[j]<node[2*j+1] || node[j]<node[2*j+2])){
        if(node[2*j+1]>=node[2*j+2]){
            b=node[2*j+1];
            node[2*j+1]=node[j];
            node[j]=b;
            j=2*j+1;
        }else{
            b=node[2*j+2];
            node[2*j+2]=node[j];
            node[j]=b;
            j=2*j+2;
        }
    }
    return a;
}

int main(){
    ll n,m;cin>>n>>m;
    ll a[n];
    for(ll i=0;i<n;i++){
        cin>>a[i];
        update(a[i]);
    }
    ll hoge;
    for(ll i=0;i<m;i++){
        hoge=find();
        update(hoge/2);
    }
    ll ans=0;
    for(ll i=0;i<n;i++){
        ans+=node[i];
    }
    cout<<ans<<endl;
    return 0;
}



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

#include <bits/stdc++.h>

int main() {
  string s;
  cin >> s;
  if (s == "SUN")
    cout << 7;
  else if (s == "MON")
    cout << 6;
  else if (s == "TUE")
    cout << 5;
  else if (s == "WED")
    cout << 4;
  else if (s == "THU")
    cout << 3;
  else if (s == "FRI")
    cout << 2;
  else if (s == "SAT")
    cout << 1;
  cout << endl;
}


Measured memory_bytes: 256
#include<queue>
#include<cstdio>
#include<cstdlib>

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

using namespace std;

const int INF=1<<29;

struct edge{ int v,cost; };

int n_cake,n_land,home,goal;

int parse(const char *s){
	if(s[0]=='C') return atoi(s+1)-1;
	if(s[0]=='L') return atoi(s+1)-1+n_cake;
	if(s[0]=='H') return home;
	return goal;
}

int main(){
	for(int cal,m;scanf("%d%d%d%d",&n_cake,&n_land,&cal,&m),n_cake;){
		int cake[6];
		rep(u,n_cake) scanf("%d",cake+u);

		home=n_cake+n_land;
		goal=home+1;
		int n=goal+1;
		vector<edge> G[108];
		rep(i,m){
			char s[8],t[8];
			int d; scanf("%s%s%d",s,t,&d);
			int u=parse(s),v=parse(t);
			G[u].push_back((edge){v,d});
			G[v].push_back((edge){u,d});
		}

		int d[108][1<<6];
		rep(u,n) rep(S,1<<n_cake) d[u][S]=INF;
		d[home][0]=0;

		int ans=INF;
		priority_queue< pair< int,pair<int,int> > > Q;
		Q.push(make_pair(0,make_pair(home,0)));
		while(!Q.empty()){
			int d_now=-Q.top().first,u=Q.top().second.first,S=Q.top().second.second;
			Q.pop();

			if(d[u][S]<d_now) continue;

			if(u==goal) ans=min(ans,d_now);

			rep(i,G[u].size()){
				int v=G[u][i].v,S2,d2;
				if(v<n_cake){
					if(S&1<<v) continue;
					S2=S|1<<v;
					d2=d_now+cal*G[u][i].cost-cake[v];
				}
				else{
					S2=S;
					d2=d_now+cal*G[u][i].cost;
				}
				if(d2<d[v][S2]){
					d[v][S2]=d2;
					Q.push(make_pair(-d2,make_pair(v,S2)));
				}
			}
		}

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

	return 0;
}

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

long long int N, cs[200010];

bool check(int l, int m, int r) {
  if (l >= m || m >= r) return true;
  long long int curr = std::abs((cs[r] - cs[m]) - (cs[m] - cs[l]));
  long long int next = std::abs((cs[r] - cs[m + 1]) - (cs[m + 1] - cs[l]));
  return curr > next;
}

long long int maximum(int l, int m, int r) {
  long long int p1 = cs[l], p2 = cs[m] - cs[l], p3 = cs[r] - cs[m], p4 = cs[N] - cs[r];
  return std::max(p1, std::max(p2, std::max(p3, p4)));
}

long long int minimum(int l, int m, int r) {
  long long int p1 = cs[l], p2 = cs[m] - cs[l], p3 = cs[r] - cs[m], p4 = cs[N] - cs[r];
  return std::min(p1, std::min(p2, std::min(p3, p4)));
}

int main() {
  std::cin >> N;
  std::vector<int> A(N+1);

  for (int i = 0; i < N; i++) {
    std::cin >> A[i+1];
    cs[i+1] = A[i+1] + cs[i];
  }

  long long int answer = 1LL << 60, l = 1, r = 3;

  for (int i = 2; i < N - 1; i++) {
    while (check(0, l, i)) l++;
    while (check(i, r, N)) r++;

    // std::cout << l << " " << i << " " << r << " " << maximum(l, i, r) << " " << minimum(l, i, r) << std::endl;

    answer = std::min(answer, maximum(l, i, r) - minimum(l, i, r));
  }

  std::cout << answer << std::endl;
}


Measured memory_bytes: 2560
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        long s = in.nextLong(), c = in.nextLong();
        Long ans = Math.min(s, c / 2);
        c -= s * 2;
        if(c > 0) {
            ans += c / 4;
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 23764
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long A = sc.nextLong();
		long B = sc.nextLong();
		long K = sc.nextLong();
		if (K>=A) {
			System.out.print(0);
			System.out.print(" ");
			K-=A;
			if (B>=K) {
				System.out.println(B-K);
			} else {
				System.out.print(0);
			}
		} else {
			System.out.print(A-K);
			System.out.print(" ");
			System.out.print(B);
		}
	}
}


Measured memory_bytes: 35596
/* ex 7_1
   KitamoriFumiya */

#include <stdio.h>
#include <math.h>

// 頂点の構造体を作る
typedef struct point{
	int x_elem;
	int y_elem;
}point;

// ある頂点をx軸,y軸について移動させた頂点を返す関数
point shift_point(point move_vertex, point center_vertex){
	point next_vertex; // 移動させた頂点
	next_vertex.x_elem = move_vertex.y_elem - center_vertex.y_elem + center_vertex.x_elem;
	next_vertex.y_elem = -(move_vertex.x_elem - center_vertex.x_elem) + center_vertex.y_elem;
	
	return next_vertex;
}

int main(){
	point vertex1, vertex2, vertex3, vertex4;
	// 頂点1,2を入力
	scanf("%d %d %d %d", &vertex1.x_elem, &vertex1.y_elem, &vertex2.x_elem, &vertex2.y_elem);
	// 頂点3を求めて出力（改行せず）
	vertex3 = shift_point(vertex1, vertex2);
	printf("%d %d", vertex3.x_elem, vertex3.y_elem);
	// 頂点4を求めて出力（最後に改行）
	vertex4 = shift_point(vertex2, vertex3);
	printf(" %d %d\n", vertex4.x_elem, vertex4.y_elem);
	
	return 0;
}

Measured memory_bytes: 1732
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(300000)


def solve(N: int, H: "List[int]"):
    ret = 0
    tmp = 0
    for i in range(1, N):
        if H[i] <= H[i - 1]:
            tmp += 1
            ret = max(ret, tmp)
        else:
            tmp = 0
    ret = max(ret, tmp)
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    H = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, H)

if __name__ == '__main__':
    main()


Measured memory_bytes: 15476
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int cross[110];

int main() {
	int a,b;
	while(cin>>a>>b){
		if(a){
			cross[a]++;
			cross[b]++;
		}else{
			int i=0;
			if(cross[1]%2==1&&cross[2]%2==1){
				for(i=3;i<101;i++){
					if(cross[i]%2==1)break;
				}
			}
			if(i==101)cout<<"OK"<<endl;
			else cout<<"NG"<<endl;
			memset(cross,0,sizeof(cross));
		}
	}
	return 0;
}

Measured memory_bytes: 0
#include "bits/stdc++.h"
#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl
#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vector<int>>
#define vvl vector<vector<ll>>
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
typedef long long ll;
const int inf = 1000000001;
const ll INF = 1e18 * 4;
using namespace std;

int main(){
    ll N,cnt=0,dep=100;
    cin>>N;
    while(dep<N){
        dep = (ll)(dep*1.01);
        cnt++;
    }
    cout<<cnt<<endl;
    return 0;
}


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

using namespace std;

#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)((x).size()))

typedef pair<int, int> PII;
typedef vector<int> VI;
typedef long long int64;
typedef unsigned int uint;
typedef unsigned long long uint64;

#define gi(x) ((x) = F())
#define gii(x, y) (gi(x), gi(y))
#define giii(x, y, z) (gii(x, y), gi(z))

int F()
{
	char ch;
	int x, a;
	while (ch = getchar(), (ch < '0' || ch > '9') && ch != '-');
	if (ch == '-') ch = getchar(), a = -1;
	else a = 1;
	x = ch - '0';
	while (ch = getchar(), ch >= '0' && ch <= '9')
		x = (x << 1) + (x << 3) + ch - '0';
	return a * x;
}

int n;

char s[500010];

int x[500010];

int sum;

int main()
{
	scanf("%s", s + 1);
	n = strlen(s + 1);
	reverse(s + 1, s + n + 1);
	for (int i = 1; i <= n; ++i) x[i] = (s[i] - 48) * 9;
	for (int i = 1; i <= n; ++i) x[i + 1] += x[i] / 10, x[i] %= 10;
	if (x[n + 1]) ++n;
	for (int i = 1; i <= n; ++i) sum += x[i];
	for (int k = 1; k <= 2 * n; ++k)
	{
		int v = 9, j = 1;
		while (v)
		{
			sum -= x[j];
			x[j] += v;
			v = x[j] / 10;
			x[j] %= 10;
			sum += x[j];
			if (j > n) ++n;
			++j;
		}
		if (sum <= 9 * k) 
		{
			printf("%d\n", k);
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 2688
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <functional>
#include <math.h>
#include <stdlib.h>
#include <map>
#include <deque>
#include <sys/timeb.h>
#include <fstream>

using namespace std;

#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define repi(itr,ds) for(auto itr=ds.begin();itr!=ds.end();itr++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define INF 1050000000
#define INFL 1100000000000000000LL
#define EPS (1e-10)
#define MOD 1000000007
#define PI 3.1415926536
#define RMAX 4294967295

typedef long long ll;
typedef pair<int, int> Pi;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<vector<int> > vvi;
typedef vector<vector<bool> > vvb;
typedef vector<vector<ll> > vvll;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<double> > vvd;
typedef vector<vector<Pi> > vvPi;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<ll, vector<ll>, greater<ll> > pqlll;
typedef priority_queue<Pi, vector<Pi>, greater<Pi> > pqlP;
struct Edge {
	int from, to, cost;
	bool operator<(Edge e) {
		return cost < e.cost;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
template <class T>
using vec = vector<T>;
template<class T>
using pql = priority_queue<T, vector<T>, greater<T>>;
string debug_show(Pi a) {
	return "(" + to_string(a.first) + "," + to_string(a.second) + ")";
}

template<class T>
struct augEdge {
	T from, to;
	int cost;
	bool operator<(augEdge e) { return cost < e.cost; }
	bool operator>(augEdge e) { return cost > e.cost; }
};
template<class T>
using augGraph = vector<augEdge<T>>;


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

	string a, b;
	cin >> a >> b;
	string t = a + b;
	double ans = 0;
	rep(i, t.size()) {
		ans += (t[t.size() - 1 - i] - '0') * pow(10, i);
	}

	if (pow((int)sqrt(ans), 2) == ans) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}


Measured memory_bytes: 512
// c++include
#include <iostream>
// cinclude
#include <stdio.h>
#include<string.h>
#include<math.h>
//c++標準ライブラリ
#include<vector>
#include<string>
//std使用<-namespace
using namespace std;

// define, typedef
#define rpt(i, n) for(i = 0; i < (n); i++)
typedef long long ll;

// main関数
int main(void) {
	int sx, sy, tx, ty, countx, county, i;
	string str;
	cin >> sx >> sy >> tx >> ty;

	countx = tx - sx;
	county = ty - sy;

	// 1回目
	rpt(i, countx) {
		str.push_back('R');
	}
	rpt(i, county) {
		str.push_back('U');
	}

	// 2回目
	if (countx == 0) {
		str.push_back('R');
	}
	else if(county )
	rpt(i, countx) {
		str.push_back('L');
	}
	rpt(i, county) {
		str.push_back('D');
	}
	countx++;
	county++;
	str.push_back('D');
	rpt(i, countx) {
		str.push_back('R');
	}
	rpt(i, county) {
		str.push_back('U');
	}
	str.push_back('L');
	str.push_back('U');
	rpt(i, countx) {
		str.push_back('L');
	}
	rpt(i, county) {
		str.push_back('D');
	}
	str.push_back('R');

	cout << str;
	return 0;
}

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

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

using ll = long long;
#define INF 1e9



int main(){
  int N;
  cin >> N;
  vector<int> a(N+1), b(N+1, 0);
  REP(i, N){
    cin >> a[i+1];
  }
  int cnt = 0;
  for(int i = N; i > 0; i--){
    int sum = 0;
    for(int j = 2; j*i <= N; j++){
      sum+= b[i*j];
    }
    if(sum % 2 == a[i]){
      b[i] = 0;
    }
    else{
      b[i] = 1;
      cnt++;
    }
  }
  cout << cnt << endl;
  if(cnt){
    FOR(i, 1, N+1){
      if(b[i] == 1){
        cout << i << " ";
      }
    }
    cout << endl;
  }


  return 0;
}


Measured memory_bytes: 2560
//

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

int A[3][3];
int B[3][3];

int main(){
	for (int i=0; i<3; i++) {
		for (int j=0; j<3; j++) {
			cin >> A[i][j];
		}
	}

	int N;
	cin >> N;

	for (int k=0; k<N; k++) {
		int b;
		cin >> b;
		for (int i=0; i<3; i++) {
			for (int j=0; j<3; j++) {
				if (b == A[i][j]) {
					B[i][j] = 1;
				}
			}
		}
	}

	string ans = "No";
	for (int i=0; i<3; i++) {
		if (B[i][0] + B[i][1] + B[i][2] == 3) ans = "Yes";
	}

	for (int j=0; j<3; j++) {
		if (B[0][j] + B[1][j] + B[2][j] == 3) ans = "Yes";
	}

	if (B[0][0] + B[1][1] + B[2][2] == 3) ans = "Yes";
	if (B[0][2] + B[1][1] + B[2][0] == 3) ans = "Yes";

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
import heapq
# 単一始点最短経路。2地点間ではなく、始点が一つで各点へのコストを計算する
# eは隣接リストでe[v] = [(u1,cost1), (u2,cost2)]みたいな形を想定
# 辺の重みは正である必要がある
# O(ElogV)
def dijkstra(e,n,s):
    inf = 10**18
    d = [inf]*n
    prev = [s]*n
    d[s] = 0

    q = [(d[s],s)] # priority queueのソートキーが第一要素
    heapq.heapify([q])
    while len(q)>0:
        _,v = heapq.heappop(q)
        for u,c in e[v]:
            if d[v]+c>=d[u]:
                continue
            d[u] = d[v] + c
            prev[u] = v
            heapq.heappush(q, (d[u],u))
    return d, prev

n,m = map(int, input().split())
e = [[] for _ in range(n)]
for _ in range(m):
    a,b = map(int, input().split())
    a -= 1
    b -= 1
    e[a].append((b,1))
    e[b].append((a,1))

d,prev = dijkstra(e,n,0)
if max(d)==10**18:
    print("No")
    exit()
print("Yes")
for i in range(1,n):
    print(prev[i]+1)

Measured memory_bytes: 64008
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <algorithm>
#include <map>
#include <set>
#include <bitset>
#include <vector>
#include <complex>
#include <queue>
#include <stack>
#include <sstream>
#define mp(a, b) make_pair(a, b)
using namespace std;
typedef pair<pair<int, int>, pair<int, int> > pp;
const int maxn = 805;
char c[maxn][maxn];
int cnt[maxn][maxn];
int step[maxn][maxn];
bool mark[maxn][maxn];
int dx[4] = {-1, 1, 0, 0};
int dy[4] = {0, 0, -1, 1};
int asd(const int &x, const int &k)
{
	return (x - 1) / k + 1;
}
int main()
{
	std::ios::sync_with_stdio(false);
	int h, w, k;
	cin >> h >> w >> k;
	int posx = 0, posy = 0;
	for(int i = 1; i <= h; i ++)
		for(int j = 1; j <= w; j ++)
		{
			cin >> c[i][j];
			if(c[i][j] == 'S')
			{
				posx = i;
				posy = j;
			}
		}
	if(posx == 1 || posx == h || posy == 1 || posy == w)
	{
		cout << 0 << endl;
		return 0;
	}
	priority_queue<pp, vector<pp>, greater<pp> > q;
	q.push(mp(mp(1, 0), mp(posx, posy)));
	int ans = max(h, w);
	while(!q.empty())
	{
		pp p = q.top();
		q.pop();
		int a = p.first.first, b = p.first.second, x = p.second.first, y = p.second.second;
		if(mark[x][y])
			continue;
		mark[x][y] = 1;
		ans = min(ans, min(min(asd(x - 1, k), asd(h - x, k)), min(asd(y - 1, k), asd(w - y, k))));
		if(x == 1 || x == h || y == 1 || y == w)
		{
			cout << a << endl;
			return 0;
		}
		if(b < k)
			for(int i = 0; i < 4; i ++)
				if(c[x + dx[i]][y + dy[i]] == '.') 
					q.push(mp(mp(a, b + 1), mp(x + dx[i], y + dy[i])));
	}
	cout << ans + 1 << endl;
	
	return 0;
}

Measured memory_bytes: 2816
/*
  AOJ 2217
  Title:Let's JUMPSTYLE
  @kankichi573
*/
#include <stdio.h>

int N;
int jump_x[100][100];
int jump_y[100][100];
int loop[100][100];
int find(int *x,int *y)
{
    int i,j;
    for(i=0;i<N;i++)
      for(j=0;j<N;j++)
	if(loop[i][j]==0)
	  {
	    *x=i;*y=j;
	    return(-1);
	  }
    return(0);
}
int solve()
{
  int n_loop,count,x,y,xn,yn;

  n_loop=count=1;
  while(find(&x,&y))
    {
      //printf("%d %d\n",x,y);
      while(loop[x][y]==0)
	{
	  loop[x][y]=n_loop;
	  xn=jump_x[x][y];
	  yn=jump_y[x][y];
	  x=xn;y=yn;
	  //printf(">%d %d\n",x,y);
	}
      if(loop[x][y]==n_loop)
	{
	  //printf("*\n");
	  count++;
	}
      n_loop++;      
    }
  return(count-1);
}
void clear()
{
  int i,j;
  for(i=0;i<N;i++)
    for(j=0;j<N;j++)
      loop[i][j]=0;
}
main()
{
  int i,j,ret;

  while(scanf("%d",&N) && N)
    {
      for(i=0;i<N;i++)
	for(j=0;j<N;j++)
	  scanf("%d %d",&jump_x[j][i],&jump_y[j][i]);
      clear();
      ret=solve();
      printf("%d\n",ret);
    }
  return(0);
}

Measured memory_bytes: 716
@_=map[glob],<>;
for$y(1,2){
	for$x(0,1){
		if($_[$y][$x+1]-$_[$y][$x]!=$_[0][$x+1]-$_[0][$x]){
			exit!print'No'
		}
	}
}
for$x(1,2){
	for$y(0,1){
		if($_[$y+1][$x]-$_[$y][$x]!=$_[$y+1][0]-$_[$y][0]){
			exit!print'No'
		}
	}
}
print'Yes'


Measured memory_bytes: 768
#include<iostream>
#include<algorithm>
#include<vector>

using namespace std;

int N;
vector<vector<int>> E;

int dp1[100000 + 100], dp2[100000 + 100];

void dfs1(int pos, int bef) {
	for (int i = 0; i < E[pos].size(); i++) {
		int nxt = E[pos][i];
		if (nxt == bef)continue;
		dfs1(nxt, pos);
		dp1[pos] = max(dp1[pos], dp1[nxt] + 1);
	}
}

//bef_infoは親方向での最長を伝播する
//dp2[]はその頂点から木の末端まで行くときの最遠の距離
void dfs2(int pos, int bef, int bef_info) {
	vector<pair<int, int>> sl;
	for (int i = 0; i < E[pos].size(); i++) {
		int neighbor = E[pos][i];
		if (neighbor == bef) {
			dp2[pos] = max(dp2[pos], bef_info + 1);
			sl.push_back(make_pair(bef_info + 1, bef));
		}
		else {
			dp2[pos] = max(dp2[pos], dp1[neighbor] + 1);
			sl.push_back(make_pair(dp1[neighbor] + 1, neighbor));
		}
	}
	
	sort(sl.rbegin(), sl.rend());
	
	for (int i = 0; i < E[pos].size(); i++) {
		int nxt = E[pos][i];
		if (nxt == bef)continue;
		dfs2(nxt, pos, sl[nxt == sl[0].second].first);
	}
}

int main() {

	cin >> N;
	E.resize(N);
	for (int i = 0; i < N - 1; i++) {
		int u, v;
		cin >> u >> v;
		u--, v--;
		E[u].push_back(v), E[v].push_back(u);
	}

	for (int i = 0; i < N; i++) {
		if (E[i].size() < 2)continue;
		dfs1(i, -1);
		dfs2(i, -1, 114514);

		for (int i = 0; i < N; i++)cout << (N - 1) * 2 - dp2[i] << endl;
		return 0;
	}
	cout << 1 << endl << 1 << endl;
	return 0;
}


Measured memory_bytes: 24748
#include <iostream>
#include <algorithm>
#include <utility>
#include <queue>
#include <cstring>
using namespace std;

typedef pair<int, int> P;

struct State {
  int turn;
  char board[10][10];
};

int main() {
  while(true) {
    int X, Y;
    cin >> X >> Y;
    if(X == 0 && Y == 0) break;
    char board[10][10];
    for(int i = 0; i < Y; i++) {
      for(int j = 0; j < X; j++) {
        char c; cin >> c;
        if(c == 'R') board[i][j] = 0;
        if(c == 'G') board[i][j] = 1;
        if(c == 'B') board[i][j] = 2;
      }
    }
    State S;
    S.turn = 0;
    memcpy(S.board, board, sizeof(board));
    queue<State> Q;
    Q.push(S);
    int res;
    while(!Q.empty()) {
      State s = Q.front(); Q.pop();
      bool ok = true;
      for(int i = 0; i < Y; i++) {
        for(int j = 0; j < X; j++) {
          if(s.board[i][j] != s.board[0][0]) {
            ok = false;
            break;
          }
        }
      }
      if(ok) {
        res = s.turn;
        break;
      }
      for(char c = 0; c < 3; c++) {
        if(s.board[0][0] == c) continue;
        memcpy(S.board, s.board, sizeof(s.board));
        queue<P> Q2;
        Q2.emplace(0, 0);
        char prev = S.board[0][0];
        S.board[0][0] = c;
        while(!Q2.empty()) {
          P p = Q2.front(); Q2.pop();
          for(int i = 0; i < 4; i++) {
            const int dy[4] = { 0, -1, 0, 1 };
            const int dx[4] = { 1, 0, -1, 0 };
            int ny = p.first + dy[i];
            int nx = p.second + dx[i];
            if(0 <= ny && ny < Y && 0 <= nx && nx < X && S.board[ny][nx] == prev) {
              S.board[ny][nx] = c;
              Q2.emplace(ny, nx);
            }
          }
        }
        S.turn = s.turn + 1;
        Q.push(S);
      }
    }
    cout << res << endl;
  }
}

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

N = int(input())

task = [[] for _ in range(N)]
for i in range(N):
    a,b = [int(z) for z in input().split()]
    task[i] = [b,a]

task.sort()

time = 0
for i in range(N):
    time += task[i][1]
    if time > task[i][0]:
        print('No')
        exit()

print('Yes')


Measured memory_bytes: 67744
#include <stdio.h>

main(){
  int data[12][31];
  int i, j, k, a, b;

  k=3;
  for(i=0;i<12;i++){
    for(j=0;j<31;j++){
      if(i==1 && j>28) break;
      if(i==3 && j>29) break;
      if(i==5 && j>29) break;
      if(i==8 && j>29) break;
      if(i==10 && j>29) break;
      data[i][j]=k;
      k++;
      if(k>=7) k=0;
    }
  }



  while(1){
    scanf("%d %d", &a, &b);
    if(a==0 && b==0) break;
    switch(data[a-1][b-1]){
    case 0:printf("Monday\n");
      break;
    case 1:printf("Tuesday\n");
      break;
    case 2:printf("Wednesday\n");
      break;
    case 3:printf("Thursday\n");
      break;
    case 4:printf("Friday\n");
      break;
    case 5:printf("Saturday\n");
      break;
    case 6:printf("Sunday\n");
      break;
    }
  }
  return 0;
}

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

int main() {
    int N;
    cin >> N;
    long long A[N];
    map<int, int> onlyone;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        if (onlyone[A[i]] != 1) onlyone[A[i]] = 1;
        else onlyone[A[i]] ++;
    }

    bool ok = true;
    for (pair<int, int> t : onlyone) {
        if (t.second != 1) ok = false; 
    }

    if (ok) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 11136
#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    vector<int> color(8,0);
    int uppper8=0;
    for(int i=0;i<n;i++){
        int r=a[i]/400;
        if(r<8){
            color[r]=1;
        }else{
            uppper8++;
        }
    }
    int sum=0;
    for(int i=0;i<8;i++){
        sum+=color[i];
    }
    int max=sum+uppper8;
    int min;
    if(sum==0){
        min=1;
    }else{
        min=sum;
    }
    cout<<min<<" "<<max<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <unordered_map>
typedef long long ll;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i == n-1];}
#define printp(x,n) for(ll i = 0; i < n; i++){ cout << "(" << x[i].first << ", " << x[i].second << ") "; } cout << endl;
#define INF (1e18)
using namespace std;
const ll MOD = 1e9 + 7;
typedef pair<ll, ll> lpair;
ll f(ll n){
    return (n*n + 4) / 8;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N,M;
    ll a[55], b[55];
    cin >> N >> M;
    map<ll,ll> mp;
    rep(i,0,M){
        cin >> a[i] >> b[i];
        a[i]--; b[i]--;
        mp[a[i]]++;
        mp[b[i]]++;
    }
    rep(i,0,N) print(mp[i]);
}

Measured memory_bytes: 256