akhauriyash/Code-Regression huggingface dataset:
//ID:computerbox --> Hajiyev Huseyn
#include <bits/stdc++.h>
//#pragma comment(linker, "/vector:200000000")
#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#define _CRT_SECURE_NO_WARNINGS
//#include <boost/multiprecision/cpp_int.hpp>
//using boost::multiprecision::cpp_int;
#define FAST_READ ios_base::sync_with_stdio(0);/*cin.tie(0); cout.tie(0);*/
#define in freopen("input.txt", "r", stdin);
#define out freopen("output.txt", "w", stdout);
#define ll long long
#define debt(x,y)cout<<"#x = "<<(x)<<" and "<<"#y = "<<(y)<<endl;
#define deb(x)cout<<"#x = "<<(x)<<endl;
#define COUT(n, a) cout<< fixed << setprecision(a) << n<<endl
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define endl "\n"
#define arr(a,n) for(ll i=1;i<=n;i++) cout<<a[i]<<" "; cout << "\n";
#define vecc(a,n) for(ll i=0;i<n;i++) cout<<a[i]<<" "; cout << "\n";
#define CURTIME() cerr << clock() * 1.0 / CLOCKS_PER_SEC << endl
#define DTIME(ccc) __begin = clock(); ccc; cerr<<"Time of work = "<<(clock()-__begin)/CLOCKS_PER_SEC<<endl;
#define MAXN 10010

using namespace std;

#define debug(args...)(Debugger()) , args
class Debugger
{
  public:
  Debugger(const std::string& _separator=", ") :
  first(true),separator(_separator){}
  template<typename ObjectType>
  Debugger& operator,(const ObjectType& v)
  {
        if(!first)cerr<<separator;
        cerr<<v;
        first=false;
        return *this;
  }
  ~Debugger() {cerr<<endl;}
  private:
    bool first;
    string separator;
};

template <typename T1, typename T2>
inline ostream& operator<<(std::ostream& os, const std::pair<T1, T2>& p)
{
   return os<<"("<<p.first<<", "<<p.second<<")";
}
template<typename T>
inline ostream &operator<<(ostream & os,const vector<T>& v)
{
    bool first=true;
    os<<"[";
    for(unsigned ll i=0;i<v.size();i++)
    {
        if(!first)os<<", ";
        os<<v[i];
        first=false;
    }
        return os<<"]";
}
template<typename T>
inline ostream &operator<<(ostream & os,const set<T>&v)
{
    bool first=true;
    os<<"[";
    for(typename set<T>::const_iterator ii=v.begin();ii!=v.end();++ii)
    {
        if(!first)os<<", ";
        os<<*ii;
        first=false;
    }
    return os<<"]";
}
template<typename T1, typename T2>
inline ostream &operator<<(ostream & os,const map<T1, T2>&v)
{
        bool first=true;
        os<<"[";
        for(typename map<T1,T2>::const_iterator ii=v.begin(); ii!=v.end();++ii)
        {
            if(!first)os<<", ";
            os<<*ii;
            first=false;
        }
        return os<<"]";
}

ll a,b;

ll poww(ll a,ll b)
{
    ll res=1;
    for(;b;b>>=1)
    {
     if(b&1)res=(res*a);
     a=a*a;
    }
    return res;
}

ll massiv[MAXN];

ll check(ll n)
{
  ll cnt=0;
  for(ll i=1;i<=n;i++)
  {
     if(massiv[i]%2==0)cnt++;
  }
  if(cnt==0)return 0;
  else return 1;
}
ll n;

ll cmp(ll a,ll b)
{
    return a>b;
}

int main(){
FAST_READ;
cin>>n;
ll nec=0;
for(ll i=1;i<=n;i++)
{
  cin>>massiv[i];
  while(massiv[i]%2==0 && massiv[i]!=0)
  {
    massiv[i]/=2;
    nec++;
  }
}
cout<<nec<<endl;

return 0;
}


Measured memory_bytes: 384
Public Class Main
    Public Shared Sub Main(ByVal args() As String)
        Dim S, T, U as String
        Dim A, B as Integer
        Dim arr(2) as String
        arr = Split(Console.ReadLine())
        S = arr(0) : T = arr(1)
        arr = Split(Console.ReadLine())
        A = arr(0) : B = arr(1)
        U = Console.ReadLine()
        If S = U
            A -= 1
        Else
            B -= 1
        End If
        Console.WriteLine(A.ToString() & " " & B.ToString())
    End Sub
End Class


Measured memory_bytes: 20304
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <cmath>
using namespace std;

#define FOR(i,s,e) for (int i = int(s); i < int(e); i++)
#define FORIT(i,c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define ISEQ(c) (c).begin(), (c).end()

int SURP = 1000000007;

int main(){
	int A,B,C,D;
	cin >> A >> B >> C >> D;
	string ret;
	if(A+B > C+D) ret = "Left";
	else if(A+B == C+D) ret = "Balanced";
	else ret = "Right";
	cout << ret << endl;
	return 0;

}


Measured memory_bytes: 764
#include<bits/stdc++.h>
#define maxn 505050

using namespace std;
typedef long long ll;
ll dp[maxn][3],a[maxn][3],n,k;
int main(){
    cin >> n;
    for (int i=1;i<=n;i++) cin >> a[i][0] >> a[i][1] >> a[i][2];
    for (int i=1;i<=n+2;i++){
        dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a[i][0];
        dp[i][1]=max(dp[i-1][0],dp[i-1][2])+a[i][1];
        dp[i][2]=max(dp[i-1][0],dp[i-1][1])+a[i][2];
    }
    cout << dp[n+2][0] << endl;
}


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

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

	string s;
	cin >> s;
	int l=2, i=0, ans=0;
	while(i<s.size()) {
		if(l==2) {
			++i;
			l=1;
			++ans;
		} else {
			if(s[i]==s[i-1]) {
				if(i+1<s.size()) {
					++ans;
				}
				i+=2;
				l=2;
			} else {
				++i;
				++ans;
			}
		}
	}
	cout << ans;
}

Measured memory_bytes: 720
fn main() {
    let input: Vec<i32> = read_as_vec();
    let w = input[0];
    let h = input[1];
    let x = input[2];
    let y = input[3];
    let r = input[4];
    if (x - r) >= 0 &&
       (y - r) >= 0 &&
       (x + r) <= w &&
       (y + r) <= h {
      println!("Yes");
    } else {
      println!("No");
    }
}

