akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using Graph = vector<vector<pii>>;
const int MOD = 1e9 + 7;

struct UnionFind {
    vector<int> par, rnk;

    UnionFind(int N) : par(N), rnk(N) {
        for (int i = 0; i < N; ++i)
            par[i] = i;
    }

    int root(int x) {
        return (par[x] == x ? x : par[x] = root(par[x]));
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    void unite(int x, int y) {
        x = root(x), y = root(y);
        if (x == y)
            return;
        if (rnk[x] < rnk[y])
            swap(x, y);
        par[y] = x;
        if (rnk[x] == rnk[y])
            rnk[x]++;
    }
};

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

    int N, M;
    cin >> N >> M;
    vector<int> p(N);
    for (int i = 0; i < N; ++i) {
        cin >> p[i];
        p[i]--;
    }

    UnionFind uf(N);
    for (int i = 0; i < M; ++i) {
        int x, y;
        cin >> x >> y;
        x--, y--;
        uf.unite(x, y);
    }

    int ans = 0;
    for (int i = 0; i < N; ++i)
        if (uf.issame(i, p[i]))
            ans++;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1408
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
using ll = long long;
int main(){
	string str;
	int a[4]={};
	cin >> str;
	for(int i=0;i<str.size();i++){
		if(str[i]=='N')	a[0]=1;
		else if(str[i]=='W')	a[1]=1;
		else if(str[i]=='S')	a[2]=1;
		else if(str[i]=='E')	a[3]=1;
	}
	if(a[0]==a[2]&&a[1]==a[3])	cout << "Yes\n";
	else cout << "No\n";
	return 0;
}

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

public class Main {

	public static void main(String[] args) throws IOException {
		double r = 0;
		double pi = Math.PI;
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str = br.readLine();
		
		r = Double.parseDouble(str);
		
		double equ = r * r * pi; 
		double loc = r * 2 * pi;
		
		String eAnswer = String.format("%.6f", equ);
		String lAnswer = String.format("%.6f", loc);
		
		System.out.println(eAnswer + " " + lAnswer);
	}
}

Measured memory_bytes: 24684
# coding: utf-8
# Your code here!
import sys

S = str(input())
odd = ["R","U","D"]
even = ["L","U","D"]
for i in range(len(S)):
    if (i+1) % 2 == 0:
        if S[i] not in even:
            print("No")
            sys.exit()
    else:
        if S[i] not in odd:
            print("No")
            sys.exit()
print("Yes")

Measured memory_bytes: 3060
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <bitset>
using namespace std;

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



const int BIG_NUM = 1e9;
const ll INF = 1000000000000000000;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;



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

	int ans = 0;
	for (int i = 0; i < s.length(); i++) {
		for (int j = 1; j + i <= s.length(); j++) {
			string t = s.substr(i, j);
			//cout << t << endl;
			bool isACGT = true;
			for (int k = 0; k < t.length(); k++) {
				switch (t[k])
				{
				case 'A':
				case 'T':
				case 'G':
				case 'C':

					break;
				default:
					isACGT = false;
					break;
				}

				
			}

			if (isACGT) {
				ans = max(ans, j);
			}
		}
	}
	cout << ans << endl;
}


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

using namespace std;

int main() {
    int n,a,b=1,c=0;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a;
        if(a == b) {
            b++;
        } else {
            c++;
        }
    }
    if (c == n) {
        c = -1;
    }
    cout << c;
    return 0;
}

Measured memory_bytes: 256
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
typedef long long ll;

int main(void) {
  int n, k;
  cin >> n >> k;
  if(k == 1) {
    cout << 0 << endl;
  } else {
    cout << n-k << endl;
  }
  return 0;
}


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

#define rep(i,n) for (int i = 0; i< (n); ++i)
#define vvec(m,n) vector<vector<int>> (int(m), vector<int>(n))
#define ALL(a) (a).begin(), (a).end()

using ll = long long;

