akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cstdlib>
#include <cmath>
#define MAX 1000000000000000000LL

using namespace std;
int main(){
    string str;
    cin>>str;
    int ans=0;
    for(int i=1; i<str.length(); i++){
        for(int j=0; j<i; j++){
            if(str[i]==str[j])ans=1;
        }
    }
    if(ans==1)cout<<"no"<<endl;
    else cout<<"yes"<<endl;
    return 0;
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pi 3.141592653589793238
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MOD 1000000007
int main(){
	fast;
	string s;
	cin>>s;
	int rem=s.length();
	for(int i=s.length()-1;i>=3;i--)
	{
		// cout<<rem<<i<<endl;
		
		if(s.substr(max(i-4,0),5)=="dream")
			i-=4,rem-=5;
		else if(s.substr(max(i-6,0),7)=="dreamer")
			i-=6,rem-=7;
		else if(s.substr(max(i-4,0),5)=="erase")
			i-=4,rem-=5;
		else if(s.substr(max(i-5,0),6)=="eraser")
			i-=5,rem-=6;
		
		// cout<<rem<<i<<endl;
	}
	if(rem==0)
		cout<<"YES";
	else
		cout<<"NO";
	return 0;
}



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

int res, kari;

int main() {
	int N, M, num =25000;
	char NM[50][50]; // ???????¨?
	cin >> N;
	cin >> M;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++) cin >> NM[i][j];
	}

	for (int i = 0; i < N - 2; i++) {
		for (int a = 0; a <= i; a++) {
			for (int b = 0; b < M; b++) {
				if (NM[a][b] != 'W') {
					res++;
				}
			}
		}
		kari = res;
		for (int j = i + 1; j < N - 1; j++) {
			for (int a = 1; a <= j - i; a++) {
				for (int b = 0; b < M; b++) {
					if (NM[i + a][b] != 'B') {
						res++;
					}
				}
			}
			for (int a = 1; a < N - j; a++) {
				for (int b = 0; b < M; b++) {
					if (NM[j + a][b] != 'R') {
						res++;
					}
				}
			}
			if (res < num) num = res;
			res = kari;
		}
		res = 0;
	}
	
	cout << num << "\n";
	return 0;
}

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

int main(){
    int n;
    string s;
    cin >> n>> s;
    int M = 0;
    int now = 0;
    rep(i,n){
        if (s[i]=='I'){
            now++;
            M=max(now,M);
        }
        else{
            now--;
        }
    }
    cout << M << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using ii=pair<ll,ll>;
using vi=vector<ll>;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF (ll)1e18
#define all(x) (x).begin(),(x).end()
#define print(a); for(auto x:a)cout<<x<<" "; cout<<"\n";
#define mset(a); memset(a,0,sizeof(a));

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
    string s,t;cin>>s>>t;
    vector<vi>v(26);
    for(int i=0;i<s.size();i++){
        v[s[i]-'a'].pb(i);
    }
    ll x=0,ans=0;
    for(int i=0;i<t.size();i++){
        ll val=t[i]-'a';
        if(v[val].empty()){ans=-1;break;}
        auto y=lower_bound(all(v[val]),x);
        if(y==v[val].end()){ans+=(s.size()-x);x=0;y=lower_bound(all(v[val]),0);}
        ans+=*y-x+1;
        x=*y+1;
    }
    cout<<ans<<"\n";
}


Measured memory_bytes: 1736
#include <cstdio>
#include <cstring>
#include <algorithm>
 
using namespace std;
 
int p[1000000];
int cnt[1000000];
 
int main()
{
  fill(p, p + 1000000, 1);
  p[0] = p[1] = 0;
  for(int i=2;i<1000000;i++)
    for(int j=i*2;j<1000000;j+=i)
      p[j] = 0;
 
  for(int i=1;i<1000000;i++)
    cnt[i] = cnt[i-1] + p[i];
 
  int n;
  while(scanf("%d", &n) != -1)
    printf("%d\n", cnt[n]);
 
  return 0;
} 


Measured memory_bytes: 10528
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, N) for(int i=0; i<N; i++)
typedef long long ll;
#define dump(x) cerr<<#x<<"="<<x<<endl
using P = pair<int, int>;

int main() {
    string a, b; cin >> a >> b;
    if(a.at(0)==b.at(2) && b.at(0)==a.at(2) && a.at(1)==b.at(1)){
        cout << "YES" << endl;
    }
    else cout << "NO" << endl;
    return 0;
}


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

using namespace std;
using ll = long long;

const int MOD = 1e9 + 7;
#define REP(i, n)  for(int i = 0; i < n; ++i)
#define FOR(i, t, n)  for(ll i = t; i <= (ll)n; ++i)
struct edge {
    int from, to;
    ll cost;
};


class Eratosthenes {
public:
    vector<bool> prime;

    Eratosthenes(ll size) {
        size = max((int) sqrt(size) + 1, 101010);
        prime.resize(size, 1);
        prime[0] = 0;
        prime[1] = 0;
        for (size_t i = 2; i * i <= size; ++i)
            if (prime[i]) {
                for (size_t j = 2; i * j <= size; ++j)prime[i * j] = false;
            }
    }
};


class Combination {
    vector<ll> fac; //n!(mod M)
    vector<ll> ifac; //k!^{M-2} (mod M)
public:
    Combination(ll size) {
        fac.resize(size);
        ifac.resize(size);
        fac[0] = 1;
        ifac[0] = 1;
        for (ll i = 0; i < size; i++) {
            fac[i + 1] = fac[i] * (i + 1) % MOD;
            ifac[i + 1] = ifac[i] * mpow(i + 1, MOD - 2) % MOD;
        }
    }

    ll mpow(ll x, ll n) {
        ll ans = 1;
        while (n != 0) {
            if (n & 1) ans = ans * x % MOD;
            x = x * x % MOD;
            n = n >> 1;
        }
        return ans;
    }

    ll comb(ll a, ll b) {
        if (a == 0 && b == 0)return 1;
        if (a < b || a < 0)return 0;
        ll tmp = ifac[a - b] * ifac[b] % MOD;
        return tmp * fac[a] % MOD;
    }
};


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

ll LCM(ll a, ll b) {
    ll gcd = GCD(a, b);
    return a / gcd * b;
}

ll N;