fn read<T: std::str::FromStr>() -> T {
    let mut input = String::new();
    std::io::stdin().read_line(&mut input).unwrap();
    input.trim().parse::<T>().ok().unwrap()
}

fn read_as_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse::<T>().ok().unwrap())
        .collect()
}


Measured memory_bytes: 5024
import itertools

primes = [2,3,5,7] + [x for x in range(10,100) if (x%2 and x%3 and x%5 and x%7)]

def fact_ord(p,n):
  return n//p+fact_ord(p,n//p) if n else 0

N = int(input())

order = [fact_ord(p,N) for p in primes]

arr = [0]*80 # 約数の個数ごとにいくつあるか
arr[1] = 1

for e in order:
  temp = [0]*80
  for ee,j in itertools.product(range(e+1),range(80)):
    y = min((ee+1)*j,79)
    temp[y] += arr[j]
  arr = temp
  
answer = arr[75]
print(answer)

Measured memory_bytes: 3064
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <chrono>
#include <random>
#include <tuple>
#include <utility>
#include <fstream>

const long INF = (1l << 30);
const long LINF = (1l << 60);
const long MOD = 1000000007;

long n, m;
std::vector<long> edge[100005];
long pat[100005];
long det[100005];

void dfs(long vis){
    for(int i = 0; i < edge[vis].size(); i++){
        long nx = edge[vis][i];
        if(pat[nx] != -1){
            continue;
        }
        pat[nx] = m - det[vis];
        det[vis]++;
        det[nx] = 2;
        dfs(nx);
    }
}

int main(){
    scanf("%ld%ld", &n, &m);
    for(int i = 0; i < n-1; i++){
        long a, b;
        scanf("%ld%ld", &a, &b);
        edge[a].push_back(b);
        edge[b].push_back(a);
    }
    for(int i = 1; i <= n; i++){
        pat[i] = -1;
    }
    pat[1] = m;
    det[1] = 1;
    long ans = 1;
    dfs(1);
    for(int i = 1; i <= n; i++){
        //printf("  %d %ld\n", i, pat[i]);
        ans *= std::max(0l, pat[i]);
        ans %= MOD;
    }
    printf("%ld\n", ans);
}


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

