akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
char P[100001][110];
int main()
{
	long long int N,M=0,A=0,R=0,C=0,H=0;
	scanf("%lld",&N);
	for(int i=0;i<N;i++)
	    {
	    	scanf("%s",P[i]);
	    	if(P[i][0]=='M') M++;
	    	if(P[i][0]=='A') A++;
	    	if(P[i][0]=='R') R++;
	    	if(P[i][0]=='C') C++;
	    	if(P[i][0]=='H') H++;
		}
	long long int sum=0;
	sum=(M*A*R+M*A*C+M*A*H+M*R*C+M*R*H+M*C*H+A*R*C+A*R*H+R*C*H+A*C*H);
	printf("%lld\n",sum);
	return 0;
 } 


Measured memory_bytes: 11008
N, X, Y = map(int, input().split())
d = [0 for i in range(N)]
for a in range(1, N):
  for b in range(a+1, N+1):
    dest = min(b-a, abs(b-Y)+abs(a-X)+1)
    d[dest] += 1
for n in d[1:]:
  print(n)

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

int divide(int n) {
  int ret = 0;
  for (int i = 1; i * i <= n; ++i) {
    if (n % i == 0) {
      ++ret;
      if (i * i != n) ++ret;
    }
  }
  return ret;
}

int main(void) {
  int N;
  cin >> N;
  int answer = 0;
  for (int i = 1; i <= N; ++i) {
    if (i % 2 == 0) continue;
    int div_num = divide(i);
    if (div_num == 8) ++answer;
  }
  cout << answer << endl;
  return 0;
}

Measured memory_bytes: 256
// by DenyTianly
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

typedef long long LL;

const int inf = 1 << 26;

int p[100005];

int main(){
	int n, m;
	scanf("%d %d", &n, &m);
	for ( int i = 0; i < m; i ++ ) {
		int a, b;
		scanf("%d %d", &a, &b);
		p[a] ++; p[b] ++;
	}
	for ( int i = 1; i <= n; i ++ ) printf("%d\n", p[i]); 

	return 0;
}


Measured memory_bytes: 256
n,a,b = map(int, input().split())
s = input()
c = a+b

for i in range(n):
    if s[i]=='a':
        print('Yes' if c>0 else'No')
        c-=1
    elif s[i]=='b':
        if c>0 and b>0:
            print('Yes')
            c-=1
            b-=1
        else:
            print('No')
    else:
        print('No')

Measured memory_bytes: 54488
N,M,X=list(map(int,input().split()))

C=[]
A=[]
for n in range(N):
  AC=list(map(int,input().split()))
  C.append(AC[0])
  A.append(AC[1:])
ans=10**9

for n in range(2**N):
  total=0
  und=[0]*M
  for j in range(N):
    if n >> j & 1:
      total+=C[j]
      for m in range(M):
        und[m]+=A[j][m]
  if X <= min(und):
    ans=min(total,ans)
if ans==10**9:
  print(-1)
else:
  print(ans)

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

N, Q = map(int, input().split())

F = [0 for i in range(N)]
T = [[]for i in range(N)]

for i in range(N-1):
    a, b = map(int, input().split())
    T[a-1].append(b-1)
    T[b-1].append(a-1)

X = [0 for i in range(N)]
for i in range(Q):
    p, x = map(int, input().split())
    X[p-1] += x

ans = [X[i] for i in range(N)]
for i in range(N):
    F[i] = 1
    for j in range(len(T[i])):
        if F[T[i][j]] == 1:
            continue
        ans[T[i][j]] += ans[i]

for i in range(N):
    print(ans[i], end =" ")


Measured memory_bytes: 96076
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int N;cin >> N;
  vector<int> v(N+1,0);
  rep(i,N){
    int inp;cin >> inp;
    ++v[inp];
  }
  vector<int> w(N+1,0);
  vector<int> x(N+1,0);
  rep(i,N+1) ++w[v[i]];
  rep(i,N+1) x[i] = i*w[i];
  rep(i,N){
    x[i+1] += x[i];
    w[i+1] += w[i];
  }
  vector<int> f(N+1,0);
  f[0] = MAX_I;
  repp(X,1,N+1) f[X] = (x[X] + X*(w[N] - w[X]))/X;
  int id = N;
  repp(k,1,N+1){
    while(k>f[id])--id;
    cout << id << endl;
  }
  return 0;
}


Measured memory_bytes: 5632
import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int ans=0;
		int a=scan.nextInt();
		int b[]=new int[a];
		for(int i=0;i!=a;i++) {
			b[i]=scan.nextInt();
		}
		int i=0;
		int k=0;
		for(int o=0;;o++) {
			if(o==a) {
				k=1;
				break;
		}
		if(b[o]!=0) {
			break;
		}
		}
		if(k==1) {
			System.out.println(0);
		}
		else {
			k=0;
		for(;;) {
			if(k==1) {
				break;
			}
			if(b[i]!=0) {
				for(int j=i;;j++) {
					if(j==a) {
						break;
					}
					if(b[j]==0) {
						break;
					}
					b[j]--;
				}
				ans++;
				i=0;
				for(int j=0;j!=a+1;j++) {
					if(j==a) {
						k=1;
						break;
				}
				if(b[j]!=0) {
					break;
				}
					
				}
				continue;
			}
			
			i++;
		}
		System.out.println(ans);
	}
		}
	}

Measured memory_bytes: 21972
#include <iostream>
#include <limits.h>
using namespace std;