int main() {
    cin >> N;
    vector<int> L(N);
    REP(i, N)cin >> L[i];
    sort(L.begin(), L.end());
    ll ans = 0;
    REP(a, N) {
        FOR(b, a + 1, N - 1) {
            auto i2 = lower_bound(L.begin() + b, L.end(), L[a] + L[b]);
            int res = i2 -L.begin() - b-1;
            ans += max(0, res);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
int main(){
    int n,k;
    cin>>n>>k;
    set<int> s;
    for(int i=1;i<=k;i++){
        int x;cin>>x;
        for(int j=1;j<=x;j++){
            int v;cin>>v;
            s.insert(v);
        }
    }
    cout<<n-s.size()<<endl;
}

Measured memory_bytes: 3632
from collections import deque

def main():
    n, m = map(int, input().split())
    to = [[] for _ in range(n+1)]
    ans = [None]*(n+1)
    for _ in range(m):
        a, b = map(int, input().split())
        to[a].append(b)
        to[b].append(a)
    q = deque([1])
    while q:
        p = q.pop()
        children = to[p]
        for child in children:
            if ans[child] is None:
                ans[child] = p
                q.appendleft(child)
    print("Yes")
    print("\n".join(list(map(str, ans[2:]))))
            
    

if __name__ == "__main__":
    main()

Measured memory_bytes: 98824
def mult(a,b):
    #a以上の最小のbの倍数
    d = (a-1)//b
    return b*(d+1)

def mov(CSF,st):
    N = len(CSF)
    time = 0
    for i in range(st,N):
        c,s,f = CSF[i][0],CSF[i][1],CSF[i][2]
        time = max(time,s)
        time = mult(time,f) + c
    return time

def main():
    N = int(input())
    CSF = [list(map(int,input().split())) for _ in range(N-1)]

    for i in range(N-1):
        print(mov(CSF,i))
    print(0)

if __name__ == "__main__":
    main()


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

using namespace std;

typedef long long ll;

const ll mod = 1e9 + 7;

int main() {
  string s;
  cin >> s;
  int L = s.size();
  int pos_a = 0;
  int pos_z = L - 1;
  while (s[pos_a] != 'A') pos_a++;
  while (s[pos_z] != 'Z') pos_z--;
  cout << pos_z - pos_a + 1 << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  int a[4];
  cin >> N;
  a[3]=N%10;
  a[2]=N/10%10;
  a[1]=N/100%10;
  a[0]=N/1000;
  for (int bit=0;bit<(1<<3);bit++){
    int sum=a[0];
    vector<char> v(3);
    for (int i=0;i<3;i++){
      if (bit&(1<<i)){
        sum+=a[i+1];
        v[i]='+';
      }
      else {
        sum-=a[i+1];
        v[i]='-';
      }
    }
    if (sum==7){
      cout << a[0] << v[0] << a[1] << v[1] << a[2] << v[2] << a[3] << "=7";
      break;
    }
  }
}

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

typedef long long ll;

int a[10];
bool f(int n) {
    while(n > 0) {
        if(a[n % 10])
            return true;
        n /= 10;
    }
    return false;
}
int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);

    int n, k;
    cin >> n >> k;
    while(k--) {
        int e;
        cin >> e;
        a[e] = 1;
    }

    while(f(n)) n++;
    cout << n << '\n';
    return 0;
}



Measured memory_bytes: 3616
#include <iostream>
#include <algorithm>
#include <vector>
#include <limits.h>
#include <cmath>
#include <map>
using namespace std;
using ll=long long;
int main(){
    int n;
    cin>>n;
    map<int,int> m;
    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    ll ret=0;
    for(int i=n-1;i>=0;i--){
        ret+=m[a[i]+i];
        m[i-a[i]]++;
    }
    cout<<ret<<endl;
}

Measured memory_bytes: 21212
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define MAXN 100005
#define eps 1e-12
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T> void read(T &res)
{
    res=0;
    T f=1;char c=getchar();
    while(c<'0'||c>'9')
    {
        if(c=='-')f=-1;
        c=getchar();
    }
    while(c>='0'&&c<='9')
    {
        res=res*10+c-'0';
        c=getchar();
    }
    res*=f;
}
template<class T>
void out(T x)
{
    if(x<0){x=-x;putchar('-');}
    if(x>=10)
    {
        out(x/10);
    }
    putchar('0'+x%10);
}
bool Query(int64 t) {
    putchar('?');space;out(t);enter;fflush(stdout);
    char s[5];scanf("%s",s);
    return s[0] == 'Y';
}
void Solve(){
    int64 v=1;
    bool f=0;
    for(int i=1;i<=10;++i)
    {
        if(!Query(v)){f=1;v/=10;break;}
        v*=10;
    }
    if(!f){
        v = 1;
        for(int i= 1;i<=10;++i)
        {
            if(Query(v*10-1)){putchar('!');space;out(v);enter;return;}
            v*=10;
        }
    }
    int64 L=v,R=min(v*10-1,(int64)1e9);
    while(L<R)
    {
        int64 mid=(L+R+1)>>1;
        if(!Query(mid*10))L=mid;
        else R=mid-1;
    }
    putchar('!');
    space;
    out(L + 1);
    enter;
}
int main()
{
    Solve();
    return 0;
}


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

#define IOS cin.tie(0);ios_base::sync_with_stdio(false)

#define ll      long long
#define Fi      first
#define Se      second
#define Pb      push_back
#define vi      vector<int>
#define vs      vector<string>
#define vp      vector<pair<int,int>>
#define vvi     vector<vector<int>>
#define vvp     vector<vector<pair<int,int>>>
using Graph  =  vector<vector<int>>; //Caution!! Segmentation Fault!! Don't forget to add +1!

#define sz(x) (int)x.size()
#define all(v) v.begin(),v.end()
#define output_s(s) printf("%s\n",(s).c_str())

#define rep(i,n)        for(int i=0;i<(int)(n);i++)
#define Rep(i,n,m)      for(int i=(int)(n);i<(int)(m);i++)
#define RepS(i,n,m)     for(int i=(int)(n);i<=(int)(m);i++)
#define RRepS(i,n,m)    for(int i=(int)(n);i>=(int)(m);i--)
#define SRepS(i,n,m)    for(int i=(int)(n);i*i<=(int)(m);i++)
#define RepA(x)         for(auto &item:(x))

void CINT(){} //@shibh308's template
template<class Head,class... Tail> void CINT(Head&& head,Tail&&... tail){cin>>head; CINT(move(tail)...);}    
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)
#define VCIN(x) for(auto &item:x) cin>>item

