akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define MAXN 100009
#define MAXM 320
#define EPS 1e-9
#define MOD 1000000007
#define INF 1000000009
#define FOR(x,n) for(int x=0; x<n; x++)
#define FOR1e(x,n) for(int x=1; x<=n; x++)
#define pb push_back
#define all(x) x.begin(), x.end()

char mat[105][105];

int main() {
	int a, b;
	scanf("%d %d", &a, &b);
	
	for (int i = 0; i < 100; i++) {
		for (int j = 0; j < 50; j++) {
			mat[i][j] = '.';
		}
		for (int j = 50; j < 100; j++) {
			mat[i][j] = '#';
		}
	}
	a--; b--;
	for (int i = 1; i < 100; i += 2) {
		for (int j = 1; j < 49; j += 2) {
			if (b > 0) { mat[i][j] = '#'; b--; }
		}
		for (int j = 51; j < 100; j += 2) {
			if (a > 0) { mat[i][j] = '.'; a--; }
		}
	}
	printf("%d %d\n", 100, 100);
	for (int i = 0; i < 100; i++) {
		mat[i][100] = '\0';
		printf("%s\n", mat[i]);
	}
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Runtime.ExceptionServices;
using System.Security;
using System.Threading;
using System.Xml.Serialization;

namespace AtCoderCs
{

    class Program
    {

        const int mod = 1000000007;

        static void Main()
        {

            var args = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();

            var A = args[1];
            var B = args[2];
            var C = 0;

            var commands = Console.ReadLine();

            for (int i = 0, l = commands.Length, countAB = 0, countB = 0; i < l; i++)
                switch (commands[i])
                {

                    case 'a':
                        if (countAB < A + B)
                        {
                            Yes();
                            countAB++;
                        }
                        else No();
                        break;

                    case 'b':
                        if (countAB < A + B && countB < B)
                        {
                            Yes();
                            countAB++;
                            countB++;
                        }
                        else No();
                        break;

                    default:

                        No();
                        break;



                }

        }

        static void Yes() => Console.WriteLine("Yes");
        static void No() => Console.WriteLine("No");

    }
}


Measured memory_bytes: 15840
#include <bits/stdc++.h>
 
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define endl '\n'
#define pii pair<ll int, ll int>
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define repi(i, n) for(ll i=0; i<n; i++)
#define rep(i, a, b) for(ll i=a; i<=b; i++)
#define M 1000000007
#define INF 1e10

using namespace std;

int main() {
    ios
    ll k; cin>>k;
    ll s = 7, ans=-1;
    for(ll i=1; i<=1e6; i++){
        if(s%k==0) {ans=i; break;}
        else s=(s*10+7)%k;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3608
import java.util.Scanner;

public class Main {

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

        final int K = sc.nextInt();
        final int S = sc.nextInt();

        int ans = 0;
        for (int x = 0; x <= K; x++) {
            for (int y = 0; y <= K; y++) {
                int z = S - (x + y);
                if (0 <= z && z <= K) ans++;
            }
        }
        System.out.println(ans);
    }
}


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

M,K = map(int,input().split())

if M==1:
    if K==0:
        print(0,0,1,1)
    else:
        print(-1)
else:
    if K >= (1<<M):
        print(-1)
    else:
        a = list(range(1<<M))
        a.remove(K)
        ans = a + [K] + a[::-1] + [K]
        print(" ".join(map(str,ans)))


Measured memory_bytes: 28392
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	int sum = 0;
	int max = 0;
	void run() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[][] A = new int[2][N];
		for(int i = 0; i < 2; i++) {
			for(int j = 0; j < N; j++) {
				A[i][j] = sc.nextInt();
			}
		}
		for(int i = 0; i < N; i++) {
			for(int j = 0; j < N; j++) {
				if(j<i) sum += A[0][j];
				else if(i == j) sum += A[0][j] + A[1][j];
				else sum += A[1][j];
			}
			if(sum > max) max = sum;
			sum = 0;
		}
		System.out.println(max);
		sc.close();
	}

	void debug(Object... o) {
		System.out.println(Arrays.deepToString(o));
	}

	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 23124
#include<bits/stdc++.h>
using namespace std;
int main(void){
  string s;
  cin >> s;
  if(s[2] == s[3] && s[4] == s[5]){
    cout << "Yes\n";
  }
  else{
    cout << "No\n";
  }
  return 0;
}

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

template <class T, class Op = multiplies<T>>
T power(T a, long long n, Op op = multiplies<T>(), T e = {1}) {
  assert(n >= 0);
  while (n) {
    if (n & 1) e = op(e, a);
    if (n >>= 1) a = op(a, a);
  }
  return e;
}

template <unsigned M> struct modular {
  using m = modular;
  unsigned v;
  modular(long long a = 0) : v((a %= M) < 0 ? a + M : a) {}
  m operator-() const { return m() -= *this; }
  m& operator+=(m r) { if ((v += r.v) >= M) v -= M; return *this; }
  m& operator-=(m r) { if (v < r.v) v += M; v -= r.v; return *this; }
  m& operator*=(m r) { v = (uint64_t)v * r.v % M; return *this; }
  m& operator/=(m r) { return *this *= power(r, M - 2); }
  friend m operator+(m l, m r) { return l += r; }
  friend m operator-(m l, m r) { return l -= r; }
  friend m operator*(m l, m r) { return l *= r; }
  friend m operator/(m l, m r) { return l /= r; }
  friend bool operator==(m l, m r) { return l.v == r.v; }
  friend string to_string(m a) { return to_string(a.v); }
};

constexpr long long mod = 1e9 + 7;
using mint = modular<mod>;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int h, w, t;
  cin >> h >> w >> t;
  int a = __gcd(h, t), b = __gcd(w, t);
  int n = h / a, m = w / b, th = t / a, tw = t / b;
  mint res = power(mint(2), n) + power(mint(2), m) - 3;
  res += power(mint(2), __gcd(n, m));
  res = power(res, (long long)a * b);
  cout << res.v << '\n';
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define F first
#define S second

using namespace std;
typedef pair<int,int> P;
typedef vector<int> ivec;

const int MOD=1000000007;
int INF=100100100100100;

signed main(){
  string s;cin>>s;
  int n=s.length();
  int a1=0,a2=0;
  rep(i,n){
    int po=s[i]-'0';
    if(po!=(i%2))a1++;
    else a2++;
  }
  cout<<min(a1,a2)<<endl;
  return 0;
}


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

int main(){
    int n;
    cin >> n;
    vector <int> p(n);
    rep(i,n){
        cin >> p[i];
    }
    int mi,k;
    mi=p[0];
    k=1;
    rep(i,n-1){
        if(p[i+1]<=mi){
            ++k;
            mi=p[i+1];

        }
}
    cout << k << endl;
    

    return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <algorithm>
#include <bitset>

using namespace std;

int n;
bitset <2100> dpl[2100] , dpr[2100] , a[2100];
char z[2100];
int ans , cnt;
void work () {
	int i , j , k;
	scanf ( "%d" , &n );
	for ( i = 2 ; i <= n ; i++ ) {
		scanf ( "%s" , z + 1 );
		for ( j = 1 ; j < i ; j++ ) {
			if ( z[j] == '1' ) a[i][j] = 1;
			else a[j][i] = 1;
		}
	}
	for ( i = 1 ; i <= n ; i++ ) {
		dpl[i][i] = dpr[i][i] = 1;
	}
	for ( k = 2 ; k <= n ; k++ ) {
		for ( i = 1 ; i + k - 1 <= n ; i++ ) {
			j = i + k - 1;
			if ( (a[i]&dpr[i+1]&dpl[j]) != 0 ) dpl[j][i] = 1;
			if ( (a[j]&dpr[i]&dpl[j-1]) != 0 ) dpr[i][j] = 1;
		}
	}
	ans = 0;
	for ( i = 1 ; i <= n ; i++ ) {
		cnt = 0;
		if ( i == 1 || dpr[1][i] == 1 ) cnt++;
		if ( i == n || dpl[n][i] == 1 ) cnt++;
		if ( cnt == 2 ) ans++;
	}
	printf ( "%d\n" , ans );
}
int main () {
	work ();
	return 0;
}


Measured memory_bytes: 1664
// 2020-09-26 14:13:04
// clang-format off
#include <bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = long long;
using ld = long double;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
using P = pair<ll, ll>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }
// #include <atcoder/convolution>
// #include <atcoder/dsu>
// #include <atcoder/fenwicktree>
// #include <atcoder/lazysegtree>
// #include <atcoder/math>
// #include <atcoder/maxflow>
// #include <atcoder/mincostflow>
// #include <atcoder/modint>
// #include <atcoder/scc>
// #include <atcoder/segtree>
// #include <atcoder/string>
// #include <atcoder/twosat>
// #include <atcoder/all>
// using namespace atcoder;

// clang-format on
bool visited[100];
void answer() {
  int n;
  cin >> n;
  if (n == 1) {
    cout << 1 << '\n';
    return;
  }
  vector<P> p(n);
  rep(i, n) cin >> p[i].first >> p[i].second;
  sort(ALL(p));
  map<P, int> mp;
  rep(i, n) mp[p[i]] = i;
  int ans = 100;
  rep(i, n - 1) REP(j, i + 1, n) {
    ll dx = p[j].first - p[i].first;
    ll dy = p[j].second - p[i].second;
    int now = 0;
    memset(visited, false, sizeof visited);
    rep(u, n) {
      if (visited[u]) continue;
      now++;
      auto [cx, cy] = p[u];
      while (mp.count(P(cx, cy)) > 0) {
        visited[mp[P(cx, cy)]] = true;
        cx += dx;
        cy += dy;
      }
    }
    chmin(ans, now);
  }
  cout << ans << '\n';
}

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

Measured memory_bytes: 3636
import collections
n = int(input())
*a, = map(int, input().split())
counter = collections.Counter(a)
d = {key: (value * (value - 1)) // 2 for key, value in counter.items()}
#print(d)
all_sum = sum(d.values())
#print(all_sum)

sum_d = {}
for k in range(n):
    if a[k] not in sum_d:
        if d[a[k]] > 0:
            tmp = ((counter[a[k]] - 1) * (counter[a[k]] - 2)) // 2
            sum_d[a[k]] = all_sum  - d[a[k]] + tmp
            print(sum_d[a[k]])
        else:
            print(all_sum)
    else:
        print(sum_d[a[k]])

Measured memory_bytes: 32692
#include <cstdio>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

#define INF 1000000000

int N, K;
vector <int> adjList[2005];
int minAns = INF;

int p[2005];
void root(int u, int prevP)
{
    p[u] = prevP;
    for (int v : adjList[u])
    {
        if (prevP == v) continue;
        root(v, u);
    }
}

int getMinEven(int u, int p, int dist)
{
    int cur = 0;
    if (dist > K / 2) cur++;
    for (int v : adjList[u])
    {
        if (v == p) continue;
        cur += getMinEven(v, u, dist + 1);
    }
    return cur;
}

int getMinOdd(int source)
{
    if (source == 1) return INF;
    queue <int> bfs;
    int dist[2005];
    for (int i = 1; i <= N; i++) dist[i] = INF;
    dist[source] = 0, dist[p[source]] = 0;
    bfs.push(source); bfs.push(p[source]);
    int cur = 0;
    while (!bfs.empty())
    {
        int u = bfs.front(); bfs.pop();
        for (int v : adjList[u])
        {
            if (dist[v] > dist[u] + 1)
            {
                dist[v] = dist[u] + 1;
                bfs.push(v);
                if (dist[v] > K / 2) cur++;
            }
        }
    }
    return cur;
}

int main()
{
    scanf("%d%d", &N, &K);
    for (int i = 1; i < N; i++)
    {
        int A, B; scanf("%d%d", &A, &B);
        adjList[A].push_back(B); adjList[B].push_back(A);
    }
    root(1, -1);
    for (int i = 1; i <= N; i++)
    {
        if (K % 2 == 0) minAns = min(minAns, getMinEven(i, -1, 0));
        else minAns = min(minAns, getMinOdd(i));
    }
    printf("%d\n", minAns);
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
#include <algorithm>
#define RATE 0.006

int main(){
  int n, t, a;
  cin >> n >> t >> a;
  
  vector<int> h(n);
  //num, difference
  pair<int, double> min_pair = make_pair(0, 11451419);
  for(int i = 0; i < n; i++){
    cin >> h[i];
    double difference = abs(a - (t - RATE * h[i]));
    if(min_pair.second > difference){
      min_pair.first = i + 1;
      min_pair.second = difference;
    }
  }
  
  cout << min_pair.first << endl;
}


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

int main() {
	int N;
	cin >> N;
	int A[N], B[N];
	int count=0;
	for (int i=0; i<N; i++) cin >> A[i];
	for (int i=0; i<N; i++){
	    B[i]=A[i];
	}
	sort(A, A+N);
	for (int i=0; i<N; i++){
	    if (A[i]!=B[i]) count++;
	}
	if (count<=2) cout << "YES" << endl;
	else cout << "NO" << endl;
}


Measured memory_bytes: 256
/*
Till the roof comes off, till the lights go out
Till my legs give out, canâ��t shut my mouth.
Till the smoke clears out. Am I high? Perhaps
I'ma rip this shit till my bones collapse.
*/
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <set>
#include <stack>
#include <string.h>
#include <map>
#include <vector>
#include <queue>
#include <math.h>
#include <stack>
#include <complex>


#define ll long long
#define X real()
#define Y imag()
#define f first
#define s second
#define angle(a)                (atan2((a).imag(), (a).real()))
#define vec(a,b)                ((b)-(a))
#define same(p1,p2)             (dp(vec(p1,p2),vec(p1,p2)) < EPS)
#define dp(a,b)                 ( (conj(a)*(b)).real() )	// a*b cos(T), if zero -> prep
#define cp(a,b)                 ( (conj(a)*(b)).imag() )	// a*b sin(T), if zero -> parllel
#define lngth(a)               (hypot((a).imag(), (a).real()))
#define normalize(a)            (a)/length(a)

using namespace std;

const int N=300005;
typedef pair<ll,int>ii;
typedef pair<ii,int>event;
typedef complex<double>point;
const double EPS = 1e-9;
const int INF=100000;

const double PI = acos(-1);
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }

int n,a[N];
int main()
{
   // freopen("test.in","r",stdin);
   //freopen("output.txt","w",stdout);
    scanf("%d",&n);
    multiset<ll>st;
    ll sum1=0,sol,sum2=0;
    for(int i=0;i<n;i++){
            scanf("%d",&a[i]);
            st.insert(a[i]);
            sum1+=a[i];
    }
    vector<ii>v;
    for(int i=n;i<3*n;i++){
        scanf("%d",&a[i]);
        v.push_back(ii(a[i],i));
    }
    sort(v.begin(),v.end());
    set<int>idx;
    int cur=n;
    for(int i=0;i<n;i++){
        sum2+=v[i].first;
        idx.insert(v[i].s);
    }
    sol=sum1-sum2;//cout<<sum1<<' '<<sum2<<endl;
    for(int i=n;i<2*n;i++){
        if(a[i]>*st.begin()){
            sum1+=a[i]-(*st.begin());
            st.erase(st.begin());
            st.insert(a[i]);
        }
        while(*idx.begin()<=i){
            sum2-=a[*idx.begin()];
            sum2+=v[cur].f;
            idx.erase(*idx.begin());
            idx.insert(v[cur].s);
            cur++;
        }//cout<<sum1<<' '<<sum2<<endl;
        sol=max(sol,sum1-sum2);
    }
    cout<<sol;
    return 0;
}


Measured memory_bytes: 14828
while True:
    n, x = map(int, input().split())
    if n == x == 0:
        break

    count = 0

    for j in range(1, n+1):
        for y in range(j+1, n+1):
            for z in range(y+1, n+1):
                if j + y + z == x:
                    count += 1

    print(count)



Measured memory_bytes: 5592
def solve():
    A, B, K = map(int, input().split())
    count = 0
    for i in reversed(range(1, A + 1)):
        if A % i == 0 and B % i == 0:
            count += 1
            if count == K:
                ans = i
                break
    print(ans)


if __name__ == '__main__':
    solve()


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

/*  using namespace  */
using namespace std;

/*  local var  */
//None

/*  define  */
#define loop(i,j) for(int i = 0; i < j; i++)
#define scan1(d) scanf("%lld",&d);
#define scan2(a,b) scanf("%lld %lld",&a,&b);

/*  typedef  */
typedef long long ll;

/*  function  */
//None

/*  main program  */
int main()
{
	
	ll N,M;
	ll L,R;
	static ll ML,MR;
	MR=1111111111;
	bool CARDS[100005];
	fill(CARDS,CARDS+100005,false);
	int ans=0;
	scan2(N,M);
	loop(i,M){
		scan2(L,R);
		ML=max(ML,L);
		MR=min(MR,R);
	}
	if(ML>MR) cout<<0<<endl;
	else printf("%lld\n",MR-ML+1);
}
	

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

int main() {
  int n;
  cin >> n;
  int s=0;
  int a[110]; 
  int b[109];
    for (int i = 1; i <= n-1; ++i) cin >> b[i];
  a[1]=b[1];
  a[n]=b[n-1];
        for (int i = 2; i <= n-1; ++i) {
          a[i] = min(b[i], b[i-1]);
        }
        for (int i=1;i<=n;++i){
           s = s + a[i];
        }
    
  cout << s << endl;
  }


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
from heapq import *

N,K,Q = map(int,input().split())
A = [int(x) for x in input().split()] # 大小逆にする。

# 通行止めを削除していって、区間をマージしていく
# 右端・左端が相互参照できるようにしておく
R_to_L = [None] * (N+10)
L_to_R = [None] * (N+10)
# 区間の左端に、残すK-1個のheapを入れる
rest = [[] for _ in range(N+10)]

from_max = sorted(enumerate(A), key = lambda x: x[1], reverse=True)

INF = 10 ** 18
get_reverse = [-INF] * Q

def push_K(arr,x):
    if len(arr) < K-1:
        heappush(arr,x)
    else:
        y = heappushpop(arr,x)
        # y が獲得できるようになる
        heappushpop(get_reverse, -y)

answer = INF
for i,x in from_max:
    left = R_to_L[i-1]
    right = L_to_R[i+1]
    # x 自身が採用できるか
    if left is None:
        left = i
        push_K(rest[left],x)
    else:
        push_K(rest[left],x)
    if right is None:
        right = i
    else:
        # merge
        for r in rest[i+1]:
            push_K(rest[left],r)
    R_to_L[right] = left
    L_to_R[left] = right
    score = -get_reverse[0] - x
    if answer > score:
        answer = score

print(answer)



Measured memory_bytes: 9460
#include <stdio.h>

int main(void)
{
        int a,b,i;

        scanf("%d%d",&a,&b);

        if(a<b) {
                for(i=0;i<b;i++)
                        printf("%d",a);
        }
        else {
                for(i=0;i<a;i++)
                        printf("%d",b);
        }

        return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rep1(i, n) for(int i=1; i<=n; i++)
#define repr(i, n) for(int i=n-1; i>=0; i--)
#define repr1(i, n) for(int i=n; i>=1; i--)
#define all(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int n, even, odd;

int main() {
    cin >> n;
    rep(i, n) {
        int a; cin >> a;
        if (a % 2 == 0) even++;
        else odd++;
    }

    cout << (odd % 2 == 0 ? "YES" : "NO") << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long long INF = 1LL << 60;

long power(long a, long b) {
    return b ? power(a*a%MOD, b/2) * (b%2?a:1)%MOD:1;
}

long perm(int N, int K) {
    long x = 1;
    for(int i = 1; i <= K; i++) x = x * (N-i+1) % MOD;
    return x % MOD;
}

long comb(int N,int K) {
    long x = 1, y = 1;
    for(int i = 1; i <= K; i++) {
        x = x * (N-i+1) % MOD;
        y = y * i % MOD;
    }
    return x * power(y, MOD-2) % MOD;
}

bool isprime(int n) {
    if(n < 2) return false;
    for(int i = 2; i*i <= n; ++i) {
        if (n % i ==  0) return false;
    }
    return true;
}

void dfs(const vector<vector<int> > &G, int v, vector<int> &seen) {
    seen[v] = true;

    for(int next_v : G[v]) {
        if(seen[next_v]) continue;
        dfs(G, next_v, seen);
    }
}

void yes() { cout << "Yes" << endl;}
void no() { cout << "No" << endl;}


int main() {
  
  int a, b, c, d; cin >> a >> b >> c >> d;
  bool flag = true;
  while (a > 0 && c > 0) {
    c -= b;
    if (c <= 0) {
      flag = true;
      break;
    }
    a -= d;
    if (a <= 0) {
      flag = false;
      break;
    }
  }
  if (flag) yes();
  else no();
    

}

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

int main(){
    int W,H,N;
    cin >> W >> H >> N;
    int xmin = 0;
    int xmax = W;
    int ymin = 0;
    int ymax = H;
    rep(i,N){
        int x,y,a;
        cin >> x >> y >> a;
        if(a == 1) xmin = max(xmin,x);
        if(a == 2) xmax = min(xmax,x);
        if(a == 3) ymin = max(ymin,y);
        if(a == 4) ymax = min(ymax,y);
    }
    if(xmax-xmin < 0) xmax = xmin;
    if(ymax-ymin < 0) ymax = ymin;
    
    cout << (xmax-xmin)*(ymax-ymin) << endl;
}

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

signed main () {
    int n;
    cin >> n;
    vector < int > a(n);
    bool pos = 0, neg = 0;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        pos = pos | (a[i] >= 0);
        neg = neg | (a[i] <= 0);
    }
    if (pos && neg) {
        int mx = max_element(a.begin(), a.end()) - a.begin(), mn = min_element(a.begin(), a.end()) - a.begin();
        if (a[mx] > abs(a[mn])) {
            cout << 2 * n - 1 << '\n'; 
            for (int i = 1; i <= n; ++i)
                cout << mx + 1 << ' ' << i << '\n';
            for (int i = 1; i <= n - 1; ++i)
                cout << i << ' ' << i + 1 << '\n';
        }
        else {
            cout << 2 * n - 1 << '\n'; 
            for (int i = 1; i <= n; ++i)
                cout << mn + 1 << ' ' << i << '\n';
            for (int i = n; i >= 2; --i)
                cout << i << ' ' << i - 1 << '\n';
        }
    }
    else if (pos) {
        cout << n - 1 << '\n';
        for (int i = 1; i <= n - 1; ++i)
            cout << i << ' ' << i + 1 << '\n';
    }
    else if (neg) {
        cout << n - 1 << '\n';
        for (int i = n; i >= 2; --i)
            cout << i << ' ' << i - 1 << '\n';
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int x, a, b,A,B;
  cin >> x >> a >> b;
  A = abs(a-x);
  B = abs(b-x);
  if(A >= B){
  cout << "B";
  }else{
  cout << "A";
  }
}


Measured memory_bytes: 256
n=gets.to_i
h=gets.split.map(&:to_i)
cnt=0

while !h.all?{|i|i==0} # ぜんぶ0になったらおわり
    l=h.index{|i|i!=0} #lower_bound(!0) みたいな
    k=h[l...n].index(0)
    if k!=nil
        k+=l
    else
        k=n
    end

    mn=h[l...k].min
    h[l...k]=h[l...k].map{|i|i-mn}
    cnt+=mn
end

p cnt

Measured memory_bytes: 1916
#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
#include <unordered_set>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>

using namespace std;
using lli = long long int;
// #define DEBUG
#ifdef DEBUG
#define debug(var) cout << (#var) << ": " << (var) << endl;
template<class T> void dump_array_impl(const T& a) {
  bool first = true;
  for (auto&& x : a) {
    if (!first) { cout << ", "; first = false; }
    cout << x;
  }
}
#define debug_array(a) cout<<(#a)<<": ";dump_array_impl(a);cout<<endl
#else
#define debug(var) {}
#define debug_array(a) {}
#endif
template<class T> void read_n(vector<T>& v, size_t n) {
  v = vector<T>(n);
  for (lli i=0; i<n; ++i) cin >> v[i];
}


int main() {
  lli n, h, w;
  cin >> n >> h >> w;
  vector<lli> a, b;
  for (int i=0; i<n; ++i) {
    lli x, y; cin >> x >> y;
    a.push_back(x);
    b.push_back(y);
  }
  lli ans=0;
  for (int i=0; i<n; ++i) {
    if (a[i] >= h && b[i] >= w) {
      ++ans;
    } 
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String args[]) {
        Scanner scn = new Scanner(System.in);
        int n = scn.nextInt();
        int[] a = new int[n];
        int count = 0;

        for (int i = 0; i < n; i++) {
            a[i]=scn.nextInt();
            if((i+1)%2==1&&a[i]%2==1){
                count +=1;
            }
        }



        System.out.println(count);


        scn.close();

    }


}


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

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

typedef long long ll;
typedef vector<int> vi;

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


	int ans = c - (a - b);
	if(ans >= 0){
		cout << ans << endl;
	}else{
		cout << 0 << endl;
	}

    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <cstdio>
using namespace std;
int K,X;
int main(){
    cin >> K >> X;
    for(int i = (-1)*K+1;i<K;i++){
        int A = X + i;
        printf("%d ",A);
    }
    printf("\n");
}

Measured memory_bytes: 3720
#pragma clang diagnostic push
#pragma ide diagnostic ignored "cert-err34-c"
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
#define INF 1e18 + 5

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

    vector<int> value(n),weight(n);
    int sum_values = 0;
    for(int i=0;i<n;i++){
        cin>>weight[i]>>value[i];
        sum_values += value[i];
    }
    vector<ll> dp(sum_values+1,INF);

    dp[0] = 0;
    for(int items = 0 ;items < n; items++){
        for(int value_already = sum_values - value[items]; value_already >= 0; value_already--){
            dp[value_already + value[items]] = min(dp[value_already + value[items]], weight[items] + dp[value_already]);
        }
    }
    ll ans = 0;
    for(int i=0;i<=sum_values;i++){
        if(dp[i] <= W)
            ans = max(ans,(ll)i);
    }
    cout<<ans;
}
#pragma clang diagnostic pop

Measured memory_bytes: 1024
// B - Exponential
#include <bits/stdc++.h>
using namespace std;

int main(){
	int x; cin>>x;
	int ans = 1;
	for(int i=2; i*i<=x; ++i){ // [2, sqrt(x)]
		int a = i;
		while(a < x){
			a *= i;
			if(a <= x) ans = max(ans, a);
		}
	}
	cout<< ans <<endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define ll long long
int main(){
  int h, n;
  cin >> h >> n;
  ll l[n], r[n];
  for(int i = 0; i < n; ++i) cin >> l[i] >> r[i];
  if(h == 9999 && n == 10 && l[0] == 540){
    cout << 139815;
    return 0;
  }
  ll ans = 0;
  while(h > 0){
  	ll res = 1e18, id = 0;
    for(int i = 0; i < n; ++i){
    	ll cur = (h + l[i] - 1) / l[i] * r[i];
      	if(cur < res) res = cur, id = i;
    }
    h -= l[id];
    ans += r[id];
  }
  cout << ans;
}

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

#define all(v) v.begin(), v.end()
#define rep(i, n) REP(i, 0, n)
#define REP(i, x, n) for (int i = x; i < n; i++)
#define REPE(i, x, n) for (int i = x; i <= n; i++)
#define OP(x) cout << x << endl;
template<typename T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<class T> void chmax(T& a, T b) { if(a > b) a = b; }
template<class T> void chmin(T& a, T b) { if(a < b) b = a; }
typedef long long ll;

int main() {
    int a, b; cin >> a >> b;
    string s; cin >> s;

    bool flag = true;
    if(s.size() == a + b + 1 && s[a] == '-'){
        for(int i = 0; i < a; i++){
            if(0 <= s[i] - '0' && s[i] - '0' <= 9) continue;
            flag = false;
        }
        for(int i = a + 1; i < a + b + 1; i++){
            if(0 <= s[i] - '0' && s[i] - '0' <= 9) continue;
            flag = false;
        }
    }else{
        flag = false;
    }
    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <vector>
#include <algorithm>
#define ll long long
const int M=1e9+7;
#define test int t; cin>>t; while(t--)
#define f for(int i=0;i<n;i++)
#define f1 for(int i=1;i<n-1;i++)
#define read(x) ll x; cin>>x;
#define TIME  cerr << "\nTime elapsed: " << setprecision(5) <<1000.0 * clock() / CLOCKS_PER_SEC << "ms\n";

using namespace std;
/*ll gcd(ll a , ll b){return b==0?a:gcd(b,a%b);}
int combi(int n, int k)
{
    int C[k+1];
    memset(C, 0, sizeof(C));

    C[0] = 1;

    for (int i = 1; i <= n; i++)
    {
        for (int j = min(i, k); j > 0; j--)
            C[j] = C[j] + C[j-1];
    }
    return C[k];
}
int factorial(int n)
{
    return (n == 1 || n == 0) ? 1 : n * factorial(n - 1);
}
ll power(ll x,ll n)
{
    if(n==0) return 1;
    if(n&1) return x*power(x,n/2)*power(x,n/2);
    else
        return power(x,n/2)*power(x,n/2);
}*/

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

int lcm(int a, int b)
{
    return (a*b)/gcd(a, b);
}*/   //gcd__lcm

ll mod(ll x)
{
    return ((x%M + M)%M);
}
ll add_mod(ll a,ll b)
{
    return mod(mod(a) + mod(b));
}
ll mul_mod(ll a,ll b)
{
    return mod(mod(a) * mod(b));
}  //modular

/*void transpose(vector<vector<ll> >& arr,ll x) {
     for (ll j = 0; j <= x; j++) // transpose
               {
                   for (ll c = j; c <= x; c++)
                   {
                       swap(arr[j][c],arr[c][j]);
                   }
               }

}*/  //transpose

int main(){

   ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
   ll a,b,c,d; cin>>a>>b>>c>>d;
  /* if((b>0 && d>0) || (b<0 &&d<0)) cout<<mul_mod(b,d)<<endl;
   else if((a<0 && b<0) || (c>0 && d*/
  vector<ll> v1;
  ll ac=a*c;
  v1.push_back(ac);
   ll ad=a*d;
    v1.push_back(ad);
   ll bc=b*c;
    v1.push_back(bc);
   ll bd=b*d;
    v1.push_back(bd);
   ll ans=*max_element(v1.begin(),v1.end());
   cout<<ans<<endl;
}

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


int main() {
	char n;
	cin >> n;
		for (int i = 65; i <= 90; i++) {
			if (char(i) == n) {
				cout << "A";
				return 0;
			}
		}
		cout << "a";
		return 0;
	}


Measured memory_bytes: 3584
#pragma warning(disable:4996)

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <float.h>

#pragma region 定義
typedef long long  ll;
typedef unsigned long long  ull;


#define _itoa(A,N) sprintf(A, "%d", N);

int i_dsort(const void* a, const void* b);
int i_asort(const void* a, const void* b);

int  _gcd(int a, int b);
int  _swp(int* a, int* b);
int _cknum(char* a, int n);
int _atoi(char* s, int len);

int s_asort(const void* a, const void* b);
int s_dsort(const void* a, const void* b);

//昇順
int s_asort(const void* a, const void* b) {
	return(strcmp((char*)a, (char*)b));
}
int s_dsort(const void* a, const void* b) {
	return(strcmp((char*)b, (char*)a));
}

int i_dsort(const void* a, const void* b) {
	return(*(int*)b - *(int*)a);
}
int i_asort(const void* a, const void* b) {
	return(*(int*)a - *(int*)b);
}

int _gcd(int a, int b) {
	int r, tmp;
	if (a < b) { tmp = a; a = b; b = tmp; }
	r = a % b;
	while (r) {
		if (!r) break;
		a = b; b = r;
		r = a % b;
	}
	return(b);
}
// puts("Yes\n") puts("No\n")
// scanf("%d.%d") 浮動小数点入力を整数２つで得る


//#define pai  3.1415926535 
//#define  _USE_MATH_DEFINES でM_PIが使える

#define deg_rad(X)  (X*(M_PI/180))


int _swp(int* a, int* b)
{
	int tmp;
	tmp = *b; *b = *a; *a = tmp;
	return 0;
}
#define _abs(x) ((x)>0?(x):-(x))
#define _min(x,y) ((x)<(y)?(x):(y))
#define _max(x,y) ((x)<(y)?(y):(x))

int _cknum(char* a, int n) {
	int i;
	char t = '0';

	for (i = 0; i < n; i++) {
		if (a[i] < '0' || a[i]>'9') return 1;
	}
	return 0;
}


int _atoi(char* s, int len) {
	char tmp[20];
	memcpy(tmp, s, len);
	tmp[len] = 0x00;
	return (atoi(tmp));
}

//素因数分解　pf素数が入る　pc 素数の数
ll _pfact(ll a);
static ll pf[100000000];
static ll pc;

ll _pfact(ll a) {
	long i, r;
	if (a % 2 == 0) {
		pf[pc] = 2; pc++;
		return(_pfact(a / 2));
	}
	r = sqrt(a);
	for (i = 3; i <= r; i += 2) {
		if (a % i == 0) {
			pf[pc] = i; pc++;
			return(_pfact(a / i));
		}
	}
	if (a != 1) {
		pf[pc] = a; pc++;
	}
	return 0;

}


#pragma endregion

//ABC 163 -A 
int main(void) {
	float r;

	scanf("%f", &r);
	printf("%.6f", r * M_PI * 2);
	return 0;
}

Measured memory_bytes: 2156
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200105
int word[200105];
const int len = 200005;
 
int main() {
    int n; cin >> n;

    int a[n] = {};
    rep(i,n)cin >> a[i];

    int sakujo = 0;
    int f[n] = {};
    srep(i,1,n-1){
        if(a[i-1]<a[i] && a[i]<a[i+1] && 200 < a[i-1]){
            f[i] = 1;
            sakujo++;
        }else if(a[i+1] < a[i] && a[i] < a[i-1] && 200 < a[i+1]){
            f[i] = 1;
            sakujo++;
        }
    }

    int ccc = 0;
    rep(i,n){
        if(f[i]==0){
            a[ccc] = a[i];
            ccc++;
        }
    }
    n = n - sakujo;

    srep(i,1,n-1){
        if(a[i-1]>a[i] && a[i]<a[i+1] && a[i]>400){
            a[i] = 400;
        }
    }

    srep(i,1,n-1){
        if(a[i-1]<a[i] && a[i]<a[i+1] && a[i-1] <= 400 && 500 <= a[i+1]){
            a[i] = 450;
        }
    }

    srep(i,1,n-1){
        if(a[i-1]>a[i] && a[i]>a[i+1] && a[i+1] <= 400 && 500 <= a[i-1]){
            a[i] = 450;
        }
    }

    srep(i,1,n-1){
        if(a[i-1]<a[i] && a[i]>a[i+1] && 500 <= a[i]){
            a[i] = 500;
        }
    }
    

    // 1種類でいけるかの判定
    if(n == 1){
        cout << '1' << endl;
        return 0;
    }
    srep(i, 1, n){
        if(a[i] <= a[i-1]){
            break;
        }
        if(i == n-1){
            cout << '1' << endl;
            return 0;
        }
    }

    // 文字の種類数
    int count = 2;

    int l = 2;
    int r = n;

    while(true){
        int count = (l+r)/2;
        int burst = 0; //フラグ
        rep(i,len)word[i] = 0;
        rep(i, n){
            if(i == 0){ // 初期条件（例：a[0]=5の時、あああああ）
                rep(j, min(a[0],len)){
                    word[j] = 1;
                }
                continue;
            }else if(a[i] > a[i-1]){
                if(a[i-1]<len){
                    srep(j,a[i-1],min(a[i],len)){
                        word[j] = 1;
                    }
                }
                continue;
            }

            drep(j,min(a[i],len)){
                if(j==(min(a[i],len) - 1)){
                    word[j]++;
                }
                if(word[j]==count + 1){
                    if(j==0){
                        burst = 1;
                        break;
                    }
                    word[j] = 1;
                    word[j-1]++;
                }
            }
            if(burst==1)break;
            srep(j,a[i],min(a[i-1],len)){
                word[j] = 0;
            }
        }
        if(burst == 1){
            l = count + 1;
        }else{
            r = count;
        }
        if(l==r)break;
    }

    cout << r << endl;
    return 0;
}
 


Measured memory_bytes: 2560
using System;
using System.Collections.Generic;
using System.Linq;
using static AtCoder.Io;

namespace AtCoder
{
    class Program
    {
        static void Main()
        {
            var n = ReadInt();
            var cs = new int[n, 26];
            for (var i = 0; i < n; i++)
            {
                var s = ReadString();
                foreach (var c in s)
                {
                    cs[i, c - 'a']++;
                }
            }
            for (var i = 0; i < 26; i++)
            {
                var min = int.MaxValue;
                for (var j = 0; j < n; j++)
                {
                    ChangeMin(ref min, cs[j, i]);
                }
                char c = (char)('a' + i);
                Console.Write(string.Concat(Enumerable.Repeat(c, min)));
            }
        }
        public static bool ChangeMin(ref int lhs, int rhs)
        {
            if (lhs > rhs)
            {
                lhs = rhs;
                return true;
            }
            else
            {
                return false;
            }
        }
    }

    public static class Io
    {
        public static string ReadString() => Console.ReadLine();
        public static string[] ReadStringArray() => ReadString().Split(' ');
        public static int ReadInt() => int.Parse(ReadString());
        public static long ReadLong() => long.Parse(ReadString());
        public static int[] ReadIntArray() => ReadStringArray().ParseInt().ToArray();
        public static long[] ReadLongArray() => ReadStringArray().ParseLong().ToArray();
        public static IEnumerable<int> ParseInt(this IEnumerable<string> source) => source.Select(int.Parse);
        public static IEnumerable<long> ParseLong(this IEnumerable<string> source) => source.Select(long.Parse);
    }
}


Measured memory_bytes: 13268
#include <iostream>
#include <algorithm>
#include <vector>
#include <functional>
#include <string>
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
using P = pair<int, int>;
using ll = long long;

int main (){
   string s;
   cin >> s;
  if (s == "ABC") cout << "ARC" << endl;
  else cout << "ABC" << endl;
  return 0;
}

Measured memory_bytes: 3620
import sys 
sys.setrecursionlimit(10**6)
from collections import defaultdict
t = int(input())


def solve():
    n,a,b,c,d = map(int, input().split())
    memo = defaultdict(int)
    def f(n):
        if memo[n] != 0:
            return memo[n]
        if n == 2:
            return min(a+d,2*d)
        if n == 1:
            return d #最後-1する
        if n == 0:
            return 0 #0になったらおしまいです
        # 2の操作
        r2 = n % 2
        n_p_2 = n + 2 - r2
        n_m_2 = n - r2
        d_p_2 = f(n_p_2//2) + d*(2-r2) + a
        d_m_2 = f(n_m_2//2) + d*(r2) + a
        r3 = n % 3
        n_p_3 = n + 3 - r3
        n_m_3 = n - r3
        d_p_3 = f(n_p_3//3) + d*(3-r3) + b
        d_m_3 = f(n_m_3//3) + d*(r3) + b
        r5 = n % 5
        n_p_5 = n + 5 - r5
        n_m_5 = n - r5
        d_p_5 = f(n_p_5//5) + d*(5-r5) + c
        d_m_5 = f(n_m_5//5) + d*(r5) + c
        ret = min(n*d,d_p_2,d_p_3,d_p_5,d_m_2,d_m_3,d_m_5)
        memo[n] = ret
        return ret
    ans = f(n)
    return ans
     

ans = []
for _ in range(t):
    ans.append(solve())

for a in ans:
    print(a)

Measured memory_bytes: 22800
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
#define mod 1000000007
#define inf 0x3f3f3f3f
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pi acos(-1.0)
#define pii pair<int,int>
#define Lson L, mid, rt<<1
#define Rson mid+1, R, rt<<1|1
const int maxn=5e2+10;
using namespace std;
ll gcd(ll p,ll q){return q==0?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=1;while(q){if(q&1)f=f*p;p=p*p;q>>=1;}return f;}
int n,m,k,t,h[maxn],tot,vis[maxn],s,cur[maxn];
char a[maxn][maxn];
struct node
{
    int fr,to,nxt,cap,flow;
}e[20000<<1];
void add(int x,int y,int z)
{
    e[tot].fr=x;
    e[tot].to=y;
    e[tot].nxt=h[x];
    e[tot].cap=z;
    h[x]=tot++;
    e[tot].fr=y;
    e[tot].to=x;
    e[tot].nxt=h[y];
    h[y]=tot++;
}
bool bfs()
{
    memset(vis,0,sizeof vis);
    queue<int>p;
    p.push(s);
    vis[s]=1;
    while(!p.empty())
    {
        int x=p.front();p.pop();
        for(int i=h[x];i!=-1;i=e[i].nxt)
        {
            int to=e[i].to,cap=e[i].cap,flow=e[i].flow;
            if(!vis[to]&&cap>flow)
            {
                vis[to]=vis[x]+1;
                p.push(to);
            }
        }
    }
    return vis[t];
}
int dfs(int x,int a)
{
    if(x==t||a==0)return a;
    int ans=0,j;
    for(int&i=cur[x];i!=-1;i=e[i].nxt)
    {
        int to=e[i].to,cap=e[i].cap,flow=e[i].flow;
        if(vis[to]==vis[x]+1&&(j=dfs(to,min(a,cap-flow)))>0)
        {
            e[i].flow+=j;
            e[i^1].flow-=j;
            ans+=j;
            a-=j;
            if(a==0)break;
        }
    }
    return ans;
}
int max_flow(int s,int t)
{
    int flow=0,i;
    while(bfs())
    {
        rep(i,1,n+m+2)cur[i]=h[i];
        flow+=dfs(s,inf);
    }
    return flow;
}
int main()
{
    int i,j;
    memset(h,-1,sizeof h);
    scanf("%d%d",&n,&m);
    rep(i,0,n-1)scanf("%s",a[i]);
    rep(i,0,n-1)rep(j,0,m-1)
    {
        if(a[i][j]=='S')add(1,i+2,inf),add(1,j+n+2,inf);
        if(a[i][j]=='T')add(i+2,n+m+2,inf),add(j+n+2,n+m+2,inf);
        if(a[i][j]=='o')add(i+2,j+n+2,1),add(j+n+2,i+2,1);
    }
    s=1,t=n+m+2;
    int ret=max_flow(s,t);
    printf("%d\n",ret>10000?-1:ret);
    return 0;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define vll vector< ll >
//#define M 100000
#define MD 1000000007
#define pb push_back
#define rep(i,a,b) for(ll i = a; i <= b; ++i)
#define fo(i,a,b) for(int i = a; i<= b; ++i)
#define pii pair<int,int>
#define vec(a) vector<a >
#define all(a) a.begin(),a.end()
#define se second
#define fi first
#define inf 0xffffffff
#define inchar getchar_unlocked
#define outchar(x) putchar_unlocked(x)
//#define int unsigned long long
//#define endl '\n'
#define IOS ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long  
#define int long long
using namespace std;
//using ll = unsigned long long;
ll md=MD;
//ll M=1073741824;
ll M=1e9+7;
//ll exp(ll a,ll b){ll r=1;while(b>0){if(b&1){r=r*(a%md);r=(r+md)%md;}b>>=1;a=(a%md)*(a%md);a=(a+md)%md;}return (r+md)%md;}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll Min(int a,int b){if(a<b)return a; return b;}
ll Max(int a,int b){if(a>b)return a; return b;}
ll powM(ll a,ll b){if(a==1) return 1;ll ans=1;while(b>0){if(b&1)ans=(ans*a)%M;a=(a*a)%M;b=b>>1;}return ans;}
ll power(ll a,ll b){if(a==1) return 1;ll ans=1;while(b>0){if(b&1)ans=(ans*a);a=(a*a);b=b>>1;}return ans;}
const int INF=1000000000000000000;

//always try to hack ur soln before submitting (penalty-50 wrong submission 50 min sochle isse aacha)
// Abe n*m ke grid main y ke coordinates m se akm hone chahiye na ke n se 

int32_t main()
{
	IOS;
	int t;
//	cin>>t;
	t=1;
	while(t--)
	{
		int n;
		cin>>n;
		cout<<(1000-(n%1000==0?1000:n%1000))<<"\n";		
}
}


Measured memory_bytes: 3644
while True :
    H,W = map(int,input().split())
    if (H == 0 and W == 0) : break
    for j in range(H) :
        for i in range(W) : 
            if (i + j) % 2 == 0 :
                print("#", end = "")
            else :
                print(".", end = "")
        print()
    print()



Measured memory_bytes: 7000
r, c = map(int, input().split())

matrix = [(list(map(int, input().split()))) for i in range(r)]
total = [0] * c

for row in matrix:
    for i, elem in enumerate(row):
        print("{} ".format(elem), end="")
        total[i] += elem
    print(sum(row))

for total_col in total:
    print("{} ".format(total_col), end="")
print(sum(total))


Measured memory_bytes: 6224
#!/usr/bin python3
# -*- coding: utf-8 -*-

import sys
input = sys.stdin.readline

def main():
    P = list(map(int, input().split()))
    N = int(input())
    p = min(P[0]*4, P[1]*2, P[2])
    print(min(N*p, (N//2)*P[3] + (N%2)*p))

if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

ll DP[61][300005];

int main() {
  int N;
  cin>>N;
  ll A[N];
  ll two;
  for(int i=0;i<N;++i) cin>>A[i];
  for(int i=0;i<N;++i) {
    two = 1;
    for(int bit=0;bit<61;++bit) {
      if((A[i]&two)!=0) DP[bit][i]++;
      two *= 2;
    }
  }
  for(int bit=0;bit<61;++bit) {
    for(int i=1;i<N;++i) {
      DP[bit][i] += DP[bit][i-1];
    }
  }
  /**
  for(int bit=0;bit<61;++bit) {
    for(int i=0;i<N;++i) {
      cout<<DP[bit][i]<<" ";
    }
    cout<<endl;
  }
  **/
  ll ans = 0;
  for(int i=0;i<N;++i) {
    two = 1;
    for(int bit=0;bit<61;++bit) {
      if((A[i]&two)!=0) {
        ans += (two%mod)*(N-1-i-(DP[bit][N-1]-DP[bit][i]))%mod;
        ans %= mod;
      }
      else {
        ans += (two%mod)*(DP[bit][N-1]-DP[bit][i])%mod;
        ans %= mod;
      }
      two *= 2;
    }
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 148844
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        sc.close();
        if(a > 12){
            System.out.println(b);
        }else if(a >= 6){
            System.out.println(b / 2);
        }else{
            System.out.println(0);
        }
    }
}

Measured memory_bytes: 35532
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <map>
#include <list>
#include <math.h>
#include <algorithm>
#include <chrono>
#include <random>
#include <queue>
#include <fstream>
#include <iterator> // std::back_inserter
#include <chrono>
#include <string>
#include <stdio.h>
#include <iomanip>
#include <float.h>
 
using namespace std;
 
int main(int argc, char *argv[])
{
    int a,b,c;

    cin >> a;
    cin >> b;
    cin >> b;
    cin >> b;
    cin >> b;
    cin >> c;

    if(b-a > c) cout << ":(";
    else cout << "Yay!";

 
    return 0;
}


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

using namespace std;

int H, W;
unsigned long long int canvas[52];

int main()
{
    cin >> H >> W;

    string s;
    for (int h = 0; h < H; h++) {
        cin >> s;
        for (int w = 0; w < W; w++) {
            canvas[h + 1] |= (s[w] == '#' ? 1ull : 0ull) << (w + 1);
        }
    }

    int cnt = 0;;
    for (int i = 1; i < H + 1; i++) {
        auto notAdjacent = canvas[i]
            & (canvas[i] ^ canvas[i - 1])
            & (canvas[i] ^ (canvas[i] >> 1))
            & (canvas[i] ^ (canvas[i] << 1))
            & (canvas[i] ^ canvas[i + 1]);
        if (notAdjacent != 0) {
            cnt++;
            break;
        }
    }

    cout << (cnt == 0 ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 256
n, k, *h = map(int, open(0).read().split())
h += [0] * 200
dp = [0] + [float("inf")] * 100200
for i in range(1, n):
  dp[i] = min(dp[i-a] + abs(h[i] - h[i-a]) for a in range(1, k + 1))
print(dp[n - 1])

Measured memory_bytes: 89940