int main() {
  int n;
  int a[5000];
  int sum[5001];
  int tmp;
  int max;
  while (cin >> n, n) {
    for (int i=0; i<n; i++) {
      cin >> a[i];
    }
    sum[0] = 0;
    for (int i=0; i<n; i++) {
      sum[i+1] = sum[i] + a[i];
    }

    max = -INT_MAX;
    for (int i=0; i<n; i++) {
      for (int j=i+1; j<=n; j++) {
        tmp = sum[j] - sum[i];
        if (tmp > max) max = tmp;
      }
    }
    cout << max << endl;
  }

  return 0;
}

Measured memory_bytes: 1192
k = int(input())

def gcd(a, b):
    if a < b: a, b = b, a
    c = a % b
    if c == 0: return b
    while c!=0:
        c = a % b
        a, b = b, c
    return a

ans = 0
for a in range(1, k+1):
    for b in range(1, k+1):
        t = gcd(a, b)
        if t == 1:
            ans += k
            continue
        for c in range(1, k+1):
            ans += gcd(t, c)
print(ans)


Measured memory_bytes: 68528
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define pp pair<ll,ll>
typedef tree<pp,null_type,less<pp>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
#define ld long double
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin() , (x).end()
#define rep(i,a,b) for( ll i = a ; i < b ; i+=1 )
#define sz(v) (ll)(v.size())
#define hell (ll)1000000007
#define slld(x) scanf("%lld",&x)
ll t = 1;
const ll inf = hell, N=200005;
inline ll mult(ll x,ll y){return (x*y)%hell;}
inline ll add(ll x,ll y){x+=y;return x%hell;}
vector<ll> adj[N], revg[N], dist(N,inf);
void solve(){
	ll ans=inf, n, k;
	cin>>k>>n;
	vector<ll> v(n);
	rep(i,0,n)
		cin>>v[i];
	rep(i,0,n){
		if(i==0 || i==n-1)ans=min(ans,abs(v[n-1]-v[0]));
		if(i>0)ans=min(ans,k-v[i]+v[(i-1+n)%n]);
		if(i<n-1)ans=min(ans,v[i]+k-v[(i+1)%n]);
		//cout<<k-v[i]+v[(i-1+n)%n]<<" "<<v[i]+k-v[(i+1)%n]<<endl;
	}
	cout<<ans<<"\n";
}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
//    cin >> t ;
    while(t--){
        solve();
    }
    return 0 ;
}


Measured memory_bytes: 12800
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};
#[allow(unused_imports)]
use std::io::{stdout, stdin, BufWriter, Write};

fn main() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }

    input!{
      n: usize,
    }
    let ans = n*(n-1) / 2;
    puts!("{}\n", ans);
}


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


int main(void){
  
  long long int x, k, d;
  cin>>x>>k>>d;

  long long int g, a=abs(x);
  
  
  
    if(a>=abs(k*d)){
      g=a-k*d;
    }else{
      long long int n=a/d;
		
        if((k-n)%2==0){
            g=a-n*d;
        }else{
            g=a-n*d-d;
        }

    }
  
  cout<<abs(g);
    
}

Measured memory_bytes: 3620
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <map>
#include <cmath>
#include <cstring>

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;

const ll LINF = 1001002003004005006LL;
const int INF = 1001001001;

const int mod = 1000000007;

int main() {
    int n, m; cin >> n >> m;
    ll k; cin >> k;
    vector<ll> a(n), b(m);
    rep(i,n) cin >> a[i];
    rep(i,m) cin >> b[i];

    vector<ll> asum(n+1);
    vector<ll> bsum(m+1);
    rep(i,n) asum[i+1] = asum[i]+a[i];
    rep(i,m) bsum[i+1] = bsum[i]+b[i];

    int ans = 0;
    rep(i,n+1) {
        if (asum[i]>k) break;
        ll r = k-asum[i];
        auto itr = upper_bound(all(bsum), r);
        int bsize = itr-bsum.begin()-1;
        //cout << "i: " << i << " asize: " << i << " bsize: " << bsize << endl;
        ans = max(ans, i+bsize);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 9592
fun main() {
    var (a, b, c, k) = readIntList()
    var count = 0
    for (i in 1..a) {
        if (k-- > 0) {
            count += 1
        }
    }
    for (i in 1..b) {
        if (k-- > 0) {
            count += 0
        }
    }
    for (i in 1..c) {
        if (k-- > 0) {
            count += -1
        }
    }
    println(count)
}

fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)
fun <T> Array<Array<T>>.print() {
    this.forEach {
        println(it.joinToString(" "))
    }
}

Measured memory_bytes: 36456
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<string.h>
#include<complex>
#include<math.h>
using namespace std;
typedef long long int llint;
typedef vector<int> vint;
typedef vector<llint> vllint;
typedef vector<pair<int, int>> vpint;
typedef vector<pair<llint, llint>> vpllint;
#define rep(i,n) for(int i=0;i<n;i++)
#define yes(ans) if(ans)cout<<"yes"<<endl;else cout<<"no"<<endl;
#define Yes(ans) if(ans)cout<<"Yes"<<endl;else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl;else cout<<"NO"<<endl;
#define POSSIBLE(ans) if(ans)cout<<"POSSIBLE"<<endl;else cout<<"IMPOSSIBLE"<<endl;

class UnionFind {
public:
	//親の番号を格納する。親だった場合は-(その集合のサイズ)
	vector<int> Parent;

	//作るときはParentの値を全て-1にする
	//こうすると全てバラバラになる
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}

	//Aがどのグループに属しているか調べる
	int root(int A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}

	//自分のいるグループの頂点数を調べる
	int size(int A) {
		return -Parent[root(A)];//親をとってきたい
	}

	//AとBをくっ付ける
	bool connect(int A, int B) {
		//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
		A = root(A);
		B = root(B);
		if (A == B) {
			//すでにくっついてるからくっ付けない
			return false;
		}

		//大きい方(A)に小さいほう(B)をくっ付けたい
		//大小が逆だったらひっくり返しちゃう。
		if (size(A) < size(B)) swap(A, B);

		//Aのサイズを更新する
		Parent[A] += Parent[B];
		//Bの親をAに変更する
		Parent[B] = A;

		return true;
	}
};