void OUT(){}
template<class Head,class...Tail> void OUT(Head&& head,Tail&&...tail){cout<<head<<(sizeof...(tail)?" ":"\n"); OUT(move(tail)...);}
#define COUT(...) OUT(__VA_ARGS__)

template<typename TypeInt>TypeInt GCD(TypeInt a,TypeInt b){return a%b==0?b:GCD(b,a%b);} //最大公約数
template<typename TypeInt>TypeInt LCM(TypeInt a,TypeInt b){return a*b/GCD(a,b);} //最小公倍数
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}
template<class T>bool comp(T a,T b){return abs(a)<abs(b);} //比較関数

void YES(bool f){printf(f?"YES\n":"NO\n");}
void Yes(bool f){printf(f?"Yes\n":"No\n");}
void Possible(bool f){printf(f?"Possible\n":"Impossible\n");}
void POSSIBLE(bool f){printf(f?"POSSIBLE\n":"IMPOSSIBLE\n");}

//----------------------library------------------------//

//const int dx[4]={1,0,-1,0};
//const int dy[4]={0,1,0,-1};
const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};
const int NMAX = 200;
const int INF = 1e9;
const int MOD = 1e9+7;
bool flag;

//----------------------Global-------------------------//

signed main(){
    CIN(N,M);
    vvi s(M);
    rep(i,M){
        CIN(k);
        rep(j,k){
            CIN(x);x--;
            s[i].push_back(x);
        }
    }
    vi p(M);
    VCIN(p);
    int ans=0;
    for(int bit=0;bit<(1<<N);bit++){
        flag=true;
        rep(i,M){
            int cnt=0;
            RepA(s[i])if(bit&(1<<item))cnt++;
            if(cnt%2!=p[i])flag=false;
        }
        if(flag)ans++;
    }
    printf("%d\n",ans);


    return 0;
}

Measured memory_bytes: 256
H,W,A,B = map(int,input().split())
mod = 10**9+7
x1 = [1 for i in range(H+W)]
xi = [1 for i in range(H+W)]
num = 1
def power2(a,b,p):
    if b == 0:
        return 1
    if b%2 == 0:
        d = power2(a,b//2,p)
        return (d*d)%p
    return (a*power2(a,b-1,p))%p
for i in range(1,H+W):
    num = (num*i)%mod
    x1[i] = num
for i in range(1,H+W):
    x2 = power2(x1[i],mod-2,mod)
    xi[i] = x2
def comb(a,b,p):
    return (x1[a]*xi[b]*xi[a-b])%p
ans = 0
for w in range(B,W):
    ans = (ans+ (comb(H-A+w-1,w,mod)*comb(A+W-w-2,A-1,mod))%mod)%mod
print(ans)

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

typedef long long ll;
typedef vector<long long> vll;
typedef vector<int> vi;
typedef pair<int, int> pi;

#define yes "Yes"
#define yse "Yes"
#define no "No"

#define pb push_back
#define rep(i, l, n) for (int i = (l); i < n; i++)
#define rep_cs(i, l, n) for (int i = (l); i <= n; i++)
#define rep_d(j, n) for (int j = n; j >= 0; j--)
#define rep_d_op(j, n, a) for (int j = n; j >= a; j--)

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

const int MOD = 1000000007;
const vector<int> dx = {1, 0};
const vector<int> dy = {0, 1};
const ll INF = 1LL << 60;

// int max = *std::max_element(v.begin(), v.end());
// int sum = accumulate(v, v + v.size(), 0);

int GCD(int a, int b) { return b ? GCD(b, a % b) : a; }

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

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

int main()
{
    stack<int> S;
    int a, b, x;
    string s;
    while (cin >> s)
    {
        if (s[0] == '+')
        {
            a = S.top();
            S.pop();
            b = S.top();
            S.pop();
            S.push(a + b);
        }
        else if (s[0] == '-')
        {
            b = S.top();
            S.pop();
            a = S.top();
            S.pop();
            S.push(a - b);
        }
        else if (s[0] == '*')
        {
            a = S.top();
            S.pop();
            b = S.top();
            S.pop();
            S.push(a * b);
        }
        else
        {
            S.push(atoi(s.c_str()));
        }
    }
    cout << S.top() << endl;
}


Measured memory_bytes: 3164
# -*- coding: utf-8 -*-
a,b,c,d = map(int, input().split())

def gcd(x,y):
    while y>0:
        x,y = y,x%y
    return x

x = c*d//gcd(c,d)
a -= 1
ans = b//c - a//c
ans += b//d - a//d
ans -= b//x - a//x

ans = b-a-ans
print(ans)


Measured memory_bytes: 2940
#define _CRT_SECURE_NO_WARNINGS

#include<iostream>
#include<functional>
#include<algorithm>
#include<stack>
#include<queue>
#include<iomanip>
#include<set>
#include<map>
#include<utility>
#include<string>
#include<vector>

using namespace std;

#define LL long long
const int dx[4] = { 1,0,-1,0 };
const int dy[4] = { 0,1,0,-1 };
bool OOA(int x, int y, int H, int W) { return (0 <= x && x<H) && (0 <= y && y<W); }

int lim,puz[4][4];

int estmd(){
	int ret=0;
	for(int i=0;i<4;i++)for(int j=0;j<4;j++){
		if(puz[i][j] == -1)continue;
		ret+=abs(puz[i][j]/4-i)+abs(puz[i][j]%4-j);
	}
	return ret;
}

bool IDAst(int nc,int bd,int si,int sj){
	int md=estmd();
	if(md==0)return true;
	if(nc+md>lim)return false;
	for(int d=0;d<4;d++){
		int ni=si+dy[d],
			nj=sj+dx[d];
		if(!OOA(nj,ni,4,4)||(abs(d-bd)==2))continue;
		swap(puz[si][sj],puz[ni][nj]);
		if(IDAst(nc+1,d,ni,nj))return true;
		swap(puz[si][sj],puz[ni][nj]);
	}
	return false;
}

int main(){
	int z;
	for(int i=0;i<16;i++){
		cin>>puz[i/4][i%4];
		if(puz[i/4][i%4]==0)z=i;
		puz[i/4][i%4]--;
	}

	for(lim=0;lim<100;lim++){
		if(IDAst(0,10,z/4,z%4)){
			cout<<lim<<endl;
			return 0;
		}
	}
	return 0;
}



Measured memory_bytes: 3116
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int n;
  cin >> n;
  int l;
  cin >> l;
  int temp = 101;
  int ans = 0;
for(int i=0;i<n;i++){
  ans += l;
  if(abs(temp) > abs(l))temp = l;
  l++;
}
cout << ans - temp << endl;
//cout << temp << endl;
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
using namespace std;

int main() {
    int s, now, ans=0;
    cin >> s;
    vector<int> a(1000000, 0);
    now = s;
    while(true){
        ans++;
        if(a[now] > 0)break;
        a[now]++;
        if(now % 2 == 0)now /= 2;
        else now = 3 * now + 1;
    }
    cout << ans;
}

Measured memory_bytes: 4224
#include<stdio.h>
#include<algorithm>
#include<functional>
#include<cmath>
using namespace std;
long long  mod = 1000000007;

int power(int x) {
	return x * x;
}
int judge(int x) {
	for (int i = 0; i < 10000; i++) {
		if (power(i) == x) {
			return 1;
		}
	}
	return 0;
}
int main()
{
	int N, D, X[20][20];
	int an = 0, count = 0;
	scanf("%d%d", &N, &D);
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < D; j++) {
			scanf("%d", &X[i][j]);
		}
	}
	for (int i = 0; i < D; i++) {
		X[N][i] = X[0][i];
	}
	int k = 0;
	while (true) {
		if (k > N) break;
		for (int i = k+1; i < N; i++) {
			an = 0;
			for (int j = 0; j < D; j++) {

				an += power(X[k][j] - X[i][j]);
			}
			if (judge(an)) {
				count++;
			}
		}

		k++;
	}
	printf("%d", count);
	return 0;
}