int main()
{
	long long n;
	cin>>n;
	string ans;
	while(n>0)
	{
		n--;
		ans += n%26+'a';
		n = n/26;
	}
	reverse(ans.begin(),ans.end());
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <utility>
#include <cmath>
using namespace std;

void print(const pair<float, float>& p)
{
    cout << p.first << " " << p.second << endl;
}

void koch(int n, const pair<float, float>& p0, const pair<float, float>& p1)
{
    if (n == 0) {
        return;
    }
    pair<float, float> s, u, t;
    s.first  = (2 * p0.first  + p1.first)  / 3.f;
    s.second = (2 * p0.second + p1.second) / 3.f;
    t.first  = (p0.first  + 2 * p1.first)  / 3.f;
    t.second = (p0.second + 2 * p1.second) / 3.f;
    u.first  = 0.5f * (s.first - p0.first) - sqrt(3) * 0.5f * (s.second - p0.second) + s.first;
    u.second = sqrt(3) * 0.5f * (s.first - p0.first) + 0.5f * (s.second - p0.second) + s.second;
    koch(n - 1, p0, s);
    print(s);
    koch(n - 1, s, u);
    print(u);
    koch(n - 1, u, t);
    print(t);
    koch(n - 1, t, p1);
}

int main()
{
    int n;
    cin >> n;
    pair<float, float> p0(0.f, 0.f);
    pair<float, float> p1(100.f, 0.f);
    print(p0);
    koch(n, p0, p1);
    print(p1);
    return 0;
}


Measured memory_bytes: 3288
inputLine = input()
tempStr = inputLine.split(' ')

numPeople = int(tempStr[0])
numCandy = int(tempStr[1])

candyList = [0] * numPeople
for index in range(numCandy) :

		inputLine = input()
		inputLine = input()
		tempStr = inputLine.split(' ')

		for eachPeople in tempStr :
			candyList[int(eachPeople) - 1] += 1

finalAns = 0
for eachCandy in candyList :
	finalAns = finalAns + 1 if eachCandy == 0 else finalAns

print(finalAns)

Measured memory_bytes: 9220
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
const double PI = acos(-1);
const ll MOD = 1000000007;
using Graph = vector<vector<int>>;

int main() {
  int N,M; cin >> N >> M;
  vector<int> data(M);
  vector<int> a(M);
  rep(i,M) {
    cin >> a[i];
    int b; cin >> b;
    rep(j,b) {
      int c; cin >> c; c--;
      data[i] += pow(2,c);
    }
  }
  
  const int k = pow(2,N);
  vector<vector<int>> dp(M+1, vector<int>(k,1e9));
  rep(i,M+1) dp[i][0] = 0;
  rep(i,M) {
    rep(j,k) dp[i+1][j] = dp[i][j];
    rep(j,k) {
      dp[i+1][(j | data[i])] = min(dp[i][j] + a[i],dp[i+1][(j | data[i])]);
    }
  }
  if (dp[M][k-1] != 1e9) cout << dp[M][k-1] << endl;
  else cout << -1 << endl;
}

Measured memory_bytes: 16384
#include <bits/stdc++.h>
using namespace std;
using ll = unsigned long long;

ll lcd(ll a, ll b) {
  if (a < b) {
    swap(a, b);
  }
  if (b == 0) {
    return a;
  } else {
    return lcd(b, a % b);
  }
}

int main() {
  int N;
  cin >> N;
  vector<ll> T(N);
  for (int i = 0; i < N; ++i) {
    cin >> T[i];
  }
  ll lcm = T[0];
  for (int i = 1; i < N; ++i) {
    ll cur = T[i];
    lcm = lcm / lcd(cur, lcm) * cur;
  }
  cout << lcm << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define INF 1<<29
typedef pair<int,int> P;
struct PP {
  P a,b;
  int kk;
};

int dx[5]={-1,0,1,0,0},dy[5]={0,1,0,-1,0};
bool check(int n,int m,int x,int y){return x>=0&&x<n&&y>=0&&y<m;}

int main() {
  int n,m;
  while(cin >> n >> m && n) {
    string s[n],t;
    for(int i=0; i<n; i++) cin >> s[i];
    cin >> t;
    for(int i=0; i<t.size(); i++) {
      if(t[i]=='5') t[i]='4';
      else if(t[i]=='8') t[i]='0';
      else if(t[i]=='6') t[i]='1';
      else if(t[i]=='2') t[i]='2';
      else t[i]='3';
    }
    P p1,p2;
    for(int i=0; i<n; i++) {
      for(int j=0; j<m; j++) {
        if(s[i][j]=='A') p1=P(i,j);
        if(s[i][j]=='B') p2=P(i,j);
      }
    }
    int d[n][m][n][m][t.size()];
    for(int i=0;i<n;i++)for(int i2=0;i2<m;i2++)for(int i3=0;i3<n;i3++)for(int i4=0;i4<m;i4++)for(int i5=0;i5<t.size();i5++)d[i][i2][i3][i4][i5]=INF;
    d[p1.F][p1.S][p2.F][p2.S][t.size()-1]=0;
    queue<PP> que;
    que.push((PP){p1,p2,t.size()-1});
    while(!que.empty()) {
      PP p=que.front();que.pop();
      int nx=p.a.F,ny=p.a.S,k=p.kk;
      P q=p.b;
      int cost=d[nx][ny][p.b.F][p.b.S][p.kk];
      if(p.a==p.b) {
        cout << cost << " " << nx << " " << ny << endl;
        goto end;
      }
      k=(k+1)%t.size();
      int r=t[k]-'0';
      q.F+=dx[r],q.S+=dy[r];
      if(!check(n,m,q.F,q.S)) q=p.b;
      for(int i=0; i<5; i++) {
        int x=nx+dx[i],y=ny+dy[i];
        if(!check(n,m,x,y)||s[x][y]=='#') continue;
        if(d[x][y][q.F][q.S][k]>cost+1) {
          d[x][y][q.F][q.S][k]=cost+1;
          que.push((PP){P(x,y),q,k});
        }
      }
    }
    cout << "impossible" << endl;
  end:;
  }
  return 0;
}


Measured memory_bytes: 7492
#include <stdio.h>		// standard input output
#include <iostream>		// input output stream, cin cout( console in console out)
#include <cmath>		// circle math ( sin, con, sinh
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>		// input output manipulation

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define rep3(i, a, n) for(int i = (int)(a); i < (int)(n); i++)
#define ll long long

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






int main() {
  ll N; // 変数の宣言
  cin >> N; // 標準入力
  ll ans = 0;
  
  
  rep3(i,1,N){
    if(N % i ==0){
    ans  += N/i -1;
   // cout << ans <<N/i << endl;
  }else{
      ans  += N/i;
    //cout << ans <<N/i << endl;
    }
  
  }
  
  
 
  cout << setprecision(12) << ans << endl; // 標準出力
  
}




Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
using namespace std;

int main() {
  int N;
  cin >> N;
  vector<int> X(N);
  for(int i=0; i<N; ++i) cin >> X[i];
  int cnt=0;
  
  for(int i =1; i<N-1; ++i){
    if(X[i-1] < X[i] && X[i] < X[i+1]) ++cnt;
    if(X[i-1] > X[i] && X[i] > X[i+1]) ++cnt;
  }
  cout << cnt << endl;
}

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

using ll = long long;
const int mod = 1e9 + 7;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    string S;
    cin >> S;
    ll ans = 0;
    for (int i = 0; i < N; i++) {
        int L[3] = {}, R[3] = {};
        for (int j = 0; j < i; j++) {
            if (S[j] == 'R')
                L[0]++;
            else if (S[j] == 'G')
                L[1]++;
            else
                L[2]++;
        }
        for (int j = i + 1; j < N; j++) {
            if (S[j] == 'R')
                R[0]++;
            else if (S[j] == 'G')
                R[1]++;
            else
                R[2]++;
        }
        if (S[i] == 'R')
            ans += L[1] * R[2] + L[2] * R[1];
        else if (S[i] == 'G')
            ans += L[0] * R[2] + L[2] * R[0];
        else
            ans += L[0] * R[1] + L[1] * R[0];
        for (int j = 0; j < i; j++) {
            if (2 * i - j >= N)
                continue;
            if (S[i] != S[j] && S[i] != S[2 * i - j] && S[j] != S[2 * i - j])
                ans--;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3648
#include<cstdio>
#include<queue>
#include<iostream>
#include<algorithm>
using namespace std;
const int MAXN = 200000;
int A[MAXN + 5], B[MAXN + 5];
priority_queue<pair<int, int> >que;
int main() {
	int N; scanf("%d", &N);
	for(int i=0;i<N;i++) scanf("%d", &A[i]);
	for(int i=0;i<N;i++) {
		scanf("%d", &B[i]);
		que.push(make_pair(B[i], i));
	}
	long long ans = 0;
	while( !que.empty() ) {
		int x = que.top().first, y = que.top().second; que.pop();
		if( x == A[y] ) continue;
		if( x - (B[(y + N - 1)%N] + B[(y + 1)%N]) < A[y] ) {
			puts("-1");
			return 0;
		}
		int tmp = (x - A[y]) / (B[(y + N - 1)%N] + B[(y + 1)%N]);
		ans += tmp;
		B[y] = B[y] - tmp*(B[(y + N - 1)%N] + B[(y + 1)%N]);
		que.push(make_pair(B[y], y));
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 3700
#include<bits/stdc++.h>
typedef long long int ll;
using namespace std;

int main(){

int n;
cin>>n;
vector<int> arr(n);
vector<int> dp(n,INT_MAX);
for(int i=0;i<n;i++){
  cin>>arr[i];
}	
dp[0]=0;
for(int i=0;i<n;i++){
   for(int j=i+1;j<=i+2;j++){
       if(j<n){
	 dp[j]=min(dp[j],dp[i]+abs(arr[i]-arr[j]));	
       }
       
  }
}
cout<<dp[n-1]<<"\n";
 return 0;
}

Measured memory_bytes: 1024
#include<algorithm>     //sort,二分探索,など
#include<bitset>        //固定長bit集合
#include<cmath>         //pow,logなど
#include<complex>       //複素数
#include<deque>         //両端アクセスのキュー
#include<fstream>       //ファイルストリーム（標準入力変更用）
#include<functional>    //sortのgreater
#include<iomanip>       //setprecision(浮動小数点の出力の誤差)
#include<iostream>      //入出力
#include<iterator>      //集合演算(積集合,和集合,差集合など)
#include<map>           //map(辞書)
#include<numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include<queue>         //キュー
#include<set>           //集合
#include<stack>         //スタック
#include<string>        //文字列
#include<unordered_map> //イテレータあるけど順序保持しないmap
#include<unordered_set> //イテレータあるけど順序保持しないset
#include<utility>       //pair
#include<vector>        //可変長配列

//名前
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef map<string, int> msi;
typedef map<string, ll> msll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pllll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef vector<vector<string>> vvs;
typedef vector<vector<bool>> vvb;

//定数
const ll MOD = 1000000007;
const ll INF = 1000000000000000000;

//マクロ
#define rep(i,n) for(int i=0;i<n;i++)
#define reps(i,s,e) for(int i=s;i<e;i++)
#define repse(i,s,e) for(int i=s;i<=e;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define in1(x1) cin >> x1
#define in2(x1, x2) cin >> x1 >> x2
#define in3(x1, x2, x3) cin >> x1 >> x2 >> x3
#define inN(x, N) rep(i, N) in1(x[i])
#define outl(x) cout << x << endl
#define out2l(x, y) cout << x << " " << y << endl 

//よく使う関数
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

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

    //標準入力をファイルに変更
    //std::ifstream in("input.txt");
    //std::cin.rdbuf(in.rdbuf());
    int N, K;
    in2(N, K);

    vll h(N);
    inN(h, N);

    sort(all(h));

    ll ans = INF;

    rep(i, N - K + 1)
    {
        chmin(ans, h[i + K - 1] - h[i]);
    }

    outl(ans);

    return 0;
}


Measured memory_bytes: 3976
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; double w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;
int INF = INT_MAX / 100;

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

int main() {
	for (;;) {
		int w, h; cin >> w >> h;
		if (w == 0) break;
		vector<string> c(h);
		vector<int> X(1), Y(1);
		for (int y = 0; y < h; y++) {
			cin >> c[y];
			for (int x = 0; x < w; x++)
				if (c[y][x] == '*') {
					X.push_back(x);
					Y.push_back(y);
				}
				else if (c[y][x] == 'o') {
					X[0] = x;
					Y[0] = y;
				}
		}
		int n = X.size();
		vector< vector<int> > a(n, vector<int>(n));
		for (int i = 0; i < n; i++) {
			int x = X[i], y = Y[i];
			vector< vector<int> > d(h, vector<int>(w, INF));
			d[y][x] = 0;
			queue<i_i> q;
			q.push(i_i(x, y));
			while (!q.empty()) {
				i_i p = q.front(); q.pop();
				int x = p.first, y = p.second;
				for (int k = 0; k < 4; k++) {
					int _x = x + dx[k], _y = y + dy[k];
					if (_x >= 0 && _x < w && _y >= 0 && _y < h && c[_y][_x] != 'x' && d[_y][_x] > d[y][x] + 1) {
						d[_y][_x] = d[y][x] + 1;
						q.push(i_i(_x, _y));
					}
				}
			}
			for (int j = 0; j < n; j++) {
				int x = X[j], y = Y[j];
				a[i][j] = d[y][x];
			}
		}
		/*for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++)
				cout << a[i][j] << ' ';
			cout << endl;
		}*/
		vector<int> v(n);
		for (int i = 0; i < n; i++)
			v[i] = i;
		int mini = INF;
		do {
			int sum = 0;
			for (int i = 0; i + 1 < n; i++)
				sum += a[v[i]][v[i + 1]];
			mini = min(mini, sum);
		} while (next_permutation(v.begin() + 1, v.end()));
		cout << (mini < INF ? mini : -1) << endl;
	}
}

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

int main() {
  int i,n,m,f,max=0,cnt=0;
  cin>>n;
  for(i=1;i<n+1;i++){
    m=i;
    cnt=0;
    if(n==1){
      f=1;
    }
    //cout<<n<<m<<i<<endl;
    while(m%2==0){
      m/=2;
      cnt++;
      if(m==0){
        break;
      }
    }
    if(max<cnt){
      max=cnt;
      f=i;
    }
  }
  cout<<f<<endl;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll n,a,b;
	cin>>n>>a>>b;
	a--;b--;
	vector<ll>ch[2010];
	for(ll i=0;i<n-1;i++){
		ch[i].push_back(i+1);
		ch[i+1].push_back(i);
	}
	ch[a].push_back(b);
	ch[b].push_back(a);
	ll ans[2010]={};
	for(ll i=0;i<n;i++){
		ll cnt[2010];
		for(ll j=0;j<n;j++){
			cnt[j]=-1;
		}
		cnt[i]=0;
		queue<ll>q;
		q.push(i);
		while(q.size()!=0){
			ll now=q.front();
			q.pop();
			for(ll i=0;i<ch[now].size();i++){
				ll next=ch[now][i];
				if(cnt[next]!=-1){
					continue;
				}
				cnt[next]=cnt[now]+1;
				q.push(next);
			}
		}
		for(ll i=0;i<n;i++){
			ll now=cnt[i];
			ans[now]++;
		}
	}
	for(ll i=1;i<=n-1;i++){
		cout <<ans[i]/2<<endl;
	}
	return 0;
}

Measured memory_bytes: 384
# encoding: utf-8
N = int(input())
a = list(map(int, input().split()))

cnt = [0] * (10 ** 5 + 2) # +2 for contain (min(ai) - 1) and (max(ai) + 1)

for ai in a:
    cnt[ai] += 1 
    cnt[ai + 1] += 1
    cnt[ai + 2] += 1

print(max(cnt))

Measured memory_bytes: 13964
import java.util.*;
public class Main { 
	static int[] l;
	public static void main(String[] args) {
		Scanner x=new Scanner(System.in);
		int n=x.nextInt();
		for(int i=0;i<n;i++) {
			l=new int[10];
			for(int j = 0; j < 10; j++)l[j]=x.nextInt();
			System.out.println((s(0,0,0)==1)?"YES":"NO");
		}
	}
	static int s(int L, int R, int c) {
		if(c==10)return 1;
		int a=l[c];
		if((c==10)||(L<a&&s(a,R,c+1)==1)||(R<a&&s(L,a,c+1)==1))return 1;
		return 0;
	}
}

Measured memory_bytes: 16524
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <queue>
#include <tuple>
#include <bitset>
#include <map>
#include <math.h>
//　ceil(a/b)   (a + (b - 1))/ b
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
typedef long long ll;
typedef pair<int,int> P;
const int inf = 1012345678;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};

int gcd(int a, int b){
  if (a%b==0){
    return(b);
  }
  else{
    return(gcd(b,a%b));
  }
}


int ans[1000000];
int sum[1000000];

int main(){
  int X;
  cin >> X;
  if(X == 3||X==5||X==7) cout << "YES" << endl;
  else cout << "NO" << endl;
}




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

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

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

    vector<string> s(n);

    rep(i, n) {
      cin >> s.at(i);
    }

    sort(s.begin(), s.end());
    s.erase(unique(s.begin(), s.end()), s.end());

    cout << s.size() << endl;
}

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

int main() {
  int n;
  while(cin >> n && n) {
    vector<int> v(n);
    for(int i = 0; i < n; ++i) cin >> v[i];
    int num = 32;
    int p = 0;
    while(num) {
      int d = (num - 1) % 5;
      assert(d);
      num -= d;
      cout << num << endl;
      if(num) {
        num -= v[p];
        num = max(num, 0);
        p = (p + 1) % v.size();
        cout << num << endl;
      }
    }
  }
  return 0;
}

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

int main(){
  string s;
  cin >> s;
  reverse(s.begin(), s.end());
  vector<string> d = {"dream", "dreamer", "erase", "eraser"};
  for(int i = 0; i < 4; i++){
    reverse(d.at(i).begin(), d.at(i).end());
  }
  bool flag = true;
  for(int i = 0; i < s.size(); ){
    bool flagD = false;
    for(int j = 0; j < 4; j++){
      if(s.substr(i , d.at(j).size()) == d.at(j)){
        i += d.at(j).size();
        flagD = true;
      }
    }
    if(!flagD){
      flag = false;
      break;
    }
  }
  if(flag){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
    int n,m,k,ans=0;
    cin >> n >> m >> k;
    int a[n],b[m];
    rep(i,n) cin >> a[i];
    rep(i,m) cin >> b[i];
    long Sa[n+1],Sb[m+1];
    Sa[0]=0;Sb[0]=0;
    rep(i,n) Sa[i+1] = Sa[i]+a[i];
    rep(i,m) Sb[i+1] = Sb[i]+b[i];
    rep(i,n+1){//Aを何番目まで読むか
        long cur = k-Sa[i];
        if(cur<0) continue;
        else{
            int ok = -1,ng = m+1;
            while(ng-ok>1){
                int mid = (ok+ng)/2;
                if(Sb[mid]<=cur) ok = mid;
                else ng = mid;
            }
            ans = max(ans,i+ok);
        }
    }
    cout << ans << endl;
}


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

int main(){
    int n;
    ll k;
    cin >> n >> k;
    vector<int> a(n);
    vector<int> f(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    for(int i = 0; i < n; i++){
        cin >> f[i];
    }
    sort(a.begin(), a.end());
    sort(f.begin(), f.end());
    reverse(f.begin(), f.end());

    ll l = -1;
    ll r = 1e+12;
    while(l + 1 < r){
        ll m = (l + r) / 2;
        ll cnt = 0;
        for(int i = 0; i < n; i++){
            cnt += max(a[i] - m / f[i], 0LL);
        }
        if(cnt <= k) r = m;
        else l = m;
    }
    cout << r << endl;
    return 0;
}

Measured memory_bytes: 1792
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
        String spt[] =str.split("");
        int count=0;
        int answer =0;
        
        for(int i=0;i<spt.length;i++){
            if(spt[i].equals("A")||spt[i].equals("T")||spt[i].equals("C")||spt[i].equals("G")){
                count+=1;
                if(answer<count){
                
                    answer=count;
                }
            }else{
                count =0;
            }
            
        }
        if(answer<count){
            answer=count;
        }
        System.out.println(answer);
    }
}


Measured memory_bytes: 35596
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        String S = sc.next();
        int res = 0;
        for(int i = 0; i < N - 2; i++) {
            if(S.substring(i,i+3).equals("ABC")) res++;
        }
        System.out.println(res);
    }
}


Measured memory_bytes: 35596
import math
n = int(input())
a = [int(i) for i in input().split()]

chk = [0]*(10**6+1)

for i in range(n):
    #if chk[a[i]] == 1 and a[i] >= 2:
    #    print("not coprime")
    #    exit()
    chk[a[i]] += 1

flag = True

for i in range(2,10**6+1):
    #tmp = i
    kake = 1
    num = 0
    #print(i)
    while i * kake <= 10**6:
        if chk[i*kake] >= 2:
            flag = False
            break
        #print(i)
        if chk[i*kake] == 1:
            if num == 1:
                flag = False
                break
            num = 1
            #break
        kake += 1
gcd_num = math.gcd(a[0],a[1])
        
for i in range(n-2):
    gcd_num = math.gcd(gcd_num,a[i+2])
    
if flag == True:
    print("pairwise coprime")
elif gcd_num == 1:
    print("setwise coprime")
else:
    print("not coprime")

Measured memory_bytes: 204788
n = int(input())
a = [int(_) for _ in input().split()]
even_p = 0
even_n = 0
odd_p = 0
odd_n = 0

cnt = 0
# a[0] positive ver.
if a[0] > 0:
    sum_i = a[0]
else:
    cnt += abs(a[0]-1)
    sum_i = 1

for i in range(1, n):
    if sum_i > 0:
        if sum_i + a[i] < 0:
            sum_i += a[i]
        else:
            cnt += abs(a[i]+sum_i+1)
            sum_i = -1
    elif sum_i < 0:
        if sum_i + a[i] > 0:
            sum_i += a[i]
        else:
            cnt += abs(a[i]+sum_i-1)
            sum_i = 1
ans = cnt

cnt = 0
# a[0] negative ver.
if a[0] < 0:
    sum_i = a[0]
else:
    cnt += abs(a[0]+1)
    sum_i = -1

for i in range(1, n):
    if sum_i > 0:
        if sum_i + a[i] < 0:
            sum_i += a[i]
        else:
            cnt += abs(a[i]+sum_i+1)
            sum_i = -1
    elif sum_i < 0:
        if sum_i + a[i] > 0:
            sum_i += a[i]
        else:
            cnt += abs(a[i]+sum_i-1)
            sum_i = 1

print(min(ans, cnt))

Measured memory_bytes: 14332
#include <stdio.h>
#include <vector>
using namespace std;
const int C=100001, N=101, Inf=1500000000;
typedef long long ll;

int n, k, a, b, c, v;
ll dp[N][C], w, mw;

int main(){
	int j, i;
	scanf ("%d %lld", &n, &mw);
	for (j=1;j<C;j++)	dp[0][j]=Inf;
	for (i=1;i<=n;i++)	{
		scanf ("%lld %d", &w, &v);
		for (j=0;j<C;j++)	{
			dp[i][j]=Inf;
			if (j>=v)	dp[i][j]=min(dp[i-1][j-v]+w, dp[i-1][j]);
			else dp[i][j]=dp[i-1][j];
		}
	}
	
	for (i=C-1;i>=0;i--)	if (dp[n][i]<=mw)	break;
	printf ("%d", i);
	
return 0;}

Measured memory_bytes: 79104
//  ROAD TO GREEN
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <stack>
#include <iomanip>
#include <queue>
#include <set>
#include <bitset>

#define ll long long
#define uint unsigned int
#define ull unsigned ll
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define speedhack() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);