bool check(int a, int b) {
	return a > b;
}

int main() {
	int h, w;
	cin >> h >> w;
	char s[52][52];
	rep(i, h) {
		cin >> s[i];
	}
	bool ans = true;
	rep(i, h) {
		rep(j, w) {
			if (s[i][j] == '#') {
				if (i != 0) {
					if (s[i - 1][j] == '#') {
						continue;
					}
				}
				if (i != h - 1) {
					if (s[i + 1][j] == '#') {
						continue;
					}
				}
				if (j != 0) {
					if (s[i][j - 1] == '#') {
						continue;
					}
				}
				if (j != w - 1) {
					if (s[i][j + 1] == '#') {
						continue;
					}
				}
				ans = false;
				break;
			}
		}
		if (!ans)break;
	}
	Yes(ans);
	return 0;
}

Measured memory_bytes: 256
using System;

public class Hello
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        string[] line = Console.ReadLine().Trim().Split(' ');
        var a = Array.ConvertAll(line, int.Parse);
        getAns(n, a);
    }
    static void getAns(int n, int[] a)
    {
        var m = 1000L;
        var k = 0L;
        for (int i = 0; i < n - 1; i++)
        {
            m += k * a[i];
            k = 0;
            if (a[i + 1] > a[i])
            {
                k = m / a[i];
                m -= k * a[i];
            }
        }
        m += k * a[n - 1];
        Console.WriteLine(m);
    }
}


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

int main() {
	uint64_t n, m, s; cin >> n;

	for (uint64_t i = 1, f = 1; ; f += ((2 * i) + 1), ++i)
		if (n <= f) { m = i; s = f; break; }

	while (n % m)--m;

	cout << ((m - 1) + (n / m - 1)) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int (i) = 0; (i) <(n); (i)++) 
#define so(v) sort(v.begin(),v.end())
using ll = long long;
using vi=vector<int>;
using vii=vector<vi>;
const int MAX = 510000;
const int MOD = 1000000007;
ll gcd(ll a, ll b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}
ll lcm(ll a, ll b)
{
   return a * b / gcd(a, b);
}
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
// 二項係数計算
long long com(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main() {
  ll n,m,a,b,c,x,y;cin>>a;
  a=a%10;
  if(a==3){
    cout<<"bon"<<endl;
  }
  else if(a==0||a==1||a==6||a==8){
    cout<<"pon"<<endl;
  }
  else{
    cout<<"hon"<<endl;
  }
  
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define sz(x) ((ll)(x).size())
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;

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;
}


template <class T>
T find_max(T l, T r, bool f(T)) {
  T c;
  while (r - l > 1) {
    c = (r + l) / 2;
    if (f(c)) {
      l = c;
    } else {
      r = c;
    }
  }

  return l;
}

ll N;
vector<int> a;


bool f(ll trial) {
  int num = 1;
  rep(i, N) {
    if (num == a[i])
      num++;
  }
  num--;
  return (trial <= num);
}

int main() {
  cin >> N;
  a = vector<int>(N);
  rep(i, N) {
    cin >> a[i];
  }

  bool ok = false;
  rep(i, N) {
    if (a[i] == 1)
      ok = true;
  }
  if (!ok) {
    cout << -1 << endl;
    return 0;
  }

  ll res = find_max(0LL, N + 1, f);
  cout << N - res << endl;
}

Measured memory_bytes: 1024
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>

#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

template <typename T>
using vector2 = vector<vector<T>>;
template <typename T>
vector2<T> initVec2(size_t n0, size_t n1, T e = T()){
    return vector2<T>(n0, vector<T>(n1, e));
}

template <typename T>
using vector3 = vector<vector<vector<T>>>;
template <typename T>
vector3<T> initVec3(size_t n0, size_t n1, size_t n2, T e = T()){
    return vector3<T>(n0, vector2<T>(n1, vector<T>(n2, e)));
}

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

    int n;
    string s;
    cin >> n >> s;

    vector<P> range;
    int head = -1;
    for(int i = 0; i < n; i++){
        if(s[i] == '1'){
            if(head == -1){
                head = i;
            }
            continue;
        }
        if(head != -1 && i - head >= 1){
            range.emplace_back(head, i - 1);
        }
        head = -1;
    }
    if(head != -1 && n - head >= 1){
        range.emplace_back(head, n - 1);
    }

    auto c = initVec2<P>(n, 0);
    for(P p : range){
        if(p.first - 2 >= 0 && s.substr(p.first-2, 3) == "101"){
            c[p.first-2].emplace_back(p.second + 1, p.second - p.first + 1);
            if(p.second - p.first + 1 >= 2){
                c[p.first-2].emplace_back(p.second, p.second - p.first);
            }
        }
        if(p.second + 2 < n && s.substr(p.second, 3) == "101"){
            c[p.first].emplace_back(p.second + 3, p.second - p.first + 1);
            if(p.second - p.first + 1 >= 2){
                c[p.first+1].emplace_back(p.second + 3, p.second - p.first);
            }
        }
    }

    vector<int> dp(n + 1);
    rep(i, n){
        for(P p : c[i]){
            dp[p.first] = max(dp[p.first], dp[i] + p.second);
        }
        dp[i+1] = max(dp[i+1], dp[i]);
    }
    cout << dp[n] << endl;

    return 0;
}