Measured memory_bytes: 128
n, sum = map(int, input().split())

for x in range(n+1):
    for y in range(n+1):
        z = n - x - y        
        if 10000 * x + 5000 * y + 1000 * z == sum and z >= 0:
                break
        else:
            continue
        break
    else:
        continue
    break
else:
    x, y, z = -1, -1, -1


print("{} {} {}".format(x, y, z))

Measured memory_bytes: 3060
N, M = map(int, input().split())

set_list = {N}
len_list = -1

while len(set_list) != len_list:
    # print(set_list)
    len_list = len(set_list)
    if N >= M:
        set_list.add(N%M)
        N = N%M
    else:
        set_list.add(abs(N-M))
        N = abs(N-M)

    # print(set_list, len_list, N%M)
print(min(set_list))

Measured memory_bytes: 38384
using System;

namespace ABC060B
{
    class Program
    {
        static void Main(string[] args)
        {
            var target = Console.ReadLine().Split(' ');
            int A = int.Parse(target[0]);
            int B = int.Parse(target[1]);
            int C = int.Parse(target[2]);
            int[] remind = new int[B];
            bool f = false;
            for(int i=1;i<=B;i++){
                int tmp = A*i % B;
                if(tmp == C) {f = true;break;}
            }
            if(f) Console.WriteLine("YES"); else Console.WriteLine("NO"); 
        }
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
typedef long long ll;
typedef vector<vector<ll>> vvl;
typedef vector<ll> vl;
typedef vector<vector<char>> vvc;
typedef vector<char> vc;
typedef pair<ll,ll> pll;
ll max(ll x,ll y){
if(x>y)return x;
else return y;
}
ll min(ll x,ll y){
  return x+y-max(x,y);
}

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


void dfs(vector<vector<int>> &graph,int x,int y,vector<vector<bool>> &seen,int h,int w){
  seen[x][y]=true;
  rep(i,8){
    rep(j,8){
      int ax=x+dx[i];
      int ay=y+dy[i];
      if(ax<0||ay<0||ax>=h||ay>=w)continue;
      if(seen[ax][ay])continue;
      if(graph[ax][ay]==0)continue;
      dfs(graph,ax,ay,seen,h,w);
    }
  }
}

int main() {
rep(aaa,100000000){
  int h,w;cin >> w >> h;
  if(h==0&&w==0)return 0;
  vector<vector<bool>> seen(h,vector<bool>(w,false));
  vector<vector<int>> graph(h,vector<int>(w));
  rep(i,h)rep(j,w)cin >> graph[i][j];
  int ans=0;
  rep(v,h){
    rep(u,w){
      if(seen[v][u])continue;
      if(graph[v][u]==0)continue;
      dfs(graph,v,u,seen,h,w);
      ans++;
    }
  }
  cout << ans << endl;
}
}


Measured memory_bytes: 3508
#include<iostream>
#include<algorithm>
#include<sstream>
#include<string>
using namespace std;
int main(){
	int n;
	for(cin>>n;n--;){
		string a,b;
		cin>>a;
		cin>>b;
		reverse(a.begin(),a.end());
		reverse(b.begin(),b.end());
		while(a.size()<b.size())a+='0';
		while(b.size()<a.size())b+='0';
		int f=0;
		for(int i=0;i<a.size();i++){
			if(a[i]+(b[i]-'0')+f>'9'){
				a[i]+=+(b[i]-'0')+f-10;
				f=1;
			}else{
				a[i]+=+(b[i]-'0')+f;
				f=0;
			}
		}
		reverse(a.begin(),a.end());
		if(f)a="1"+a;
		if(a.size()>80){
			cout<<"overflow"<<endl;
		}else{
			for(int i=0;i<a.size();i++){
				if(a[i]!=0)
				cout<<a[i];
			}
			cout<<endl;
		}
	}
	return 0;
}

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

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

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

template <typename T> void dump(T x) { cout << x << endl; }
void dumpf(ld x, int t) { cout << setprecision(t) << fixed << x << endl; }
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
	fill((T *)array, (T *)(array + N), val);
}

inline ll mod(ll a, ll b) {
	if (a > 0) return a % b;
	if (a % b == 0) return 0;
	ll x = -a / b + 1;
	a += x * b;
	return a % b;
}

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

vector<ll> cnt(ll x) {
	vector<ll> res(60);
	for (int i = 0; i < 60; i++) {
		ll t   = (1ll << (i + 1));
		res[i] = x / t; // i桁目の1の個数
		res[i] *= t / 2;
		res[i] += max(0ll, (x % t) - t / 2 + 1);
		// dump(res[i]);
	}
	return res;
}

int main() {
	IOS();
	ll a, b;
	cin >> a >> b;
	vector<ll> ax = cnt(a - 1), bx = cnt(b);
	ll ans = 0;
	if (a == 0) {
		for (int i = 0; i < 60; i++) {
			ll t = (1ll << i);
			if (bx[i] % 2) {
				ans += t;
			}
		}
		dump(ans);
		return 0;
	}
	// dump(ax[0]);
	for (int i = 0; i < 60; i++) {
		ll t = (1ll << i);
		if (mod(bx[i] - ax[i], 2) == 1) {
			ans += t;
		}
	}
	dump(ans);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m;
  scanf("%d %d",&n,&m);
  int a[100000],b[100000],c,d,now,ans;
  a[0] = 0;
  now = 0;
  for(int i=1;i<n;i++){
    scanf("%d",&c);
    a[i] = a[i-1]+c;
  }
  ans = 0;
  for(int j=0;j<m;j++){
    scanf("%d",&d);
    ans = (ans+max(a[now],a[now+d])-min(a[now],a[now+d]))%100000;
    now += d;
  }
  printf("%d\n",ans);
  return (0);
}

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

using namespace std;

int main(){
	int a;
	
	long long int k = 0;
	
	cin>>a;
	
	for(int i = 1; i<=a; i++){
		if(i%3==0 || i%5==0) continue;
		k+=i;
		}
		cout<<k<<"\n";
}


Measured memory_bytes: 3596
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<array>
#include<vector>
#include<functional>
#include<unordered_map>
#include<map>
#include<numeric>
#include<limits>
#include<utility>
#include<queue>
#include<random>
 
using namespace std;
 
int main(){
  int N,K;
  int A = 1;
  int i;
  
  cin >> N >> K;
  
  for(i = 1;i<=N;i++){
  if(A > K){
  A = A + K;
  }else{
  A = A * 2;
  }
  
  }
  
  cout << A << endl;
  
  return 0;
 
 }

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
	int a,b;
  cin>>a>>b;
  if(a+b >= a-b && a+b >= a*b)
  {
  cout<<a+b<<endl;
  }
   else if(a-b >= a+b && a-b >= a*b)
  {
  cout<<a-b<<endl;
  }
  else if(a*b >= a-b && a*b >= a+b)
  {
  cout<<a*b<<endl;
  }
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
int N;
  double T,A;
  cin>>N>>T>>A;
  vector<double>H(N);
  for(int i=0;i<N;i++)
    cin>>H.at(i);
  int ans=1;
  double Min=abs(T-0.006*H.at(0)-A);
  for(int i=0;i<N;i++){
  if(abs(T-0.006*H.at(i)-A)<=Min){
  Min=abs(T-0.006*H.at(i)-A);
    ans=i+1;
  }
  
  }cout<<ans<<endl;
  