using namespace std;
const ll MAXN = 2e9+2;
const ll SIZE = 2e5+2;
const ll mod = 1e9+7;
int p[SIZE];

int main(){ 
	speedhack()
	int n,k; cin >> n >> k;
	string s; cin >> s;
	for(int i = 0; i < s.size(); i++){
		if(k == i+1){
			s[i] = tolower(s[i]);
		}
	}
	cout << s << endl;
	return 0;
}


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

#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<ll,int> pii;
typedef vector<ll> VL; const int MD = (int)1e9 + 7;
void dbg(){ cerr << "\n"; } template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T, class T2> void amax(T& a,T2 b){ if(a < b) a = b;}

ll gcd(ll x, ll y){ return y? gcd(y, x%y): x; }
int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n, m;
	cin >>n >>m;
	VI a(m);
	rep(i, m) cin >>a[i];
	const VI kt = {6, 2, 5, 5, 4, 5, 6, 3, 7, 6};
	vector<string> dp(n+2);
	sort(a.rbegin(), a.rend());

	rep(i, m) rep(j, n) if(j==0 || sz(dp[j])){
		int su = j+kt[a[i]];
		string ns = dp[j]+ to_string(a[i]);
		if(su > n) continue;
		if((sz(dp[su]) < sz(ns))||(sz(dp[su])<=sz(ns) && ns > dp[su])) dp[su] = ns;
	}
	cout <<dp[n] <<"\n";
	//for(auto x :dp) cerr<<x<<" "; dbg();
	return 0;
}


