akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using vec=vector<ll>;
using mat=vector<vec>;
#define For(i,a,b) for(i=a;i<b;i++)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define all(v) (v).begin(),(v).end()
#define vsort(v) sort(all(v))
#define mod 1000000007
using data=pair<ll,ll>;

typedef struct unionfind{
  vector<int> par,treesize;
  unionfind(int N) :par(N){
    for(int i=0;i<N;i++)par[i]=i;
    treesize.resize(N);
    for(int i=0;i<N;i++)treesize[i]=1;
  }
  int root(int x){
    int r;
    if(par[x]==x)return x;
    r=root(par[x]);
    if(par[x]!=r){
      treesize[r]+=treesize[x];
      treesize[x]=0;
      par[x]=r;
    }
    return r;
  }
  void unite(int x,int y){
    int px=root(x);
    int py=root(y);
    if(px!=py){
      par[px]=py;
      treesize[py]+=treesize[px];
      treesize[px]=0;
    }
  }
  bool parcheck(int x,int y){
    int px=root(x);
    int py=root(y);
    return px==py;
  }
  int size(int x){
    int px=root(x);
    return treesize[px];
  }
};


long mmid(long a,long b,long c){return a<b?(b<c?b:max(a,c)):(b>c?b:min(a,c));}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

ll modncr(ll n,ll r){
  ll i,plus=1;
  rep(i,r){
    plus=(plus*(n-i))%mod;
    plus=moddevide(plus,i+1);
  }
  return plus;
}

ll euclidean_gcd(ll a, ll b) {
  if(a<b) return euclidean_gcd(b, a);
  ll r;
  while ((r=a%b)){a=b;b=r;}
  return b;
}

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}

void printmap(vector<ll>& a,ll H,ll W){
  ll i,j;
  For(i,0,H+2){
    For(j,0,W+2){cout<<a[i*(W+2)+j];}
    cout<<endl;
  }
}
void inputmap(vector<ll>& a,ll H,ll W){
  ll i,j;
  string ss;
  For(i,1,H+1){
    cin>>ss;
    For(j,1,W+1){
      if(ss[j-1]=='#'){
        a[i*(W+2)+j]=1;
      }else{
        a[i*(W+2)+j]=0;
      }
    }
  }
}


int main(){
  ll i,N,M,a,b,ans;
  cin>>N>>M;
  unionfind tree(N);
  vector<data> v(M);
  stack<ll> st;
  rep(i,M){
    cin>>a>>b;
    v[i]=data(a-1,b-1);
  }
  ans=N*(N-1)/2;
  st.push(ans);
  while(M--){
    a=v[M].first;b=v[M].second;
    if(tree.root(a)==tree.root(b)){
      st.push(ans);
      continue;
    }
    ans-=tree.size(a)*tree.size(b);
    st.push(ans);
    tree.unite(a,b);
  }
  st.pop();
  while(!st.empty()){
    cout<<st.top()<<endl;
    st.pop();
  }
  return 0;
}

Measured memory_bytes: 4252
#include<stdio.h>
int MIN(int a,int b){return a<b?a:b;}
int main(){
  int n,m,s,i,a,b;
  while(scanf("%d %d",&n,&m),n){
    int d[20]={0};
    for(s=0;n--;d[b]+=a)scanf("%d %d",&a,&b);
    for(i=10;i>-1;i--){
      s+=d[i]*i;
      s-=MIN(d[i],m)*i;
      m-=MIN(d[i],m);
    }
    printf("%d\n",s);
  }
  return 0;
}

Measured memory_bytes: 600
import numpy as np
N = int(input())
S = input()
LW = np.array([0]*N)
RE = np.array([0]*N)
for i in range(1,N):
    LW[i] = LW[i-1] + int(S[i-1]=="W")
    RE[-(i+1)] = RE[-i] + int(S[-i]=="E")
P = LW + RE
print(min(P))

Measured memory_bytes: 21728
use std::collections::VecDeque;

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

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

fn main() {
    let n = read::<usize>();
    let mut a = read_vec::<usize>();
    a.push_back(0);
    a.push_front(0);

    let mut sum_a = vec![0; n + 2];
    for i in 1..n + 2 {
        sum_a[i] = sum_a[i - 1] + a[i];
    }

    let mut dp: Vec<Vec<usize>> = vec![vec![0; n + 2]; n + 1];

    for w in 2..n + 2 {
        for i in 0..n + 2 - w {
            let j = i + w;
            let mut t = std::usize::MAX;
            for k in i + 1..j {
                t = std::cmp::min(t, dp[i][k] + dp[k][j]);
            }
            dp[i][j] = t + sum_a[j] - sum_a[i];
        }
    }
    println!("{:?}", dp[0][n]);
}


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

int main() {
    int a, b, c;
    cin>>a>>b>>c;
    if (a==b && a != c)
    {
        cout<<"Yes";
    }
    else if (a!=b && a==c)
    {
        cout <<"Yes";
    }
    else if (b==c && b!=a)
    {
        cout<<"Yes";
    }
    else 
    {
        cout<<"No";
    }

	return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a; i< (int)(b); ++i)
#define ALL(x) (x).begin(),(x).end()
#define rALL(x) (x).rbegin(),(x).rend()
typedef long double ld;
using ll=long long;
using namespace std;
const auto mod=1e9+7;


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
 
  string s; cin >> s;
  bool no=false;
  rep(i,0,s.size()-1){
  	if(s[i]==s[i+1]) no=true;
  }
   if(no) cout << "Bad" << endl;
   else cout << "Good" << endl;
 }

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

inline u_long lcm(u_long a, u_long b) {
    return a * b / std::__gcd(a, b);
}

int main(void) {
    u_long a, b;

    while (std::cin >> a >> b) {
        std::cout << std::__gcd(a, b) << " " << lcm(a,b) << std::endl;
    }

    return 0;
}