Measured memory_bytes: 24816
#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <cstring>
#include <cassert>
#include <utility>
#include <iomanip>
#include <chrono>
#include <random>
#include <bitset>

using namespace std;

#define sz(x) (int) x.size()
#define unique(x) x.erase(unique(x.begin(), x.end()), x.end())
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x)) 
#define y1 aksjdaskdjksjfksdjf
#define left kdnvldvoiwejifejg
#define right lkdsjflksdjfdjfk
#define prev asdasfsadjkjsdfjs
#define tm aklsjdasjdasjdkdjjf
#define lcm hddalkwjeidjjhasda
#define random_shuffle asdasdd

int a, b;

int main() { 
  cin >> a >> b;
  string aa = "", bb = "";

  for (int i = 0; i < a; i++) {
    aa.append(1, '0' + b);
  }
  for (int i = 0; i < b; i++) {
    bb.append(1, '0' + a);
  }

  if (aa < bb) {
    cout << aa << endl;
  } else {
    cout << bb << endl;
  }

  return 0;
}


Measured memory_bytes: 256
N=int(input())
A=list(map(int,input().split()))
A.sort()
flag=[0]*N

ans=0
M=A[-1]
B=[0]*(M+1)
for i in A:
    B[i]+=1

for i in A:
    if B[i]==1:
        ans+=1
    for j in range(i,M+1,i):
        B[j]+=1
print(ans)

Measured memory_bytes: 32176
k = int(input())+1
def gcd(a,b):
  if a < b:
    a, b = b, a
  while b!=0:
    a, b = b ,a%b
  return a
res = 0
for a in range(1,k):
  for b in range(1,k):
    for c in range(1,k):
      res += gcd(a,gcd(b,c))

print(res)

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

#define MEMSET_INF          127 // ~2B
#define MEMSET_HALF_INF     63  // ~1B
#define forn(i, n)          for(int i = 0; i < n; ++i)
#define fori(i, a, b)       for(int i = a; i < b; ++i)

using namespace std;

typedef long long           ll;
typedef vector<int>         vi;
typedef vector<vi>          vvi;
typedef pair<int, int>      ii;
typedef vector<ii>          vii;
typedef set<int>            si;
typedef map<string, int>    msi;

static auto speedup = [](){
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    return nullptr;
}();

const int mxn = 2e5;
ll k, a[mxn+1], b[mxn+1];

int main() {

    int n, m; cin >> n >> m >> k;

    for(int i = 1; i <= n; ++i) {
        cin >> a[i];
        a[i] += a[i-1];
    }
    for(int i = 1; i <= m; ++i) {
        cin >> b[i];
        b[i] += b[i-1];
    }

    int ans = 0;
    for(int i = 0, j = m; i <= n; ++i) {
        if(a[i] > k) { break; }
        while(a[i]+b[j] > k) { --j; }
        ans = max(ans, i+j);
    }
    cout << ans << endl;

}

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




























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

    vector <int> odd, even, div4;
    for (int i = 0; i < N; i++) {
        if (a[i] % 2 != 0) {
            odd.push_back(i);
        }
        else if (a[i] % 4 != 0) {
            even.push_back(i);
        }
        else {
            div4.push_back(i);
        }
    }
    if (odd.size() <= div4.size() || (even.size() == 0 && odd.size() == div4.size() + 1)) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 4792
n = gets.to_i
max = 0
array = []
 
(1..n).each do |number|
  cnt = 0
  while true
    if number % 2 == 0
      number /= 2
      cnt += 1
    else
      break
    end
  end
  array.push(cnt)
end
 
p 2** array.max

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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a,b,c,d;cin >> a >> b >> c >> d;
	cout << max(a*b,c*d) << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
 public static void main (String[ ] args) {
    String str;
    int sx, sy, tx, ty, i;
    int x, y, c1 = 0, c2 = 0, c3= 0, c4 = 0, c5 = 0, c6 = 0, c7 = 0, c8 = 0;
    Scanner scan = new Scanner(System.in);
     str = scan.next();
     sx = Integer.parseInt(str);
     str = scan.next();
     sy = Integer.parseInt(str);
     str = scan.next();
     tx = Integer.parseInt(str);
     str = scan.next();
     ty = Integer.parseInt(str);


     x = sx;
     for ( i = 1; i <= (tx - sx); i++) {
      x++;
      c1++;
     }
     y = sy;
     for (i = 1; i <= (ty - sy); i++) {
      y++;
      c2++;
     }
     for ( i = 1; i <= (tx - sx); i++ ) {
      x--;
      c3++;
     }
     for (i = 1; i <= (ty - sy); i++) {
      y--;
      c4++;
     }
     x--;
     for (i = 1; i <= (ty - sy) + 1; i++) {
      y++;
     c5++;
     }
     for ( i = 1; i <= (tx - sx) + 1; i++) {
      x++;
      c6++;
     }
     y--;
     x++;
     for (i = 1; i <= (ty - sy) + 1; i++) {
      y--;
      c7++;
     }
     for (i = 1; i <= (tx - sx) + 1; i++) {
      x--;
      c8++;
     }
     y++;

     StringBuilder sb = new StringBuilder();
     for (i = 1; i <= c1; i++) {
      sb.append("R");
     }
     for (i =1; i <= c2; i++) {
      sb.append("U");
     }
     for (i = 1; i <= c3; i++) {
      sb.append("L");
     }
     for (i = 1; i <= c4; i++) {
      sb.append("D");
     }
     sb.append("L");
     for (i = 1; i <= c5; i++) {
      sb.append("U");
     }
     for (i =1; i <= c6; i++) {
      sb.append("R");
     }
     sb.append("D");
     sb.append("R");
     for ( i = 1; i <= c7; i++) {
      sb.append("D");
     }
     for (i = 1; i <= c8; i++) {
      sb.append("L");
     }
     sb.append("U");

     System.out.println(new String(sb));

    
 }
}