int main(){
    string S;
    cin >> S;
    if(S.at(0)==S.at(1)&&S.at(2)==S.at(3)&&S.at(0)!=S.at(2)) cout << "Yes"<< endl;
    else if(S.at(0)==S.at(2)&&S.at(1)==S.at(3)&&S.at(0)!=S.at(1)) cout << "Yes" << endl;
    else if(S.at(0)==S.at(3)&&S.at(1)==S.at(2)&&S.at(0)!=S.at(1)) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(void){
    string a;
    int ans=700;
    cin>>a;
    for(int i=0;i<3;i++){
        if(a[i]=='o'){
            ans=ans+100;
        }
    }
    cout<<ans<<endl;
}


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

int main () {
  string a , b ;
  cin >> a >> b ;
  int j = 0 ;
  for(int i = a.size()-b.size() + 1; i >= 0 ; i-- ){
    for( j = 0 ; j < b.size() ; j++ ){
      if(a[i+j]!=b[j]&&a[i+j]!='?') break ;
    }
  if(j==b.size()){
    for(j=0;j<b.size();j++) a[i+j]=b[j];
    for(j=0;j<a.size();j++) if(a[j]=='?') a[j]='a';
    cout << a << endl ;
    return 0;
  }
  }
  cout <<"UNRESTORABLE"<< endl;
  return 0 ;
}

Measured memory_bytes: 256
#include <cmath>
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<iomanip>
#include<queue>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll inf = 1000000007;
int main() {
	int n; 
	ll k;
	cin >> n >> k;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	vector<int> s;
	vector<int> ord(n+1, -1);
	int c = 1, l = 0;
	{
		int v = 1;
		while (ord[v]==-1) {
			ord[v] = s.size();
			s.push_back(v);
			v = a[v - 1];
		}
		c = s.size() - ord[v];
		l = ord[v];
	}
	if (k < l) {
		cout << s[k] << endl;
	}
	else {
		k -= l;
		k %= c;
		cout << s[l + k] << endl;
	}
	return 0;
}


Measured memory_bytes: 5836
#include "bits/stdc++.h"

using namespace std;

int main() {
	string s;
	cin >> s;
	int n = s.size();
	int ans = 999;
	for (int i = 0; i <= n - 3; i++) {
		int res = (s[i] - '0') * 100 + (s[i+1] - '0') * 10 + s[i+2] - '0';
		ans = min(ans, abs(res - 753));
	}

	cout << ans << endl;
	return 0;
}

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

int main()
{
  int n, m; cin>>n>>m;
  vector<vector<int>> s(m);
  rep(i, m) {
    int k; cin>>k;
    rep(j, k) {
      int t; cin>>t;
      t--;
      s[i].push_back(t);
    }
  }
  vector<int> p(m, 0);
  rep(i, m) cin>>p[i];

  int ans = 0;
  rep(bits, 1<<n) {
    bool flg = true;
    rep(i, m) {
      int sum = 0;
      for(auto v:s[i]) {
        sum ^= (bits>>v)&1;
      }
      if (sum != p[i]) flg = false;
    }
    if (flg) ans++;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
class Main{
    public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int m,f,r;
		m=f=r=0;
		m=sc.nextInt();
		f=sc.nextInt();
		r=sc.nextInt();
		while(true){
			if(m==-1&&f==-1&&r==-1) break;
			if(m==-1||f==-1){
				System.out.println("F");
			}else if(m+f>=80){
				System.out.println("A");
			}else if(m+f>=65){
				System.out.println("B");
			}else if(m+f>=50){
				System.out.println("C");
			}else if(m+f>=30){
				if(r>=50){
					System.out.println("C");
				}else{
					System.out.println("D");
				}
			}else{
				System.out.println("F");
			}
			m=sc.nextInt();
			f=sc.nextInt();
			r=sc.nextInt();
		}
    }
}


Measured memory_bytes: 26340
using System;
using System.Linq;

namespace abc048_b
{
    class Program
    {
        static void Main(string[] args)
        {
            long[] x = Console.ReadLine().Split().Select(long.Parse).ToArray();
            long a = x[1] / x[2] - x[0] / x[2];
            if (x[0] % x[2] == 0)
            {
                a++;
            }
            Console.WriteLine(a);
            Console.ReadLine();
        }
    }
}

Measured memory_bytes: 2904
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define Cout(s) cout << s << endl;
using ll = long long;
using P = pair<int, int>;

const ll INF = 1ll << 60;
ll MOD = 1e9 + 7;

int main()
{

    int x;
    cin >> x;

    if (!(x - 7) || !(x - 5) || !(x - 3))
    {
        Cout("YES");
    }
    else
    {
        Cout("NO");
    }

    return 0;
}

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

int main() {
    string s1, s2, s3;
    cin >> s1 >> s2 >> s3;
    cout << (char)toupper(s1.front()) << (char)toupper(s2.front()) << (char)toupper(s3.front()) << endl;

    return 0;
}


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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int x, n;
    cin >> x >> n;
    vi p(n);
    rep(i, n) cin >> p[i];
    vector<bool> np(102);
    rep(i, n) np[p[i]] = true;
    pii ans(INF, -1);
    rep(i, 102) {
        if (np[i]) continue;
        ans = min(ans, pii(abs(x-i), i));
    }
    cout << ans.second << endl;
    return 0;
}


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

char Decryption(int k, char s) {
  char station[] = {'a','b','c','d','e','f','g','h','i','j','k','l','m',
                    'n','o','p','q','r','s','t','u','v','w','x','y','z',
                    'A','B','C','D','E','F','G','H','I','J','K','L','M',
                    'N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
  int num;

  for(int i = 0; i < 52; i++) {
    if(s >= 'a' && s <= 'z')
      num = s - 'a';
    else
      num = s - 39;
  }
  return station[(52 + num - k) % 52];
}

int main() {
  vector<int> K;
  int n;
  string s_in;
  string s_out;

  while(1) {
    cin >> n;
    if(n == 0)
      break;

    for(int i = 0; i < n; i++) {
      int k;
      cin >> k;
      K.push_back(k);
    }

    cin >> s_in;

    for(int i = 0; i < s_in.size(); i++) {
      s_out += Decryption(K[i%n], s_in[i]);
    }

    cout << s_out << endl;

    s_out.erase();
    K.clear();
  }
  return 0;
}



Measured memory_bytes: 3196
#include <bits/stdc++.h>
using namespace std;
long long A[50];
int main()
{
long long a,b,i,c=1,d=0,n,m,t,k;
string s;
cin>>s;
sort(s.begin(),s.end());
if(s[0]=='a'&&s[1]=='b'&& s[2]=='c') std::cout << "Yes" << '\n';
else std::cout << "No" << '\n';
return 0;
}


Measured memory_bytes: 3604
#include<bits/stdc++.h>
 
#define REP(i,s,n) for(int (i)=s; (i)<(int)(n);(i)++)
#define RIT(it,c) for(__typeof(c.begin()) it = c.begin();it!=c.end();it++)
#define ALL(x) x.begin(), x.end()
#define SZ(x) (int)(x).size()
#define MSET(m,v) memset(m,v,sizeof(m))
 
 
using namespace std;
 
 
typedef long long LL;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<LL> vL;
typedef vector<bool> vb;
typedef pair<int,vi> iv;
typedef pair<LL,LL> pLL; 
typedef long double LD;
 
const long MOD = 998244353;



int main(){
	std::ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	int N,M;
	unordered_map<int, int> ref,tar;
	cin>>N;
	for(int i=0;i<N;++i){
		int D;
		cin>>D;
		ref[D]++;
	}
	cin>>M;
	for(int i=0;i<M;++i){
		int D;
		cin>>D;
		tar[D]++;
	}
	for(auto p:tar) if(p.second > ref[p.first]){
		cout<<"NO"<<endl;
		return 0;
	}
	cout<<"YES"<<endl;
	return 0;
}

Measured memory_bytes: 16712
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

//typedef pair<int,int> P;


int main(){
	int X,A,B;
	scanf("%d", &X);
	scanf("%d", &A);
	scanf("%d", &B);

	int ans = (X - A)%B;
	printf("%d\n", ans);

	return 0;
}


Measured memory_bytes: 256
/* AtCoder Regular Contest 078. Problem D, by Abreto<m@abreto.net>. */
#include <stdio.h>

#define MAXN    100001

struct
{
    int id;
    int next;
}node[MAXN<<2];
int nnodes;
int front[MAXN];
void add_edge(int u, int v)
{
    int newnode = ++nnodes;
    node[newnode].id = v;
    node[newnode].next = front[u];
    front[u] = newnode;
}

int N;
int vis[MAXN];
int par[MAXN];
int nxt[MAXN];
int chd[MAXN];
int nb, nw;

int dfs2N(int u)
{
    int v = front[u];
    vis[u] = 1;
    if(u == N) return 1;
    while(v)
    {
        int w = node[v].id;
        if(!vis[w])
        {
            if(dfs2N(w))
            {
                u[nxt] = w;
                w[par] = u;
                return 1;
            }
        }
        v = node[v].next;
    }
    return 0;
}

void find_path(void)
{
    int i = 0;
    dfs2N(1);
    for(i = 1;i <= N;++i)
        vis[i] = 0;
    for(i = nxt[1];i != N;i = nxt[i])
        vis[i] = 1;
    vis[1] = vis[N] = 1;
}

int countchd(int u)
{
    int  v = front[u];
    int cnt = 1;
    vis[u] = 1;
    while(v)
    {
        int w = node[v].id;
        if(!vis[w]) cnt += countchd(w);
        v = node[v].next;
    }
    return cnt;
}

void travel_path(void)
{
    int i = 0;
    int u = 1[nxt], v = N[par];
    nb = countchd(1); nw = countchd(N);
    while(u != v && u != v[nxt])
    {
        nb += countchd(u);
        nw += countchd(v);
        u = u[nxt]; v = v[par];
    }
    if(u == v) nb += countchd(u);
}

int main(void)
{
    int i = 0;
    int ai = 0, bi = 0;

    scanf("%d", &N);
    for(i = 1;i < N;++i)
    {
        scanf("%d%d", &ai, &bi);
        add_edge(ai, bi);
        add_edge(bi, ai);
    }
    find_path();
    travel_path();
    printf("%s\n", (nb>nw)?"Fennec":"Snuke");
    return 0;
}


Measured memory_bytes: 9472
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto N = readln.chomp.to!int;
    auto T = new int[][](N, N);
    
    int x = 1, s = 2;
    foreach (i; 1..N) {
        if (T[0][i] == 0) {
            while (i < N) {
                T[0][i] = x;
                i += s;
            }
            ++x;
            s *= 2;
        }
    }

    foreach (i; 1..N) {
        foreach (j; i+1..N) {
            T[i][j] = T[i-1][j-1];
        }
    }

    foreach (i; 0..N-1) {
        writeln(T[i][i+1..$].to!(string[]).join(" "));
    }
}

Measured memory_bytes: 8700
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<typename Q_temp>
using smaller_queue = priority_queue <Q_temp, vector<Q_temp>, greater<Q_temp> >;

const int INF = (int) 1e9;
const ll LINF = (ll) 4e18;
const ll MOD = (ll) (1e9 + 7);
const double PI = acos(-1.0);

#define REP(i,m,n) for(ll i = m; i < (ll)(n); ++i)
#define rep(i,n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbg2(x_) for(auto a_ : x_) cerr << a_ << " "; cerr << endl;
#define dbg3(x_ , sx_) rep(i, sx_) cerr << x_[i] << " "; cerr << endl;
vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

inline ll CEIL(ll a, ll b) {
    return (a + b - 1) / b;
}

void finish() {
    cout << -1 << endl;
    exit(0);
}

//------------------------------------------------------

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    ll a[n];
    rep(i, n) cin >> a[i];

    int sgn = 1;
    ll sum = 0;

    rep(i, n) {
        sum += a[i] * 2 * sgn;
        sgn *= -1;
    }
    ll ans[n];
    ans[0] = sum / 2;

    rep(i, n - 1) {
        ans[i + 1] = a[i] * 2 - ans[i];
    }

    rep(i, n) cout << ans[i] << (i == n - 1 ? "\n" : " ");

    return 0;
}