Measured memory_bytes: 33152
#include<stdio.h>
#include<stdlib.h>
#define NIL NULL

struct node{
  struct node *l;
  struct node *r;
  struct node *p;
  int key;
};

typedef struct node *Node;

Node root;
Node TreeMin(Node x){
}

Node TreeSearch(Node x, int k){
  if(x==NIL||k==x->key) return x;
  if(k<x->key) return TreeSearch(x->l,k);
  else return TreeSearch(x->r,k);
}

Node TreeSuccessor(Node x){
}

void TreeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y
}

void TreeInsert(int k){
  Node y=NIL;
  Node x=root;
  Node z;
  z=malloc(sizeof(struct node));
  z->key=k;
  z->l=NIL;
  z->r=NIL;

  while(x!=NIL){
    y=x;
    if(z->key<x->key) x=x->l;
    else x=x->r;
  }
  z->p=y;
  if(y==NIL) root=z;
  else if(z->key<y->key) y->l=z;
  else y->r=z;
}

void Iorder(Node u){ //Inorder
  if(u!=NIL){
      Iorder(u->l);
      printf(" %d",u->key);
      Iorder(u->r);
  }
}

void Porder(Node u){ //Preorder
  printf(" %d",u->key);
  if(u!=NIL){
    if(u->l!=NIL)Porder(u->l);
    if(u->r!=NIL)Porder(u->r);
  }
}