   return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<map>
#include<algorithm>
using namespace std;

const int N = 3e5+1000;
#define ll long long
#define read(x) scanf("%d",&x)
#define Read(x,y) scanf("%d%d",&x,&y)
#define sread(x,y,z) scanf("%d%d%d",&x,&y,&z)
int w[20][20];
int A[20];
int x[20][20],y[20][20];
int main()
{
    int n,m;
    cin>>n;
    for(int i = 1;i <= n;++i){
        cin>>A[i];
        for(int j= 1;j <= A[i];++j){
            cin>>x[i][j]>>y[i][j];
        }
    }
    int S = (1 << n);
    int M = 0;
    for(int i = 1;i < S;++i){
        bool ok = true;
        for(int k = 1;k <= n;++k){
            if(!(i & (1<<(k-1)))) continue;
            for(int p = 1;p  <= A[k];++p){
                if(((i >> (x[k][p]-1))&1) ^ y[k][p])  ok = false;
            }
            if(!ok) break;
        }
        if(ok) M = max(M,__builtin_popcount(i));
    }
    cout<<M;

    
}

Measured memory_bytes: 256
// Gaurav Aggarwal

/*
useful stl
array<ll,size> ar;         //size(),front(),back(),fill(),empty()
deque<ll> d                //push_back(),push_front(),pop_front(),pop_back()
vector<ll> v(size,val);    //push_back(),*max_element(v.begin(),v.end()),accumulate(v.begin(),v.end(),0)
stack<ll> g;               //push(),pop(),top(),size(),empty()         LIFO
queue<ll> q;               //push(),size(),front(),back(),empty()      FIFO
priority_queue<ll> pq
*/

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<ll,ll> ipair;
typedef pair<long,long> lpair;
#define scan(x) do{while((x=getchar_unlocked())<'0'); for(x-='0'; '0'<=(_=getchar_unlocked()); x=(x<<3)+(x<<1)+_-'0');}while(0)
char _;
#define For(i, a, b) for(__typeof (a) i=a; i<=b; i++)
#define mod 1000000007
#define PI 3.141592653589793238462643383279502884 
#define debug1(a) cout<<a<<"\n";
#define debug2(a,b) cout<<a<<" "<<b<<"\n";
#define debug3(a,b,c) cout<<a<<" "<<b<<" "<<c<<"\n";
#define debug_arr(a,n) {for(__typeof (n) i=0; i<n; ++i) {cout<<a[i]<<" ";}}
#define inp_arr(a,n) for(__typeof (n) i=0; i<n; ++i) {cin>>a[i];}
#define beg_arr(a,n) for(__typeof (n) i=0; i<n; ++i) {a[i] = 0;}

ll power(ll x, ll y) 
{ 
    ll res = 1;   
    while (y > 0) { 
        if (y & 1) 
            res = (res*x)%mod; 
        y = y>>1;
        x = (x*x)%mod; 
    } 
    return res%mod; 
}

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

    // #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin);
    // freopen("out.txt", "w", stdout); 
    // #endif  

    ll n,a,b;
    cin>>n>>a>>b;
    ll tot = a + b;
    ll mini = 0;
    if(tot > n)
        mini = tot - n;
    ll maxi = min(a,b);
    cout<<maxi<<" "<<mini;

    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.math.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		// 整数の入力

		int n = sc.nextInt();
		List<Long> list = new ArrayList<>();

		for (int i = 0; i < n-1; i++) {
			long b = sc.nextLong();
			list.add(b);
		}