Measured memory_bytes: 2944
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.Scanner;
public class Main {
    public static int matchsticks[] = {0,2,5,5,4,5,6,3,7,6};
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int untastyAntidote = sc.nextInt();
        int tastyAntidote = sc.nextInt();
        int tastyPoison = sc.nextInt();
        int ans = 0;
        int min = Math.min(untastyAntidote,tastyPoison);
        ans += min;
        tastyPoison -= min;
        min = Math.min(tastyAntidote,tastyPoison);
        ans += 2 * min;
        tastyAntidote -= min;
        tastyPoison -= min;
        if(tastyPoison > 0){
            ans++;
        }
        ans += tastyAntidote;
        System.out.println(ans);
    }
}

Measured memory_bytes: 23764
#include <iostream>
#include <cstdio>
#include <string>
#include <sstream> 
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <ctime>
#include <cassert>
using namespace std;
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define vi vector<int>
#define vpii vector<pii>
#define SZ(x) ((int)(x.size()))
#define fi first
#define se second
#define FOR(i,n) for(int (i)=0;(i)<(n);++(i))
#define FORI(i,n) for(int (i)=1;(i)<=(n);++(i))
#define IN(x,y) ((y).find((x))!=(y).end())
#define ALL(t) t.begin(),t.end()
#define FOREACH(i,t) for (typeof(t.begin()) i=t.begin(); i!=t.end(); i++)
#define REP(i,a,b) for(int (i)=(a);(i)<=(b);++i)
#define REPD(i,a,b) for(int (i)=(a); (i)>=(b);--i)
#define REMAX(a,b) (a)=max((a),(b));
#define REMIN(a,b) (a)=min((a),(b));
#define DBG cerr << "debug here" << endl;
#define DBGV(vari) cerr << #vari<< " = "<< (vari) <<endl;