int main(){
  int n,i,x;
  char array[20];
  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%s",array);
    if(array[0]=='f'){
      scanf("%d",&x);
      Node t = TreeSearch(root,x);
      if(t!=NIL) printf("yes\n");
      else printf("no\n");
    } else if(array[0]=='i'){
      scanf("%d",&x);
      TreeInsert(x);
    } else if(array[0]=='p'){
      Iorder(root);
      printf("\n");
      Porder(root);
      printf("\n");
    } else if(array[0]=='d'){
      scanf("%d",&x);
      TreeDelete(TreeSearch(root,x));
    }
  }
  return 0;
}

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

using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;
#define DEBUG freopen("in.txt", "r", stdin);

struct fastio {
    fastio() {
        ios::sync_with_stdio(false);
        cout << setprecision(10) << fixed;
        cin.tie(0);
    }
};

fastio _fast_io;

constexpr int N = 105;
int a[N];
int n, sum;

int main() {
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        sum += a[i];
    }
    sort(a, a + n);
    if (sum % 10) {
        cout << sum << endl;
    } else {
        for (int i = 0; i < n; ++i) {
            if (a[i] % 10) {
                cout << sum - a[i] << endl;
                exit(0);
            }
        }
        cout << 0 << endl;
    }
    return 0;
}


Measured memory_bytes: 3652
def f(x,y):
  global B
  B[y][x]^=1
  if y>0: B[y-1][x]^=1
  if y<9: B[y+1][x]^=1
  if x>0: B[y][x-1]^=1
  if x<9: B[y][x+1]^=1
  return (x,y)
R=range(10)
n=input()
for _ in [0]*n:
  A=[map(int,raw_input().split()) for _ in R]
  for p in range(1024):
    B=[e[:] for e in A]
    x=[]
    for j in R:
      a=[map(int,list(format(p,'010b'))),B[j-1]][j!=0]
      for i in R:
        if a[i]==1: x.append(f(i,j))
    if sum(B[9])==0: break
  for i,j in x: B[j][i]=1
  for e in B: print " ".join(map(str,e))

Measured memory_bytes: 4296
#include <iostream>

using namespace std;

int main(){
  int W, H, x, y, r;

  cin >> W >> H >> x >> y >> r;
  if(x-r < 0 || x+r > W || y-r < 0 || y+r > H){
    cout << "No" << endl;
  }else{
    cout << "Yes" << endl;
  }

  return 0;
}

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