		long result = 0;
		
		result += list.get(0);
		for (int i = 1; i < n-1; i++) {
			long left = list.get(i-1);
			long right = list.get(i);
			long a = Math.min(left, right);
			result += a;
		}
		result += list.get(n-2);


		System.out.println(result);

	}
}


Measured memory_bytes: 21844
#include <stdio.h>
#include <iostream>
using namespace std;

int main(){
	int n, b;
	char a;
	cin>>n;
	int S[13], H[13], C[13], D[13];
	//初始化
	for(int i=0;i<13;i++){
		S[i]=0;H[i]=0;C[i]=0;D[i]=0;
	} 
	for(int i=0;i<n;i++){
		cin>>a>>b;
		if(a=='S')
			S[b-1]++;
		if(a=='H')
			H[b-1]++;
		if(a=='C')
			C[b-1]++;
		if(a=='D')
			D[b-1]++;
	}
	for(int i=0;i<13;i++){
		if(S[i]==0)
			cout<<'S'<<" "<<i+1<<endl;
	}
	for(int i=0;i<13;i++){
		if(H[i]==0)
			cout<<'H'<<" "<<i+1<<endl;
	}
	for(int i=0;i<13;i++){
		if(C[i]==0)
			cout<<'C'<<" "<<i+1<<endl;
	}
	for(int i=0;i<13;i++){
		if(D[i]==0)
			cout<<'D'<<" "<<i+1<<endl;
	}
//	cout<<endl;
	return 0;
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
#define se second
#define fi first
typedef long long ll;
const int maxn = 2000005;
typedef pair<int, int>par;
typedef pair<int, par>tres;
const ll mod = 1e9+7;

int n;
char s[maxn];

par get( char *s ){
    int l = strlen(s);
    int b = 0, mb = 0;
    for( int i = 0; i < l; i++ ){
        if( s[i] == '(' ) b++;
        else b--;
        mb = min(b, mb);
    }
    return par(b, mb);
}

par get1( char *s ){
    int l = strlen(s);
    reverse(s, s+l);
    int b = 0, mb = 0;
    for( int i = 0; i < l; i++ ){
        if( s[i] == '(' ) b--;
        else b++;
        mb = min(mb, b);
    }
    return par(b, mb);
}

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    #ifdef acm
    freopen("a.in", "r",stdin);
    #endif // acm

    cin >> n;

    int sum = 0;
    vector<tres>pos, neg;
    for( int i = 1; i <= n; i++ ){
        cin >> s;
        auto a = get(s);
        sum += a.fi;
        if( a.fi >= 0 )
           pos.push_back(tres(i, par(a.fi, a.se)));
        else{
            auto b = get1(s);
            neg.push_back(tres(i,par(b.fi, b.se)));
        }

    }

    if( sum ){
        cout << "No\n";
        return 0;
    }

    sort(pos.begin(), pos.end(), [](const tres &s1, const tres &s2){
        if( s1.se.se != s2.se.se ) return s1.se.se > s2.se.se;
        return s1.se.fi > s2.se.fi;
    });

    sort(neg.begin(), neg.end(), [](const tres &s1, const tres &s2){
        if( s1.se.se != s2.se.se ) return s1.se.se > s2.se.se;
        return s1.se.fi > s2.se.fi;
    });

    int b = 0;
    vector<int>s1, s2;
    for( auto i : pos ){
        if( b + i.se.se < 0 ){
            cout << "No\n";
            return 0;
        }
        b += i.se.fi;
        s1.push_back(i.fi);
    }

    b = 0;
    for( auto i : neg ){
        if( b + i.se.se < 0 ){
            cout << "No\n";
            return 0;
        }
        b += i.se.fi;
        s2.push_back(i.fi);
    }

    cout << "Yes\n";

    return 0;
}


Measured memory_bytes: 20796
l,r = list(map(int,input().split()))

ans = 2018
def f(a,b):
    while a > 2019:
        a = a % 2019
    while b > 2019:
        b = b % 2019 
    return (a*b) % 2019 

if (r - l) > 2019:
    print(0)
else:
    for i in range(l,r+1):
        for j in range(i+1,r+1):
            ans = min(ans,f(i,j))
    print(ans)

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