typedef long long ll;
const int INF = 1e9;

int solve(vector<int> v, int c) {
    int res = 0;
    int k = v.size();
    while (k > 1) {
        bool found = false;
        for (int i = 0; i < k; ++i) {
            if (v[i] == c) continue;
            found = true;
            if (v[i+1] == c) {
                v[i] = c;
            }
        }
        if (!found) {
            return res;
        }
        --k;
        ++res;
    }
    if (v[0] == c) { 
        return res;
    } 
    return INF;
}
int main()
{
    ios_base::sync_with_stdio(0);
    string s;
    cin >> s;
    vector<int> v(s.size());
    for (int i = 0; i < s.size(); ++i) {
        v[i] = int(s[i]-'a');
    }
    int res = INF;
    for (int c = 0; c < 26; ++c) {
        REMIN(res, solve(v, c));
    }
    cout << res << endl;
    return 0;
}


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

using namespace std;
typedef long long ll;
#define int ll

template<typename T1,typename T2> inline void chmin(T1 &a, T2 b){ if(a > b) a = b; }
template<typename T1,typename T2> inline void chmax(T1 &a, T2 b){ if(a < b) a = b; }

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
const int MAX_N = 100010;

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

    int X;
    cin >> X;

    int ans = (X / 500) * 1000;
    ans += (X % 500) / 5 * 5;

    printf("%lld\n", ans);

    return 0;
}



Measured memory_bytes: 764
#include<stdio.h>
#include<stdlib.h>
#define LEN 7

struct node{
  int key;
  struct node *parent, *left, *right;
};

typedef struct node node;
typedef struct node * nodepointer;

void insert(int);
void inorder(nodepointer);
void preorder(nodepointer);
nodepointer find(int);

nodepointer root;

int main(){
  int n, k;
  int i;
  char com[LEN];

  scanf("%d", &n);
  for(i=0;i<n;i++){
    scanf(" %s", com);
    if(com[0] == 'i'){
      scanf("%d", &k);
      insert(k);
    }
    else if(com[0] == 'p'){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
    else{
      scanf("%d", &k);
      if(find(k) == NULL) printf("no\n");
      else printf("yes\n");
    }
  }

  return 0;
}

void insert(int k){
  nodepointer x, y, z; //zが新しく挿入するノード

  z = (nodepointer)malloc(sizeof(node));
  //zの設定　zは葉だからleft,rightはnullでok
  z -> key = k;
  z -> left = NULL;
  z -> right = NULL;

  x = root; //たどる際のスタートは根
  y = NULL; //yはxの親
  //xがnullになるまでたどる。このときyはxの直前のノード、つまりxの親であり葉ノードである。
  while(x != NULL){
    y = x;
    if(z -> key < x -> key) x = x -> left;
    else x = x -> right;
  }
  z -> parent = y;

  //rootがnullのときwhile回らずにyはnullのまま
  //つまり、木が空っぽのときyはnull
  if(y == NULL) root = z;
  else if(z -> key < y -> key) y -> left = z;
  else y -> right = z;
}

void inorder(nodepointer n){
  if(n == NULL) return;
  inorder(n -> left);
  printf(" %d", n -> key);
  inorder(n -> right);
}

void preorder(nodepointer n){
  if(n == NULL) return;
  printf(" %d", n -> key);
  preorder(n -> left);
  preorder(n -> right);
}

nodepointer find(int k){
  nodepointer n;
  n = root;
  while(n != NULL && n -> key != k){
    if(k < n -> key) n = n -> left; //nのkeyの方が大きければ探したいkeyは左にある
    else n = n -> right; //nのkeyの方が小さければ探したいkeyは右にある
  }
  return n;
}



Measured memory_bytes: 20492
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <climits>
#include <set>
#include <map>
#include <iomanip>
#include <cassert>
#include <functional>
#include <cstring>

using namespace std;

typedef pair<int, int> P;
#define mp make_pair
#define FOR(i, a, b) for(int (i)=a;(i)<(b);++(i))
#define rep(i, n)  FOR(i,0,n)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort((v).begin(), (v).end());					//小さい順
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());		//大きい順
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define all(c) (c).begin(),(c).end()
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define Print(p) cout<<(p)<<endl
#define F first
#define S second
#define pb1 push_back
#define mod 1000000007LL
#define INF 1234567890

