akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);

const int N = 2e5+5, M = 1e6+6, OO = 0x3f3f3f3f;
const ll OOL = 0x3f3f3f3f3f3f3f3f;
int tc;
ll grid[3005][3005];
ll dp[3005][3005][6];
int main()
{
    FIO
    ll r, c, k;
    cin>>r>>c>>k;
    for(int i =0 ; i<k ; i++)
    {
        ll tr, tc, tv;
        cin>>tr>>tc>>tv;
        tr--, tc--;
        grid[tr][tc] = tv;
        // dp[tr][tc][1] = tv;
    }
    // dp[0][0][1] = grid[0][0];
    for(int i = 0 ; i< r ; i++)
    {
        for(int j = 0 ; j<c ; j++)
        {
            for(int t = 0 ; t < 3 ; t++)
            {
                dp[i+1][j][0] = max({dp[i+1][j][0], dp[i][j][t] + grid[i][j], dp[i][j][t]}); 
                dp[i][j+1][t+1] = max(dp[i][j+1][t+1], dp[i][j][t] + grid[i][j]); 
                dp[i][j+1][t] = max(dp[i][j+1][t], dp[i][j][t]); 
            }
        }
    }
    ll ans = 0;
    for(int i = 0 ; i<= r ; i++)
    {
        for(int j = 0 ; j <= c; j++)
        {
            for(int t = 0 ; t< 4 ; t++)
            {
                ans = max(ans, dp[i][j][t]);
                // cout<<i<<" "<<j<<" "<<t<<" "<<dp[i][j][t]<<endl;
            }
        }
    }
    // for(int i = 0 ; i<= 3 ; i++)
    //     ans = max(ans, dp[r][c][i]);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 496728
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var (
	BufferSize = 20
)

func readLine(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func scanStr(sc *bufio.Scanner) string {
	if !sc.Scan() {
		panic(nil)
	}
	return sc.Text()
}

func scanInt(sc *bufio.Scanner) int {
	if !sc.Scan() {
		panic(nil)
	}
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	buf := make([]byte, BufferSize)
	sc.Buffer(buf, BufferSize)
	sc.Split(bufio.ScanWords)

	n := scanInt(sc)
	c := make([]int, n)
	v := make([]int, n)
	for i := 0; i < n; i++ {
		v[i] = scanInt(sc)
	}
	for i := 0; i < n; i++ {
		c[i] = scanInt(sc)
	}

	// v-c
	var ans int
	for i := 0; i < n; i++ {
		tmp := v[i] - c[i]
		if tmp > 0 {
			ans += tmp
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<int, int>;
using VI = vector<int>;
#define fst first
#define snd second

const int N = 2005;
const int mod = 1e9 + 7;
int choose[N][N];

int main() {
#ifdef LOCAL_EXEC
//	freopen("sample.in", "r", stdin);
//	freopen("sample.out", "w", stdout);
#else
//	freopen("sample.in", "r", stdin);
//	freopen("sample.out", "w", stdout);
//  ios_base::sync_with_stdio(false); cin.tie(NULL);
#endif

  for (int n = 0; n < N; n++) {
    choose[n][0] = choose[n][n] = 1;
    for (int r = 1; r < n; r++) {
      choose[n][r] = (choose[n - 1][r] + choose[n - 1][r - 1]) % mod;
    }
  }

  int n; cin >> n;
  ll ways = 0;
  for (int l = 1; 3 * l <= n; l++) {
    int s = n - 3 * l;
    ways += choose[s + l - 1][l - 1];
  }
  ways %= mod;
  cout << ways << endl;

  return 0;
}


Measured memory_bytes: 17404
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <functional>
#include <string>
#include <cstring>
#include <tuple>
using namespace std;

using ii = pair < int, int >;
using lint = long long;
using ti = tuple < int, int, int >;

int main() {
	//freopen("in.txt","r",stdin);
	lint x, y;
	scanf("%lld%lld", &x, &y);
	int cnt = 0;
	while (true) {
		++cnt;
		if (x * (lint)2 > y)break;
		x = x * (lint)2;
	}
	printf("%d\n", cnt);
	return 0;
}

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

int gcd(int a, int b)
{
  int c;
  while (b != 0){
    c = a % b;
    a = b;
    b = c;
  }
  return (a);
}

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

int main()
{
  int a, b;
  while (cin >> a >> b){
    cout << gcd(a, b) << " " << lcm(a, b) << endl;
  }
}

Measured memory_bytes: 1160
from collections import deque 
#スタック
s = deque([])

N,Q = map(int,input().split())
node = [[]for i in range(0,N+1,1)]
for i in range(0,N-1,1):
    a,b = map(int,input().split())
    node[a].append(b)
    node[b].append(a)
node_score = [0]*(N+1)#スコア
for i in range(0,Q,1):
    p,x = map(int,input().split())
    node_score[p] += x

ans = [0]*(N+1)

s.append([1,0])
while len(s) > 0:
    n,preN = s.pop()
    ans[n] = ans[preN]+node_score[n]
    for to in node[n]:
        if to != preN:
            s.append([to,n])

print(" ".join(list(map(str,ans[1:N+1]))))
        



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

using namespace std;
using ll = long long;

inline long double dist(long double x1,long double x2,long double y1,long double y2){return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));}

int main()
{
    int n;
    cin >> n;
    vector<pair<int,int>> point(n);
    for(int i = 0; i < n; i++)cin >> point[i].first >> point[i].second;
    sort(point.begin(), point.end());

    long double sum = 0;
    int cnt = 0;    

    do{

        for(int i = 1; i < n; i++){
            sum += dist(point[i].first, point[i - 1].first, point[i].second, point[i - 1].second);
        }
        cnt++;
        

    }while(std::next_permutation(point.begin(), point.end()));

    cout << fixed <<setprecision(12) << sum / cnt << endl; 

}

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

#define pb push_back
#define eb emplace_back

using namespace std;

using vi = vector<int>;
using ll = long long;

int main(){
    ios :: sync_with_stdio(false);
    int n, m;
    string s;
    cin >> n >> m;
    cin >> s;

    s[m-1] = tolower(s[m-1]);

    cout << s << endl;

    return 0;
}


Measured memory_bytes: 256
#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>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const ll INF = 1LL << 60;

int main() {

    set<char> S;
    rep(i,4){
        char tmp;
        cin >> tmp;
        S.insert(tmp);
    }

    if(S.size() == 2){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 3572
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
long long int INF = 1001001001001001LL;
int inf = 1000000007;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;

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

#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()

/* do your best */


int main() {

  map<int, int> mp;

  for (int x = 1; x <= 100; x++) {
    for (int y = 1; y <= 100; y++) {
      for (int z = 1; z <= 100; z++) {
        int val = x * x + y * y + z * z + x * y + x * z + y * z;
        mp[val]++;
      }
    }
  }
  
  int n; cin >> n;
  for (int i = 1; i <= n; i++) {
    cout << mp[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 5380
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	scanInit()

	n := nextInt()

	for i := 0; i < 50001; i++ {
		if i*108/100 == n {
			fmt.Println(i)
			return
		}
	}
	fmt.Println(":(")
	return
}
func isInteger(x float64) bool {
	return math.Floor(x) == x
}

// ---- readfunc
func scanInit() {
	const cap = 64 * 1024
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


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

int main() {
  long long N, Q;
  cin >> N >> Q;

  vector<int> Point(N,0);
  vector<vector<int>> Root(N);

  for (int i = 1; i < N; i++) {
    int parent, children;
    cin >> parent >> children; 
    Root.at(children - 1).push_back(parent);
  }

  for ( int i = 0; i < Q; i++ ){
    long long index, Number;
    cin >> index >> Number;
    Point.at(index - 1) += Number;
  }

  for ( int i = 0; i < N; i++ ){
    for ( int j = 0; j < Root.at(i).size(); j++ ){
      Point.at(i) += Point.at( Root.at(i).at(j) - 1 );
    }
  }

  for ( int i = 0; i < N - 1; i++ ){
    cout << Point.at(i) << " ";
  }
  cout << Point.at(N-1) << endl; 

}


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


using namespace std;


// Powered by caide (code generator, tester, and library code inliner)


class Solution {
public:
  void solve(std::istream& in, std::ostream& out)
  {
    string str;
    in >> str;
    out << str.substr(0, 4) << " " << str.substr(4, 8) << "\n";
  }
};

void solve(std::istream& in, std::ostream& out)
{
  out << std::setprecision(12);
  Solution solution;
  solution.solve(in, out);
}


#include <fstream>
#include <iostream>


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


  istream& in = cin;


  ostream& out = cout;

  solve(in, out);
  return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
        using namespace std;
        #define tani_nachi_ke  ios_base::sync_with_stdio(false); cin.tie(NULL);
        #define M_PI 3.14159265358979323846
        #define data data_
        #define ff first
        #define ss second
        #define pb push_back
        #define ll long long
        #define ld long double

        int const N = 1009;
        long long dp[1009][10009];
        long long const inf = 1e15;
        long long a[N],b[N];
        int n,h;
        long long fun(int id,int x)
        {
            if(x <= 0)
                return 0;
            else if(id == -1)
            {
                if(x <= 0)
                    return 0;
                else
                    return inf;
            } 
            else if(dp[id][x] != -1)
                return dp[id][x];
            else 
                return dp[id][x] = min(fun(id-1,x-a[id]) + b[id],
                                        min(fun(id,x - a[id]) + b[id],fun(id-1,x)));
        }
        int main()
        {
            tani_nachi_ke  

            cin >> h >> n;
            for(int i = 0; i < n; i++)
                cin >> a[i] >> b[i];
            memset(dp,-1,sizeof(dp));
            cout << fun(n-1,h) << endl;








           return 0;
        }

Measured memory_bytes: 79872
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cstring>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<long long, long long> P;
#define rep(i, n) for(long long i=0; i<n; i++)
#define reps(i, s, e) for(long long i=s; i<e; i++)
#define repr(i, n) for(long long i=n-1; i>=0; i--)
#define reprs(i, s, e) for(long long i=e-1; i>=s; i--)

int main(){

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

    string s; cin >> s;

    ll n = s.size();
    stack<ll> stk;
    ll ans = 0;

    rep(i, n){
        if(stk.size() == 0){
            if(s[i] == 'T'){
                ans++;
            }
            else{
                stk.push(1);
            }
        }
        else{
            if(s[i] == 'T'){
                stk.pop();
            }
            else{
                stk.push(1);
            }
        }
    }

    cout << ans + stk.size() << endl;

    return 0;
}

Measured memory_bytes: 1300
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		int i, j, n, q, index, b, e;
		try (Scanner sc = new Scanner(System.in)) {
			n = sc.nextInt();
			int[] a = new int[n];
			for(i = 0; i < n; i++) {
				a[i] = sc.nextInt();
			}
			q = sc.nextInt();
			for(i = 0; i < q; i++) {
				b = sc.nextInt();
				e = sc.nextInt();
				for(j = b; j < (e - b)/2 + b; j++) {
					index = e - j + b - 1;
					a[j] = a[j] ^ a[index];
					a[index] = a[j] ^ a[index];
					a[j] = a[j] ^ a[index];
				}
			}
			for(i = 0; i < n - 1; i++){
				System.out.print(a[i] + " ");
			}
			System.out.println(a[n - 1]);
		}
	}
}


Measured memory_bytes: 35104
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a;
	cin>>a;
	int b;
	if(a%10==1)
	{
		b=9;
	}
	else
	{
		b=1;
	}
	if((a%100-a%10)/10==1)
	{
		b=90+b;
	}
	else
	{
		b=10+b;
	}
	if((a-a%100)/100==1)
	{
		b=900+b;
	}
	else
	{
		b=100+b;
	}
	cout<<b;
	return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using P   = pair<ll, ll>;
using mat = vector<vector<ll>>;

void IOS() { ios::sync_with_stdio(false), cin.tie(0); }

const ll INF = 1e16;
const ll MOD = 1e9 + 7;
const ld EPS = 1e-12;

template <typename T>
void dump(T x) { cout << x << endl; }
void dumpf(ld x, int t) { cout << setprecision(t) << fixed << x << endl; }
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
	fill((T *)array, (T *)(array + N), val);
}
inline ll mod(ll a, ll b) {
	if (a > 0) return a % b;
	if (a % b == 0) return 0;
	ll x = -a / b + 1;
	a += x * b;
	return a % b;
}
ll powm(ll a, ll b, ll c) {
	if (b == 0)
		return 1;
	else if (b % 2 == 0) {
		ll d = powm(a, b / 2, c);
		return (d * d) % c;
	} else
		return (a * powm(a, b - 1, c)) % c;
}
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

//ll dx[4] = {1, 0, -1, 0};
//ll dy[4] = {0, 1, 0, -1};

int main() {
	IOS();
	ll n, k;
	cin >> n >> k;
	ld ans = 0;
	for (int i = 1; i <= n; i++) {
		ll j;
		ll tmp = i;
		for (j = 0; tmp < k; j++) {
			tmp *= 2;
		}
		ans += 1.0 / n * powl(2.0, -j);
	}
	dumpf(ans, 10);
	return 0;
}

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

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

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

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

//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する
class Solve {
public:
    int H, W, K;
    ll dp[10][200];

    vector<ll> cnt;

    void input() {
        cin >> H >> W >> K;
        cnt.resize(W, -1);
    }

    ll calc_cnt(int n) {
        if (n < 1) return 1;
//        if (n < 3) return 2;
        if (cnt[n] != -1) return cnt[n];
        return cnt[n] = (calc_cnt(n - 1) + calc_cnt(n - 2)) % MOD;
    }

    void solve() {
        input();

        dp[1][0] = 1;
        for (int h = 0; h < H; ++h) {
            for (int i = 1; i <= W; ++i) {
                if (i != 1) {
                    dp[i - 1][h + 1] += (1ll * calc_cnt(i - 3) * calc_cnt(W - i - 1) % MOD) * dp[i][h];
                    dp[i - 1][h + 1] %= MOD;
                }
                if (i != W) {
                    dp[i + 1][h + 1] += (1ll * calc_cnt(i - 2) * calc_cnt(W - i - 2) % MOD) * dp[i][h];
                    dp[i + 1][h + 1] %= MOD;
                }
                dp[i][h + 1] += (1ll * calc_cnt(i - 2) * calc_cnt(W - i - 1) % MOD) * dp[i][h];
                dp[i][h + 1] %= MOD;
            }
        }

        ll ans = dp[K][H];
        cout << ans << endl;


    }
};


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

    Solve().solve();


    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  int dp[N+1];
  dp[0] = 0;
  for (int i = 1; i <= N; i++) {
    dp[i] = dp[i-1]+1;
    for (int j = 6; i-j >= 0; j *= 6) {
      dp[i] = min(dp[i],dp[i-j]+1);
    }
    for (int j = 9; i-j >= 0; j*= 9) {
      dp[i] = min(dp[i],dp[i-j]+1);
    }
  }
  cout << dp[N];
}

Measured memory_bytes: 3920
def main():
    h, w, d = map(int, input().split())
    ans = [[0] for _ in range(d)]
    s = [0] * d
    ans[0].append(0)
    dict = {}
    for i in range(h):
        for j, a in enumerate(list(map(int, input().split()))):
            dict[a] = (i, j)
    for i in range(1, h * w + 1 - d):
        m = i % d
        s[m] += abs(dict[i][0] - dict[i + d][0]) + abs(dict[i][1] - dict[i + d][1])
        ans[m].append(s[m])
    q = int(input())
    for _ in range(q):
        l, r = map(int, input().split())
        m = l % d
        print(ans[m][r // d] - ans[m][l // d])

if __name__ == '__main__':
    main()


Measured memory_bytes: 33852
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define per(i,a,n) for(int i=n;i>=a;i--)
#define pb push_back
#define SZ(x) ((int)(x).size())
#define fastin ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
typedef long long ll;
typedef pair<int,int> pii;
typedef double db;
const int bd=1000000;
bool np[1000010],vis[1000010];
vector<int> fac[1000010];
int n,a[1000010],f1,f2;
int main(){
	rep(i,2,bd){
		if(!np[i]){
			fac[i].pb(i);
			for(int j=2;j*i<=bd;j++){
				int tmp=i*j;
				fac[tmp].pb(i);
				np[tmp]=1;
			}
		}
	}
	cin>>n;
	f1=f2=1;
	rep(i,1,n)	scanf("%d",&a[i]);
	rep(i,1,n){
		for(auto f:fac[a[i]]){
			if(vis[f]==1){
				f1=0;break;
			}vis[f]=1;
		}
		if(!f1)	break;
	}
	int g=a[1];
	rep(i,2,n){
		g=__gcd(g,a[i]);
	}
	if(g!=1)	f2=0;
	if(f1)	puts("pairwise coprime");
	else if(f2)	puts("setwise coprime");
	else	puts("not coprime");
	return 0;
}

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



int main() {
    double d, t, s;
    cin >> d >> t >> s;
    
    if(d / s <= t)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    
    
    
    
    return 0;
}




Measured memory_bytes: 3720
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define int ll
#define pb push_back
#define setbits(x)          __builtin_popcountll(x)
#define endl "\n"
typedef long long ll;
void solve()
{
    int n,k;
  cin>>n>>k;
  int ans=0;
  for(int i=0;i<n;i++)
  {
    int x,y;
    cin>>x>>y;
    if(x*x+y*y<=k*k)
      ans++;
  }
  cout<<ans<<endl;
}
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
solve();
    return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <string>
#include <vector>
#include <cctype>
#include <algorithm>
using namespace std;

int w,h;
string m[100];
string dp[100][100];

string max_string(const vector<string>& vs){
    int max_len=0;
    string s;
    for(int i=0 ; i < vs.size() ; i++ ){
        max_len = max( max_len , (int)vs[i].size() );
    }
    for(int i=0 ; i < vs.size() ; i++ ){
        if( vs[i].size() == max_len && ( s.empty() || s < vs[i] ) ){
            s = vs[i];
        }
    }
    return s;
}

void solve(){
    for(int y=0 ; y < 100 ; y++ ){
        for(int x=0 ; x < 100 ; x++ ){
            dp[y][x].clear();
        }
    }
    int max_len=0;
    string ans;
    for(int y=h-1 ; y >= 0 ; y-- ){
        for(int x=w-1 ; x >= 0 ; x-- ){
            if( isdigit( m[y][x] ) ){
                dp[y][x].push_back( m[y][x] );
                vector<string> vs;
                if( x != w-1 && isdigit( m[y][x+1] ) ){
                    vs.push_back( dp[y][x+1] );
                }
                if( y != h-1 && isdigit( m[y+1][x] ) ){
                    vs.push_back( dp[y+1][x] );
                }
		dp[y][x] += max_string( vs );
            }
            if( !dp[y][x].empty() && dp[y][x][0] != '0' ){
                max_len = max( max_len , (int)dp[y][x].size() );
            }
        }
    }
    for(int y=0 ; y < h ; y++ ){
        for(int x=0 ; x < w ; x++ ){
            if( dp[y][x].size() == max_len && ( ans.empty() || ans < dp[y][x] ) ){
                ans = dp[y][x];
            }
        }
    }
    cout << ans << endl;
}

int main(){
    while( cin >> w >> h , w || h ){
        for(int i=0 ; i < h ; i++ ){
            cin >> m[i];
        }
        solve();
    }
}

Measured memory_bytes: 1048
import sys
A,B = map(int,input().split())
if not ( 3 <= A <= 20 and 3 <= B <= 20 ): sys.exit()

sum = 0
for I in range(2):
    sum += A if A > B else B
    if A > B:
         A -= 1
    else:
         B -= 1
print(sum)

Measured memory_bytes: 9112
#include<iostream>
#include<cstdio>
#include<queue>
#include<set>
#include<stack>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<map>
using namespace std;
typedef long long ll;
const int N = 100 + 10, inf = 0x3f3f3f3f;
int w[N], v[N];
ll dp[N][N][4*N];
int main()
{
    ll n, m;
    while(cin>>n>>m)
    {
        int sum = 0;
        for(int i = 1; i<=n; i++)
        {
            scanf("%d%d", &w[i], &v[i]);
            if(i>1)
                sum += w[i]-w[1], w[i] -= w[1];
        }
        int tmp = w[1];
        w[1] = 0;
        memset(dp, 0, sizeof(dp));
        ll ans = 0;
        for(int k = 1; k<=n; k++)
        {
            for(int i = 1; i<=n; i++)
            {
                for(int j = 0; j<=sum; j++)
                {
                    if(j>=w[k])
                    dp[k][i][j] = max(dp[k-1][i-1][j-w[k]] + v[k], dp[k][i][j]);
                    dp[k][i][j] = max(dp[k-1][i][j], dp[k][i][j]);
                    if(1LL*i*tmp+j<=m)
                        ans = max(ans, dp[k][i][j]);
                  //  cout<<dp[k][i][j]<<" "<<i*tmp+j<<" "<<i<<" "<<j<<" "<<k<<endl;
                }
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 41856
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define allr(x) (x).rbegin(), (x).rend()
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define ll long long
#define ld long double
typedef pair<ll,ll> pll;
typedef vector <ll> vi;
#define out(x) return cout<<x,0;
#define precision(x,d) cout<<fixed<<setprecision(d)<<x
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));
const ll N = 15;

int main(){
    FAST;
    ll n, ans = 0, k, m, j = 0, t = 1, x = 0, y = 0, c = 0, i, z = 0;
    cin >> n >> m ;
    bool dp[n][m][13000];
    memset ( dp , 0 , sizeof(dp));
    ll a[n][m] , b[n][m];
    
    for ( i = 0 ; i < n ; i ++ )
        for ( j = 0 ; j < m ; j ++)
            cin >> a[i][j];
            
    for ( i = 0 ; i < n ; i ++ )
        for ( j = 0 ; j < m ; j ++)
            cin >> b[i][j];
            
    x = abs(a[0][0] - b[0][0]);
    dp[0][0][x] = 1;

    for ( i = 0 ; i < n ; i ++ ){
        for ( j = 0 ; j < m ; j ++ ){
            if ( i == 0 && j == 0 ) continue;
            else {
                if ( i > 0 ){
                    for ( k = 0 ; k < 13000 ; k ++ ){
                        if ( dp[i-1][j][k] == 1 ){
                            z = abs(a[i][j] - b[i][j]);
                            dp[i][j][k + z] = 1;
                            dp[i][j][abs(k - z)] = 1;
                        } 
                    }
                }
                if ( j > 0 ){
                    for ( k = 0 ; k < 13000 ; k ++ ){
                        if ( dp[i][j-1][k] == 1 ){
                            z = abs(a[i][j] - b[i][j]);
                            dp[i][j][k + z] = 1;
                            dp[i][j][abs(k - z)] = 1;
                        } 
                    }
                }
            }   
        }
    }
    for ( i = 0 ; i < 13000 ; i ++ ){
        if(dp[n-1][m-1][i] == 1) 
            out(i);
    }
}

Measured memory_bytes: 81664
#MLE注意！0や1のケースに注意

def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    import math
    from math import gcd

    #inf = 10**17
    #mod = 10**9 + 7

    s,w = map(int, input().split())
    if s<=w:
        print('unsafe')
    else:
        print('safe')

if __name__ == '__main__':
    main()

Measured memory_bytes: 65224
/* Kadai2_2
 saitomo*/

#include <stdio.h>

int main(void){
  int number;
  int white;
  //値を入力
  scanf("%d",&number);
  scanf("%d",&white);
  //全体のマス目はnumber*number,白くするマス目はwhite
  printf("%d",number*number-white);
  return 0;
}


Measured memory_bytes: 128
// -----------------------------------
// Author     : MatsuTaku
// Country    : Japan
// Created    : 05/10/20 23:28:18
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

  int n; cin>>n;
  vector<pair<int,int>> I(n);

  for (int i = 0; i < n; i++) {
    string s; cin>>s;
    I[i].first = 0;
    I[i].second = 0;
    for (auto c:s) {
      if (c=='(') I[i].first++;
      else I[i].first--;
      I[i].second = min(I[i].second, I[i].first);
    }
  }
  auto solve = [&]() {
    vector<pair<int,int>> U,D;
    for (auto p:I) {
      if (p.first >= 0) U.push_back(p);
      else D.push_back(p);
    }
    int s = 0;
    {
      sort(U.begin(), U.end(), [](auto l, auto r) {return l.second > r.second;});
      for (auto u:U) {
        if (s+u.second < 0)
          return false;
        s += u.first;
      }
    }
    {
      sort(D.begin(), D.end(), [](auto l, auto r) {return (l.second-l.first) < (r.second-r.first);});
      for (auto u:D) {
        if (s+u.second < 0)
          return false;
        s += u.first;
      }
    }
    return s == 0;
  };
  cout << (solve() ? "Yes" : "No") << endl;

  return 0;
}


Measured memory_bytes: 19116
N=int(raw_input())
lis = []
for i in range(0,N):
	num = int(raw_input())
	lis.append(num)
get = sum(lis)
if sum(lis) % 10 == 0:
	for j in range(0,N-1):
		if min(lis) % 10 != 0:
			print get - min(lis)
			break
		lis.remove(min(lis))
	else:
		print 0
else:
	print get

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

int main(){
    string N;
    cin >> N;
    int A=0;
    for(int i=0;i<3;i++){
        if(N[i] == 'A') A++;
    }
    if(A==0 || A==3) cout<<"No";
    else cout <<"Yes";
}

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

typedef long long ll;

const int MOD = 1000000007;
const int INF = 1001001001;
const double PI = acos(-1);

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


int main() {
    int N, M;
    cin >> N >> M;
    vector<vector<int>> G(N);
    vector<int> ans(N, -1);
    vector<bool> isReach(N, false);
    rep(i, M) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        G[a].push_back(b);
        G[b].push_back(a);

    }

    queue<pair<int, int>> points;
    points.emplace(0, -1);
    isReach[0] = true;

    while(!points.empty()) {
        auto pts = points.front();
        ans[pts.first] = pts.second + 1;
        isReach[pts.first] = true;
        points.pop();
        for(int i = 0; i < G[pts.first].size(); i++) {
            if (isReach[G[pts.first][i]] == false) {
                points.emplace(G[pts.first][i], pts.first);
                isReach[G[pts.first][i]] = true;
            }
        }
    }

    bool flag = true;
    rep(i, N) if (isReach[i] == false) flag = false;

    if (flag) {
        cout << "Yes" << endl;
        rep(i, N-1) {
            cout << ans[i+1] << endl;
        }
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 10560
#include<bits/stdc++.h>
 using namespace std;
 
 
 int main()
 {
 	int g[4][4];
 	
 	for(int i=1;i<=3;i++)
 	{
 	   for(int j=1;j<=3;j++)
		{
			cin>>g[i][j];
		}	
	}
	
	for(int i=0;i<=100;i++)
	{
		int a1=i;	
		int b1=(g[1][1])-a1;
		int a2=(g[1][2]-b1);
		int a3=g[1][3]-b1;		
		int b2=(g[2][1])-a1;
		int b3=g[3][1]-a1;
		int ok=0;
		if(g[1][1]!=a1+b1)ok=1;
		if(g[1][2]!=a2+b1)ok=1;
		if(g[1][3]!=a3+b1)ok=1;
		if(g[2][1]!=b2+a1)ok=1;
		if(g[2][2]!=b2+a2)ok=1;
		if(g[2][3]!=b2+a3)ok=1;
		if(g[3][1]!=b3+a1)ok=1;
		if(g[3][2]!=b3+a2)ok=1;
		if(g[3][3]!=b3+a3)ok=1;
		if(ok==0)
		{
			cout<<"Yes\n";
			return 0;
		}
		
	}
	cout<<"No\n";
 }

Measured memory_bytes: 3616
f=lambda:map(int,input().split())
n=int(input())
g=[[] for _ in range(n)]
for i in range(n-1):
  a,b=f()
  g[a-1]+=[(b-1,i)]
  g[b-1]+=[(a-1,i)]
l=[0]*(n-1)
u=[0]*n
q=[(0,0)]
while q:
  v,s=q.pop()
  u[v]=1
  t=1
  for c,i in g[v]:
    if u[c]: continue
    if t==s: t+=1
    l[i]=t
    q+=[(c,t)]
    t+=1
print(max(l))
for i in l: print(i)

Measured memory_bytes: 43092
#include<stdio.h>
int main(){
  long long n,d[100010],s=0,m,i,p;
  scanf("%lld",&n);
  m=(n*(n+1))/2;
  for(i=0;i<n;i++){
    scanf("%lld",&d[i]);
    s+=d[i];
  }
  if(s%m)goto END;
  s/=m;//printf("%lld\n",s);
  p=d[0];
  for(i=1;i<n;i++)d[i-1]+=s-d[i];
  d[n-1]+=s-p;
  //for(i=0;i<n;i++)printf("%lld ",d[i]);printf("\n");
  for(i=0;i<n;i++){
    if(d[i]<0||d[i]%n)goto END;
  }
  printf("YES\n");
  return 0;
 END:;
  printf("NO\n");
  return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
using sint = int64_t;

template<class T> T read() {
	T t;
	cin >> t;
	return t;
}

template<class T> vector<T> read_vector(sint n) {
	vector<T> vs;
	for (sint i = 0; i < n; ++i) {
		vs.push_back(read<T>());
	}
	return vs;
}

inline void write() {
}

template<class T> void write(T const& t) {
	cout << t;
}

template<class T> void write(vector<T> const& ts) {
	if (ts.size() > 0) {
		cout << ts[0];
	}
	for (size_t i = 1; i < ts.size(); ++i) {
		cout << ' ' << ts[i];
	}
}

template<class T, class... Args> void write(T const& t, Args const&... args) {
	cout << t << ' ';
	write(args...);
}

template<class... Args> void writeln(Args const&... args) {
	write(args...);
	cout << '\n';
}

int main() {
	ios_base::sync_with_stdio(false);
	cin .exceptions(ios_base::badbit | ios_base::failbit);
	cout.exceptions(ios_base::badbit | ios_base::failbit);
	cin .tie(nullptr);
	cout.tie(nullptr);
	cout.precision(16);
	void run();
	run();
	return 0;
}

void run() {
	auto const N = read<sint>();
	auto as = read_vector<sint>(N);

	sint r = 0;
	sint n = 1;
	for (sint i = 0; i < N; ++i) {
		if (as[i] != n) {
			++r;
		}
		else {
			++n;
		}
	}

	if (r == N) {
		writeln(-1);
	}
	else {
		writeln(r);
	}
}

Measured memory_bytes: 2420
#include <iostream>
#include <string>
using namespace std;
int main(){
  string s;
  cin >> s;
  if(s == "SUN") cout << 7 << endl;
  else if(s == "MON") cout << 6 << endl;
  else if(s == "TUE") cout << 5 << endl;
  else if(s == "WED") cout << 4 << endl;
  else if(s == "THU") cout << 3 << endl;
  else if(s == "FRI") cout << 2 << endl;
  else if(s == "SAT") cout << 1 << endl;
}

Measured memory_bytes: 3628
#include <stdio.h>
#include <stdlib.h>

struct Node{
  int key;
  struct Node *parent;
  struct Node *left;
  struct Node *right;
};

#define NIL NULL
typedef struct Node* NodePointer;
NodePointer root;

void inOrder(NodePointer);
void preOrder(NodePointer);
void print(void);
void insert(int);
NodePointer makeNode(int);
int find(int);
NodePointer findNode(int);
NodePointer treeSuccessor(NodePointer);
NodePointer treeMinimum(NodePointer);
NodePointer treeMaximum(NodePointer);
void deleteNode(int);

int main(){
  int Q,i,x;
  char order[7];
  scanf("%d",&Q);
  for(i = 0 ; i < Q ; i++){
    scanf("%s",order);
    if(order[0] == 'i'){
      scanf("%d",&x);
      insert(x);
    }else if(order[0] == 'f'){
      scanf("%d",&x);
      puts(find(x) ? "yes" : "no");
    }else if(order[0] == 'd'){
      scanf("%d",&x);
      deleteNode(x);
    }else{
      print();
    }
  }
  return 0;
}

void inOrder(NodePointer x){
  if(x == NIL){ return; }
  inOrder(x->left);
  printf(" %d",x->key);
  inOrder(x->right);
}

void preOrder(NodePointer x){
  if(x == NIL){ return; }
  printf(" %d",x->key);
  preOrder(x->left);
  preOrder(x->right);
}

void print(){
  inOrder(root); printf("\n");
  preOrder(root); printf("\n");
}

void insert(int key){
  NodePointer x = root,y = NIL;
  NodePointer z = makeNode(key);
  while(x != NIL){
    y = x;
    if(z->key < x->key){
      x = x->left;
    }else{
      x = x->right;
    }
  }
  z->parent = y;
  if(y == NIL){
    root = z;
  }else if(z->key < y->key){
    y->left = z;
  }else{
    y->right = z;
  }
}

NodePointer makeNode(int key){
  NodePointer newNode = malloc(sizeof(struct Node));
  newNode->key = key;
  newNode->left = newNode->right = NIL;
  return newNode;
}

int find(int key){
  NodePointer x = root;
  while(x != NIL){
    if(key < x->key){
      x = x->left;
    }else if(key > x->key){
      x = x->right;
    }else{
      return 1;
    }
  }
  return 0;
}

NodePointer findNode(int key){
 NodePointer x = root;
  while(x != NIL){
    if(key < x->key){
      x = x->left;
    }else if(key > x->key){
      x = x->right;
    }else{
      return x;
    }
  }
  return NIL;
}

NodePointer treeSuccessor(NodePointer x){
  NodePointer y;
  if(x->right != NIL){
    return treeMinimum(x->right);
  }
  y = x->parent;
  while(y != NIL && x == y->right){
    x = y;
    y = y->parent;
  }
  return y;
}

NodePointer treeMinimum(NodePointer x){
  while(x->left != NIL){
    x = x->left;
  }
  return x;
}

NodePointer treeMaximum(NodePointer x){
  while(x->right != NIL){
    x = x->right;
  }
  return x;
}

void deleteNode(int key){
  NodePointer x,y;
  NodePointer z = findNode(key);
  if(z == NIL){ return; }
  if(z->left == NIL || z->right == NIL){
    y = z;
  }else{
    y = treeSuccessor(z);
  }
  if(y->left != NIL){
    x = y->left;
  }else{
    x = y->right;
  }
  if(x != NIL){
    x->parent = y->parent;
  }
  if(y->parent == NIL){
    root = x;
  }else if(y == y->parent->left){
    y->parent->left = x;
  }else{
    y->parent->right = x;
  }
  if(y != z){
    z->key = y->key;
  }
}

Measured memory_bytes: 19364
#include <iostream>
#include <algorithm>
#include <string>
#include <cstdio>

using namespace std;

int aa[2000][2000];
string s[2000];

int main(void) {
    int i, x, y;
    int h, w;
    scanf("%d", &h);
    scanf("%d", &w);

    for(i = 0; i < h; ++i) {
        cin >> s[i];
    }

    for(y = 0; y < h; ++y) {
        int l = 0;
        for(x = 0; x < w; ++x) {
            if(s[y][x] == '#') {
                for(i = l; i < x; ++i) {
                    aa[y][i] = x - l;
                }
                l = x + 1;
            }
        }
        for(i = l; i < w; ++i) {
            aa[y][i] = w - l;
        }
    }

    int ans = 0;
    for(x = 0; x < w; ++x) {
        int t = 0;
        for(y = 0; y < h; ++y) {
            if(s[y][x] == '#') {
                for(i = t; i < y; ++i) {
                    aa[i][x] += y - t;
                    ans = max(ans, aa[i][x]);
                }
                t = y + 1;
            }
        }
        for(i = t; i < h; ++i) {
            aa[i][x] += h - t;
            ans = max(ans, aa[i][x]);
        }
    }
    printf("%d\n", ans - 1);
    return 0;
}

Measured memory_bytes: 22016
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>
#include <string>

using namespace std;
typedef long long ll;
const long double EPS = 1e-9;
const ll mod = 1e9 + 7;

#define rep(i, n) for(int i = 0; i < n ; i++ )
#define For(i, a, b) for(int i = (a); i < (b) ; i++ )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

const int MAX_N = 100000;

int main(void){
    string S;
    cin >> S;
    
    int N = S.length();
    int a = 0;

    rep(i, N){
        if(S[i] == '0'){
            a ++;
        }
    }

    cout << min(a, N - a) * 2 << endl;

    return 0;
}

Measured memory_bytes: 512
#!/usr/bin/env python3
import sys


def solve(A: int, B: int, C: int, K: int):
    if A > K:
        print(K)
        return
    K -= A
    if B > K:
        print(A)
        return
    K -= B
    print(A - K)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(A, B, C, K)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9200
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
#define int         long long
#define ld          long double
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define sd(t)       scanf("%d",&(t))
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define hii         cout << "hii" << endl
#define okay        cout << "okay" << endl
#define hey         cout << "hey" << endl
const int INF = 1e12;
const int MOD = 1e9+7;
 
template <class T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T> ostream& operator << (ostream &os, const set<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T, class S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << v.x << ' ' << v.y; return os; }
template <class T, class S> ostream& operator << (ostream &os, const unordered_map<T, S> &v) { for (auto i : v) os << '(' << i.x << "=>" << i.y << ')' << ' '; return os; } 
 
 
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <class Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << endl; }
    template <class Arg1, class... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args) {
        const char* sep = strchr(names + 1, ',');
        cerr.write(names, sep - names) << " : " << arg1 << "  ";
        __f(sep + 1, args...);
    }
#else
#define trace(...) 
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#endif // ifndef ONLINE_JUDGE
 
clock_t time_p=clock();
void starboy1299()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}
 
void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("jjj.txt", "w", stdout);
    #endif
}

const int N = 2e5+10;

void solve(){  

    int x;
    cin >> x;

    cout << 1-x << endl;

}              


int32_t main(){
    fast();
    int t = 1;
    // cin>> t;
    for(int i=1; i<=t; i++){
        // cout << "Case #" << i << ": ";
        solve();
    }
    starboy1299();
}

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

using namespace std;

using int64 = long long;
const int mod = 1e9 + 7;
//const int mod = 998244353;

const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;


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

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}

template< typename F >
struct FixPoint : F {
  FixPoint(F &&f) : F(forward< F >(f)) {}

  template< typename... Args >
  decltype(auto) operator()(Args &&... args) const {
    return F::operator()(*this, forward< Args >(args)...);
  }
};

template< typename F >
inline decltype(auto) MFP(F &&f) {
  return FixPoint< F >{forward< F >(f)};
}

int main() {
  int N;
  cin >> N;
  vector< pair< int, int > > mx;
  for(int i = 0; i < N; i++) {
    int64 a, b;
    cin >> a >> b;
    mx.emplace_back(a - b, a + b);
  }
  sort(begin(mx), end(mx));
  int64 last = -infll, ret = 0;
  for(auto &p : mx) {
    if(last <= p.first) {
      last = p.second;
      ++ret;
    } else {
      chmin(last, p.second);
    }
  }
  cout << ret << endl;
}

Measured memory_bytes: 1400
#include <stdio.h>

int main(){
   char s[5];
    
   scanf("%s",s);
   if ((s[0]==s[1] && s[2]==s[3] && s[0]!=s[2] ) ||
       (s[0]==s[2] && s[1]==s[3] && s[0]!=s[1] ) ||
       (s[0]==s[3] && s[1]==s[2] && s[0]!=s[1] )) puts("Yes");
   else     puts("No");
   return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(void){
	int n;
	int box[50];
	int box1[50];
	int cnt;
	int i;
	cin>>n;
	for(i=0;i<n;i++){
		cin>>box[i];
		box1[i]=box[i];
	}
	sort(box,box+n);
	cnt=0;
	for(i=0;i<n;i++){
		if(box[i]!=box1[i])	cnt++;
	}
	if(cnt<=2)	cout<<"YES"<<endl;
	else		cout<<"NO"<<endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
mv1 = 0
mi1 = 0
mv2 = 0
for i in range(n):
    tmp = int(input())
    if tmp > mv1:
        mv1 = tmp
        mi1 = i
    elif tmp > mv2:
        mv2 = tmp

for i in range(n):
    if i != mi1:
        print(mv1)
    else:
        print(mv2)

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

int main()
{
  int a[6];
  int k;

  rep(i,5) cin >> a[i];
  cin >> k;

  if(a[4]-a[0]<=k) cout << "Yay!" << endl;
  else cout << ":(" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
using namespace std;
#define MAX 2000000000

int a[25][25];
int h, w;

int kyori(int m, int n)
{
	int sum = 0;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			sum += ((abs(i - m) < abs(j - n)) ? abs(i - m) : abs(j - n)) * a[i][j];
		}
	}
	return sum;
}

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

	int min = MAX;
	for (int m = 0; m < h; m++) {
		for (int n = 0; n < w; n++) {
			int l = kyori(m, n);
			if (min > l)
				min = l;
		}
	}

	cout << min << endl;

	return 0;
}


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

int main() {
  int A,B; cin >>A >>B;
  int ans=0;
  rep_eq(i,A,B) {
    string check=to_string(i);
    if (check[0]==check[4] and check[1]==check[3]) ans++;
  }
  cout <<ans <<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <queue>
#include <string>

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using vi = vector<int> ;
using vl = vector<ll>;

int main(){
    ll n,d;
    cin >> n >> d;
    ll x,y;
    ll cnt=0 ;
    ll dis;
    rep(i,n){
        cin >> x >> y;
        dis = x*x+y*y;
        if(dis <= d*d){
            cnt++; 
        }
    }
    cout << cnt <<endl;
    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <map>
using namespace std;

int N;
vector<int> A;

map<int,int> paper;// 数,登場回数
int main(){
    cin >> N;
    A.push_back(-1);
    for(int i = 0;i < N;i++){
        int j;
        cin >> j;
        A.push_back(j);
    }

    int ans = 0;

    for(int i = 1;i < N+1;i++){
        paper[A[i]]++;
    }

    int key = 0;
    int value = 0;
    for(auto x : paper){
        if(x.second % 2 == 1){
            ans++;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 5368
import sys
from itertools import product

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    query = [[] for _ in range(n)]
    for i in range(n):
        a = int(input())
        for _ in range(a):
            x, y = map(int, input().split())
            query[i].append([x - 1, y])

    res = 0
    for pattern in product([0, 1], repeat=n):
        for idx, p in enumerate(pattern):
            if p == 1:
                for x, y in query[idx]:
                    if pattern[x] != y:
                        break
                else:
                    continue
                break
        else:
            res = max(res, sum(pattern))

    print(res)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 3064