int main() {
    int K, S, ans = 0;
    cin >> K >> S;
    for (int x = 0; x <= K; x++) {
        for (int y = 0; y <= K; y++) {
            if (0 <= S-x-y && S-x-y <= K) {
                ans++;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
def solve():
    X, N = [int(x) for x in input().split()]
    if N > 0:
        pn = [int(x) for x in input().split()]
    else:
        pn = []
    pn = set(pn)
    ans = X
    if N == 0 or X not in pn:
        return ans
    left = 0
    right = 0
    while True:
        left += 1
        if (X - left) not in pn:
            return X - left
        right += 1
        if (X + right) not in pn:
            return X + right


if __name__ == '__main__':
    print(solve())


Measured memory_bytes: 61948
#include <bits/stdc++.h>
#define REP(i, N) for (int i = 0; i < (N); ++i)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define PB push_back
#define MP make_pair
using namespace std;
typedef long long ll;
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll div_ceil(ll, ll);

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

int main() {
  int N, X;
  std::cin >> N >> X;
  int L[N];
  REP(i, N) { std::cin >> L[i]; }
  int count = 1;
  int D = 0;
  REP(i, N) {
    D += L[i];
    if (D <= X) {
      count++;
    }
  }
  std::cout << count << '\n';
}

ll div_ceil(ll a, ll b) {
  ll quotient = a / b;
  ll remainder = a % b;
  if (remainder == 0) {
    return quotient;
  } else {
    return quotient + 1;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(void){
    // Your code here!
    string s;
    getline(cin,s);
    
    for(int i = 0; i < s.size(); i++){
        if('a' <= s[i] && 'z' >= s[i]){
           s[i] -= 'a' - 'A';
        }
        else if('A' <= s[i] && 'Z' >= s[i]){
           s[i] += 'a' - 'A';
        }
    }
    
    cout << s << endl;
}



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

using namespace std;

#ifdef LOCAL
#include "rfd_wrap.h"
#endif

typedef long long ll;
typedef long double lf;
typedef pair<int, int> pii;

#define bt(x) (1LL << (x))
#define all(x) (x).begin(), (x).end()
#define FastIO ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

const int inf = 0x3f3f3f3f;
const ll INF = 2e18;
const lf EPS = 1e-9;

inline lf dense(lf w, lf s) {
	return s * 100 / (w + s);
}

int main() {
	FastIO;

	int a, b, c, d, e, f;
	cin >> a >> b >> c >> d >> e >> f;

	lf per = 0;
	int wat = 100 * a, sug = 0;

	for(int i=0; a*i*100 <= f; ++i) {
		for(int j=(i?0:1); a*i*100 + b*j*100 <= f; ++j) {
			int w = 100 * (a * i + b * j);
			for(int k=0; w+k*c <= f; ++k) {
				for(int l=0; w+k*c+l*d <= f; ++l) {
					int s = k * c + l * d;
					if(w * e < 100 * s) continue;
					
					lf p = dense(w, s);
					// prnt w, " ", s, " ", p;
					if(p > per + EPS) per = p, wat = w, sug = s;
				}
			}
		}
	}

	cout << (wat + sug) << " " << sug << "\n";

	return 0;
}

Measured memory_bytes: 3604
N = int(input())
hs = list(map(int, input().split()))

Cost = [1e29 for _ in range(N)]
Cost[0] = 0

for i in range(N):
  if (i+1 > N-1):
    continue
  Cost[i+1] = min(Cost[i+1], Cost[i] + abs(hs[i]-hs[i+1]))
  if (i+2 > N-1):
    continue
  Cost[i+2] = min(Cost[i+2], Cost[i] + abs(hs[i]-hs[i+2]))

print(Cost[N-1])


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

using namespace std;
#define ll long long int
ll n,ara[505],dp[505][505],cum[505];

int main()
{
    ll i,j,a=0;
    cin>>n;
    for(i=1; i<=n; i++)
    {
        cin>>ara[i];
        dp[i][i]=0;
        a+=ara[i];
        cum[i]=a;
    }
    for(ll l=2; l<=n; l++)
    {
        for(i=1; i<=n-l+1; i++)
        {
            if(l==2)
            {
                dp[i][i+l-1]=ara[i]+ara[i+1];
            }
            else
            {
                ll st=i,en=i+l-1,mn=1e18;
                for(j=st; j<en; j++)
                {
                    mn=min(mn,cum[en]-cum[st-1]+dp[st][j]+dp[j+1][en]);
                }
                dp[st][en]=mn;
            }

        }

    }
    cout<<dp[1][n]<<endl;
    return 0;
}


Measured memory_bytes: 1792
import java.util.*;

public class Main {
  public static void main(String[] args) throws Exception {
    Scanner sc = new Scanner(System.in);
    while (true) {
      int H = sc.nextInt();
      int W = sc.nextInt();
      if (H == 0 && W == 0) {
        break;
      }
      for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
          if((i%2) == 0){
            if((j%2) != 0){
              System.out.print(".");
            }else{
              System.out.print("#");
            }
          }else if((i%2) != 0){
            if((j%2) == 0){
              System.out.print(".");
            }else{
              System.out.print("#");
            }
          }
        }
        System.out.println();
      }
      System.out.println();
    }
  }
}



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

int main() {
  int K,tmp;
  long long Ans=0;
  cin>>K;
  for(int i=1;i<K+1;i++){
  for(int j=1;j<K+1;j++){tmp=__gcd(i, j);
  for(int l=1;l<K+1;l++){Ans+=__gcd(l, tmp);}
            }
  }
  cout<<Ans<<endl;
}

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

using namespace std;
typedef pair<int,int> pii;
typedef long long int ll;

#define INF 1 << 30
#define REP(i,n) for(ll i=0; i<(int)(n); i++)
#define FOR(i,k,n) for(ll i=(k);i<(int)(n);i++)



vector<bool> gen_sosuu(vector<bool> sosuu){
  int size = sosuu.size();
  REP(i,size){
    sosuu[i] = true;
  }
  sosuu[0] = false;
  sosuu[1] = false;
  sosuu[2] = true;
  FOR(i,2,sqrt(size)+1){
    if(sosuu[i] == false) continue;
    for(int j = 2; i*j<size;j++){
      sosuu[i*j] =false;
    }
  }
  return sosuu;
}

int n;

int main(){
  cin >> n;
  ll ans = 0;
  REP(i,n){
    int s;
    cin >>s;
    ans += s-1;
  }
  cout << ans <<endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        
        int X;
        
        if(A + B > A - B){
            X = A + B;
        }else{
            X = A - B;
        }
        
        if(X < A * B){
            X = A * B;
        }
        
       System.out.println(X);
    }
}

Measured memory_bytes: 23892
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,M;
  cin >> N >> M;
  int sum = 0;
  for (int i = 0; i < M; i++){
    int A;
    cin >> A;
    sum += A;
  }
  if (N >= sum){
    cout << N - sum;
  }
  else {
    cout << -1;
  }
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define dbg(x) cout<<#x<<":"<<x<<endl
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;

int ans;
int cnt[13];
int flag[25];

void dfs(int tn=1){
  if(tn==12){
    int rn=0;
    int mi=100;
    for(int i=1;i<25;i++){
	 if(flag[i]==0)rn++;
	 else {
	   mi=min(mi,rn);
	   rn=0;
	 }
    }
    ans=max(ans,mi+1);
    return;
  }

  if(cnt[tn]==1){
    flag[tn]=1;
    dfs(tn+1);
    flag[tn]=0;
    flag[24-tn]=1;
    dfs(tn+1);
    flag[24-tn]=0;
    return;
  }
  
  dfs(tn+1);
}

int main(){
  int n,a[55];
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>a[i];
  }

  cnt[0]=2;
  cnt[12]=1;
  for(int i=0;i<n;i++){
    cnt[a[i]]++;

    if(cnt[a[i]]==2){
	 flag[a[i]]=1;
	 flag[24-a[i]]=1;
    }
    
    if(cnt[a[i]]==3){
	 cout<<0<<endl;
	 return 0;
    }
    if(a[i]==12)flag[12]=1;
  }

  flag[0]=flag[24]=1;
  dfs();
  cout<<ans<<endl;
  return 0;
}


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

int main() {
    std::ios::sync_with_stdio(false);
    lld tc = 1;
    // cin >> tc;
    while (tc--) {
        lld n, k;
        cin >> n >> k;
        vector<lld > v(n);
        for (lld i = 0; i < n; i++) {
            cin >> v[i];
        }
        map<lld, lld > mp;
        for (lld i = 0; i < k; i++) {
            mp[v[i]]++;
        }
        for (lld i = k; i < n; i++) {
            mp[v[i - k]]--;
            mp[v[i]]++;
            if (v[i] > v[i - k]) {
                cout << "Yes\n";
            } else {
                cout << "No\n";
            }
        }
    }
}


Measured memory_bytes: 17248
n,x,m = map (int,input().split())
next=[0] * (m+1)
memo = [-1] * (m+1)
memo[x] = 0
a = 0
now = x
unti = [x]
flag = True
b = -1
for i in range(m):

    next[now] = (now **2) % m
    #print(1,next)
    if memo[next[now]]!=-1:
        b = memo[next[now]]
        break
    elif next[now] == 0:
        flag =False
        break
    else:
        memo[next[now]] = i+1
    a += 1
    now = next[now]
    unti.append(now)
if flag:
    if b== 0:
        if (n-b)%(a-b+1) !=0:
            print(sum(unti[b:a+1]) * ((n - b) // (a - b + 1)) + sum(unti[b:b+(n - b) % (a - b + 1)]))
        else:
            print(sum(unti[b:a+1]) * ((n - b) // (a - b + 1)))
    else:
        if (n - b) % (a - b + 1) != 0:
            print(sum(unti[b:a+1]) * ((n-b)//(a-b+1)) + sum(unti[b:b+(n-b)%(a-b+1)])  + sum(unti[:b]))
        else:
            print(sum(unti[b:a + 1]) * ((n - b) // (a - b + 1)) + sum(unti[:b]))
else:
    print(sum(unti))


Measured memory_bytes: 14264
//**************************
//*** writer  :  Alex Hu **
//************************

#include<bits/stdc++.h>

using namespace std;

#define CLEAN(a,b) memset(a,b,sizeof(a))
#define mkp make_pair
#define pb push_back
#define rept(i,a,b) for(int i=(int)(a);i<(int)(b);i++)

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

const int maxn=1e5+10;

int input[maxn][3];
int ma[maxn],an[maxn];
int bfs[maxn];
vi e[maxn];

void go(int in[])
{
	int x=in[0]-1;
	int dd=in[1];
	int v=in[2];
	if (dd<=ma[x]) return;
	ma[x]=dd;
	bfs[0]=x;
	int rr=1;
	rept(i,0,rr)
	{
		int x=bfs[i];
		if (!an[x]) an[x]=v;
		if (!ma[x]) continue;
		rept(j,0,e[x].size())
		{
			int y=e[x][j];
			int nd=ma[x]-1;
			if (nd>ma[y])
			{
				ma[y]=nd;
				bfs[rr++]=y;
			}
		}
	}
}

int n,m,q;

int main()
{
	cin>>n>>m;
	rept(i,0,m)
	{
		int x,y;
		cin>>x>>y;
		x--;
		y--;
		e[x].pb(y);
		e[y].pb(x);
	}
	cin>>q;
	rept(i,0,q)
	{
		rept(j,0,3)
		{
			cin>>input[i][j];
		}
	}
	CLEAN(ma,-1);
	for (int i=q-1;i>=0;i--) go(input[i]);
	rept(i,0,n) cout<<an[i]<<endl;
	return 0;
}

Measured memory_bytes: 8824
#include "bits/stdc++.h"
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

ll a,b,k;

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    cin>>a>>b>>k;
    if(k<a){
        a-=k;
    }else if(a+b > k){
        k -= a;
        a = 0;
        b -= k;
    }else{
        a = 0;
        b = 0;
    }
    princ(a);
    print(b);
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define pb push_back
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define mod 1000000007
using namespace std;

ll dp[102][100005];
bool dpv[102][100005];

int main(){
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL);cout.tie(NULL);
	int n,w;
	cin>>n>>w;

	vector<pair<int,int> > a(n);
	for (int i = 0; i < n; ++i)
	{
		cin>>a[i].ff>>a[i].ss;
	}
	memset(dpv,0,sizeof dpv);
	
	dpv[0][0] = 1;
	
	for(int i=0;i<n;++i){
		for(int j=0;j<100005;++j){
			dpv[i+1][j] = dpv[i][j];
			dp[i+1][j] = dp[i][j];
			if(j>=a[i].ss && dpv[i][j-a[i].ss]){
				if(dp[i][j-a[i].ss]+a[i].ff<=w){
					if(!dpv[i+1][j])
						dp[i+1][j] = dp[i][j-a[i].ss]+a[i].ff;
					else
						dp[i+1][j] = min(dp[i+1][j],dp[i][j-a[i].ss]+a[i].ff);
					dpv[i+1][j] = 1;
				}
			}
		}
	}

	// for(int i=0;i<n;++i){
	// 	for(int j=0;j<105;++j)
	// 		cout<<dp[i+1][j]<<" ";
	// 	cout<<'\n';
	// }

	int i;
	for( i=100004;i>=0;--i)
		if(dpv[n][i])
			break;
	cout<<i;
	// cerr<< '\n' << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms\n" ;
	return 0;
}

Measured memory_bytes: 89088
s=input()+'$';t=0;l=len(s);m=X=Y=1<<l
for c in s:
 if'F'==c:t+=1
 else:
  if m<1:X=X>>t|X<<t
  elif m<2:Y=Y>>t|Y<<t
  else:X<<=t;m=0
  t=0;m^=1
x,y=map(int,input().split());print("Yes"*(X>>l+x&Y>>l+y&1)or"No")

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

int main(void)
{
    int N;
    cin >> N;
    string s = "ACL";

    rep(i, N){
        cout << s;
    }

    return 0;
}

Measured memory_bytes: 3624
import numpy as np

N, M = map(int, input().split())
AC = np.zeros(N, dtype = int)
WA = np.zeros(N, dtype = int)

for i in range(M):
  p, s = input().split()

  if s == 'WA' and AC[int(p) - 1] == 0:
    WA[int(p) - 1] += 1
  else:
    AC[int(p) - 1] = 1

print(sum(AC), sum(AC * WA))
  

Measured memory_bytes: 28800
#include <iostream>
#include <vector>
using namespace std;
int main(void){
    // Your code here!
    int N,M;
    cin >> N >> M;
    
    if(N==M){
        cout << "Yes" << endl;
        return 0;
    }
    
    
    cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256