const int maxn = 2e5 + 10;


//initialization here
//
vector<P> v;

//
//initialization finish


// your function is here
//



//
// your function finished



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

	// your code is here
	//
	string s[3]; cin >> s[0] >> s[1] >> s[2];
	int next = 0;
	for (;;)
	{
		if (s[next].size() == 0)
		{
			if(next ==0)Print("A");
			else if (next == 1)Print("B");
			else if (next == 2)Print("C");
			break;
		}
		int now = next;

		if (s[now][0] == 'a') next = 0;
		else if (s[now][0] == 'b') next = 1;
		else if (s[now][0] == 'c') next = 2;

		s[now].erase(s[now].begin());
	}

	//
	// your code finished



	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

			int N = scan.nextInt();
			long []a = new long[N];
			long S = 0;

			for(int i = 0;i<N;i++) {
				a[i] = scan.nextLong();
				S = S^a[i];

			}

			for(int i = 0;i<N;i++) {
				System.out.println(S^a[i]);
			}






		}


	}


}


Measured memory_bytes: 62236
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a;
	cin>>a;
	int b=a/1.08;
	int c=b-1,ans;
	if(c*1.08-a<1&&c*1.08-a>=0)
	{
		cout<<c;
		return 0;
	}
	if(b*1.08-a<1&&b*1.08-a>=0)
	{
		cout<<b;
		return 0;
	}
	c=b+1;
	if(c*1.08-a<1&&c*1.08-a>=0)
	{
		cout<<c;
		return 0;
	}
	cout<<":(";
}

Measured memory_bytes: 256
fukuri x = floor $ (toDouble x) * 1.01

solve target = loop 100 0
  where
    loop x n
      | target <= fukuri x = (n+1)
      | otherwise = loop (fukuri x) (n+1)


toDouble :: Int -> Double
toDouble x = fromInteger $ toInteger x

main = do
  x <- readLn :: IO Int
  print $ solve x


Measured memory_bytes: 4916
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
int main() {
  int n;
  cin >> n;
  vector<ll> x(n), y(n);
  for(int i = 0; i < n; i++) {
    cin >> x[i] >> y[i];
  }
  map<pair<ll, ll>, int> mp;
  for(int i = 0; i < n; i++) {
    for(int j = 0; j < n; j++) {
      if(i == j) {
        continue;
      }
      mp[{(x[i] - x[j]), (y[i] - y[j])}]++;
    }
  }
  int maxi = 0;
  for(auto p : mp) {
    maxi = max(maxi, p.second);
  }
  cout << n - maxi << endl;
  return 0;
}

Measured memory_bytes: 3760
#include <iostream>

using namespace std;

const int mod = (int)1e9 + 7;

inline void addmod(int &a, int b) {
	a += b;
	a %= mod;
}

int main() {
	const int mid = 1300;
	static int pdp[2601][51] = {}, dp[2601][51] = {};
	int n, k; cin >> n >> k;
	if (k % 2 != 0) {
		cout << 0 << endl;
		cerr << "bad" << endl;
		return 0;
	}
	k /= 2;
	dp[mid][0] = 1;
	int mxSum = n*(n-1)/2;
	int lSum = mid-mxSum, rSum = mid+mxSum;
	for (int step = 0; step < n; ++step) {
		for (int sum = lSum; sum <= rSum; ++sum) {
			for (int p = 0; p <= step; ++p) {
				pdp[sum][p] = dp[sum][p];
				dp[sum][p] = 0;
			}
		}
		for (int sum = lSum; sum <= rSum; ++sum) {
			for (int p = 0; p <= step; ++p) {
				if (!pdp[sum][p]) {
					continue;
				}
				int64_t val = pdp[sum][p];
				// place is L, item is L
				addmod(dp[sum][p], val * (p+1) % mod);
				// place is L, item is S
				addmod(dp[sum-step][p+1], val);
				// place is S, item is L
				if (p) addmod(dp[sum+step][p-1], val * p * p % mod);
				// place is S, item is S
				if (p) addmod(dp[sum][p], val * p % mod);
			}
		}
	}
	cout << dp[k+mid][0] << endl;
	return 0;
} 