Measured memory_bytes: 1160
//include
//------------------------------------------
#include <bits/stdc++.h>
using namespace std;
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const long long INF = 1000000007;
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
// chmax chmin
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main(void){
    int N,K; cin >> N >> K;
    int now=1;
    REP(i,N){
        if(2*now < now+K) now *= 2;
        else now += K;
    }
    cout << now << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdbool.h>

int main(){
    int i, j, n;
    char mark;
    char marks[4]={'S', 'H', 'C', 'D'};
    int num;
    bool cards[4][13]={false};

    scanf("%d ", &n);
    for(i=0;i<n;i++){
        scanf("%c %d ", &mark, &num);
        for(j=0;j<4;j++){
            if(mark==marks[j]){
                cards[j][num-1]=true;
                break;
            }
        }
    }
    for(i=0;i<4;i++){
        for(j=0;j<13;j++){
            if(!cards[i][j]){
                printf("%c %d\n", marks[i], j+1);
            }
        }
    }
    return 0;
}


Measured memory_bytes: 2088
import sys
from collections import defaultdict
def input(): return sys.stdin.readline().strip()
from math import sqrt


def factor(n):
    """
    nの約数を個数と共にリストにして返す。
    ただしあとの都合上１は除外する。
    """

    if n == 1:
        return 0, []
    if n == 2:
        return 1, [2]
    if n == 3:
        return 1, [3]

    d = int(sqrt(n))
    num = 1
    factor_pre = []
    factor_post = [n]
    for i in range(2, d):
        if n % i == 0:
            factor_pre.append(i)
            factor_post.append(n // i)
            num += 2
    if d * d == n:
        factor_pre.append(d)
        num += 1
    elif n % d == 0:
        factor_pre.append(d)
        factor_post.append(n // d)
        num += 2
    factor_post.reverse()
    return num, factor_pre + factor_post


def main():
    N = int(input())

    """
    題を満たすKは、
        N = K^e * n、(n, K) = 1
    として
        n = K * m + 1 (m ¥in ¥mathbb{N})
    とかければ良い。

    ２つ目の式からnとKが互いに素なのは明らかなので、問題文は
        N = K^e * (K * m + 1) (m ¥in ¥mathbb{N})
    なるKを求めることに同値。

    なのでまずはNの約数を全列挙して、あとはNをそれで割った商がKで割って1余るか確かめれば良い。
    """

    _, fact = factor(N)
    ans, ans_list = factor(N - 1)
    # print(ans_list)

    # print("Now we check the list {}".format(fact))
    for K in fact:
        n = N
        while n % K == 0:
            n //= K
        if n % K == 1:
            ans += 1
            ans_list.append(K)
            # print("{} added".format(K))
    # print("ans={}: {}".format(ans, ans_list))
    print(ans)



if __name__ == "__main__":
    main()


Measured memory_bytes: 3692
import numpy as np
e=0
N=int(input())
c=np.arange(1, N+1)
for i in range(N):
 a=np.array([(i+1)]*N)
 for j in range(N):
  b=np.array([(j+1)]*N)
  d=np.gcd.reduce([a, b, c])
  e+=np.sum(d)
print(e)

Measured memory_bytes: 27268
#include <cstdio>
#include <algorithm>

const int inf = 1e9;

using namespace std;

int main()
{
    int e;
    
    while (scanf("%d", &e), e) {
        int mi = inf;

        for (int z = 0; z * z * z <= e; ++z) {
            for (int y = 0; y * y <= e - z * z * z; ++y) {
                mi = min(mi, e - z * z * z - y * y + y + z);
            }
        }

        printf("%d\n", mi);
    }
}

Measured memory_bytes: 1028
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define show(x) cout << #x << " = " << (x) << endl;
using namespace std;
using ll = long long;
using pii = pair<int,int>;
ll mod=998244353;
ll combi(ll N_, ll C_) {
    const int NUM_=400001;
    static ll fact[NUM_+1],factr[NUM_+1],inv[NUM_+1];
    if (fact[0]==0) {
        inv[1]=fact[0]=factr[0]=1;
        for (int i=2;i<=NUM_;++i) inv[i] = inv[mod % i] * (mod - mod / i) % mod;
        for (int i=1;i<=NUM_;++i) fact[i]=fact[i-1]*i%mod, factr[i]=factr[i-1]*inv[i]%mod;
    }
    if(C_<0 || C_>N_) return 0;
    return factr[C_]*fact[N_]%mod*factr[N_-C_]%mod;
}
ll dp[4005][4005];
ll sum[2005];
ll sum2[2005];
int n;
bool ok1(int i,int j){
    if(i>=n){
        return sum[n]-j>=1;
    }else{
        return sum[i]-j>=1;
    }
}
bool ok2(int i,int j){
    if(i>=n){
        return sum2[n]-j>=1;
    }else{
        return sum2[i]-j>=1;
    }
}
int main(){
    string s;
    cin >> s;
    n = (int)s.size();
    int r = 0;
    int b = 0;
    rep(i,n){
        if(s[i] == '0'){
            sum[i] += 2;
        }
        else if(s[i] == '1'){
            sum[i]++;
            sum2[i]++;
        }else{
            sum2[i]+=2;
        }
        sum[i+1] += sum[i];
        sum2[i+1] += sum2[i];
    }
//    rep(i,n){
//        show(sum[i]);
//    }
    dp[0][0] = 1;
    rep(i,2*n){
        for(int j = 0; j <= i; j++){
            if(dp[i][j]==0)continue;
            if(ok1(i,j)){
                dp[i+1][j+1] = (dp[i+1][j+1] + dp[i][j])%mod;
            }
            if(ok2(i,i-j)){
                dp[i+1][j] = (dp[i+1][j] + dp[i][j])%mod;
            }
        }
    }
//    rep(i,2*n+1){
//        show(i);
//        rep(j,i+1){
//            show(dp[i][j]);
//        }
//    }
    ll ans = 0;
    rep(i,2*n+1){
        ans += dp[2*n][i];
        ans %= mod;
    }
    cout << ans << endl;
}

Measured memory_bytes: 125440
n = int(input())
m,a,r,c,h = 0,0,0,0,0
for i in range(n):
  o = input()[0]
  if o == "M":
    m += 1
  elif o == "A":
    a += 1
  elif o == "R":
    r += 1
  elif o == "C":
    c += 1
  elif o == "H":
    h += 1
ans = m*a*r+m*a*c+m*a*h+m*r*c+m*r*h+m*c*h+a*r*c+a*r*h+a*c*h+r*c*h
print(ans)

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

inline int gcd(int a, int b){ return b?gcd(b,a%b):a; }
inline int lcm(int a, int b){ return a/gcd(a,b)*b; }
inline int hex(char a){ return isdigit(a)?(a-'0'):(a-'A'); }
inline char inv_hex(int a){ return (a<10)?(a+'0'):(a-10+'A'); }

inline vi reduce(vi a){
  int n = a.size();
  for(int i=n;i>=1;i--){
    if(n%i)continue;
    bool f = true;
    rep(j,n){
      if(j%i && a[j]){	f = false; break; }
    }
    if(f){
      vi res(n/i);
      for(int j=0;j<n;j+=i)res[j/i] = a[j];
      return res;
    }
  }
  return a;
}

int main(){
  cin.tie(0); ios::sync_with_stdio(0);
  int casenum;
  cin >> casenum;
  while(casenum--){
    int n;
    cin >> n;
    int len = 1;
    vector< vi > rhythm(n);
    rep(i,n){
      string s;
      cin >> s;
      vi tmp(s.size()/2);
      rep(j,s.size()/2){
	tmp[j] = hex(s[2*j])*16 + hex(s[2*j+1]);
      }
      rhythm[i] = reduce(tmp);
      if(len<=1024)len = lcm(len,rhythm[i].size());
    }

    if(len>1024)cout << "Too complex." << endl;
    else{
      vi res(len,0);
      rep(i,n){
	int k = len/rhythm[i].size();
	rep(j,rhythm[i].size())res[j*k] |= rhythm[i][j];
      }
      rep(i,len){
	cout << inv_hex(res[i]/16) << inv_hex(res[i]%16);
      }
      cout << endl;
    }
  }
}

Measured memory_bytes: 1280
/*siddharth goyal*/
#include<bits/stdc++.h>
using namespace std;
#define   pb              push_back
#define   REP(i,n)        for(int i=1;i<=n;i++)
#define   FOR(i,a,b)      for(int i=a;i<=b;i++)
#define   all(v)          v.begin(),v.end()
#define   F               first
#define   S               second
#define   vl              vector<LL>
#define   itr             ::iterator it
#define   lb              lower_bound
#define   ub              upper_bound
#define   LL              long long
#define   ULL             unsigned long long
#define   ret             return 
LL n,i,j,ans = 0;
LL m,a,b ; 
int main()
{   // Read the constraints,highlights,Time Limit,Test Cases
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n>>m ; 
    cin>>a>>b ; 
    cout<<(n-a) * (m-b) ; 
}
//Check for 0,1 and other corner cases.

Measured memory_bytes: 256
def partition(A, p, r):
    x = A[r][1]
    i = p-1
    for j in range(p, r):
        if A[j][1] <= x:
            i += 1
            A[i],A[j] = A[j],A[i]
    A[i+1],A[r] = A[r],A[i+1]
    return i+1


def quicksort(A, p, r):
    if p < r:
        q = partition(A, p, r)
        quicksort(A, p, q-1)
        quicksort(A, q+1, r)


n = int(input())
A = [(t[0], int(t[1]), i) for t, i in [(input().split(), i) for i in range(n)]]
quicksort(A, 0, n-1)
notstable = any([True for i in range(1, n) if A[i][1] == A[i-1][1] and A[i][2] < A[i-1][2]])
print("Not stable" if notstable else "Stable")
for v in A:
    print(f"{v[0]} {v[1]}")


Measured memory_bytes: 48400
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ll long long 
#define REP(i, a, b) for (ll i = a; i < b; i++)
#define REPI(i, a, b) for (ll i = b - 1; i >= a; i--)
#define i_os ios::sync_with_stdio(0);  cin.tie(0);  cout.tie(0);
#define INF (ll)1e18 + 100
#define endl "\n"
#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define p3(a, b, c) cout << a << " " << b << " " << c << endl
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl
#define MAX 1e6
/*SOME BITMASK KNOWLEDGE
1)x & (x - 1):sets the last one bit of x to zero
power of two exactly when x & (x − 1) = 0.
2)x & -x:sets all the one bits to zero, except last one bit
3)x | (x - 1):inverts all the bits after the last one bit*/
#define o_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define o_setll tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
typedef tree<pair<ll, ll>,null_type,less<pair<ll, ll>>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set

int main() 
{
	ll n,k;
	cin>>n>>k;
	ll arr[k];
	REP(i,0,k) cin>>arr[i];
	ll maxi = 0;
	REP(i,1,k){
		maxi = max(maxi,arr[i]-arr[i-1]);
	}

	cout<<min(n - maxi,arr[k-1]-arr[0])<<endl;
	return 0;
}  


Measured memory_bytes: 1792
k , n = map(int , input().split(' '))
l = list(map(int,  input().split(' ')))
l.sort()
b = []
for i in range(n - 1):
	b.append(l[i + 1] - l[i])
b.append(l[0] + k - l[n - 1])
print(k - max(b))


Measured memory_bytes: 84956
#include<bits/stdc++.h>
#define pb push_back
#define p2(x) (x)*(x)
#define len(x) (int)(x).size()
using namespace std;
typedef long double ld;
typedef long long ll;

signed main(){
    ios_base::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
    ll n;
    cin >> n;
    if(n & 1)return cout << 0 , 0;
    vector<ll>cnt;
    for(ll mx = 5; mx * 2 <= n; mx *= 5){
        cnt.pb(n / (mx * 2));
    }
    ll cnt5 = 0;
    for(int j = len(cnt) - 1; j >=0 ; --j){
        for(int i = j + 1; i < len(cnt);++i)
            cnt[j] -= cnt[i];
        cnt5 += 1ll * cnt[j] * (j + 1);
    }
    ll cnt2 = 0;
    cnt.clear();
    for(ll mx = 2; mx  <= n; mx *= 2){
        cnt.pb(n / (mx));
    }
    for(int j = len(cnt) - 1; j >=0 ; --j){
        for(int i = j + 1; i < len(cnt);++i)
            cnt[j] -= cnt[i];
        cnt2 += 1ll * cnt[j] * (j + 1);
    }
    cout << min(cnt5 , cnt2);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for (long long i=0;i<(n);i++)
#define FOR(i,a,b) for (long long i=(a);i<(b);i++)
#define dump(x)  cerr << #x << " => " << (x) << endl
#define MIN(vec) *min_element(vec.begin(), vec.end())
#define MAX(vec) *max_element(vec.begin(), vec.end())
#define UNIQ(vec) vec.erase(unique(vec.begin(), vec.end()),vec.end()) //ソートの必要あり
#define IN(n,m)  (!(m.find(n) == m.end()))
#define FINDL(vec,x) (lower_bound(vec.begin(),vec.end(),x) - vec.begin())
#define FINDU(vec,x) (upper_bound(vec.begin(),vec.end(),x) - vec.begin())
#define EQ(a,b) (abs(a - b) < 1e-10)
using namespace std;
typedef long long LL;
constexpr int dx[4] = {0,1,0,-1};
constexpr int dy[4] = {1,0,-1,0};
constexpr long double pi = M_PI;
constexpr double eps = 1e-10;
constexpr long mod = 1000000007;
// LONG_MAX,LLONG_MAX
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class Key,class Value> ostream& operator << (ostream &s, map<Key,Value> M)
{ for ( auto itr = begin(M); itr != end(M); ++itr) { s << itr->first << ":" << itr->second; } return s;}
typedef vector<LL> VL;
int main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int L;
    cin >> L;
    VL A(L);
    REP(i, L) cin >> A[i];
    vector<VL> DP(L,VL(5,0));

    // <通らない(Z)> [A_D <偶数回通る>] [A_S <奇数回数通る>] [A_G <偶数回通る>] [A_U <通らない>]
    constexpr int Z = 0,D = 1,S = 2,G = 3,U = 4;
    DP[0][Z] = A[0];
    DP[0][D] = A[0] != 0 ? A[0] % 2 : 2;
    DP[0][S] = (A[0] % 2 == 0) ? 1 : 0;
    DP[0][G] = A[0] != 0 ? A[0] % 2 : 2;
    DP[0][U] = A[0];
    /* 愚直に書く
    REP(i,L-1) {
        DP[i+1][Z] = DP[i][Z] + A[i+1];
        DP[i+1][D] = min(DP[i][Z],DP[i][D]) + ((A[i+1] != 0) ? A[i+1] % 2 : 2);
        DP[i+1][S] = min({DP[i][Z],DP[i][D],DP[i][S]}) + ((A[i+1] % 2 == 0) ? 1 : 0);
        DP[i+1][G] = min({DP[i][Z],DP[i][D],DP[i][S],DP[i][G]}) + ((A[i+1] != 0) ? A[i+1] % 2 : 2);
        DP[i+1][U] = min({DP[i][Z],DP[i][D],DP[i][S],DP[i][G],DP[i][U]}) + A[i+1];
    }
    */
    REP(i,L-1) {
        LL minValue = DP[i][Z];
        DP[i+1][Z] = minValue + A[i+1];
        minValue = min(minValue,DP[i][D]);
        DP[i+1][D] = minValue + ((A[i+1] != 0) ? A[i+1] % 2 : 2);
        minValue = min(minValue,DP[i][S]);
        DP[i+1][S] = minValue + ((A[i+1] % 2 == 0) ? 1 : 0);
        minValue = min(minValue,DP[i][G]);
        DP[i+1][G] = minValue + ((A[i+1] != 0) ? A[i+1] % 2 : 2);
        minValue = min(minValue,DP[i][U]);
        DP[i+1][U] = minValue + A[i+1];
    }
    cout << MIN(DP[L-1]) << endl;
}


Measured memory_bytes: 15872
#include <bits/stdc++.h>
#include <string>
using namespace std;
#define ll long long
#define lim 500009
#define QUICK ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define CASE int t; cin>>t; while(t--)
#define FOR(z,n) for(int i= z; i<=n; i++)
#define endl '\n'
#define elif else if
// templates end here


int main(){
   QUICK;
   ll n,u=0;
   ll k;

   cin>>n>>k;
   int a[n+5];
   bool visited [n+5]={0};
   vector<ll>path;
   ll s = 1;
   bool ya = 0;

   FOR(1,n){
    cin>>a[i];
    if(a[i]==1){
        s = i;
        ya = 1;
    }
   }

    if(ya ==0)
        path.push_back(1);

   while(visited[s] != 1){
        visited[s]=1;
        path.push_back(a[s]);
        s = a[s];
    }


    while(path[u] != a[s])
        u++;

    if(k < u)
        cout << path[k];
    else{
        k-=u;
        ll l = path.size()-u;
        cout << path[(k%l)+u];
    }
}





Measured memory_bytes: 6316
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
typedef long long ll;
typedef long long unsigned int llu;
ll MOD = 1000000007;
ll INF = 1000000009;



void solve(){

  int x,y,z;
  cin >> x >> y >> z;
  int tmp;
  int a,b,c;
  a = x;
  b = y;
  c = z;

  cout << z << " " << x << " " << y << endl;
  

}

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


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

int main() {
  vector<char> S(4);
  for (int i=0; i<4; i++) S[i]=getchar();
  int a1 = (S[0]-'0')*10 + (S[1]-'0');
  int a2 = (S[2]-'0')*10 + (S[3]-'0');
  bool flg1, flg2;
  if (a1>=1&&a1<=12) flg1=true;
  else flg1=false;
  if (a2>=1&&a2<=12) flg2=true;
  else flg2=false;
  
  if(flg1&&flg2) cout << "AMBIGUOUS" << "\n";
  else if(flg1) cout << "MMYY" << "\n";
  else if(flg2) cout << "YYMM" << "\n";
  else cout << "NA" << "\n";
}

Measured memory_bytes: 256
#include <stdio.h>
 
int main() {
  int a[101][101] = {0};
  int b[101] = {0};
  int d[101] = {0};
  int i,j,r,c;
  int x;
  int e = 0;
 
  scanf("%d %d" , &r,&c);
 
  for(j=0; j<r; j++) {
    for(i=0; i<c; i++) {
      scanf("%d",&x);
      a[j][i] = x;
    }
  }
 
  for(j=0; j<r; j++){
    for(i=0; i<c; i++) {
      b[i] += a[j][i];
    }
  }
 
  for(j=0; j<r; j++){
    for(i=0; i<c; i++){
      d[j] += a[j][i];
    }
  }
 
  for(j=0; j<r; j++) {
    for(i=0; i<c; i++) {
      printf("%d ",a[j][i]);
    }
    printf("%d\n", d[j]);
  }
  for(i =0; i<c; i++) {
    printf("%d " ,b[i]);
    e += b[i];
  }
  printf("%d\n", e);
 
  return 0;
}


Measured memory_bytes: 2108
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main(){
  long long int i,a,b,v,n,k;
  scanf("%lld%lld",&n,&k);
  a=n/k;
  if((n%k)*2>=k)
    b=a+1;
  else
    b=a;
  v=0;v+=a*a*a;
  if(k%2==0)
    v+=b*b*b;
  printf("%lld",v);
}

Measured memory_bytes: 128
#include <iostream>

using namespace std;

int main()
{
    long long l,r;
    cin>>l>>r;
    long long i=l,j=l+1,d=((i%2019)*(j%2019))%2019,k=r-l;
    if(k>=2019){
        cout<<0;
        return 0;
    }else{
    for(i;i<r;i++){
        for(j=i+1;j<=r;j++){
            d=min(((i%2019)*(j%2019))%2019,d);
        }
    }


    cout<<d;}
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>

#define repd(i,a,b) for (int i=(a);i<(b);++i)
#define rep(i,n) repd(i,0,n)
#define reprd(i,a,b) for (int i=(a);i>=(b);--i)
#define repr(i,n) reprd(i,n,0)
typedef long long ll;

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

using namespace std;

const ll BIG = 1000000007LL;

int inputValue(){
    int a;
    cin >> a;
    return a;
};

template<typename T>
void inputArray(T* p, int a){
    rep(i, a){
        cin >> p[i];
    }
};

template<typename T>
void inputVector(vector<T> * p, int a){
    rep(i, a){
        T input;
        cin >> input;
        p -> push_back(input);
    }
}

template <typename T>
void output(T a, int precision = 0) {
    if(precision > 0){
        cout << setprecision(precision)  << a << "\n";
    }
    else{
        cout << a << "\n";
    }
}

const int Max = 110000;
int N, K;
string S;
vector<pair<int, char>> r;

int main(int argc, const char * argv[]) {
    cin >> N >> K >> S;
    {
        char curr = S[0];
        int count = 1;
        repd(i, 1, N) {
            if (S[i] != curr) {
                r.push_back(make_pair(count, curr));
                count = 1;
                curr = S[i];
            } else {
                count++;
            }
        }
        r.push_back(make_pair(count, curr));
    }

    int ansMax = 0;
    int sum = 0;
    int countK = 0;
    rep(i, r.size()) {
        // printf("%d,%c,\n", r[i].first,r[i].second);
        sum += r[i].first;
        if (r[i].second == '0') {
            countK++;
            if (countK > K) {
                sum -= r[i - K*2].first;
                if (i-K*2-1>=0) {
                    sum -= r[i - K*2 - 1].first;
                }
                countK--;
            }
        }
        chmax(ansMax, sum);
        // printf("%d,%d\n",ansMax, sum);
    }

    output(ansMax);

    return 0;
}

Measured memory_bytes: 1528
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<iostream>
#include<vector>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<string>
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define rep2(i,s,n) for(int i=s;i< (int)n; i++)
#define ll long long
#define all(v) v.begin(),v.end()
using namespace std;
int main(){
  ll x,y; cin >>x>>y;
  if(x==-y){
    cout <<1<<endl;
    return  0;
  }
  if(abs(x)>abs(y)){
    if(x*y>0){
      if(x>0){
        cout <<abs(x)-abs(y)+2<<endl;
      }else{
        cout <<abs(x)-abs(y)<<endl;
      }
    }else if(x*y<0){
        cout <<abs(x)-abs(y)+1<<endl;
    }else{
      if(x>0)cout<<x+1<<endl;
      else cout <<-x<<endl;
    }
  }else{
    if(x*y>0){
      if(x>0){
        cout <<abs(y)-abs(x)<<endl;
      }else{
        cout <<abs(y)-abs(x)+2<<endl;
      }
    }else if(x*y<0){
        cout <<abs(y)-abs(x)+1<<endl;
    }else{
      if(y>0)cout<<y<<endl;
      else cout <<1-y<<endl;
    }
  }
}
    

Measured memory_bytes: 3572
#define __USE_MINGW_ANSI_STDIO 0
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#define MOD 1000000007
using namespace std;
bool field[51][51];
int x[51];
int y[51];
bool vis[51];
void dfs(int v, int N){
    vis[v] = true;
    for(int i = 0; i < N; i++){
        if(field[v][i] && !vis[i]){
            dfs(i, N);
        }
    }
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N, M;
    cin >> N >> M;
    int ans = 0;
    for(int i = 0; i < M; i++){
        cin >> x[i];
        cin >> y[i];
        field[--x[i]][--y[i]] = true;
        field[y[i]][x[i]] = true;
    }
    for(int i = 0; i < M; i++){
        field[x[i]][y[i]] = field[y[i]][x[i]] = false;
        for(int i = 0; i < N; i++){
            vis[i] = false;
        }
        bool val = false;
        dfs(0, N);
        for(int i = 0; i < N; i++){
            if(vis[i]==false){
                val = true;
                break;
            }
        }
        if(val){
            ans++;
        }
        field[x[i]][y[i]] = field[y[i]][x[i]] = true;
    }
    cout << ans << "\n";
    return 0;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define EB emplace_back
#define MP make_pair
#define all(o) (o).begin(), (o).end()
#define mset(m,v) memset(m,v,sizeof(m))
#define fr(i,n) for(lli i=0;i<n;++i)
#define rep(i,a,b) for(lli i=a;i<=b;++i)
#define remin(a,b) (a=min((a),(b)))
#define remax(a,b) (a=max((a),(b)))
#define endl '\n'
typedef long long int lli;
typedef long double ld;
typedef pair< lli,lli > ii;
typedef vector<lli> vi;
typedef vector<ii> vii;
typedef vector<vi> graph;
lli MOD=1000000007;long double EPS=1e-9;


void pre(){

}

void solve(){
	string s,t;
	cin>>s;
	int n=s.length();
	cin>>t;
	s=s+s;
	for(int i=0;i<s.length();i++){
		if(s.substr(i,n)==t){
			cout<<"Yes\n";
			return;
		}
	}
	cout<<"No\n";
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	pre();
	int t=1;
	//cin>>t;
	for(int i=1;i<=t;i++){
		//cout<<"Case #"<<i<<": ";
		solve();
	}
}

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

int v[1 + MAXN][1 + MAXN];
int w[1 + MAXN][1 + MAXN];
int main(){
    FILE*fi,*fo;
    //fi = fopen("a.in","r");
    //fo = fopen("a.out","w");
    fi = stdin;
    fo = stdout;

    int n;
    fscanf(fi,"%d", &n);
    for(int i = 1; i <= n; i++){
        fgetc(fi);
        for(int j = 1; j <= n; j++)
            v[i][j] = fgetc(fi);
    }
    int ans = 0;
    for(int a = 0; a < n; a++){
        for(int i = 1; i <= n; i++)
            for(int j = 1; j <= n; j++)
                w[i][j] = v[(i + a - 1) % n + 1][j];
        int ok = 1;
        for(int i = 1; i <= n; i++)
            for(int j = 1; j <= n; j++)
                if(w[i][j] != w[j][i])
                    ok = 0;
        ans += n * ok;
    }
    fprintf(fo,"%d", ans);

    return 0;
}


Measured memory_bytes: 896
#include <iostream>
using namespace std;
int main(){
  int n;
  int a[1000];
  while( cin >> n,n){
    for(int i = 0 ; i < n ; i++ )cin >> a[i];
    int ans = 0;
    for(int i = n-1 ; i >= 0 ; i-- ){
      for(int j = 0 ; j < n - 1 ; j++  ){
	if(a[j] > a[j + 1]){
	  swap(a[j],a[j + 1]);
	  ans++; 
	}
      }
    }
    cout << ans << endl;
  }  
  return 0;
}

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

struct node{
  int key;
  struct node *left;
  struct node *right;
};
typedef struct node *NodePointer;

void in(void);
NodePointer makenode(int);
void insert(int, NodePointer);
void preorder(NodePointer);
void inorder(NodePointer);
int find(int, NodePointer);

NodePointer head, tail;

int main(){
  char str[7];
  int n, k;
  in();
  scanf("%d", &n);
  while(n--){
    scanf("%s", str);
    if(str[0] == 'i'){
      scanf("%d", &k);
      insert(k, head);
    }
    else if(str[0] == 'p'){
      inorder(head->right);
      printf("\n");
      preorder(head->right);
      printf("\n");
    }
    else{
      scanf("%d", &k);
      if(find(k, head->right)) printf("yes\n");
      else printf("no\n");
    }
  }
  return 0;
}

void in(void){
  head = makenode(-1);
  tail = makenode(-1);
  head->right = tail;
  head->left = tail;
}

NodePointer makenode(int k){
  NodePointer x;
  x = malloc(sizeof(struct node));
  x->key = k;
  x->left = x->right = tail;
  return x;
}

void insert(int k, NodePointer p){
  if(k < p->key){
    if(p->left ==tail) p->left = makenode(k);
    else insert(k, p->left);
  }
  else{
    if(p->right == tail) p->right = makenode(k);
    else insert(k, p->right);
  }
}

void preorder(NodePointer node){
  if(node != tail){
    printf(" %d", node->key);
    preorder(node->left);
    preorder(node->right);
  }
}

void inorder(NodePointer node){
  if(node != tail){
    inorder(node->left);
    printf(" %d", node->key);
    inorder(node->right);
  }
}

int find(int k, NodePointer node){
  if(node == tail){
    return 0;
  }
  if(node->key == k) return 1;
  else if(node->key < k) return find(k, node->right);
  else return find(k, node->left);
}



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

int main() {
  const long wa=1000000007;
  int N,M;
  cin >> N >> M;
  if(abs(N-M)>1)cout << 0;
  else{
    long mat=1;
    for(long i=1;i<N+1;i++){
      mat*=i;
      mat=mat%wa;
    }
    for(long i=1;i<M+1;i++){
      mat*=i;
      mat=mat%wa;
    }
    if(N==M)mat*=2;
    mat=mat%wa;
    cout << mat;
  }
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
int n,s;
int Sum_of_Integers(int i,int sum,int v);
int main(){
  while(1){
    cin >> n >> s;
    if(!n && !s)break;
    cout <<  Sum_of_Integers( 0 , 0 , -1) << endl;
  }
}
int Sum_of_Integers(int i,int sum,int v){
  int ret = 0;
  if(i > n || sum > s)return 0; // あふれたとき
  if(i == n && sum == s)return 1;
  for(int j=0;j<=9;j++){
    if(v<j)ret += Sum_of_Integers( i + 1, sum + j , j );
  }
  return ret;
}

Measured memory_bytes: 1160
IDENTIFICATION                   DIVISION.
PROGRAM-ID.                      ABC_092_B.
ENVIRONMENT                      DIVISION.
DATA                             DIVISION.
WORKING-STORAGE                  SECTION.
    01 INP    PIC X(8).

    01 maxlen PIC 9(1)  VALUE 2.
    01 cur    PIC 9(8)  VALUE 1.
    01 i      PIC 9(18) VALUE 1.
    01 j      PIC 9(18).

    01 k      PIC 9(3).
    01 p      PIC 9(3).
    01 q      PIC 9(3).

    01 len    PIC 9(8).

    01 ZS     PIC Z(6).
    01 ans    PIC X(5).

    01 DX1.
        03 DX11 OCCURS 2.
            05 DX PIC 9(3).

    01 A1.
        03 A11 OCCURS 100.
            05 A PIC 9(3).

    01 X      PIC 9(3).
    01 R      PIC 9(3).

    01 N      PIC 9(3).
    01 sm     PIC 9(5).

    01 DUMMY  PIC X(1).
PROCEDURE                        DIVISION.
MAIN.
    ACCEPT N.

    ACCEPT INP.

    PERFORM maxlen TIMES

        PERFORM VARYING j FROM cur BY 1
            UNTIL INP(j:1) = SPACE
        END-PERFORM

        COMPUTE len = j - cur

        MOVE INP(cur:len) TO DX(i)

        COMPUTE cur = j + 1

        ADD 1 TO i

    END-PERFORM.

    PERFORM VARYING k FROM 1 BY 1 UNTIL N < k
        ACCEPT A(k)
    END-PERFORM.

    MOVE 0 TO sm.

    PERFORM VARYING p FROM 0 BY 1 UNTIL DX(1) < p + 1
        PERFORM VARYING q FROM 1 BY 1 UNTIL N < q
            IF p = 0 THEN
                ADD 1 TO sm
            ELSE
                DIVIDE A(q) INTO p GIVING X REMAINDER R
                IF R = 0 THEN
                    ADD 1 TO sm
                END-IF
            END-IF
        END-PERFORM
    END-PERFORM.

    ADD DX(2) TO sm.

    MOVE sm TO ZS.

    PERFORM UNANS.

    DISPLAY ans(1:FUNCTION STORED-CHAR-LENGTH(ans)).
    STOP RUN.

UNANS                            SECTION.
    UNSTRING
        ZS DELIMITED BY ALL SPACE
        INTO DUMMY ans
    END-UNSTRING.


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

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

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

  int x, a, b;
  cin >> x >> a >> b;

  if (abs(x - a) < abs(x - b)) {
    cout << "A" << endl;
  } else {
    cout << "B" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  int n,tmp=0,ans=0;	    
  string s;
  cin>>n>>s;
  for(int i=0;i<n;i++){
    if(s[i]=='I') tmp++;
    else tmp--;
    ans=max(ans,tmp);
  }
  cout<<ans<<endl;
  return 0;
}


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

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define ll long long

using namespace std;

const int MOD = 1e9 + 7;
const int MAXN = 10000010;

int sum0[MAXN];
int sum[MAXN];
int pref[MAXN];
int last[MAXN];

int add(int a, int b) {
    a += b;
    if (a >= MOD) return a - MOD;
    if (a < 0) return a + MOD;
    return a;
}

int mul(int a, int b) {
    return ((ll) a * b % MOD); 
}

int main() {
    ios_base::sync_with_stdio(false);
    REP(i, MAXN) sum0[i] = 1, last[i] = -1;
    sum[0] = 1;

    int n;
    cin >> n;

    int x = 0;
    REP(i, n) {
        int y;
        cin >> y;

        if (i > 0) pref[i] += pref[i - 1];

        x ^= y;
        if (x == 0) {
            pref[i]++;
            
            if (i == n - 1) {
                //assert(0);
                int out = 0;
                REP(i, MAXN) out = add(out, sum[i]);
                cout << out << "\n";
                return 0;
            }

            sum[0] = add(sum[0], sum[0]);
        } else {
            int num = pref[i];
            if (last[x] >= 0) num -= pref[last[x]];

            sum0[x] = add(sum0[x], mul(sum[x], num));
            sum[x] = add(sum[x], sum0[x]);
            last[x] = i;

            if (i == n - 1) {
                cout << sum0[x] << "\n";
                return 0;
            }
        }
    }


    return 0;
}

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

int main()
{
    int A, B, K;
    cin >> A >> B >> K;

    vector<int> x;
    for(int i = 1; i <= 100; i++)
    {
        if(A % i == 0 && B % i == 0)
        {
            x.push_back(i);
        }
    }

    int ans = x[x.size() - K];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <functional>
#include <utility>
#include <queue>
#include <vector>
#include <string>
#include <stack>
#include <ctime>
#include <random>
#define rep(i,n) for(ll i=0;i<n;i++)
using namespace std;
typedef long long int ll;
const ll  MOD = 1000000007;
typedef pair<ll,ll> P;
const ll INF = 100100100100100100;

int main() {
  ll N,A,B;
  cin >> N >> A >> B;
  cout << min(A,B) << " " << max(ll(0),A+B-N) << endl;
}

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

using namespace std;

typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = (ll)1e9 + 7;

int main()
{
  string s; cin >> s;
  int n = s.size();
  int gx, gy; scanf("%d %d", &gx, &gy);
  gx += 8000;
  gy += 8000;
  vector<int> X, Y;
  int i = 0;
  while (i < n and s[i] == 'F') { ++i; }
  int startx = 8000 + i, starty = 8000;
  int dir = 0;
  while (i < n) {
    if (s[i] == 'T') { dir = 1 - dir; ++i; }
    else {
      int j = i;
      while (j < n and s[j] == 'F') { ++j; }
      if (dir == 0) { X.push_back(j - i); }
      else { Y.push_back(j - i); }
      i = j;
    }
  }

  int N = 8000, xmoves = X.size(), ymoves = Y.size();
  vector<vector<bool>> dpx(xmoves + 5, vector<bool>(N * 2 + 5, false));
  dpx[0][startx] = true;
  for (int i = 0; i < xmoves; ++i) {
    for (int j = 0; j <= 2 * N; ++j) {
      if (dpx[i][j]) {
        dpx[i + 1][j + X[i]] = dpx[i + 1][j - X[i]] = true;
      }
    }
  }
  vector<vector<bool>> dpy(ymoves + 5, vector<bool>(N * 2 + 5, false));
  dpy[0][starty] = true;
  for (int i = 0; i < ymoves; ++i) {
    for (int j = 0; j <= 2 * N; ++j) {
      if (dpy[i][j]) {
        dpy[i + 1][j + Y[i]] = dpy[i + 1][j - Y[i]] = true;
      }
    }
  }
  bool ok = dpx[xmoves][gx] and dpy[ymoves][gy];
  printf("%s\n", ok ? "Yes" : "No");
  return 0;
}


Measured memory_bytes: 8320
#include <iostream>
#include <string>
#include <algorithm>
#define	MOD = 1000000007;
using namespace std;

int main()
{
	long A, B, C;
	cin >> A >> B >> C;

	int a = A;
	for (int i = 1; i <= B; i++)
	{
		if (a % B == C)
		{
			cout << "YES" << endl;
			return 0;
		}
		a += A;
	}
	cout << "NO" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int n, x;
int b[N], l[N], u[N];
long long cal(int id, int a) {
    if (a < b[id]) return 1LL * l[id] * (a - b[id]);
    else return 1LL * u[id] * (a - b[id]);
}
int id[N];
bool cmp(int a, int b) {
    return cal(a, x) - cal(a, 0) > cal(b, x) - cal(b, 0);
}
bool chk(long long t) {
    long long sum = 0;
    for (int i = 0; i < n; ++ i) sum += cal(i, 0);
    int tot = t / x;
    for (int i = 0; i < tot; ++ i) sum += cal(id[i], x) - cal(id[i], 0);
    if (tot == n) return sum >= 0;
    int rem = t % x;
    long long mx = 0;
    for (int i = 0; i < n; ++ i) {
        if (i < tot) mx = max(mx, cal(id[i], rem) - cal(id[i], x) + cal(id[tot], x) - cal(id[tot], 0));
        else mx = max(mx, cal(id[i], rem) - cal(id[i], 0));
    }
    // cerr << t << " " << sum << " " << mx << endl;
    return sum + mx >= 0;
}
int main() {
    cin >> n >> x;
    for (int i = 0; i < n; ++ i) {
        cin >> b[i] >> l[i] >> u[i];
        id[i] = i;
    }
    sort(id, id + n, cmp);
    long long lb = 0, rb = 1LL * n * x;
    while (lb < rb) {
        long long md = lb + (rb - lb) / 2;
        if (chk(md)) rb = md;
        else lb = md + 1;
    }
    cout << lb << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>

int main()
{
    int n;
    scanf("%d", &n);

    int i;
    for (i = 1; i <= n; i++) {
        if ((i % 3) == 0) {
            printf(" %d", i);
        } else {
            int j;
            j = i;
            for (;;) {
                if (j == 0) {
                    break;
                } else if ((j % 10) == 3) {
                    printf(" %d", i);
                    break;
                } else {
                    j = j / 10;
                }
            }
        }
    }
    printf("\n");
    return(0);
}



Measured memory_bytes: 2088
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(long long i=0;i<n;++i)
#define REPR(i,n) for(long long i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(long long i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define INF 999999999
#define MOD 1000000007
#define pb push_back
#define pf push_front
#define MP make_pair
#define SV(v) {for(long long sitr=0;sitr<v.size();++sitr){cin>>v[sitr];}}

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

using namespace std;

typedef pair<int,int> pii;

int main(){

  while(true){
    int n;
    cin >> n;
    if(n == 0) break;

    vector<string> v(n);
    map<string, int> mp;
    REP(i,n){
      cin >> v[i];
      mp[v[i]] = 0;
    }
    bool is_end = false;
    REP(i,n){
      mp[v[i]]++;

      //終了判定
      REPI(itr1, mp){
        int mx = 0;
        REPI(itr, mp){
          if(itr->first != itr1->first){
            mx = max(mx, itr->second);
          }
        }
        if(itr1->second > mx + n - i - 1){
          cout << itr1->first << " " << i + 1 << endl;
          is_end = true;
          break;
        }
      }
      if(is_end) break;
    }
    if(!is_end){
      cout << "TIE" << endl;
    }
  }
  return 0;
}



Measured memory_bytes: 3112
h, w = map(int, input().split())
maze = [list(input()) for i in range(h)]
mod = 10 ** 9 + 7

dp = [[0] * (w + 1) for i in range(h + 1)]

for i in range(1, h + 1):
    for j in range(1, w + 1):
        if i == j == 1:
            dp[i][j] = 1
        elif maze[i - 1][j - 1] == ".":
            dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % mod

print(dp[h][w])


Measured memory_bytes: 87664
#include "stdio.h"

int max_int(int a,int b){
  if (a>b) {return a;}
  return b;
}

int main(int argc, char const *argv[]) {
  int N;
  scanf("%d", &N);
  int A[N],B[N],C[N];
  int Am[N],Bm[N],Cm[N];
  for (size_t i = 0; i < N; i++) {
    scanf("%d%d%d",&A[i],&B[i],&C[i]);
  }
  Am[0]=A[0];Bm[0]=B[0];Cm[0]=C[0];
  for (size_t i = 1; i < N; i++) {
    Am[i]=A[i]+max_int(Bm[i-1],Cm[i-1]);
    Bm[i]=B[i]+max_int(Am[i-1],Cm[i-1]);
    Cm[i]=C[i]+max_int(Am[i-1],Bm[i-1]);
  }
  int ans=max_int(Am[N-1],Bm[N-1]);
  ans=max_int(Cm[N-1],ans);
  printf("%d", ans);
  return 0;
}


Measured memory_bytes: 2560
//#include "stdafx.h"
#include<bits/stdc++.h> 
#include <iostream>
#include <algorithm>
#include <string>
#include <set>
using namespace std;
int ans,r,d,q,n,x,a[101],c;
int main()
{
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	
	cin >>n>>d>>x;
	for(int i=0;i<n;i++)cin>>a[i];

	for(int i=0;i<n;i++){
		r=1;q=a[i];
		while(q<=d){
			q=(a[i]*r)+1;
			r++;
		}
		if(a[i]<d)
		ans+=r-2;
	}
	cout<<n+ans+x<<"\n";
	return 0;
}

Measured memory_bytes: 3568
#include<bits/stdc++.h>
#define M 100005
#define Mod 1000000007
using namespace std;
int n,cnt[26];
long long ans=0;
char s[M];
bool mark[26];
int main(){
	bool cur=0;
	scanf("%d%s",&n,s+1);
	for(int i=1;i<=n;i++){
		int x=s[i]-'a';
		cnt[x]++;
		long long sum=1;
		for(int j=0;j<26;j++)if(j!=x)sum*=(1+cnt[j]),sum%=Mod;
		ans=(ans+sum)%Mod;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 384
#include<cstdio>
#include<iostream>
#include<string>
#include<cmath>
using namespace std;
typedef long long ll;
//find_by_order, order_of_key
#define forn(i, n) for (ll i=0;i<ll(n);++i)

void solve()
{
    int a, b, h, m; scanf("%d%d%d%d", &a, &b, &h, &m);
    double m1 = h*5 + (double)m/60*5;
    double m2 = m;
    double dm = abs(m1-m2);
    double dind = dm*6;
    double pi = 3.141592653589793238462643383279502884197169399375105820974944;
    double theta = dind*pi/180;
    double res = a*a+b*b - 2*a*b*cos(theta);
    printf("%.11lf", sqrt(res));
}
int main()
{
    ll T=1;
    while(T--) solve();
    return 0;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define rep(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define repr(i, n, m) for (int i = (int)(n) - 1; i >= (int)(m); i--)
using namespace std;
using ll = int64_t;
const int MOD = 1000000007; // 10^9+7

vector<int> r, g, b;

int main() {
    int n; cin >> n;
    string s; cin >> s;
    rep(i, 0, n)
    {
        if (s[i] == 'R') r.push_back(i);
        if (s[i] == 'G') g.push_back(i);
        if (s[i] == 'B') b.push_back(i);
    }

    ll ans = r.size() * g.size() * b.size();
    rep(i, 0, r.size())
    {
        rep(k, 0, g.size()) 
        {
            if ((r[i] + g[k]) % 2 == 0 && s[(r[i] + g[k]) / 2] == 'B') ans--;
            int idx1 = 2 * r[i] - g[k];
            if (idx1 >= 0 && idx1 < n && s[idx1] == 'B') ans--;
            int idx2 = 2 * g[k] - r[i];
            if (idx2 >= 0 && idx2 < n && s[idx2] == 'B') ans--;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3660