akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

using ll = long long;

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

    ll h, w, n;
    cin >> h >> w >> n;

    vector<ll> cnt(10);
    set<pair<int, int>> pos;
    for (int i = 0; i < n; ++i) {
        int r, c;
        cin >> r >> c;
        pos.insert(make_pair(r, c));
    }

    set<pair<int, int>> check;
    for (const auto &p : pos) {
        for (int i = max(1, p.first - 2); i <= p.first; ++i)
            for (int j = max(1, p.second - 2); j <= p.second; ++j) {
                if (h < i + 2 || w < j + 2) continue;
                if (check.count(make_pair(i, j)) != 0) continue;

                int num = 0;
                for (int r = i; r <= i + 2; ++r)
                    for (int c = j; c <= j + 2; ++c)
                        if (pos.count(make_pair(r, c)) != 0) ++num;
                if (num != 0) ++cnt[num];
                check.insert(make_pair(i, j));
            }
    }

    cout << (h - 2) * (w - 2) - accumulate(cnt.begin(), cnt.end(), 0ll) << '\n';
    for (int i = 1; i < 10; ++i) cout << cnt[i] << '\n';

    return 0;
}


Measured memory_bytes: 47104
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	string s; cin>>s;
	int N=s.size(), ret=N/2;
	for (char ch : s)
		if(ch=='p')
			ret--;
	cout<<ret<<"\n";
	return 0;
}

Measured memory_bytes: 512
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <iostream>
#include <string>
#include <set>
#include <map>
#include <unordered_map>
#include <complex>
#include <iomanip>
#include <cmath>
#include <tuple>
using namespace std;

long long const MOD = 1000000007LL;

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

    if ((a + b) % 2 != 0) cout << "IMPOSSIBLE" << endl;
    else cout << (a + b) / 2 << endl;
}


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

long long n, sum = 0;
vector<int> a;
bool res = 1;