Measured memory_bytes: 1280
#include <stdio.h>
int main(void)
{
  int i,x;
  
  for(i = 1; i > 0; i++)
  {
    scanf("%d",&x);
    if(x == 0){
      break;
    }
    printf("Case %d: %d\n",i,x);
  }
  return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
using namespace std;
int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    int size = S.size();
    long long up, down;
    long long ans = 0;
    up = down = 0;
    for (int i = 0; i < size; ++i) {
        if (S[i] == '<') {
            if (down != 0) {
                ans += up*(up-1)/2;
                ans += down*(down-1)/2;
                ans += max(up, down);
                up = 0;
                down = 0;
            }
            ++up;
        } else {
            ++down;
        }
    }
    ans += up*(up-1)/2;
    ans += down*(down-1)/2;
    ans += max(up, down);
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 1172
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest.ABC_129
{
    class C
    {
        static void Main(string[] args)
        {
            Method(args);
        }

        static void Method(string[] args)
        {
            int[] nm = ReadInts();
            int n = nm[0];
            int m = nm[1];
            var dict = new HashSet<int>();
            for(int i = 0; i < m; i++)
            {
                dict.Add(ReadInt());
            }

            var dp = new long[n + 10];
            long mask = 1000000000 + 7;
            dp[0] = 1;
            for (int i = 0; i < n; i++)
            {
                if (!dict.Contains(i))
                {
                    dp[i + 1] += dp[i];
                    dp[i + 1] %= mask;
                    dp[i + 2] += dp[i];
                    dp[i + 2] %= mask;
                }
            }

            WriteLine(dp[n]);
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


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

using namespace std;

int main(){
	int n, x, y;
	scanf("%d", &n);
	int ans = 0;
	for(int i = 1; i <= n; ++i){
		scanf("%d %d", &x, &y);
		ans += y - x + 1;
	}
	cout << ans << endl;
	return 0;
}

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

using ll = long long;

using namespace std;

int main()
{
	int a, b, c, d, e, k;
	cin >> a >> b >> c >> d >> e >> k;

	if (e - a <= k)
	{
		cout << "Yay!" << endl;
	}
	else
	{
		cout << ":(" << endl;
	}
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int N,M ;
const int MAX_M = 10000;
int A[MAX_M];

int main(){

	cin >> N >> M;

	int sum = 0;
	for(int i = 0;i < M;i++){
		cin >> A[i];
		sum += A[i];
	}


	int answer = N - sum;

	if(answer < 0)
		cout << -1<< endl ;
	else
		cout << answer << endl;


	return 0;
}

Measured memory_bytes: 3636
using System;
using System.Linq;

namespace ABC076_D___AtCoder_Express
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var T = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            var V = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            var totalTime = T.Sum() * 2;

            var limits = new SpeedLimit[N + 2];
            limits[0] = new SpeedLimit(0, 0, 0);
            for (int i = 1; i < N + 1; i++) limits[i] = new SpeedLimit(limits[i - 1].End, limits[i - 1].End + T[i - 1] * 2, V[i - 1]);
            limits[N + 1] = new SpeedLimit(totalTime, totalTime, 0);

            var speed = new double[totalTime + 1];
            for (int t = 1; t <= totalTime; t++)
            {
                speed[t] = double.PositiveInfinity;
                foreach (SpeedLimit l in limits)
                {
                    if (l.Start > t)
                    {
                        speed[t] = Math.Min(speed[t], l.Limit + (l.Start - t) * 0.5);
                    }
                    else if (l.End < t)
                    {
                        speed[t] = Math.Min(speed[t], l.Limit + (t - l.End) * 0.5);
                    }
                    else
                    {
                        speed[t] = Math.Min(speed[t], l.Limit);
                    }
                }
            }

            double distance = 0;
            for (int i = 1; i < totalTime + 1; i++)
            {
                if (speed[i] > speed[i - 1])
                {
                    distance += speed[i - 1] * 0.5 + 0.125;
                }
                else if (speed[i] < speed[i - 1])
                {
                    distance += speed[i] * 0.5 + 0.125;
                }
                else
                {
                    distance += speed[i] * 0.5;
                }
            }
            Console.WriteLine(distance);
        }
        struct SpeedLimit
        {
            public double Start;
            public double End;
            public double Limit;
            public SpeedLimit(double _start, double _end, double _limit)
            {
                Start = _start;
                End = _end;
                Limit = _limit;
            }
        }
    }
}


Measured memory_bytes: 13372
# E
# -*- coding: utf-8 -*-
H, N = map(int, input().split())
A_list = []
B_list = []
for i in range(N):
    A, B = map(int, input().split())
    A_list.append(A)
    B_list.append(B)

dp = [0 for _ in range(H + 1)]
dp[0] = 0

def test_func(dp, A_list, B_list, i, N):
    return(min([(dp[i - A_list[j]] if i >= A_list[j] else 0) + B_list[j] for j in range(N)]))


for i in range(1, H + 1):
    dp[i] = test_func(dp, A_list, B_list, i, N)

print(dp[-1])

Measured memory_bytes: 3484
bells = list(map(int, input().split()))

if min(bells) == bells[0]:
    print(min(bells) + min(bells[1], bells[2]))
elif min(bells) == bells[1]:
    print(min(bells) + min(bells[0], bells[2]))
else:
    print(min(bells) + min(bells[0], bells[1]))

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

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

    int n;
    cin >> n;

    int m = 1 << n;

    multiset<int> st;
    for (int i = 0; i < m; i++) {
        int s;
        cin >> s;
        st.insert(s);
    }

    vector<int> c(m);
    auto it = st.end(); it--;
    c[0] = *it;
    st.erase(it);
    for (int k = 0; k < n; k++) {
        int l = 1 << k;
        for (int i = 0; i < l; i++) {
            auto it = st.lower_bound(c[i]);
            if (it == st.begin()) {
                cout << "No" << endl;
                exit(0);
            }
            it--;
            c[l + i] = *it;
            st.erase(it);
        }
    }

    cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 13568
#include <iostream>
#include <vector>
#include <iomanip>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

#include <iostream>

int main()
{
    int L;
    long double length;

    cin >> L;
    length = (long double) L / 3;

    cout << fixed;
    cout << setprecision(6) << (long double)(length * length * length);
}

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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

using ll = long long;

using namespace std;

int main() {
  in(ll, a, b, q);
  vector<ll> s(a);
  rep(i, a) cin >> s[i];
  set<ll> ss(all(s));
  vector<ll> t(b);
  rep(i, b) cin >> t[i];
  set<ll> ts(all(t));
  while (q--) {
    in(ll, x);
    auto lohi = [](const set<ll>& s, ll x) {
      vector<ll> v;
      auto it = s.lower_bound(x);
      if (it == s.end()) {
        --it;
        v.push_back(*it);
      } else {
        v.push_back(*it);
        if (it != s.begin()) {
          --it;
          v.push_back(*it);
        }
      }
      /*
      dbg(x);
      for (ll sx : s) cerr << sx << " ";
      cerr << endl;
      for (ll sx : v) cerr << sx << " ";
      cerr << endl;
      */
      return v;
    };
    ll ans = numeric_limits<ll>::max();
    for (ll sx : lohi(ss, x)) {
      for (ll tx : lohi(ts, x)) {
        ans = min(ans, abs(x - sx) + abs(sx - tx));
        ans = min(ans, abs(x - tx) + abs(tx - sx));
      }
    }
    out(ans);
  }
}


Measured memory_bytes: 14348
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
using namespace std; using ll = long long; using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
int ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.first > secondElof.first;
}
//**Snippetリスト**//
//rep, vin, all, iteLoop//
//gcdlcm, isPrime, eratos, modinv, bitSearch, bitList, dfs, bfs, dijkstra, UnionFind, COM, digitDP//
ll i, j, k, l, m, n; ll N, M, K, H, W, L;
ll MOD = 1000000007; ll INF = 9999999999999; ll ans = 0;
vl flag, color; vll path; vl D;
//***********//
int main() {
	ll X, Y;
	cin >> N >> X >> Y;
	vl A(N);
	for (i = 0; i < N; i++) {
		A[i] = 0;
	}
	for (i = 1; i < N; i++) {
		for (j = i+1; j <= N; j++) {
			ll d;
			if (i <= X && Y <= j) {
				 d = j - i - (Y - X - 1);
			}
			else if (j <= X || Y <= i) {
				d = j - i;
			}
			else {
				d = min(j - i, abs(X - i) + 1 + abs(Y - j));
			}
			//cout << d;

			A[d]++;
		}
	}
	for (i = 1; i <= N-1; i++) {
		cout << A[i] << endl;
	}
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    int w, n, i, a, b, temp, list[31];
    
    scanf("%d", &w);
    scanf("%d", &n);
    
    for (i = 1; i <= w; i++) {
        list[i] = i;
    }
    
    for (i = 1; i <= n; i++) {
        scanf("%d,%d", &a, &b);
        
        temp = list[a];
        list[a] = list[b];
        list[b] = temp;
    }
    
    for (i = 1; i <= w; i++) {
        printf("%d\n", list[i]);
    }
    
    return 0;
}

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

#define LSOne(S) ((S) & (-S))

#define EPS 1e-6
#define MOD 1000000007

#define fi first
#define se second
#define pb push_back
#define ende '\n'

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define mset(x, y) memset(&x, (y), sizeof(x))

using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  vi h;
  cin >> n;
  int hi;
  while (n--) {
    cin >> hi;
    h.pb(hi);
  }
  int flag = 0;
  for (int i = h.size()-1; i > 0; i--) {
    if (h[i] < h[i-1]-1) flag = 1;
    else if (h[i] == h[i-1] - 1) h[i-1]--;
  }
  cout << (flag ? "No" : "Yes") << ende;
  return 0;
}


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