Measured memory_bytes: 9812
#include <iostream>
using namespace std;
int main() {
    int n;
    cin >> n;
    int t[n+1], x[n+1], y[n+1];
    t[0] = x[0] = y[0] = 0;
    int distMinusTime;
    for (int i=1; i<n+1; i++) {
        cin >> t[i] >> x[i] >> y[i];
        distMinusTime = abs(x[i]-x[i-1]) + abs(y[i]-y[i-1]) - (t[i]-t[i-1]);
        if (distMinusTime > 0 || distMinusTime%2 != 0) {
            cout << "No" << endl;
            return 0;
        }   
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 4724
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def diff(p1, p2):
    return abs(p1[0] - p2[0]) + abs(p1[1] - p2[1])

def main():
    H, W, D = LI()
    A = []
    for _ in range(H):
        A.append(LI())
    Q = I()
    LR = []
    for _ in range(Q):
        LR.append(LI())
    nums = [[] for _ in range(90000)]
    valAndPoint = []
    for r in range(H):
        for c in range(W):
            valAndPoint.append((A[r][c], (r, c)))
    valAndPoint = sorted(valAndPoint, key=lambda x: x[0])
    dists = [[] for _ in range(90000)]
    for val, point in valAndPoint:
        nums[val % D].append(point) # val // D番目
    cum_nums = [[0] for _ in range(90000)]
    for amari, points in enumerate(nums):
        if len(points) < 1:
            continue
        cur_p = points[0]
        for p in points[1:]:
            dists[amari].append(diff(cur_p, p))
            ix = len(dists[amari])
            cum_nums[amari].append(cum_nums[amari][ix-1] + diff(cur_p, p))
            cur_p = p
    for lr in LR:
        l = lr[0]
        r = lr[1]
        l_amari = l % D

        st_hops = l // D
        en_hops = r // D
        if l % D == 0:
            st_hops -= 1
            en_hops -= 1
        print(cum_nums[l_amari][en_hops] - cum_nums[l_amari][st_hops])
main()



Measured memory_bytes: 68624
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin >> s;
    int ans=0;
     if(s[0]=='R'&&s[1]=='R'&&s[2]=='R')ans=3;
    else if(s[0]=='R'&&s[1]=='R'&&s[2]=='S')ans=2;
    else if(s[0]=='S'&&s[1]=='R'&&s[2]=='R')ans=2;
    else if(s[0]=='S'&&s[1]=='S'&&s[2]=='S')ans=0;
    else ans=1;
    cout << ans << endl;
}

Measured memory_bytes: 3584
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;

int main() {
    char s[5];
    cin >> s;

    for (int i = 0; i < 4; i++) {
        s[i] -= '0';
    }

    for (int i = 0; i < 8; i++) {
        string r = to_string((int)s[0]);
        int t = s[0];
        for (int j = 0; j < 3; j++) {
            r += ((1 << j & i) ? '+' : '-') + to_string((int)s[j + 1]);
            t += s[j + 1] * ((1 << j & i) ? 1 : -1);
        }
        if (t == 7) {
            cout << r + "=7" << endl;
            break;
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());


int main(){
    string s3,s4;

    cin >> s3;
    cin >> s4;
    if(s3.length() < s4.length()) cout << "LESS" << endl;
    else if(s3.length() > s4.length()) cout <<"GREATER" << endl;
    else if(s3 < s4) cout << "LESS"<<endl;
    else if(s3 > s4) cout << "GREATER" << endl;
    else cout << "EQUAL" << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <string>
#include <utility>
#include <map>
#include <deque>

using namespace std;
#define rep(i,n) for(int i=1;i<=(int)(n);i++)
#define Rep(i,n) for(int i=0;i<=(int)(n-1);i++)
typedef long long ll;
typedef map<int,int> mint;
typedef pair<int,int> pint;
typedef pair<ll,ll> pll;
typedef deque<pair<ll,ll>> dep;
int dx[]={-1,0,1,0};
int dy[]={0,-1,0,1};
int inf=1e9+1000;
const int mod=1e9+7;
ll infi=1e18+100;

//x=10111;
//x<<2 = 1011100 (右シフト),x>>2 = 101 (左シフト)
//(x>>2)&1 = 101 & 001 = 1
//iビット目は、(x>>i) & 1 でわかる(x>>i)%2 でもよい

ll N;
ll a[100002];
ll x;



int main(){
	cin>>N>>x;
	Rep(i,N) cin>>a[i];
	ll ans=0;
	if(a[0]>x) {ans+=(a[0]-x); a[0]=x;}
	Rep(i,N-1){
		if((a[i]+a[i+1])>x){
			ans+=(a[i+1]+a[i]-x);
			a[i+1]=x-a[i];
		}
	}
	cout<<ans<<endl;

	
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <map>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
#define LLINF (1LL<<60)
#define INF (1<<30)
#define F first
#define S second
int main(void){
    int masu[105][105]={{0}};
    int n,w,h;
    long long ans=0;
    cin>>w>>h>>n;
    for(int i=0;i<n;i++){
        long long x,y,a;
        cin>>x>>y>>a;
        a--;
        if(a==0LL){
           for(int i=0;i<h;i++){
               for(int j=0;j<x;j++){
                   masu[i][j]=1;
               }
           } 
        }
        if(a==1LL){
            
           for(int i=0;i<h;i++){
               for(int j=x;j<w;j++){
                   masu[i][j]=1;
               }
           } 
        }
        if(a==2LL){
           for(int i=0;i<y;i++){
               for(int j=0;j<w;j++){
                   masu[i][j]=1;
               }
           } 
        }
        if(a==3LL){
           for(int i=y;i<h;i++){
               for(int j=0;j<w;j++){
                   masu[i][j]=1;
               }
           } 
        }
    }
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(masu[i][j]==0) ans++;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
typedef long long LL;
int N;

int main(){
	string S;
	cin>>S;
	int ans=0;
	REP(i,S.size()){
		if(S[i]!=S[S.size()-1-i]){
			ans++;
		}
	}
	cout<<ans/2<<endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <unordered_map> 
#include <unordered_set>
#include <functional>
#include <bitset>

using namespace std;

typedef pair<long long int, long long int> P;
typedef tuple<int, int, int> T;

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

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

int main(){
	int N;
	cin >> N;
	double x[100], y[100];
	for(int i = 0; i < N; i++){
		cin >> x[i] >> y[i];
	}
	double ans = INF;
	for(int i = 0; i < N; i++){
		for(int j = i + 1; j < N; j++){
			double cx = (x[i] + x[j]) / 2;
			double cy = (y[i] + y[j]) / 2;
			double r = dist(x[i], x[j], y[i], y[j]) / 2;
			bool flag = true;
			for(int l = 0; l < N; l++){
				if(dist(cx, x[l], cy, y[l]) - 1e-9 > r){
					flag = false;
				}
			}
			if(flag){
				ans = min(ans, r);
			}
		}
	}
	for(int i = 0; i < N; i++){
		for(int j = i + 1; j < N; j++){
			for(int k = j + 1; k < N; k++){
				// y - (y[j] + y[i]) / 2 = -(x[j] - x[i]) / (y[j] - y[i]) * (x - (x[j] + x[i]) / 2)
				// (x[j] - x[i]) * (x - (x[j] + x[i]) / 2) + (y[j] - y[i]) * (y - (y[j] + y[i]) / 2) = 0
				double a1 = x[j] - x[i];
				double b1 = y[j] - y[i];
				double c1 = -(x[j] - x[i]) * (x[j] + x[i]) / 2 - (y[j] - y[i]) * (y[j] + y[i]) / 2;
				double a2 = x[k] - x[i];
				double b2 = y[k] - y[i];
				double c2 = -(x[k] - x[i]) * (x[k] + x[i]) / 2 - (y[k] - y[i]) * (y[k] + y[i]) / 2;
				if(a1 * b2 - a2 * b1 == 0){
					continue;
				}
				double cx = (b1 * c2 - b2 * c1) / (a1 * b2 - a2 * b1);
				double cy = (a2 * c1 - a1 * c2) / (a1 * b2 - a2 * b1);
				double r = dist(cx, x[i], cy, y[i]);
				//cout << cx << " " << cy << " " << r << endl;
				bool flag = true;
				for(int l = 0; l < N; l++){
					//cout << dist(cx, x[l], cy, y[l]) << endl;
					if(dist(cx, x[l], cy, y[l]) - 1e-9 > r){
						flag = false;
					}
				}
				if(flag){
					ans = min(ans, r);
				}
			}
		}
	}
	printf("%.15f\n", ans);
	return 0;
}

Measured memory_bytes: 256
def snuke_the_wizard(N: int, Q: int, s: str, queries: list)->int:
    l, r = -1, N
    for t, d in reversed(queries):
        if d == 'R':
            if 0 <= r-1 and s[r-1] == t:
                r -= 1
            if 0 <= l and s[l] == t:
                l -= 1
        else:
            if l + 1 < N and s[l+1] == t:
                l += 1
            if r < N and s[r] == t:
                r += 1
    return r - l - 1 if l < r else 0


if __name__ == "__main__":
    Q = 0
    N, Q = map(int, input().split())
    s = input()
    queries = [tuple(input().split()) for _ in range(Q)]
    ans = snuke_the_wizard(N, Q, s, queries)
    print(ans)


Measured memory_bytes: 17840
#![allow(non_snake_case)]
#![allow(unused_variables)]

fn main() {
    let N: usize = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().parse().unwrap()
    };
    let A: Vec<char> = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().chars().collect()
    };
    let B: Vec<char> = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().chars().collect()
    };
    let C: Vec<char> = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().chars().collect()
    };

    let ans: i64 = (0..N)
        .map(|i| {
            if A[i] == B[i] && B[i] == C[i] {
                0
            } else if A[i] == B[i] || B[i] == C[i] || C[i] == A[i] {
                1
            } else {
                2
            }
        })
        .sum();

    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9+7,MAX = 1e5;

int main()
{
	ll n,a,b;
	cin >> n >> a >> b;
	ll c = a+b;
	ll ans = 0;
	if(n%c>a)
	{
		ans += a;
	}
	else
	{
		ans += n%c;
	}
	//cout<<ans<<endl;
	ans += (n/c)*a;
	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>
#define ll long long

using namespace std;

long long MOD = 1000000007;

int S, T;
int N, M;

template<typename T>
void cout_vec(vector<T> &vec){
    for(int i=0; i<vec.size(); i++){
        if (i!=0){
            cout << ' ';
        }
        cout << vec[i];
    }
    cout << endl;
}

int dijkstra(int node, vector<vector<int> > &edge){
    vector<vector<int> > dist(N,vector<int>(3,MOD));

    priority_queue<tuple<int,int,int>, vector<tuple<int,int,int>>, greater<tuple<int,int,int>>> que;
    que.push(make_tuple(0, node, 0));
    while((int)que.size()>0){
        int d=get<0>(que.top());
        int x=get<1>(que.top());
        int s=get<2>(que.top());
        que.pop();

        vector<int> tmp={d,x,s};
        //cout_vec(tmp);

        if(x==T && s==0){
            return d;
        }

        if(dist[x][s]<=d){
            continue;
        }else{
            dist[x][s]=d;
        }

        if(s==2){
            d++;
        }

        for(auto nx:edge[x]){
            que.push(make_tuple(d,nx,(s+1)%3));
        }
    }
    return -1;
}

int main(){
    cin >> N >> M;
    vector<vector<int> > edge(N,vector<int>(0));
    for(int i=0; i<M; i++){
        int u, v;
        cin >> u >> v;
        u--;v--;
        edge[u].push_back(v);
    }

    cin >> S >> T;
    S--;T--;
    cout << dijkstra(S, edge) << endl;
}

Measured memory_bytes: 11136
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef pair<P,int> T;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
int a,b,c,d,n,r;
int le,ri,up,down;
int area,len;
vector<T> vec;
map<P,int> m;
map<P,int>::iterator it;
int imos[2][10004];
int main()
{
    while(1)
    {
        memset(imos,0,sizeof(imos));
        area=0;len=0;
        le=down=INF;
        ri=up=1;
        m.clear();
        scanf("%d %d",&n,&r);
        if(n==0&&r==0)break;
        for(int i=0;i<n;i++)
        {
            scanf("%d %d %d %d",&a,&b,&c,&d);
            a++;b++;c++;d++;
            ri=max(ri,c);
            le=min(le,a);
            up=max(up,d);
            down=min(down,b);
            m[P(a,b)]++;
            m[P(a,d)]--;
            m[P(c,b)]--;
            m[P(c,d)]++;
        }
        vec.pb(T(P(INF,INF),INF));
        SORT(vec);
        int index=0;
        for(int i=le;i<=ri+1;i++)
        {
            for(int j=down;j<=up+1;j++)
            {
                imos[i%2][j]=imos[i%2][j-1];
                it=m.find(P(i,j));
                if(it!=m.end())imos[i%2][j]+=(*it).sec;
            }
            for(int j=down;j<=up+1;j++)
            {
                imos[i%2][j]+=imos[(i-1)%2][j];
                if(imos[i%2][j]>0)area++;
                if(!!imos[i%2][j-1]!=!!imos[i%2][j])len++;
                if(!!imos[(i-1)%2][j]!=!!imos[i%2][j])len++;
            }
        }
        cout << area << endl;
        if(r==2)cout << len << endl;
    }
    return 0;
}

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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

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

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; }

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

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

  int N;
  cin >> N;
  if(N%2 == 0){
    cout << N/2-1 << endl;
  }else{
    cout << (N-1)/2 << endl;
  }

  return 0;
}


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

const int maxn = 505;

char mp[maxn][maxn];
char a[maxn][maxn], b[maxn][maxn];

int main()
{
	int n, m;
	scanf("%d%d", &n, &m);
	for (int i = 0; i < n; i++)
		scanf("%s", mp[i]);
	memset(a, '.', sizeof a);
	memset(b, '.', sizeof b);
	for (int i = 0; i < n; i++)
		a[i][m] = b[i][m] = 0;
	for (int i = 0; i < n; i++)
	{
		a[i][0] = '#';
		b[i][m - 1] = '#';
		if (i & 1)
			for (int j = 0; j < m - 1; j++)
				a[i][j] = '#';
		else
			for (int j = 1; j < m; j++)
				b[i][j] = '#';
	}
	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++)
			if (mp[i][j] == '#')
				a[i][j] = b[i][j] = '#';
	for (int i = 0; i < n; i++)
		puts(a[i]);
	puts("");
	for (int i = 0; i < n; i++)
		puts(b[i]);
	return 0;
}


Measured memory_bytes: 1536
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
#include <map>
#include <set>
#include <queue>

#define ll long long
#define REP(i,n) for(int i = 0; i < (n); ++i)
#define PI 3.141592653589
#define MOD 1000000007

using namespace std;

template<typename T> T gcd(T a, T b){ return (a % b)? gcd(b, a%b) : b; }
template<typename T> T lcm(T a, T b){ return a * b / gcd(a, b); }

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

    n--;
    ll ctr = 0;
    for(int i = 1; i <= n; i++){
        ctr += n/i;
    }

    cout << ctr << endl;
    
    return 0;
}

Measured memory_bytes: 3648
######################################################
############Created by Devesh Kumar###################
#############devesh1102@gmail.com####################
##########For CodeForces(Devesh1102)#################
#####################2020#############################
######################################################
import sys
input = sys.stdin.readline

# import sys
import heapq 
import copy
import math
import decimal
# import sys.stdout.flush as flush
# from decimal import *
#heapq.heapify(li) 
#
#heapq.heappush(li,4) 
#
#heapq.heappop(li)
#
# &	Bitwise AND Operator	10 & 7 = 2
# |	Bitwise OR Operator	10 | 7 = 15
# ^	Bitwise XOR Operator	10 ^ 7 = 13
 
# <<	Bitwise Left Shift operator	10<<2 = 40
# >>	Bitwise Right Shift Operator
# '''############ ---- Input Functions ---- #######Start#####'''
 

def inp():
	return(int(input()))
def inlt(): 
	return(list(map(int,input().split())))
def insr():
	s = input()
	return(list(s[:len(s) - 1]))
def insr2():
	s = input()
	return((s[:len(s) - 1]))
def invr():
	return(map(int,input().split()))
 ############ ---- Input Functions ---- #######End
 # #####   

def pr_list(a):
	print(*a, sep=" ")
def main():
	# tests =  inp()
	tests = 1
	mod = 998244353
	limit = 10**18
	ans = 0
	for test in range(tests):
		[n,w] = inlt()
		val = []
		for i in range(n):
			a = inlt()
			val.append(a)
		dp = [[-1 for i in range(w+3)]for j in range(2)]
		dp[0][0] = 0
		ans = 0
		for i in range(n):
			
			for j in range(w+3):
				dp[(i+1)%2][j] = max(dp[(i+1)%2][j],dp[(i)%2][j])
				if dp[i%2][j] != -1 and j + val[i][0]<=w:
					dp[(i+1)%2][j+val[i][0]] = max(	dp[(i)%2][j+val[i][0]] , 	dp[(i)%2][j] + val[i][1])
					ans = max(ans,dp[(i+1)%2][j+val[i][0]] )
		print(ans)

if __name__== "__main__":
	main()

Measured memory_bytes: 71660
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <math.h>
#include <stack>
#include <climits>
#include <bitset>

using namespace std;
typedef long long ll;

//最小公倍数
ll gcd(ll x, ll y) {
  ll tmp = 0;
  if (x < y){
    tmp=x;
    x=y;
    y=tmp;
  }
  while (y > 0) {
    ll r = x % y;
    x = y;
    y = r;
  }
  return x;
}

//最大公倍数
ll lcm(ll x,ll y){
  return x/gcd(x,y)*y;
}


//for(int i = ; i < ; i++){}

int main(){
  int a[3];
  cin>>a[0]>>a[1]>>a[2];
  sort(a,a+3);
  cout<<a[0]+a[1]<<endl;
  return 0;
}
  



Measured memory_bytes: 256
from fractions import gcd
import copy

class SegmentTree:
    def __init__(self, N, func, I):
        self.sz = 2 ** (N-1).bit_length()
        self.func = copy.deepcopy(func)
        self.I = copy.deepcopy(I)
        self.seg = [copy.deepcopy(I) for i in range(self.sz * 2)]

    def assign(self, k, x):
        self.seg[k + self.sz] = copy.deepcopy(x)

    def build(self):
        for i in range(self.sz - 1, 0, -1):
            self.seg[i] = self.func(self.seg[2 * i], self.seg[2 * i + 1])

    def update(self, k, x):
        k += self.sz
        self.seg[k] = copy.deepcopy(x)
        while k > 1:
            k //= 2
            self.seg[k] = self.func(self.seg[2 * k], self.seg[2 * k + 1])

    def query(self, a, b):
        L = copy.deepcopy(self.I)
        R = copy.deepcopy(self.I)
        a += self.sz
        b += self.sz
        while a < b:
            if a % 2 == 1:
                L = self.func(L, self.seg[a])
                a += 1
            if b % 2 == 1:
                b -= 1
                R = self.func(self.seg[b], R)
            a //= 2
            b //= 2
        return self.func(L, R)

N = int(input())
A = list(map(int,input().split()))

def f(x,y):
    if x * y == 0:
        return x + y
    else:
        return gcd(x,y)

seg = SegmentTree(N + 1, f, 0)
for i in range(N):
    seg.assign(i , A[i])
seg.build()

ans = 1
for i in range(N):
    ans = max(ans , f(seg.query(0 , i) , seg.query(i + 1 , N)))
print(ans)



Measured memory_bytes: 121648
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include <limits>
#include <numeric>
#include <type_traits>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }


using namespace std;
int N,X,ans;
int gcd(int x, int y)
{
	return y==0 ? x:gcd(y,x % y);
}

int main(){
    ans = 0;
    cin >> N >> X;
    int x[N];
    rep(i,N){
        cin >> x[i];
        ans = gcd(ans,abs(X-x[i]));
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,N) for(int i=0;i<N;i++)
using namespace std;
long long  INF=1000000000000000000;
long long mod=1000000007;
using namespace std;


int main(){

int r;
cin>>r;
cout<<r*r<<endl;


 return 0;
}
/*

*/

Measured memory_bytes: 256