namespace _065
{
    class Program
    {
        static long mod;
        static void Main(string[] args)
        {
            // 065-C

            var line = Console.ReadLine().Split(' ').Select(x=>long.Parse(x)).ToArray();
            var n = line[0];
            var m = line[1];

            mod=((long)Math.Pow(10,9)+7);

            long ans = 0;
            if(n == m)
            {
                long nc = kaijo(n) % mod;
                ans = (nc * nc * 2) % mod;
            }
            else if (Math.Abs(n - m) <= 1)
            {
                var nm = Math.Min(n,m);
                long nc = kaijo(Math.Min(n,m)) % mod;
                long mc = nc * Math.Max(n,m) % mod;
                ans = (nc * mc) % mod;
            }
            else
            {
                ans = 0;
            }

            Console.WriteLine(ans);
        }

        static long kaijo(long n)
        {
            if(n == 1) return 1;
            return n * kaijo(n - 1)% mod;
        }
    }
}


Measured memory_bytes: 14932
#ifdef DEBUG_IS_VALID
#define DEB 1 
#define _LIBCPP_DEBUG 0
#else
#define DEB 0
#define NDEBUG
#endif

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

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i, x, n) for(int i = x; i >= n; i--)
#define rrep(i, n) RREP(i,n,0)
#define pb push_back
#pragma GCC optimize ("-O3")

using namespace std;

#define DUMPOUT cout
#define dump(...) if(DEB) DUMPOUT<<"  "<<#__VA_ARGS__<<" :["<<__LINE__<<":"<<__FUNCTION__<<"]"<<endl<<"    "; if(DEB) dump_func(__VA_ARGS__)
template<typename T1,typename T2>ostream& operator << (ostream& os, pair<T1,T2> p){cout << "(" << p.first << ", " << p.second << ")"; return os;}
template<typename T>ostream& operator << (ostream& os, vector<T>& vec) { os << "{"; for (int i = 0; i<vec.size(); i++) os << vec[i] << (i + 1 == vec.size() ? "" : ", "); os << "}"; return os; }
template<typename T>ostream& operator << (ostream& os, set<T>& st){cout << "{"; for(auto itr = st.begin(); itr != st.end(); itr++) cout << *itr << (next(itr)!=st.end() ? ", " : ""); cout << "}"; return os;}
template<typename T1,typename T2>ostream& operator << (ostream& os, map<T1,T2> mp){cout << "{"; for(auto itr = mp.begin(); itr != mp.end(); itr++) cout << "(" << (itr->first) << ", " << (itr->second) << ")" << (next(itr)!=mp.end() ? "," : ""); cout << "}"; return os; }

void dump_func(){DUMPOUT << endl;}
template <class Head, class... Tail>void dump_func(Head&& head, Tail&&... tail){ DUMPOUT << head; if (sizeof...(Tail) == 0) { DUMPOUT << " "; } else { DUMPOUT << ", "; } dump_func(std::move(tail)...);}
template<class T> inline bool chmax(T& a,T const& b){if(a>=b) return false; a=b; return true;}
template<class T> inline bool chmin(T& a,T const& b){if(a<=b) return false; a=b; return true;}

using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

const int INF = 1<<29;
const long long LINF=1LL<<59;