int main(){
    long long n;
    cin >> n;
    long long A[n], B[n];
    for(int i = 0; i < n; i++){
        cin >> A[i] >> B[i];
    }

    long long cnt = 0;
    for(int i = n - 1; i >= 0; i--){
        A[i] += cnt;
        if(A[i] % B[i]){
            cnt  += B[i] - A[i] % B[i];
        }
    }
    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
#define int long long 
const int INF = 1e9;
const int MOD = INF + 7;
#define put(n) cout<<(n)<<endl
#define rep(i,N) for(int(i)=0;(i)<(N);++(i))
#define rrep(i,N) for(int (i)=(N-1);(i)>=(0);--(i))
#define all(v) (v).begin() , (v).end()
#define rall(v) (v).rbegin() , (v).rend()
#define pb(n) push_back(n)

vector<int> Fac;

signed main(){
    int N,M;
    cin>>N>>M;
    Fac.push_back(1);

    for(int i = 2; i <= 100000; ++i) Fac.push_back((Fac.back() * i) % MOD); 
    
    if(N == M) cout << (((2 * Fac[N-1]) % MOD) * Fac[M-1]) % MOD  << endl;
    else if(abs(N-M) == 1) cout << (Fac[N-1] * Fac[M-1]) % MOD << endl;
    else cout << 0 << endl;

}

Measured memory_bytes: 1400
w,h,n=gets.chomp.split.map(&:to_i)
I=[]
ld=[0,0]
ru=[w,h]
n.times do
    I.push(gets.chomp.split.map(&:to_i))
end

I.each do |line|
    a=line[2]
    if a==1
        ld[0]=line[0] if ld[0]<line[0]
    elsif a==2
        ru[0]=line[0] if line[0]<ru[0]
    elsif a==3
        ld[1]=line[1] if ld[1]<line[1]
    elsif a==4
        ru[1]=line[1] if line[1]<ru[1]
    end
end
if ru[0]-ld[0]<=0 || ru[1]-ld[1]<=0
    puts 0
    exit
end
p (ru[0]-ld[0])*(ru[1]-ld[1])


Measured memory_bytes: 1788
#include<stdio.h>
#include<string.h>
int main()
{
	char s[200005];
	scanf("%s", s);
	int i, n = strlen(s);
	char b[4], a[4];
	int ans = 1;
	b[0] = s[0];
	b[1] = '\0';
	for (i = 1; i < n; i++)
	{
		a[0] = s[i];
		a[1] = '\0';
		if (strcmp(a, b) == 0)
		{
			i++;
			a[1] = s[i];
			a[2] = '\0';
		}
		if (i == n)
			ans--;
		strcpy(b, a);
		ans++;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <cmath>
#include <iomanip>

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;

// #define rep(i,n) for(int i=0;i<(n);++i)
#define all(f,c,...) (([&](decltype((c)) cccc) { return (f)(begin(cccc), end(cccc), ## __VA_ARGS__); })(c))
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

#define rrep(i,n) for(int i=(n);i>=0;--i)
const int dx[4]={1,0,-1,0}, dy[4]={0,1,0,-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;}

// debug
template<class T>ostream& operator<<(ostream& os,const vector<T>& vec){os<<"{";for(int i=0;i<vec.size();++i)os<<(i?", ":"")<<vec[i];os<<"}";return os;}
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>& rhs){os<<"("<<rhs.first<<", "<<rhs.second<<")";return os;}

#ifdef LOCAL
void debug() {cerr << "\n";}
template<class First> void debug(const First& first) {cerr<<first<<"\n";}
template<class First, class... Rest> void debug(const First& first, const Rest&... rest) {cerr<<first<<",";debug(rest...);}
#else
#define debug(...) 42
#endif


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

  long double x = L/3.0;

  cout << fixed << setprecision(16) << (L - (x + x)) * x * x << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

using namespace std;
typedef long long ll;

int N;
int d1[100], d2[100];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> d1[i] >> d2[i];
    }
    for(int i = 0; i < N; i++){
        if(i >= 2){
            bool same = true;
            for(int j = 0; j < 3; j++){
                if(d1[i-j] != d2[i-j]) same = false;
            }
            if(same){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()

template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}


int main() {
    int N,K,S;
    cin >> N >> K >> S;
    ll dead = INF;
    if (INF == S) dead = INF-10;
    REP(i,N-K) {
        cout << dead << " ";
    }

    REP(i,K) {
        cout << S << " ";
    }

    cout << endl;

    return 0;
}


Measured memory_bytes: 1280
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
  long long n,a[100005]={},b[100005]={},ans=0;
  cin >> n;
  for(int i=0; i<=n; i++) {
    cin >> a[i];
  }
  for(int i=0; i<n; i++) {
    cin >> b[i];
  }
  for(int i=0; i<n; i++) {
    if(b[i]>=a[i]) {
      ans+=a[i]+min(a[i+1],b[i]-a[i]);
      a[i+1]-=min(a[i+1],b[i]-a[i]);
    }
    else {
      ans+=b[i];
    }
  }
  cout << ans << endl;
}


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

#define fr first
#define sc second
#define pb push_back
#define rep(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)

int N,D[101],A[101];
map<vector<int>,int> encd;
map<int,vector<int> > dcd;

int dp[101][5041];// dp[x][y]: encd[x][0],encd[x][1],...,encd[x][6]???????????§?£?????????¨???????????§???????????????(encd????????????i?????????????°??±???????id)
int taste[7];
int res,ans;
int main()
{
	cin>>N;
	for(int i=0;i<N;i++) cin>>D[i];
	for(int i=0;i<N;i++) cin>>A[i];
	int K=min(N,7);
	int cnt=0;
	vector<int> v(K);
	for(int i=0;i<K;i++) v[i]=i;
	do{
		encd[v]=cnt;
		dcd[cnt]=v;
		res=0;
		for(int i=0;i<K;i++) taste[i]=0;
		for(int i=0;i<K;i++){
			int eat=K-1-v[i];
			res+=taste[eat];
			for(int j=eat-D[eat];j<=eat+D[eat];j++){
				if(0<=j&&j<K) taste[j]+=A[eat];
			}
		}
		dp[K-1][cnt]=res;
		cnt++;
	}while(next_permutation(v.begin(),v.end()));
	
	if(N<=7){
		for(int i=0;i<cnt;i++){
			ans=max(ans,dp[N-1][i]);
		}
		cout<<ans<<endl;
		return 0;
	}
	//cnt=7!
	vector<int> V(7);
	for(int i=6;i<N-1;i++){//??????dp
		for(int s=0;s<cnt;s++){//
			vector<int> G=dcd[s]; //G[??????]=i-(?°??±???????id)
			int V_SIZE;
			for(int nx=0;nx<8;nx++){//i+1????°??±??????? ?????´??´????????????nx??????????£???????
				V_SIZE=0;
				res=0;
				for(int now=0;now<7;now++){
					int eat=G[now];
					if(now==nx){
						V[V_SIZE]=0;
						V_SIZE++;
					}
					if(now>=nx){//i+1??????????????¨
						//i+1???????????????????????????
						if(D[i+1]>=eat+1) res+=A[i+1];
					}
					else{//i+1????????????
						//i-eat???????????????(i+1??????????????????)????????????
						if(D[i-eat]>=eat+1) res+=A[i-eat];
					}
					if(eat<6){
						V[V_SIZE]=eat+1;
						V_SIZE++;
					}
				}
				if(nx==7){
					V[V_SIZE]=0;
					V_SIZE++;
				}
				int news=encd[V];
				dp[i+1][news]=max(dp[i+1][news],dp[i][s]+res);
			}
		}
	}
	ans=0;
	for(int i=0;i<cnt;i++){
		ans=max(dp[N-1][i],ans);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 6212