int main() {
  cin >> n;
  a.resize(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    sum += a[i];
  }
  if (sum % (n * (n + 1) / 2) != 0)
    res = 0;
  else {
    long long cnt = 0, k = sum / (n * (n + 1) / 2);
    for (int i = 0; i < n; ++i) {
      long long diff = a[(i + 1) % n] - a[i] - k;
      if (diff % n != 0 || diff > 0) res = 0;
      cnt += -diff / n;
    }
    if (cnt != k) res = 0;
  }
  if (res)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 640
n=int(input())
a=list(map(int,input().split()))
ans=0
temp=0
for i in range(n):
  ans=ans+abs(a[i]-temp)
  temp=a[i]
ans=ans+abs(temp)
a.insert(0,0)
a.append(0)
for i in range(1,n+1):
  print(ans-abs(a[i]-a[i-1])-abs(a[i+1]-a[i])+abs(a[i+1]-a[i-1]))

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

int main(){
    int n;cin>>n;
    int ans=0;
    vector<int> l(n);
    rep(i,n) cin >> l[i];
    sort(l.begin(), l.end());
    rep(i,n){
        for(int j=i+1;j<n;j++){
            for(int k=j+1;k<n;k++){
                if(l[i]==l[j] || l[j]==l[k]) continue;
                if(l[i]+l[j]>l[k]){
                    ans+=1;
                    //cout << i<<j<<k<<endl;
                }
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
using P = pair<int,int>;
vector<int> res;
int n,q;
int main()
{
    cin >> n >> q;
    string s;
    cin >> s;
    res.resize(n+1);
    res[0] = 0;
    rep(i,n){
        if(s[i] == 'A'){
            if(i+1 < n && s[i+1] == 'C')res[i+1]++;
        }
        if(i+2 <= n)res[i+2] += res[i+1];
    }
    
    
    while(q--){
        int l,r;
        cin >> l >> r;
        l--;r--;
        int ans = res[r] - res[l];
        
        cout << ans << endl;

    }
    
    return 0;
}

Measured memory_bytes: 1408
#import<cstdio>
int t,n,c[1510],i,a,j;main(){for(;~scanf("%d",n?c+j++:&n););for(;c[3*n-1]=i<n;a=!printf("%d\n",a))for(j=3*i++;t=c[j+2];j+=3)a=(a<c[j+1]?c[j+1]:~-a/t*t+t)+c[j];}

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

using namespace std;

typedef long long ll;

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

    int a,b;
    string op;

    cin>>a>>op>>b;

    if(op == "+"){
        cout<< a +b<<endl;
    } else {
        cout << a - b << endl;
    }
    return 0;
} 

Measured memory_bytes: 256
N = int(input())
A = [int(x) for x in input().split()]
ans = True
for n in range(N):
    if A[n] %2 == 0:
        if A[n] %3 != 0 and A[n] %5 != 0:
            ans = False
if ans:
    print("APPROVED")
else:
    print("DENIED")


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <cmath>
#include <functional>
using namespace std;
#define MOD 998244353
#define INF 1<<30
#define LINF (ll)1<<62
#define MAX 510000
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
#define uni(q) unique(all(q)),q.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;
const int mod = 1e9 + 7;

template< typename Monoid >
struct SegmentTree {
  using F = function< Monoid(Monoid, Monoid) >;

  int sz;
  vector< Monoid > seg;

  const F f;
  const Monoid M1;

  SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1) {
    sz = 1;
    while(sz < n) sz <<= 1;
    seg.assign(2 * sz, M1);
  }

  void set(int k, const Monoid &x) {
    seg[k + sz] = x;
  }

  void build() {
    for(int k = sz - 1; k > 0; k--) {
      seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
    }
  }

  void update(int k, const Monoid &x) {
    k += sz;
    seg[k] = x;
    while(k >>= 1) {
      seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
    }
  }

  Monoid query(int a, int b) {
    Monoid L = M1, R = M1;
    for(a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
      if(a & 1) L = f(L, seg[a++]);
      if(b & 1) R = f(seg[--b], R);
    }
    return f(L, R);
  }

  Monoid operator[](const int &k) const {
    return seg[k + sz];
  }

  template< typename C >
  int find_subtree(int a, const C &check, Monoid &M, bool type) {
    while(a < sz) {
      Monoid nxt = type ? f(seg[2 * a + type], M) : f(M, seg[2 * a + type]);
      if(check(nxt)) a = 2 * a + type;
      else M = nxt, a = 2 * a + 1 - type;
    }
    return a - sz;
  }


  template< typename C >
  int find_first(int a, const C &check) {
    Monoid L = M1;
    if(a <= 0) {
      if(check(f(L, seg[1]))) return find_subtree(1, check, L, false);
      return -1;
    }
    int b = sz;
    for(a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
      if(a & 1) {
        Monoid nxt = f(L, seg[a]);
        if(check(nxt)) return find_subtree(a, check, L, false);
        L = nxt;
        ++a;
      }
    }
    return -1;
  }

  template< typename C >
  int find_last(int b, const C &check) {
    Monoid R = M1;
    if(b >= sz) {
      if(check(f(seg[1], R))) return find_subtree(1, check, R, true);
      return -1;
    }
    int a = sz;
    for(b += sz; a < b; a >>= 1, b >>= 1) {
      if(b & 1) {
        Monoid nxt = f(seg[--b], R);
        if(check(nxt)) return find_subtree(b, check, R, true);
        R = nxt;
      }
    }
    return -1;
  }
};

int main(){
    ll n,q; cin >> n >> q;
    SegmentTree<ll> seg(n,[](ll a, ll b){return a+b;},0);
    while(q--){
        ll t; cin >> t;
        ll x,y; cin >> x >> y; x--;
        if(t==0){
            ll s = seg.operator[](x);
            seg.update(x,s+y);
        }else{
            cout << seg.query(x,y) << endl;
        }
    }
}



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

long long dfs(long long a,long long b,int t){
	if( b == 0 ){
		if(t != 2)return -a;
		return 0;
	}
	// cout << "r:" << a << " " << b << endl;
	// cout << (a/b) * 2 * b << " " << ( ((a%b!=0) && (t%2==1)) ?b:0)  << endl;
	return (a/b) * 2 * b + ( ((a%b!=0) && (t==1)) ?b:0 ) + dfs( b, a%b, t+1);
}

int main(void){
	long long n,x;
	cin >> n >> x;
	cout << dfs(x,n-x,1)+x << endl;

	return 0;
}

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

int main() {
  int N, W;
  cin >> N >> W;
  vector<int> weight(N), value(N);
  for (int i = 0; i < N; i++) {
    cin >> weight.at(i) >> value.at(i);
  }
  
  vector<vector<long long int>> DP(N + 1, vector<long long int>(100001, 0));
  for (int j = 1; j <= 100000; j++) DP.at(0).at(j) = 2000000000;
  
  for (int i = 0; i < N; i++) {
    for (int j = 0; j <= 100000; j++) {
      if (value.at(i) <= j) {
        DP.at(i + 1).at(j) = min(DP.at(i).at(j - value.at(i)) + weight.at(i),
                                 DP.at(i).at(j));
      }
      else {
        DP.at(i + 1).at(j) = DP.at(i).at(j);
      }
    }
  }
  
  long long int ans = 0;
  for (long long int i = 0; i < 100001; i++) {
    if (DP.at(N).at(i) <= W) ans = i;
  }
  cout << ans << endl;
}

Measured memory_bytes: 80256
// #include {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}

const int N = 400 , P = 1e9 + 7;
int f[N][N] , cnt[N][N];
pii nxt[N][N];
int a[N] , posa[N] , b[N] , posb[N] , n , cof;
inline void pp(int &x,int d){
    if((x+=d)>=P)x-=P;
}

int main(){
    cin >> n;
    rep(i,0,n) cin >> a[i] , posa[a[i]] = i;
    rep(i,0,n) cin >> b[i] , posb[b[i]] = i;
    per(i,0,n+1) per(j,0,n+1){
        if(i >= n || j >= n) nxt[i][j] = mp(n , n);
        else if(posb[a[i]] < j) nxt[i][j] = nxt[i+1][j];
        else if(posa[b[j]] < i) nxt[i][j] = nxt[i][j+1];
        else nxt[i][j] = mp(i , j);
    }
    rep(i,0,n+1) rep(j,0,n+1) {
        if(i) cnt[i][j]=cnt[i-1][j]+(posb[a[i-1]]>=j);
        else if(j) cnt[i][j]=cnt[i][j-1]+(posa[b[j-1]]>=i);
        else cnt[i][j]=0;
    }
    int m = n / 3;
    f[0][0] = 1;
    rep(t,1,m+1) {
        per(i,0,n) per(j,0,n) if(f[i][j]) {
            if(a[i]!=b[j]) pp(f[nxt[i+1][j+1].fi][nxt[i+1][j+1].se],f[i][j]);
            f[i][j]=0;
        }
        int full=t*3;
        rep(i,0,n) rep(j,0,n) if(f[i][j]&&cnt[i][j]<full){
            pp(f[nxt[i+1][j].fi][nxt[i+1][j].se],1ll*f[i][j]*(full-cnt[i][j])%P);
        }
        rep(i,0,n) rep(j,0,n) if(f[i][j]&&cnt[i][j]<full){
            if(nxt[i][j+1].fi==i)
                pp(f[nxt[i][j+1].fi][nxt[i][j+1].se],1ll*f[i][j]*(full-cnt[i][j])%P);
        }
    }
    cof=1;
    rep(i,0,m) cof=1ll*cof*(i*3+1)%P*(i*3+2)%P;
    cof=1ll*cof*f[n][n]%P;
    printf("%d\n",cof);
    return 0;
}


Measured memory_bytes: 2688
# でつoO(YOU PLAY WITH THE CARDS YOU'RE DEALT..)
import sys
def main(W, H, x, y):
    print(W * H / 2, 1 if x * 2 == W and y * 2 == H else 0)

if __name__ == '__main__':
    input = sys.stdin.readline
    W, H, x, y = map(int, input().split())
    main(W, H, x, y)


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

#define ASC(vec) vec.begin(), vec.end()    // 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend() // 降順ソート 例：sort(DESC(vec));
#define rep(i, n) for (int i = 0; i < (n); i++)
#define Rep(i, n) for (int i = 1; i < n; i++)
#define REP(i, vec) for (auto i = vec.begin(); i != vec.end(); ++i)

const int       mod = 1000000007;
const int       inf = (1 << 21);
const long long INF = 1LL << 60;

using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vii = vector<pair<int, int>>;
using vll = vector<pair<ll, ll>>;

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 GCD(T a, T b) { if (b == 0) return a; else return GCD(b, a % b); }
template<class T>
T LCM(T a, T b) { return a / GCD(a, b) * b; }

constexpr array<int, 9> dx = { 0, 1, 0, -1, -1, 1, 1, -1, 0 };
constexpr array<int, 9> dy = { 1, 0, -1, 0, 1, 1, -1, -1, 0 };

// ──────────────────────────────────────────────────────────────────

int main() {
	int x, y;
	cin >> x >> y;

	cout << (x + 1) + (y + 1) - 2 - (GCD(x, y) - 1) << endl;
}


Measured memory_bytes: 3128
Scanf.scanf "%d %d" (fun k n ->
    let a = Array.init n (fun _ -> Scanf.scanf " %d" (fun a -> a)) in
    let d = Array.init n (fun i ->
        let r = a.((i + 1) mod n) - a.(i) in
        if r < 0 then r + k else r
        ) in
    Array.sort compare d;
    Printf.printf "%d\n" (k - d.(n - 1))
)

Measured memory_bytes: 6400
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;

typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)

long long modinv(long long a, long long m=MOD) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
    /*MODの割り算の際に
    a/＝b;
    を
    a *= modinv(b,MOD);
    とする。
        */
}

int N,M;

int main(){
    cin >> N >> M;
    if(N==M)cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

int main(){
 int n,k,q,a;
  cin >> n >> k >> q;
  vector<int> v(n,0);
  r(i,q){
    cin >> a;
    v.at(a-1)++;
  }
  r(i,n){
    v.at(i)=k-q+v.at(i);
  if(v.at(i)>0)cout << "Yes"<<endl;
    else cout << "No"<<endl;
  }
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
const int MAXSIZE=20000020;
const int maxn=500003;
int bufpos;
char buf[MAXSIZE];
void init(){
    buf[fread(buf,1,MAXSIZE,stdin)]='\0';
    bufpos=0;
}
int readint(){
    bool isneg;
    int val=0;
    for(;!isdigit(buf[bufpos]) && buf[bufpos]!='-';bufpos++);
    bufpos+=(isneg=(buf[bufpos]=='-'))?1:0;
    for(;isdigit(buf[bufpos]);bufpos++)
        val=val*10+buf[bufpos]-'0';
    return isneg?-val:val;
}
char readchar(){
    for(;isspace(buf[bufpos]);bufpos++);
    return buf[bufpos++];
}
int readstr(char* s){
    int cur=0;
    for(;isspace(buf[bufpos]);bufpos++);
    for(;!isspace(buf[bufpos]);bufpos++)
        s[cur++]=buf[bufpos];
    s[cur]='\0';
    return cur;
}
char s[maxn];
int f[maxn][30],dp[maxn][30];
int main(){
	init();
	int n=readstr(s+1);
	for(int i=1;i<=n;i++)
		s[i]-='a';
	for(int i=n;i;i--){
		f[i][s[i]]=i+1;
		for(int j=s[i]+1;j<=26;j++)
			f[i][j]=f[f[i][j-1]][j-1];
		for(int j=0;j<s[i];j++)
			f[i][j]=f[f[i][26]][j];
	}
	for(int i=n;i;i--){
		dp[i][0]=f[i][26]; 
		for(int j=1;j<=20;j++)
			dp[i][j]=dp[dp[i][j-1]][j-1];
	}
	int q=readint();
	while(q--){
		int l=readint(),r=readint();
		for(int i=20;i>=0;i--)
			if (dp[l][i]<=r+1 && dp[l][i])
				l=dp[l][i];
		if (l==r+1)
			puts("Yes");
		else puts("No");
	}
}

Measured memory_bytes: 123520
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int mod = 1e9 + 7;
const int MAX = 510000;
const int V = 100005;
ll dy[8] = {1,0,-1,0,1,-1,1,-1};
ll dx[8] = {0,1,0,-1,1,-1,-1,1};

int main(){
    ll m; cin >> m;
    cout << 48-m << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
 
int main(){
	int a;
  	char s[53]={"ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ"};
  	char h[10002]; 	
  	scanf("%d %s",&a,h);
	
  	for(int i=0; i<strlen(h); i++){
      for(int j=0; j<26; j++){
        if(h[i]==s[j]){
        	printf("%c", s[j+a]);
        }
      }
    }
  
  	printf("\n");
  
  return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int main(){
	char S[26];
	scanf("%s",S);

	for(int i=0; i<strlen(S); i++){
		for(int j=i+1; j<strlen(S); j++){
			// printf("S[%d] = %c, ",i,S[i]);
			// printf("S[%d] = %c\n",j,S[j]);
			if(S[i] == S[j]){
				printf("no\n");
				return 0;
			}
		}
	}
	printf("yes\n");
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <numeric>
using namespace std;
typedef long long ll;
int main() {
  int N;
  cin>>N;
  vector<pair<int,int>> v(N);
  for(int i=0;i<N;i++){
    cin>> v[i].second>>v[i].first;
  }
  sort(v.begin(), v.end());
  int sum=0;
  for(int i=0;i<N;i++){
    sum+=v[i].second;
    if(sum>v[i].first){
      cout<<"No";
      return 0;
    }
  }
  cout<<"Yes";
  return 0;
}

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

int main(void){
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++) cin>>a[i];
    sort(a,a+n,greater<>());
    int ans = 0;
    for(int i=0;i<n;i++){
        if(i%2==0){
            ans += a[i];
        }else{
            ans -= a[i];
        }
    }
    cout<<ans<<endl;

}

Measured memory_bytes: 256
x1,x2,x3,x4,x5 = map(int, input().split())

if x1 == 0:
    print(1)
elif x2 == 0:
    print(2)
elif x3 == 0:
    print(3)
elif x4 == 0:
    print(4)
elif x5 == 0:
    print(5)

Measured memory_bytes: 8932
import java.util.*;

public class Main {
    public static void main(String args[]) {
       //値の取得
       Scanner sc = new Scanner(System.in);
       int N = sc.nextInt();
       int[] A = new int[N];
       for(int i = 0; i < N; ++i) {
           A[i] = sc.nextInt();
       }
       
       //うさぎのペアを探す
       int count = 0;   ///ペア数のカウント
       for(int i = 0; i < N; ++i) {
           //うさぎは1から数えるため1を加える
           if(i + 1 == A[A[i]-1]) {
               ++count;
           }
       }
       
       count = count / 2;
       //出力
       System.out.println(count);
    }
}


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

int main() {
	
	const double pi = 3.1415926535898;
	double r;
	cin >> r;
	
	printf("%.6lf %.6lf\n", pi*r*r, 2*pi*r);
	
	return 0;
}


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

#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define MP make_pair
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
ll INF = 1e18;
void chmin(ll &a,ll b){if(a>b)a=b;}
void chmax(ll &a,ll b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
void ans(bool x,ll y,ll z){if(x)cout<<y<<endl;else cout<<z<<endl;}
void anss(bool x,string y,string z){if(x)cout<<y<<endl;else cout<<z<<endl;}   
ll gcd(ll x,ll y){ll r;while((r=x%y)!=0){x=y;y=r;}return y;}

int main(){
  ll i,j,o;
  ll res=0,res1=0,res2=INF,buf=0,buf1=0,buf2=0,buf3=0,buf4=0,sum=0;
  ll l,r;
  bool judge = true;
  ll w,a,b;cin>>w>>a>>b;
  if((a<=b&&b<=a+w)||(a<=b+w&&b+w<=a+w))res=0;
  else{
    res=min(abs(a-b-w),abs(a+w-b));
  }
  cout<<res<<endl;


  return 0;
}

Measured memory_bytes: 256
#include<cstdio>

using namespace std;

int main(){
	int a, b, c, x; scanf("%d %d %d %d", &a, &b, &c, &x);
	int res = 0;
	for(int i = 0; i<= a; i++) for(int j = 0; j <= b; j++) for(int k = 0; k <= c; k++){
		if(500 * i + 100 * j + 50 * k == x) res++;
	}
	printf("%d\n", res);
	return 0;
}

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

int main() {
  string A,B;
  cin >> A >> B;
  
  if (A.size() > B.size()){
    cout << "GREATER" << endl;
  }
  
  else if (A.size() < B.size()){
    cout << "LESS" << endl;
  }
  
  else if (A.size() == B.size()){
    
    for (int i = 0; i < A.size(); i++) {
      
      if (A.at(i) > B.at(i)){
        cout << "GREATER" << endl;
        break;
      }
      
      else if (A.at(i) < B.at(i)){
        cout << "LESS" << endl;
        break;
      }
      
      else if (i == A.size() - 1){
        cout << "EQUAL" << endl;
      }
    }
  }
}
        
        
   

Measured memory_bytes: 256
from math import gcd
from functools import reduce

m,k = map(int,input().split())
L = list(map(int,input().split()))

v = reduce(gcd,L)
maxL = max(L)

if k > maxL:
    print("IMPOSSIBLE")
    exit()
if k in L:
    print("POSSIBLE")
    exit()
    
if (maxL - k)%v == 0:
    print("POSSIBLE")
    exit()
print("IMPOSSIBLE")

Measured memory_bytes: 20416
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define pp pair<ll,ll>
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll MOD=998244353;
int inf=1000001000;
ll INF=1e18+5;
ll mod=INF;


int main() {
    char a;
    cin >> a;
    bool t=false;
    int o=a-'a';
    rep(i,26){
      if (o==i) t=true;
    }
    if (t) cout << "a" << endl;
    else cout << "A" << endl;
}


Measured memory_bytes: 3628
// "include" {{{
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
#include <iomanip>
#include <tuple>
// }}}
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define pii pair<int,int>
#define int long long
#define setout(n,x) setw(n) << setfill(x)
#define Fixed fixed << setprecision(10)
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const long long mod = 1000000007;

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m;
    cin >> n >> m;
    vector<pii> sp(n);
    priority_queue<pii,vector<pii>,greater<pii> > que;
    rep(i,n){
        int a,b;
        cin >> a >> b;
        que.emplace(a,b);
    }
    int sum = 0;
    rep(i,m){
        pii x;
        x = make_pair(que.top().first,que.top().second);
        sum += x.first;
        x.second--;
        que.pop();
        if(x.second != 0){
            que.emplace(x.first,x.second);
        }
    }
    cout << sum << '\n';
    return 0;
}


Measured memory_bytes: 3956
import java.util.Scanner;

 

public class Main {

 

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s1;
        String s2;
        w: while (true) {
            s1 = sc.next();
            if (".".equals(s1)) {
                break;
            }
            s2 = sc.next();

 

            if (s1.equals(s2)) {
                System.out.println("IDENTICAL");
                continue;
            }
            s1 = s1.replaceAll("\"", "@");
            s2= s2.replaceAll("\"", "@");
            int count = 0;
            while(s1.contains("@")) {
                if(!s2.contains("@")) {
                    System.out.println("DIFFERENT");
                    continue w;
                }
                int first1 = s1.indexOf("@", 0);
                int second1 = s1.indexOf("@", first1+1);
                
                int first2 = s2.indexOf("@", 0);
                int second2 = s2.indexOf("@", first2+1);
                
                String p1 = s1.substring(first1, second1+1);
                String p2 = s2.substring(first2, second2+1);
                
                if(p1.equals(p2)) {
                    s1 = s1.replaceFirst(p1, "*");
                    s2 = s2.replaceFirst(p1, "*");
                } else {
                    count ++;
                    s1 = s1.replaceFirst(p1, "*");
                    s2 = s2.replaceFirst(p2, "*");
                }
            }
            for (int i = 0; i < Math.max(s1.length(),s2.length()); i++) {
                try {
                if(s1.charAt(i) != s2.charAt(i)) {
                    System.out.println("DIFFERENT");
                    continue w;
                }
                } catch (StringIndexOutOfBoundsException e) {
                    System.out.println("DIFFERENT");
                    continue w;
                }
                
            }
            System.out.println(count == 1 ? "CLOSE":"DIFFERENT");
        }
        sc.close();
    }

 

}


Measured memory_bytes: 32100
N = int(input())
S = input()

t_w = [0]*N
t_e = [0]*N

ans = 3*10**6
west = 0
east = 0

for i in range(N):
    if i == 0:
        if S[i] == "W":
            t_w[0] = 1 
            t_e[0] = 0
        elif S[i] == "E":
            t_w[0] = 0 
            t_e[0] = 1 
    else:
        if S[i] == "W":
            t_w[i] = t_w[i-1] + 1
            t_e[i] = t_e[i-1]
        elif S[i] == "E":
            t_w[i] = t_w[i-1]
            t_e[i] = t_e[i-1] + 1

for i in range(N):
    west = 0 if i == 0 else t_w[i-1]
    east = t_e[N-1]-t_e[i]
    t = west + east
    ans = min(ans,t)
print(ans)

Measured memory_bytes: 17632
#include<bits/stdc++.h>
#define lli unsigned long long
#define rep0(i,j) for(int i=0; i<j; i++)
#define rep1(i,j) for(int i=1; i<=j; i++)
#define all(a) a.begin(), a.end()
using namespace std;

void dfs(lli ed, lli num, vector<map<lli,lli>>& vec){
    lli n=1;
    for(auto e: vec[num]){
        if(n == ed)n++;
        if(e.second != -1)continue;
        vec[num][e.first] = n;
        vec[e.first][num] = n;   
        dfs(n, e.first, vec);
        n++;
    }
}

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

    vector<lli> vec6(1, 6);
    vector<lli> vec9(1, 9);

    for(int i=0; vec6[i]*6 <= 100000; i++){
        vec6.push_back(vec6[i]*6);
    }
    for(int i=0; vec9[i]*9 <= 100000; i++){
        vec9.push_back(vec9[i]*9);
    }
    
    vector<int>dp(100001,0);

    rep1(i,n){
        dp[i] = dp[i-1]+1;
        for(int j=0; i >= vec6[j]; j++){
            dp[i] = min(dp[i], dp[i-vec6[j]] + 1);
        }
        for(int j=0; i >= vec9[j]; j++){
            dp[i] = min(dp[i], dp[i-vec9[j]] + 1);
        }
    }
    cout <<dp[n];


}

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

#define REP(i,n) for(long long i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(long long i = (m); i < (n); ++i)

using ll = long long;
#define INF 1e9



int main(){
  int H, W;
  cin >> H >> W;
  vector<vector<int>> c(10, vector<int>(10)), A(H, vector<int>(W));
  vector<vector<int>> g(10, vector<int>(10, 10000));
  REP(i, 10){
    REP(j, 10){
      cin >> c[i][j];
    }
  }
  REP(i, H){
    REP(j, W){
      cin >> A[i][j];
    }
  }
  REP(k, 10){
    REP(i, 10){
      REP(j, 10){
        if(c[i][j] > c[i][k] + c[k][j]){
          c[i][j] = c[i][k]+c[k][j];
        }
      }
    }
  }
  int ans = 0;
  REP(i, H){
    REP(j, W){
      if(A[i][j] != -1){
        ans += c[A[i][j]][1];
      }
    }
  }
  cout << ans << endl;  
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(a,b,c) for(int a=b;a<c;++a)
#define repeq(a,b,c) for(int a=b;a<=c;++a)
#define debug(x) cerr<<(#x)<<": "<<x<<endl
typedef long long ll;
const int SZ=1000, B=6000;
int p[SZ], x[SZ];
ll dp[2][B];
vector<pair<int,int> > result;
vector<vector<int> > g;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin >> n;
	g.resize(n);
	rep(i,1,n)
	{
		cin >> p[i];
		--p[i];
	}
	rep(i,0,n)
		cin >> x[i];
	bool bad = false;
	result.resize(n);
	for(int i=n-1;i>=0 && !bad;--i)
	{
		int v = 0;
		dp[v][0] = 0;
		repeq(j,1,x[i])
			dp[v][j]=-1;
		rep(j,i+1,n)
			if(p[j]==i)
			{
				repeq(l,0,x[i])
					dp[v^1][l]=-1;
				int a = result[j].first, b=result[j].second;
				repeq(l,0,x[i])
					if(dp[v][l]!=-1)
					{
						ll z = dp[v][l]+a;
						int k = l+b;
						if(k<=x[i] && (dp[v^1][k]==-1 || z<=dp[v^1][k]))
							dp[v^1][k] = z;
						z = dp[v][l]+b, k=l+a;
						if(k<=x[i] && (dp[v^1][k]==-1 || z<=dp[v^1][k]))
							dp[v^1][k] = z;
					}
				v^=1;
			}
		int best = -1;
		repeq(j,0,x[i])
			if(dp[v][j]!=-1 && (best==-1 || dp[v][j]<best))
				best = dp[v][j];
		if(best==-1)
			bad = true;
		result[i] = make_pair(best,x[i]);
	}
	if(bad)
		cout << "IMPOSSIBLE\n";
	else
		cout << "POSSIBLE\n";
}


Measured memory_bytes: 384
#include <stdio.h>
#include <string.h>

int main()
{
  int n;
  int ret;
  int ac, wa, tle, re;
  char str[16];

  ret = scanf("%d", &n);
  if (!ret) return 0;

  ac = wa = tle = re = 0;
  while (n--)
  {
    ret = scanf("%s", str);
    if (!ret) return 0;
    if (strcmp(str, "AC") == 0) ac++;
    if (strcmp(str, "WA") == 0) wa++;
    if (strcmp(str, "TLE") == 0) tle++;
    if (strcmp(str, "RE") == 0) re++;
  }

  printf("AC x %d\n", ac);
  printf("WA x %d\n", wa);
  printf("TLE x %d\n", tle);
  printf("RE x %d\n", re);
  return 0;
}

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

int main(){
    int a,b,c;
    cin>>a>>b>>c;
    
    if((a==5&&b==5&&c==7)||(a==5&&c==5&&b==7)||(b==5&&c==5&&a==7))
        cout<<"YES"<<endl;
    else
        cout<<"NO"<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, char const *argv[])
{
	int n, x;
	int i, j, k;
	int cnt;

	while(1) {
		scanf("%d %d ", &n, &x);
		if(n==0 && x==0) break;
		cnt = 0;

		for (i = 1; i*3+3 <= x;i++) {
			for (j = i+1; i+2*j+1 <= x; j++) {
				for(k = n; k > j; k--) {
					if(x==i+j+k){
						cnt++;
						break;
					} else if(x>=i+j+k){
						break;
					}
				}
			}
		}

		printf("%d\n", cnt);
	}
	return 0;
}


Measured memory_bytes: 2108
#include<stdio.h>

int main(){
  int A[100], n, i, j, t, sw = 0, mini;

  scanf("%d", &n);
  for ( i = 0; i < n; i++ ) scanf("%d", &A[i]);

  for ( i = 0; i < n; i++ ){
    mini = i;
    for ( j = i; j < n; j++ ){
      if ( A[j] < A[mini] ) mini = j;
    }
    t = A[i]; A[i] = A[mini]; A[mini] = t;
    if ( i != mini ) sw++;
  }

  for ( i = 0; i < n; i++ ){
    if (i) printf(" ");
    printf("%d", A[i]);
  }
  printf("\n");
  printf("%d\n", sw);

  return 0;
}



Measured memory_bytes: 2752
#include <iostream>
#include <string>
#include <algorithm>
#include <iterator>
#include <functional>
#include <vector>
#include <math.h>
#include <typeinfo>
#include <numeric>
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
using namespace std;

int main()
{
	int N;

	cin >> N;

	int cnt = 0;
	for (int i = 1; i <= N; i++)
	{
		if (to_string(i).length() % 2 == 1)
		{
			cnt++;
		}
	}
	
	cout << cnt << endl;

	return 0;
 
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <map>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod (ll)(1e9+7)
#define int ll

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}


signed main() {
  string s;
  cin >> s;
  int k = 0, ans = 0;
  rep(i, 0, s.length()) {
    if(s[i] == 'B') k++;
    else {
      ans += k;
    }
  }
  cout << ans << endl;
}


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

using namespace std;

const int maxn = 1e5+10;
int n;
int h[maxn];
int dp[maxn];

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

	cin >> n;
	for(int i=0; i<n; i++)
		cin >> h[i];

	dp[n] = 1e9;
	for(int i=n-2; i>=0; i--)
		dp[i] =  min(abs(h[i]-h[i+1]) + dp[i+1], abs(h[i]-h[i+2]) + dp[i+2]);

	cout << dp[0] << endl;
}


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

int cnt_digits(ll N) {
    return to_string(N).length();
}

int main() {
    ll N;
    cin >> N;

    int ans = cnt_digits(N);
    for (ll A = 1LL; A*A <= N; A++) {
        if (N%A != 0) continue;
        const ll B = N/A;
        const int cur = max(cnt_digits(A), cnt_digits(B));
        if (ans > cur) ans = cur;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N = readline().strip()
    print('ABC' + N)
    
    return


if __name__ == '__main__':
    main()


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

#define int long long
typedef pair <char, char> pcc;

const int N = 2e5 + 10;
int n, q;
string s;
pcc ar[N];

bool checkl(int x) {
	int i = 0;
	while (x >= 0 && i < q) {
		if (s[x] == ar[i].first) {
			if (ar[i].second == 'R')
				x++;
			else
				x--;
		}
		i++;
	}
	return x < 0;
}

bool checkr(int x) {
	int i = 0;
	while (x < n && i < q) {
		if (x < 0)
			return 0;
			
		if (s[x] == ar[i].first) {
			if (ar[i].second == 'R')
				x++;
			else
				x--;
		}
		i++;
	}
	return x > n - 1;
}

int32_t main() {
	cin >> n >> q >> s;
	for (int i = 0; i < q; i++)
		cin >> ar[i].first >> ar[i].second;
	
	int st = -1, ed = n;
	while (ed - st > 1) {
		int mid = st + ed >> 1;
		if (checkl(mid))
			st = mid;
		else
			ed = mid;
	}
	int l = st;
//	cout << "l : " << l << endl;
	
	st = -1, ed = n;
	while (ed - st > 1) {
		int mid = st + ed >> 1;
		if (checkr(mid))
			ed = mid;
		else
			st = mid;
	}
	int r = ed;
//	cout << "r : " << r << endl;
	cout << max(0LL, r - l - 1);
}

Measured memory_bytes: 900
#include<stdio.h>

int main(){
    int n;
    scanf("%d", &n);
    char str[n+1];
    scanf("%s", str);
    char t[n+1];
    int x = n/2;
    for(int i=0; i<x; i++){
        t[i] = str[i];
    }
    t[x] = '\0';
    int f = 1;
    for(int i=x; i<n; i++){
        if(t[i-x] != str[i]){
            f = 0;
        }
    }
    //printf("%s", t);
    if(f){
        printf("Yes");
    }else{
        printf("No");
    }

    return 0;
}

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

using namespace std;

const int MAX_SIZE = 1000;
int mystack[MAX_SIZE];
int sp = 0;

bool is_stack_full() {
    return sp == MAX_SIZE-1;
}

bool is_stack_empty() {
    return sp == 0;
}

void push(int x) {
    if (is_stack_full()) {
        cerr << "Stack: overflow" << endl;
        exit(1);
    }

    mystack[++sp] = x;
}

int pop() {
    if (is_stack_empty()) {
        cerr << "Stack: underflow" << endl;
	exit(1);
    }
    return mystack[sp--];
}

int main() {
    string str;
    getline(cin, str);

    istringstream ss(str);
    string s;
    while (ss >> s) {

        if (s[0] == '+') {
            int b = pop();
            int a = pop();
            push(a + b);
        } else if (s[0] == '-') {
            int b = pop();
            int a = pop();
            push(a - b);
        } else if (s[0] == '*') {
            int b = pop();
            int a = pop();
            push(a * b);
        } else {
            push(stoi(s));
        }
    }

    cout << pop() << endl;
    return 0;
}




Measured memory_bytes: 3164
#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<ll,ll>;
//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define inf 2147483647 //int値の最大値
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define CST(x) cout<<fixed<<setprecision(x)//小数点以下の桁数指定
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;
}
int gcd(int a, int b) {
    if (b==0) return a;
    else return gcd(b, a%b);
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
int two(int n){
	ll ans=1;
	rep(i,n){
		ans*=2;
	}
	return ans;
}



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

  int n,x,t;
  cin >> n >>x>>t;

  

  if(n%x !=0){
      cout<<t*(n/x +1)<<endl;
  }
  if(n%x ==0){
      cout<< t*(n/x)<<endl;
  }




}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define pi pair<int,int>
#define ll long long
#define pll pair<ll,ll>
#define rep(i,a,b) for(int i = a ; i <= b;i++)
using namespace std;
void debug(int x){
    cerr<<x<<endl;
}
void debug(vector<int> v){
    for(int i = 0 ; i<v.size(); i++) cerr<<v[i]<<" ";
    cerr<<"\n";
}
void debug(int *A, int N){
    for(int i = 0 ; i < N;i++) cerr<<A[i]<<" ";
    cerr<<endl;
}
void debug(int *A, int i, int j){
    for(int k = i;k<=j;k++) cerr<<A[k]<<" ";
    cerr<<endl;
}
void scan(vector<int> &h,int N){
    for(int i = 0 ; i < N;i++){
        scanf("%d",&h[i]);
    }
}





#define NUM (1000000007)
int dp[1001][1001] = {0};
int main(){
     int H,W;
     cin>>H>>W;
     //read the grid
     char grid[H+1][W+1];
     for(int i= 1 ; i <= H ;i++){
         for(int j = 1  ; j <= W; j++){
             cin>>grid[i][j];
         }
     }

     dp[1][1] = 1;
    for(int i = 1 ; i <=H; i++){
         for(int j = 1 ; j <=W; j++){
             if(i==1 && j==1) continue;
             if(grid[i][j] == '.'){
               //  cout<<"checking for "<<i<<" and "<<j<<endl;
                   if(i - 1 >=1 && grid[i-1][j] == '.'){
                 //      cout<<i<<", "<<j<<endl;
                       dp[i][j] = (dp[i][j]%NUM + dp[i-1][j]%NUM)%NUM;
                   }
                   if(j - 1>=1 && grid[i][j-1] == '.'){
                   //  cout<<i<<" , "<<j<<endl;
                        dp[i][j] = (dp[i][j]%NUM +  dp[i][j-1]%NUM)%NUM;
                   }
                 
             }
             else{
                 dp[i][j] = 0;
             }
         }
    }
    // for(int i = 1; i<=H; i++){
    //     for(int j = 1; j <=W ; j++){
    //         cout<<dp[i][j]<<" ";
    //     }
    //     cout<<"\n";
    // }
    cout<<dp[H][W]<<"\n";
}

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

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n; cin >> n;
	int cnt=0;
	int ma=0;
	for(int i=0;i<n;i++){
		int a,b; cin >> a >> b;
		if(a==b)cnt++;
		else cnt=0;
		ma=max(ma,cnt);
	}
	if(ma>=3){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}
}

Measured memory_bytes: 3652
#include <iostream>
#include <vector>

using namespace std;

int main()
{
    int n, m;
    const int nmmax = 50;
    cin >> n >> m;
    vector<int> street_count(nmmax);

    for (int i = 0; i < n; i++){
        street_count[i] = 0;
    }

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

    for (int i = 0; i < n; i++){
        cout << street_count[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 256
N, M = [int(_) for _ in input().split()]
A = [int(_) for _ in input().split()]
A.sort()

BC = []
for i in range(M):
    v = [v for v in input().split()]
    BC.append((int(v[0]), int(v[1])))

BC.sort(key=lambda x: -x[1])

i = 0

fin = False
for b, c in BC:
    for _ in range(b):
        if i >= N:
            fin = True
            break

        if A[i] < c:
            A[i] = c
            i += 1
        else:
            fin = True
            break
    if fin:
        break
print(sum(A))


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

import fractions

N,X=map(int,input().split())
x= list(map(int, input().split()))
x.append(X)
x.sort()
dis = []
for i in range(1, N+1):
    dis.append(x[i]-x[i-1])

tmp=dis[0]
for i in range(1,N):
    tmp = fractions.gcd(tmp,dis[i])
print(tmp)


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

using namespace std;

int main(){
 int N; cin >> N;
  vector<long long >A(N);  bool flag = true;
  for(int i = 0; i < N; i++){ cin >> A[i]; if( A[i] % 2 == 1){ flag = false;}}
  
  if( flag){ cout << "second" <<endl; }
  else{ cout << "first" << endl;}
  
  return 0;}

Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<algorithm>	
#include<cmath>
#include<map>
#include<vector>
#include<math.h>
#define int long long
using namespace std;
int aa[123456];
signed main() {
	int n, p, a = 0, ans = 0; cin >> n >> p;
	if (n == 1) {
		cout << p << endl; return 0;
	}
	for (int h = 1; h <= 1000000; h++) {
		a = pow(h, n);
		if (a > p) { break; }
		if (p % a == 0) {
			ans = h;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

def readInts():
  return [int(s) for s in input().split(" ")]

def main():
  A, B = readInts()

  if 1 <= A <= 9 and 1 <= B <= 9:
    print(A * B)
  else:
    print(-1)

if __name__ == "__main__":
  main()


Measured memory_bytes: 2940
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Practice
{
    class Program
    {
        static void Main(string[] args)
        {
            Solve();
        }
        private const long MOD = 1000000007;

        static void Solve()
        {
            var o = ReadAndParseIntArr();
            int a = o[0];
            int b = o[1];
            int ans = (a + b) % 24;
            Console.WriteLine(ans);
        }
        #region よく使う便利関数
        private static bool isPrime(long x)
        {
            if (x == 2) { return true; }
            if (x < 2 || x % 2 == 0) { return false; }
            long i = 3;
            while (i * i <= x)
            {
                if (x % i == 0) { return false; }
                i = i + 2;
            }
            return true;
        }
        private static long lcm(long x, long y)
        {
            return x / gcd(x, y) * y;
        }
        private static long gcd(long x, long y)
        {
            return y > 0 ? gcd(y, x % y) : x;
        }
        private static long pow(long x, long n)
        {
            if (n == 0) { return 1; }
            long res = pow(x * x % MOD, n / 2);
            if (n % 2 == 1)
            {
                res = res * x % MOD;
            }
            return res;
        }
        private static int ReadAndParseInt()
        {
            return int.Parse(Console.ReadLine());
        }
        private static int[] ReadAndParseIntArr()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
        }
        private static long ReadAndParseLong()
        {
            return long.Parse(Console.ReadLine());
        }
        private static long[] ReadAndParseLongArr()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
        }
        #endregion
    }
}

Measured memory_bytes: 13140
import math
def main():
    a,b,h,m = map(int, input().split())
 
    ar = h * 360 / 12 + m * 30 / 60
    br = m * 360 / 60
    kakudo = x if (x := abs(ar-br)) < 180 else 360-x
    ans = a**2+b**2-2*a*b*math.cos(kakudo*math.pi/180)
    # print(ans**0.5)
    
    print(math.sqrt(ans))
if __name__ == "__main__":
    main()

Measured memory_bytes: 9604
#include <math.h>

#include <bitset>
#include <cmath>
#include <iostream>
using namespace std;
int main() {
    int l, c = 0;
    string a;
    cin >> a;
    l = a.size();
    for (int i = 0; i < l; i++) {
        char d = a[i];
        if (i % 2 == 0) {
            if (d == '0') c++;
        } else if (d == '1')
            c++;
    }
    cout << min(c, l - c) << endl;
    return 0;
}

Measured memory_bytes: 3732
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <utility>
#include <string>
#include <cmath>
#include <set>
#include <functional>
#include <map>
#include <queue>
#include <cstring>
#include <stack>
#include <iomanip>
#include <climits>
#include <numeric>
#include <cassert>
#include <unordered_map>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define show(x) cout << #x << " = " << x << endl;
typedef long long ll;
typedef pair<int,int> pii;
int main(){
    int n,m;
    int a[305][305];
    cin >> n >> m;
    rep(i,n){
        rep(j,m){
            cin >> a[i][j];
            a[i][j]--;
        }
    }
    int b[305];
    int num = 10000;
    bool kyogi[305];
    rep(i,m)kyogi[i] = true;
    rep(hoge,m){
        rep(i,m)b[i] = 0;
        rep(i,n){
            rep(j,m){
                if(kyogi[a[i][j]]){
                    b[a[i][j]]++;
                    break;
                }
            }
        }
        int temp = 0;
        rep(i,m)temp += b[i];
        num = min(num, *max_element(b,b+m));
        int k = (int)(max_element(b,b+m)-b);
        kyogi[k] = false;
    }
    cout << num << endl;
}


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

int main() {
  string S;
  cin >> S;
  int count = 0;
  if(S[0] == '1'){count++;}
  if(S[1] == '1'){count++;}
  if(S[2] == '1'){count++;}
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
	int arr[3], arr1[3], arr2[3];
	for (int i = 0; i < 3; i++) {
		cin >> arr[i];
	}
	for (int i = 0; i < 3; i++) {
		cin >> arr1[i];
	}
	for (int i = 0; i < 3; i++) {
		cin >> arr2[i];
	}
	int x = arr1[0] - arr[0], y = arr1[1] - arr[1], z = arr1[2] - arr[2];
	if (!(x == y && y == z)) {
		cout << "No\n";
		return 0;
	}
	x = arr2[0] - arr[0], y = arr2[1] - arr[1], z = arr2[2] - arr[2];
	if (!(x == y && y == z)) {
		cout << "No\n";
		return 0;
	}
	cout << "Yes\n";

}

Measured memory_bytes: 256
#include <stdio.h>
     
    int h,w,c[100][100];
    char ban[100][101];
     
    int count(int x, int y) {
       int t,tt;
     
       if (c[x][y]>=0) return c[x][y];
       if (x<h-1) 
          if (ban[x][y]==ban[x+1][y]) t=count(x+1,y);
          else                        t=count(x+1,y)+1;
       else t=9999;
       if (y<w-1)
          if (ban[x][y]==ban[x][y+1]) tt=count(x,y+1);
          else                        tt=count(x,y+1)+1;
       else tt=9999;
       if (t>tt) t=tt;
       c[x][y]=t;
       return t;
    }
     
    int main(){
       int i,j,t;
     
       scanf("%d %d",&h,&w);
       for (i=0;i<h;i++) {
          scanf("%s",ban[i]);
          for (j=0;j<w;j++) c[i][j]=-1;
       }
       c[h-1][w-1]=0;
       t=count(0,0);
       if (t%2==1) printf("%d\n",(t+1)/2);
       else if (ban[0][0]=='.') printf("%d\n",t/2);
       else                     printf("%d\n",t/2+1);
       return 0;
    }

Measured memory_bytes: 256
#include <cstdio>
int h,w,k,ans;
char a[9][9],t[9][9];
int work(int row,int column){
    for(int i=1;i<=h;i++) for(int j=1;j<=w;j++) t[i][j]=a[i][j];
    for(int i=1;i<=h;i++) if(row&(1<<i-1)) for(int j=1;j<=w;j++) t[i][j]='R';
    for(int i=1;i<=w;i++) if(column&(1<<i-1)) for(int j=1;j<=h;j++) t[j][i]='R';
    int s=0;
    for(int i=1;i<=h;i++) for(int j=1;j<=w;j++) if(t[i][j]=='#') ++s;
    return s;
}
int main(){
    scanf("%d%d%d",&h,&w,&k);
    for(int i=1;i<=h;i++) scanf("%s",a[i]+1);
    for(int i=0;i<(1<<h);i++) for(int j=0;j<(1<<w);j++) if(work(i,j)==k) ++ans;
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 1732
#include<iostream>
#include <vector>

using namespace std;
int main() {
	int n;
	cin >> n;
	vector<long long int> h(n + 1), b(n);
	for (int i = 0; i < n; i++) {
		cin >> h[i];
		if (i != 0 && h[i - 1] < h[i]) {
			--h[i];
		}
	}
	int flag = 1;
	for (int i = 0; i < n-1; i++) {
		if (h[i] > h[i + 1]) { //単調減少？
			flag = 0;
		}
	}
	flag == 1 ? cout << "Yes" << endl : cout << "No" << endl;
}

Measured memory_bytes: 1792