int main(){
  string S;
  cin >> S;
  ll ans = LINF;
  ll temp = 0;
  rep(i,S.size()){
    char x;
    if(i%2) x = '0';
    else x = '1';
    if(S[i]!=x) temp++;
  }
  chmin(ans,temp);
  temp = 0;
  rep(i,S.size()){
    char x;
    if(i%2) x = '1';
    else x = '0';
    if(S[i]!=x) temp++;
  }
  chmin(ans,temp);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 512
let rec print_list xss = match xss with
	| []  -> print_newline ()
	| [x] -> Printf.printf "%s\n" x
	| (x :: xs) -> Printf.printf "%s " x; print_list xs
;;

let () = 
	let _ = read_line() in
    read_line() 
    	|> Str.split (Str.regexp_string " ")
    	|> List.map int_of_string
    	|> List.rev
        |> List.map string_of_int
        |> print_list;
;;


Measured memory_bytes: 2324
#include <iostream>
using namespace std;
int main(){
    int n,t,a;
    cin >> n >> t >> a; 
    int tmp = 1e9;
    int ans;
    for(int i = 0; i < n; i++){
        int h; cin >> h;
        if(abs(1000*t - 6*h - 1000*a) < tmp){
            tmp = abs(1000*t - 6*h - 1000*a);
            ans = i+1;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
using namespace std;
#define mod int(1e9+7)
#define rep(i,n) for(int i=0;i<n;i++)
#define reps(i,a,b) for(int i=a;i<=b;i++)
#define repn(i,a,b) for(int i=b-1;i>=a;i--)
#define F first
#define S second
#define pb push_back
#define mp make_pair
typedef long long int ll;

int main()
{ ios_base::sync_with_stdio(false); cin.tie(0);
  ll a,b,n; cin>>a>>b>>n;
  map<ll,ll> x,y;
  for(int i=0;i<n;i++){
   ll s,t,w; cin>>s>>t>>w;
   if(w==1) for(int i=1;i<=s;i++) x[i]=1;
   else if(w==2) for(int i=s+1;i<=a;i++) x[i]=1;
   else if(w==3) for(int i=1;i<=t;i++) y[i]=1;
   else for(int i=t+1;i<=b;i++) y[i]=1;
    } ll ans=0;
    for(int i=1;i<=a;i++){
       for(int j=1;j<=b;j++) if(x[i]==0 && y[j]==0) ans++;
    }
    cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
N, Ma, Mb = map(int, input().split())
abc = [list(map(int, input().split())) for _ in range(N)]
INF = 10 ** 9 + 7
dp = [[[INF] * (Mb * N + 1) for _ in range(N * Ma + 1)] for _ in range(N + 1)]
dp[0][0][0] = 0
for i in range(N):
    for j in range(Ma * N + 1):
        for k in range(Mb * N + 1):
            if j - abc[i][0] >= 0 and k - abc[i][1] >=0:
                dp[i + 1][j][k] = min(dp[i][j - abc[i][0]][k - abc[i][1]] + abc[i][2], dp[i][j][k])
            else:
                dp[i + 1][j][k] = min(dp[i][j][k], dp[i + 1][j][k])

ans = INF
for i in range(1, Ma * N + 1):
    for j in range(1, Mb * N + 1):
        if Ma * j == Mb * i:
            ans = min(ans, dp[N][i][j])

print(ans if ans != INF else -1)

Measured memory_bytes: 121812
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <tuple>
#include <stdio.h>
#include <bitset>
#include <limits.h>
#include <complex>
#include <deque>
#include <iomanip>
using namespace std;
#define pi pair<int32,int32>
#define pl pair<int64,int64>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define en cout << endl //セミコロンつけろ
//#define MM 1000000000
//#define MOD MM+7
const int MM = 1e9;
const int MOD = MM+7;
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
// 'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122
template<typename T>
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
template<typename T>
T LCM(T x,T y){
    T gc = GCD(x,y);
    return x*y/gc;
}

long long pow_mod(long long n,long long k,long long m){
    if (k == 0){
        return 1;
    } else if (k % 2 == 1){
        return pow_mod(n,k-1,m)*n % m;
    } else {
        long long t = pow_mod(n,k/2,m);
        return t*t % m;
    }
}

const int COM_MAX = 500500;
long long fac[COM_MAX],finv[COM_MAX],inv[COM_MAX];
void init(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < COM_MAX; i++){
        fac[i] = fac[i-1]*i%MOD;
        inv[i] = MOD - inv[MOD%i]*(MOD/i)%MOD;
        finv[i] = finv[i-1]*inv[i]%MOD;
    }
}
long long COM(int n,int k){
    if(n < k || n < 0 || k < 0) return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}

int ext_gcd(int a,int b,int &x,int &y){
    int d = a;
    if (b == 0){
        x = 1; y = 0;
    } else {
        d = ext_gcd(b, a%b, y, x);
        y -= (a/b)*x;
    }
    return d;
}

int main(){
    int a,b,x,y; cin >> a >> b;
    int ans = ext_gcd(a,b,x,y);
    cout << x << " " << y << endl;
}


Measured memory_bytes: 3112
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vs = vector<string>;
using vll = vector<long long>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

int dp[5005][5005];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    string s;
    cin >> s;
    int ans = 0;
    for (int i = n-1; i >= 0; --i) {
        for (int j = n-1; j >= 0; --j) {
            if (s[i] == s[j]) dp[i][j] = dp[i+1][j+1] + 1;
            chmax(ans, min(dp[i][j], abs(i-j)));
        }
    }
    cout << ans << endl;
}

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

int main() {
    int A,B,C;
    cin>>A>>B>>C;
    if(A==B){
        if (B==C)
        {
            if (C==A)
            {
                cout<<"No"<<endl;//A=B=C
            }
        }
        else
        {
            cout<<"Yes"<<endl;//A=B
        }
        
    }
    else
    {
        if(B==C)
        {
            cout<<"Yes"<<endl;//B=C
        }
        else if(A==C)
        {
            cout<<"Yes"<<endl;//A=C
        }
        else
        {
            cout<<"No"<<endl;
        }
        
    }
    
    

}


Measured memory_bytes: 256
import sys
from math import *
x=0.0
y=0.0
dir=90
for line in sys.stdin:
    r,t=map(int,line.split(','))
    if r==0 and t==0:break
    x=x+r*cos(2*pi*(dir%360)/360)
    y=y+r*sin(2*pi*(dir%360)/360)
    dir+=-t
print int(x)
print int(y)

Measured memory_bytes: 4432
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

int d[1024][1024];
int dp[1024][1024];
int H,W,N;


int main(){
  while(scanf("%d%d%d",&H,&W,&N) && H||W||N){
    for(int i=0;i<H;i++) for(int j=0;j<W;j++) scanf("%d", &d[i][j]);
    memset(dp, 0, sizeof dp);
    dp[0][0] = N-1;
    for(int i=0;i<H;i++){
      for(int j=0;j<W;j++){
	dp[i+1][j] += (dp[i][j]+(d[i][j]^1))/2;
	dp[i][j+1] += (dp[i][j]+d[i][j])  /2;
      }
    }

    for(int i=0;i<H;i++) for(int j=0;j<W;j++) d[i][j] = (d[i][j]+dp[i][j])%2;
    int y = 0, x = 0;
    while(y < H && x < W){
      if(d[y][x]) x++;
      else y++;
    }
    printf("%d %d\n", y+1, x+1);
  }
  return 0;
}

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

int main() {
  string s;
  cin >> s;
  int cnt = 0;
  rep(i, s.size()) {
    rep(j, s.size()) {
      if(i == j) continue;
      if(s.at(i) == s.at(j)) cnt++;
    }
  }
  if(cnt == 4) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define LL long long
#define LD long double
#define REP(i,a,b) for(int i=(int)a;i<=(int)b;i++)
#define RFOR(i,a,b) for(int i=(int)a;i>=(int)b;i--)
#define int LL
using namespace std;

typedef pair<int,int> PII;
typedef pair<int,PII> PIII;
typedef vector<int> VI;

const int MX = 1e5+1;

int freq[5];
int ma[4];

signed main()
{
	//freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
    //ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    
    REP(i,0,2)
    {
    	int x,y;
    	cin>>x>>y;
    	freq[x]++;
    	freq[y]++;
    }
    REP(i,1,4)
    	ma[freq[i]]++;
    if(ma[1]==2 && ma[2]==2)
    	cout<<"YES";
    else
    	cout<<"NO";
    return 0;
}


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

int main()
{
    int N;
    cin >> N;
    int a[N] = {0};
    for(int i = 0; i < N; i++) cin >> a[i];

    int count = 0;
    for(int i = 0; i < N; i++)
    {
        bool flag = true;
        while(flag)
        {
            if(a[i] % 2 == 0)
            {
                count++;
                a[i] /= 2;
            }
            else
            {
                flag = false;
            }
        }
    }

    cout << count;
    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);(i)>=0;(i)--)
#define FOR(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define ALL(x) x.begin(),x.end()
#define REVERSE(x) reverse(x.begin(),x.end())
#define SORT(x,n) sort(x,x)
#define P pair<int,int>
typedef long long LL;
const int INF=1000000007;
using namespace std;
int gcd(int a,int b){
  if(a%b==0){return b;}
  else{return gcd(b,a%b);}
}
int main(){
int N;
cin>>N;
vector<int> a(N);
int index=0;
int max=0;
REP(i,N){
    cin>>a[i];
}
REP(i,N){
if(a[i]>max){
    max=a[i];
    index=i;
}
}
sort(ALL(a));
if(a[N-1]==a[N-2]){
    REP(i,N){
        cout<<a[N-1]<<endl;
    }
}
else{
REP(i,N){
    if(i!=index){
        cout<<a[N-1]<<endl;
    }
    else{
        cout<<a[N-2]<<endl;
    }
}
}
}

Measured memory_bytes: 2432