akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
    using namespace std;
    #define INF 2000000000
    typedef long long int ll;
    typedef pair<ll,ll> ii;
    typedef pair<ii,ll> iii;
    typedef vector<ll> vi;
    typedef vector<ii> vii;
    #define getbit(n,i) (((n)&(1<<(i)))!=0)
    #define setbit0(n,i) ((n)&(~(1<<(i))))
    #define setbit1(n,i) ((n)|(1<<(i)))
    #define togglebit(n,i) ((n)^(1<<(i)))
    #define lastone(n) ((n)&(-(n)))
    #define read freopen("debug\\in.txt","r",stdin)
    #define write freopen("debug\\out.txt","w",stdout)
    #define fi first
    #define se second
    #define getI(a) scanf("%d",&a)
    #define getII(a,b) scanf("%d%d",&a,&b)
    #define PI (acos(-1))
    #define fastread ios_base::sync_with_stdio(false);cin.tie(NULL)
    #define mod (1000000007)
    #define asz 500005
    #define pb push_back
    #define ppf pop_front
    #define ppb pop_back
    #define pf push_front
    queue<pair<ll,ll> >q;
    vector<pair<ll,ll> >v;
    void solver(){
      ll n,i,k,l,m,d,a;
      cin>>n>>d>>a;
      for(i=1;i<=n;i++){
        cin>>k>>l;
        v.pb({k,l});
      }
      sort(v.begin(),v.end());
      ///q.push(v[0].fi,(v[0].se+a-1)/a);
      ll sum=0;
      ll res=0;
      for(i=0;i<n;i++){
        while(!q.empty()&&v[i].fi-q.front().fi>0){
          sum-=q.front().se;
          q.pop();
        }
        ll temp=(v[i].se+a-1)/a;
        if(temp>sum)
        {
          temp-=sum;
          q.push(make_pair(v[i].fi+2*d,temp));
          sum+=temp;
          res+=temp;
          }
      }
      cout<<res;
    }
    int main()
    {
        fastread;
        solver();
        return 0;
    }

Measured memory_bytes: 6000
#include<bits/stdc++.h>
using namespace std;
//# define pair<int,int>  pi
void get(vector<vector<int> >& g,int i,vector<int>& dp)
{  int n=g.size();
   dp[i]=0;
  for(auto& k:g[i])
  { if(dp[k]==-1)
     get(g,k,dp);
    
  dp[i]=max(dp[i],dp[k]+1);
    
    
}
 
  
 
}
int main()
{
  int n,m;
  cin>>n>>m;
  int k1,k2;
  vector<vector<int> > g(n+1);
  for(int i=0;i<m;i++)
  { cin>>k1>>k2;
   g[k1].push_back(k2);
   }
  int max1=INT_MIN;
  int c;
// vector<bool> vis(n+1,false);
 vector<int> dp(n+1,-1);
  for(int i=1;i<=n;i++)
  { if(dp[i]==-1)
    get(g,i,dp);
   
  }
  
 int d=*max_element(dp.begin(),dp.end());
   cout<<d;
  
}


Measured memory_bytes: 8192
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <iomanip>

#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
const int inf = 1e9;
const ll linf = 1LL << 50;

int main(int argc, char const* argv[])
{
	int n;
	cin >> n;
	int res = 0;
	for(int i = 1; i <= n; i++){
			if(i % 2 == 0)continue;
			int tres = 0;
			for(int j = 1; j * j<= i; j++){
					if(i % j == 0){
							if(j == i / j)tres++;
							else tres += 2;
					}
			}
			if(tres == 8)res++;
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define All(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;

int main(){
    int N,X,Y,A,B,C;
    string S,T;
    cin>>A>>B;
    if(A<10&&B<10) cout<<A*B<<endl;
    else cout<<-1<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int N;scanf("%d",&N);
	int r=0,p=0,v=0;
	for(int i=0;i<N;i++)
	{
		p=v;
		scanf("%d",&v);
		if(p==v)r=r+1,v=0;
	}
	printf("%d",r);
	return 0;
}

Measured memory_bytes: 128
# include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
typedef long long ll;
int a,b;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>a>>b;
    int bb=b*100/10;
    int ba=(b+1)*100/10;
    for(int i=bb;i<ba;i++){
        if(i*8/100 ==a){
            cout<<i<<endl;
            return 0;
        }
    }
    cout<<"-1"<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fu(a,b,c) for(int a=b;a<=c;a++)
#define fd(a,b,c) for(int a=b;a>=c;a--)
using namespace std;
const int N = 13;
int a[N][N], n, m, x, ans = 1e7;
int b[N];
inline void dfs(int i, int b[N]) {
        if (i > n)
                return;
        fu(j, 0, m) {
                b[j] += a[i][j];
        }
        fu(j, 1, m) {
                if (b[j] < x) {
                        int t[N];
                        fu(k, i + 1, n) {
                                memcpy(t, b, 4 * N);
                                dfs(k, t);
                        }
                        return;
                }
        }
        ans = min(b[0], ans);
}
int main() {
        ios::sync_with_stdio(false);
        cin.tie(0);
        cin >> n >> m >> x;
        fu(i, 1, n) {
                fu(j, 0, m) {
                        cin >> a[i][j];
                }
        }
        fu(i, 1, n) {
                memset(b, 0, sizeof b);
                dfs(i, b);
        }
        cout << (ans == 1e7 ? -1 : ans);
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define to edge[i].v
#define mp make_pair
#define rint register int
#define fgx cerr<<"-------------"<<endl
#define N 233
using namespace std;
typedef long long ll;
typedef long double db;
typedef pair<int,int> pii;
void dbg(){cerr<<endl;}
template<typename A,typename... B>void dbg(A x,B... y){cerr<<x<<" ";dbg(y...);}
#define debug(...) cerr<<#__VA_ARGS__<<"=",dbg(__VA_ARGS__)
int a[N],del[N],b[N];
int main()
{	int n,cnt=0; vector<int> v; cin>>n;
	for(rint i=1;i<=n;i++)
	{	scanf("%d",&a[i]); b[i]=i;
		if(a[i]>i) return !printf("-1");
	}
	while(cnt!=n)
	{	int tag=0;
		for(rint i=n;i>=1;i--)
		if(!del[i]&&a[i]==b[i])
		{	del[i]=1; v.push_back(a[i]); cnt++;
			for(rint j=i+1;j<=n;j++) b[j]--;
			tag=1; break;
		}
		if(!tag) return !printf("-1");
	}
	reverse(v.begin(),v.end());
	for(auto x:v) cout<<x<<"\n";
	return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int n,m;
int main() {
	scanf("%d",&n);
	for (int i = 0; i <=n; i+=4) {
		m = n - i;
		if (m % 7 == 0) {
			printf("Yes");
			return 0;
		}
	}
	printf("No");
}

Measured memory_bytes: 128
N = int(input())
p = list(map(int, input().split()))

j= 0
for i in range(N):
	if p[i] != i+1:
		swap1 = (p[i], i)
		j=1
		break

if j == 0:
	print("YES")
	exit()
loc = p[swap1[0] - 1]
p[swap1[0] - 1] = swap1[0]
p[swap1[1]] = loc
#print(p)
for i in range(N):
	if p[i] != i+1:
		print("NO")
		exit()
print("YES")

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

int main() {
	int n, m; cin >> n >> m;
	vector<ll> a(n), b(m);
	for (int i = 0; i < n; ++i) cin >> a[i];
	for (int i = 0; i < m; ++i) cin >> b[i];
	vector<ll> c = convolution<998244353>(a, b);
	for (int i = 0; i < n+m-2; ++i) cout << c[i] << " ";
	cout << c[n+m-2] << "\n";
	return 0;
}

Measured memory_bytes: 27196
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const int inf = 1e9;
const ll INF = 1e18;
const double pi = 3.14159265358979323846;
#define rep(i,n) for(ll i=0;i<n;i++)

int main(){
	int n,p;cin>>n>>p;
	ll even=0,odd=0;
	rep(i,n){
		int b;cin>>b;
		if(b%2==0) even++;
		else odd++;
	}
	if(p==0&&odd==0) odd++;
	ll even_sum=pow(2,even),odd_sum=pow(2,odd-1);
	//evenはpが偶奇のどちらでも選び方は2^even
	//oddはpが偶ならばoddの中から0,2,4,,という偶数個取る方法
	//さらにoddはpが奇ならばoddの中から1,,3,5という奇数個取る方法
	// どちらも二項係数より2^(odd-1)

	ll ans=even_sum*odd_sum;
	cout<<ans<<"\n";
}

Measured memory_bytes: 256
/*#include <bits/stdc++.h>
using namespace std;
int a,b,c,fr[11];
int main()
{
    cin>>a>>b>>c;
    fr[a]++;
    fr[b]++;
    fr[c]++;
    if(fr[5]==2 && fr[7]==1)
        cout<<"YES";
    else cout<<"NO";
    return 0;
}                   A
*/
#include <bits/stdc++.h>
using namespace std;
int n,l,i,j;
char sir[110][110];
int main()
{
    cin>>n>>l;
    for(i=1;i<=n;i++)
        cin>>sir[i];
    for(i=1;i<n;i++)
        for(j=i+1;j<=n;j++)
            if(strcmp(sir[i],sir[j])>0)
                swap(sir[i],sir[j]);
    for(i=1;i<=n;i++)
        cout<<sir[i];
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define uint unsigned int
#define inf 0x3f3f3f3f
#define db double
using namespace std;
const int maxn=2e5+10;
struct node{
	ll num;
	ll pos1,pos2;
	ll value;
};
int k,n,m;
int ma[2][maxn];
ll cal[2][maxn];
int ans=0;
int main() {
	std::ios::sync_with_stdio(false);
	cin>>n>>m>>k;
	ll tmp=0,x=0,y=0;
	for(int i=1;i<=n;i++){
		cin>>ma[0][i];
		if(tmp>k) continue;
		tmp+=ma[0][i];
		if(tmp<=k) {
			cal[0][i]=tmp;
			x=i;
		}
	}
	tmp=0;
	for(int i=1;i<=m;i++){
		cin>>ma[1][i];
		if(tmp>k) continue;
		tmp+=ma[1][i];
		if(tmp<=k) {
			cal[1][i]=tmp;
			y=i;
		}
	}
	if(x>y){
		int j=0;
		for(int i=x;i>=0;i--){
			while(j<=y){
				if(cal[0][i]+cal[1][j]>k) break;
				ans=max(i+j,ans);
				j++;
			}
		} 
	}
	else {
		int j=0;
		for(int i=y;i>=0;i--){
			while(j<=x){
				if(cal[1][i]+cal[0][j]>k) break;
				ans=max(i+j,ans);
				j++;
			}
		} 
	} 
	cout<<ans<<endl;
}

Measured memory_bytes: 8288
S = input()

start = 0

while start < len(S):

    if start == len(S)-8 or start > len(S)-5:
        print("NO")
        exit()
    elif start == len(S)-7 and S[start:start+7] == "dreamer":
        print("YES")
        exit()
    elif start == len(S)-6 and S[start:start+6] == "eraser":
        print("YES")
        exit()
    elif start == len(S)-5 and S[start:start+5] == "erase":
        print("YES")
        exit()
    elif start == len(S)-5 and S[start:start+5] == "dream":
        print("YES")
        exit()
    elif S[start:start+6] == "eraser":
        start +=6
    elif S[start:start+5] == "erase":
        start +=5
    elif S[start:start+8] == "dreamera":
        start +=5
    elif S[start:start+7] == "dreamer":
        start +=7
    elif S[start:start+5] == "dream":
        start +=5
    else:
        print("NO")
        exit()
print("YES")

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

int main(){
    int n;
    int s[1000];
    double a,b,sum,ave;
    
    
    while(true){
        a = b = ave = sum = 0;
        
        cin >> n;
        
        if(!n) break;
        
        for(int i = 0; i < n; i++){
            cin >> s[i];
            sum += s[i];
        }
        
        ave = sum / n;
        
        for(int i = 0; i < n; i++){
            a += (s[i]-ave)*(s[i]-ave)/(double)n;
        }
        
        b = sqrt(a); 
        printf("%f\n",b);
    }
    return 0;
}

Measured memory_bytes: 1188
//https://beta.atcoder.jp/contests/agc029/tasks/agc029_d
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
#ifdef BTK
#define DEBUG if(1)
#else
#define CIN_ONLY if(1)
struct cww {cww() {CIN_ONLY{ios::sync_with_stdio(false); cin.tie(0);}}}star;
#define DEBUG if(0)
#endif
#define ALL(v) (v).begin(),(v).end()
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l, T r){bool a = l>r; if (a)l = r; return a;}
template <typename T>inline bool chmax(T &l, T r){bool a = l<r; if (a)l = r; return a;}
template <typename T>istream& operator>>(istream &is, vector<T> &v){for (auto &it : v)is >> it;return is;}
class range {private: struct I { int x; int operator*() { return x; }bool operator!=(I& lhs) { return x<lhs.x; }void operator++() { ++x; } }; I i, n;public:range(int n) :i({ 0 }), n({ n }) {}range(int i, int n) :i({ i }), n({ n }) {}I& begin() { return i; }I& end() { return n; }};

int R,C,N;
set<pair<int,int>> wall;
int pos[1123456];
int main(){
    cin>>R>>C;
    int ret=R;
    cin>>N;
    for(int i:range(R+10)){
        pos[i]=1e6;
    }
    for(int i:range(N)){
        int r,c;
        cin>>r>>c;
        wall.insert({r,c});
        chmin(pos[r],c);
    }
    for(int i:range(R+2)){
        wall.insert({i,0});
        wall.insert({i,C+1});
    }
    for(int i:range(C+2)){
        wall.insert({0,i});
        wall.insert({R+1,i});
    }
    int cur=1;
    for(int i:range(2,R+1)){
        int r = i-1;
        int c = pos[i];
        //cout<<i<<" "<<cur<<" "<<wall.count({i,cur+1})<<endl;
        if(cur<c);
        else{
        //cout<<r<<" "<<c<<endl;
        chmin(ret,r);
        }
        if(wall.count({i,cur+1})==0)cur++;
    }
    cout<<ret<<endl;
    return 0;
}

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

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <type_traits>
#include <typeindex>
#include <unordered_map>
#include <unordered_set>
#endif

template <typename A, typename B> bool cmin(A &a, const B &b) {
  return a > b ? (a = b, true) : false;
}
template <typename A, typename B> bool cmax(A &a, const B &b) {
  return a < b ? (a = b, true) : false;
}
const double PI = acos(-1);
const double EPS = 1e-9;
int inf = sizeof(int) == sizeof(long long) ? 2e18 : 1e9 + 10;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main()
{
  vector<vector<int>> a(3, vector<int> (3));
  rep(i,3){
    rep(j,3){
      cin>>a.at(i).at(j);
    }
  }
  int n,b;
  bool vertical=false,horizontal=false,diagonal=false;
  cin>>n;
  rep(i,n){
    cin>>b;
    rep(j,3){
      rep(k,3){
        if (a.at(j).at(k) == b) {
          a.at(j).at(k)=0;
        }
      }
    }
  }
  rep(i,3){
    if (a.at(i).at(0)==0&&a.at(i).at(1)==0&&a.at(i).at(2)==0) vertical=true;
    if (a.at(0).at(i)==0&&a.at(1).at(i)==0&&a.at(2).at(i)==0) horizontal=true;
  }
  if ((a.at(0).at(0)==0&&a.at(1).at(1)==0&&a.at(2).at(2)==0)||(a.at(0).at(2)==0&&a.at(1).at(1)==0&&a.at(2).at(0)==0)) diagonal=true;

  if (vertical||horizontal||diagonal) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}


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

void solve(){
  int a, b; cin >> a >> b;
  if(a == b) cout << "Draw" << endl;
  else if(a == 1 || (a > b && b != 1)) cout << "Alice" << endl;
  else cout << "Bob" << endl;
}

int main(){
  solve();
  return 0;
}

Measured memory_bytes: 3616
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;


int main() {
    int n;
    cin >> n;
    vector<pair<int, int>> vp;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        vp.emplace_back(a, i);
    }
    sort(vp.begin(), vp.end());
    int res = 0;
    for (int i = 0; i < n; i++) {
        res += abs(i - vp[i].second) % 2;
    }
    cout << res / 2 << endl;
}




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

int main(void){
int k,a,b;
int bb=0;
scanf("%d",&k);
scanf("%d %d",&a,&b);

for(int i=0;;i++){
    if(a<=bb&&bb<=b){printf("OK\n");return 0;}
    else if(b<bb){printf("NG\n");return 0;}
bb=bb+k;
}
}

Measured memory_bytes: 1620
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define _USE_MATH_DEFINES
#include <math.h>
#define NIL = -1;
#define all(x) x.begin(),x.end()
const ll INF = 1e9;
const ll mod = 1e9 + 7;
 
int digit(ll x) {
    if (x / 10 == 0) return 1;
    return digit(x / 10) + 1;
}
 
ll gcd(long long a,long long b) {
    if (a < b) swap(a,b);
    if (b == 0) return a;
    
    return gcd(b,a%b);
}

bool is_prime(long long N){
    if (N == 1) return false;
    for (long long i = 2;i * i <= N;i++){
        if (N % i == 0) return false;
    }
    return true;
}
 
ll lcm(ll a,ll b){
    return ((a * b == 0)) ? 0 : (a / gcd(a,b) * b);
}
 
double DegreeToRadian(double degree){
    return degree * M_PI / 180.0;
}
 
 
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};
 
 
///////////////////////////////////////////////////////////////////////////////////

int main(){
    int n;
    cin >> n;
    vector<int> a(100010, 0);
    for (int i = 0;i < n;i++){
        int x;
        cin >> x;
        x++;
        a[x]++;
        a[x-1]++;
        a[x+1]++;
    }

    sort(a.begin(), a.end(), greater<int>());
    
    cout << a[0] << endl;
}

Measured memory_bytes: 3780
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1e18
#define PI 3.14159265358979

using namespace std;

ll power(ll n, ll k);
ll inv(ll n);
ll genfact(ll n, ll k);
ll fact(ll n);
ll nck(ll n, ll k);

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

  for (int i = max(-1000000, x - k + 1); i < min(1000000, x + k); i++){
    cout << i << " ";
  }
  cout << endl;

  return 0;
}


ll power(ll n, ll k){
  ll res = 1;
  while(k > 0){
    if (k & 1) 
      res = res * n % MOD;
    n = n * n % MOD;
    k >>= 1;
  }
  return res;
}

ll genfact(ll n, ll k){

  ll res = 1;
  while (k >= 0){
    res = (res * (n - k)) % MOD;
    k--;
  }

  return res;
}

ll inv(ll n){
  return power(n, MOD - 2);
}

ll fact(ll n){
  return genfact(n, n - 1);
}

ll nck(ll n, ll k){
  if (k == 0)
    return 1;
  if (n <= 0)
    return 0;

  return ((genfact(n, k) % MOD) * inv(fact(k))) % MOD;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <map>
using namespace std;
typedef long long ll;
#define ALL(v) (v).begin(), (v).end()
const int inf = 1e9;
const int mod = 1e9+7;

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

    vector<int> dp(N+1, inf);
    dp[0] = 0;
    for (int x = 1; x <= N; x++) {
        int power = 1;
        while (x >= power) {
            dp[x] = min(dp[x], dp[x-power] + 1);
            power *= 6;
        }

        power = 1;
        while (x >= power) {
            dp[x] = min(dp[x], dp[x-power] + 1);
            power *= 9;
        }
    }

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


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

const int N = 200009;

int n, m;
vector<int> adj[N];

bool dfs(int u, int steps){
    if(steps == 2 && u == n) return true;
    if(steps == 2) return false;
    for(int v : adj[u]){
        bool k = dfs(v, steps+1);
        if(k) return true;
    }
    return false;
}

int main(){
    scanf("%d %d", &n, &m);
    for(int i = 0; i < m; i++){
        int x, y;
        scanf("%d %d", &x, &y);
        adj[x].push_back(y);
        adj[y].push_back(x);
    }
    printf("%s\n", dfs(1,0)? "POSSIBLE":"IMPOSSIBLE");
}


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

template< typename T >
struct Compress {
    vector< T > xs;

    Compress() = default;

    Compress(const vector< T > &vs) {
        add(vs);
    }

    Compress(const initializer_list< vector< T > > &vs) {
        for(auto &p : vs) add(p);
    }

    void add(const vector< T > &vs) {
        copy(begin(vs), end(vs), back_inserter(xs));
    }

    void add(const T &x) {
        xs.emplace_back(x);
    }

    void build() {
        sort(begin(xs), end(xs));
        xs.erase(unique(begin(xs), end(xs)), end(xs));
    }

    vector< int > get(const vector< T > &vs) const {
        vector< int > ret;
        transform(begin(vs), end(vs), back_inserter(ret), [&](const T &x) {
            return lower_bound(begin(xs), end(xs), x) - begin(xs);
        });
        return ret;
    }

    int get(const T &x) const {
        return lower_bound(begin(xs), end(xs), x) - begin(xs);
    }

    const T &operator[](int k) const {
        return xs[k];
    }

    int size() const {
        return xs.size();
    }
};

int main(void){
    int n, m;
    cin >> n >> m;
    vector<ll> a(n), b(n), c(n), d(m), e(m), f(m);
    // a,b,d -> x
    // c,e,f -> y
    Compress<ll> comX, comY;
    comX.add(0);
    comY.add(0);
    rep(i,n) {
        cin >> a[i] >> b[i] >> c[i];
        comX.add(a[i]);
        comX.add(b[i]);
        comY.add(c[i]);
    }
    rep(i,m) {
        cin >> d[i] >> e[i] >> f[i];
        comX.add(d[i]);
        comY.add(e[i]);
        comY.add(f[i]);
    }
    comX.build();
    comY.build();
    int Y = comY.size()*2;
    int X = comX.size()*2;
    vector<vector<bool>> wall(Y, vector<bool>(X));
    rep(i,n){
        int x1 = comX.get(a[i])*2;
        int x2 = comX.get(b[i])*2;
        int y = comY.get(c[i])*2;
        for (int x = x1; x <= x2; x++) {
            wall[y][x] = true;
        }
    }
    rep(i,m){
        int x = comX.get(d[i])*2;
        int y1 = comY.get(e[i])*2;
        int y2 = comY.get(f[i])*2;
        for (int y = y1; y <= y2; y++) {
            wall[y][x] = true;
        }
    }
    using P = pair<int,int>;
    queue<P> qu;
    qu.push({comY.get(0)*2, comX.get(0)*2});
    int dx[] = {-1,0,+1,0};
    int dy[] = {0,-1,0,+1};
    ll area = 0;
    while(qu.size()) {
        P front = qu.front(); qu.pop();
        int y = front.first;
        int x = front.second;
        if ((y & 1) && (x & 1)) {
            area += (comY[y/2+1] - comY[y/2]) * (comX[x/2+1] - comX[x/2]);
        }
        rep(i,4){
            int ny = y + dy[i];
            int nx = x + dx[i];
            if (ny < 0 || nx < 0 || ny >= Y || nx >= X) {
                cout << "INF" << endl;
                return 0;
            }
            if (wall[ny][nx]) continue;
            wall[ny][nx] = true;
            qu.push({ny,nx});
        }
    }
    cout << area << endl;
    return 0;
}


Measured memory_bytes: 8108
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector< vector<int> > VVI;
typedef vector< vector<ll> > VVL;
typedef pair<int,int> PII;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound

int main(){
  ll N,S;
  cin>>N>>S;
  VL A(N);
  rep(i,N) cin>>A[i];
  ll mod=998244353;
  ll dp[3001][3001][3]={};
  dp[0][0][0]=1;
  rep(i,N){
    rep(j,3001){
      (dp[i+1][j][0]+=dp[i][j][0])%=mod;
      (dp[i+1][j][1]+=dp[i][j][0]+dp[i][j][1])%=mod;
      (dp[i+1][j][2]+=dp[i][j][0]+dp[i][j][1]+dp[i][j][2])%=mod;
      if(j+A[i]<=S){
        (dp[i+1][j+A[i]][1]+=dp[i][j][0]+dp[i][j][1])%mod;
        (dp[i+1][j+A[i]][2]+=dp[i][j][0]+dp[i][j][1])%mod;
      }
    }
  }
  cout<<dp[N][S][2]<<endl;
}

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

typedef long long ll;

map<string,ll>mp;
vector<string>v;

void permute(string st)
{

    do
    {
        if(mp[st]==0)
        {
            v.push_back(st);
            mp[st]=1;
        }
    }
    while(next_permutation(st.begin(),st.end()));

}

void divide(ll n)
{
    ll i,j,k,l;
    for(i=1; i<=n; i++)
    {
        for(j=1; j<=n; j++)
        {
            for(k=1; k<=n; k++)
            {
                if((i+j+k)>n)break;
                string st;
                for(l=0; l<i; l++)st.push_back('3');
                for(l=0; l<j; l++)st.push_back('5');
                for(l=0; l<k; l++)st.push_back('7');
                permute(st);
            }
        }
    }
}

ll num(string st){

    ll res=0,i;
    for(i=0; i<st.size(); i++){
        ll a=st[i]-48;
        res=(res*10)+a;
    }
return res;
}

int main()
{
    ll i,n,c=0;
    for(i=3; i<=9; i++)
    {
        divide(i);
    }
    vector<ll>res;
   for(i=0; i<v.size(); i++){
        ll a=num(v[i]);
        res.push_back(a);
   }
   sort(res.begin(),res.end());
   cin >> n;
   for(i=0; i<res.size(); i++)
    {
        if(res[i]>n)break;
        c++;

    }
    cout << c << "\n";

    return 0;
}


Measured memory_bytes: 5116
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+10;
const int mod=1000000007;
int a[maxn];
int dp[maxn];
map<int,int>ma;
int main()
{
    int n,m;
    scanf("%d%d",&n,&m);

    for(int i=1;i<=m;i++)
        scanf("%d",&a[i]),ma[a[i]]=1;
        dp[0]=dp[1]=1;
    for(int i=2;i<=n;i++)
    {
        int f=0;
        if(!ma[i])
        {
          if(!ma[i-1])
          {
              dp[i]=(dp[i]+dp[i-1])%mod;
                f=1;
          }
          if(!ma[i-2]){
             dp[i]=(dp[i]+dp[i-2])%mod;
             f=1;
          }
          if(!f){
            puts("0");
            return 0;
          }
        }
     }
     printf("%d\n",dp[n]);
    return 0;
}


Measured memory_bytes: 5504
from fractions import gcd
from functools import reduce

lcm = lambda a, b: b // gcd(a, b) * a
mod = 10 ** 9 + 7

N, *A = map(int, open(0).read().split())

L = reduce(lcm, A) % mod
print(L * sum(pow(a, mod - 2, mod) for a in A) % mod)

Measured memory_bytes: 6136
#include <stdio.h>
#include <string.h>
#define MAX 200001
int main(void){
  char s[MAX];
  int i,head=MAX,end=0,l=0;
  scanf("%s",s);
  for(i=0;i<strlen(s);i++){
    if(s[i] == 'A'){
      if(head > i){
        head = i;
      }
    }
    else if(s[i] == 'Z'){
      if(end < i){
        end = i;
      }
    }
  }
  l = end -head + 1;
  printf("%d",l);
  return 0;
}

Measured memory_bytes: 1856
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int t[] = new int[n];
		
		for (int i = 0; i <= n - 1; i++) {
			t[i] = sc.nextInt();
		}
		
		int m = sc.nextInt();
		int p[] = new int[m];
		int x[] = new int[m];
		
		for (int i = 0; i <= m - 1; i++) {
			p[i] = sc.nextInt();
			x[i] = sc.nextInt();
		}
		
		int sum = 0;
		int y = 0;
		
		for (int i = 0; i <= m - 1; i++) {
			y = t[p[i] - 1];
			t[p[i] - 1] = x[i];
			for (int j = 0; j < t.length; j++) {
				sum += t[j];
			}
			System.out.println(sum);
			sum = 0;
			t[p[i] - 1] = y;
		}
	}
}

Measured memory_bytes: 10184
import java.io.*;
import java.util.*;
import java.util.regex.*;


public class Main {

	final static long MOD = 1000000007;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static long cnt=0;
	public static PrintWriter pw = new PrintWriter(System.out);
	public static void main(String[] args) throws Exception {
		solutionA(args);
		if(in!=null){
			in.close();
		}
		pw.flush();
		pw.close();
	}

	public static void solutionA(String[] args) throws Exception{

		String S =nextString();
		String T =nextString();

		for(int i=S.length()-1;i>=T.length()-1;i--){
			boolean flg  = true;
			for(int k=0;k<T.length();k++){
				if(S.charAt(i-T.length()+1+k)!='?'&&S.charAt(i-T.length()+1+k)!=T.charAt(k)){
					flg=false;
					break;
				}
			}
			if(flg){
				StringBuffer sb = new StringBuffer();
				sb.append(S);
				sb.replace(i-T.length()+1, i+1, T);
				pw.println(sb.toString().replaceAll("\\?", "a"));
				return;
			}
		}
		pw.println("UNRESTORABLE");

	}

	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}

}



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

#define ff first
#define ss second
#define ins insert
#define ll long long
#define ld long double
#define vl vector<ll>
#define sz(c) (ll) c.size()
#define all(c) begin(c), end(c)
#define trv(x,c) for(auto &x : c)
#define tc ll t; cin >> t; while(t--)
#define rep(i,a,n) for(ll i = a; i < n; ++i)
#define per(i,a,n) for(ll i = n-1; i >= a; --i)
#define godspeed cin.tie(0) -> sync_with_stdio(0)

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

    ll ans = 0;

    rep(i,1,n) ans += (n-1)/i;

    cout << ans;
}

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

int main() {
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  int l=a+b,r=c+d;
  ((l) > (r)) ?
    cout << "Left" << endl :
    ((l) == (r)) ? cout << "Balanced" << endl :
    cout << "Right" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=1010010010010010000;
int main(){
    int n;cin >> n;
    vector<int> num;
    vector<bool> isPrime(55556,true);
    for(int i=2;i*i<=55556;i++){
        if(isPrime[i]){
            for(int j=2*i;j<=55556;j+=i){
                isPrime[j]=false;
            }
        }
    }
    int cnt=0;
    for(int i=2;i<=55556;i++){
        if(isPrime[i]&&i%5==1){
            if(cnt==n) continue;
            num.push_back(i);
            cnt++;
        }
    }
    for(int i=0;i<num.size();i++) cout << num[i] << " ";
    cout << endl;
    return 0;
}

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

using namespace std;

int main() {

    string s;

    cin >> s;

    int cnt = 0;

    if (s[0] == '1') ++cnt;
    if (s[1] == '1') ++cnt;
    if (s[2] == '1') ++cnt;

    cout << cnt << endl;

    return 0;
}

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

using namespace std;

int a[100];
int x, n;

bool find(int x)
{
	int left = 0, right = n - 1;
	int mid;
	while (left <= right)
	{
		mid = (left + right) / 2;
		if (a[mid] == x) return true;
		if (a[mid] > x) right = mid - 1;
		if (a[mid] < x) left = mid + 1;
	}
	return false;
}

int main(void)
{
	cin >> x >> n;
	for (int i = 0; i < n; i++) cin >> a[i];
	sort(a, a + n);

	int i = 0;
	while (1)
	{
		if (find(x - i) == false) { cout << x - i; return 0; }
		if (find(x + i) == false) { cout << x + i; return 0; }
		i++;
	}

	return 0;
}

Measured memory_bytes: 3636
n, m = map(int, input().split())

graph1 = [[] for _ in range(n * 3)]

for _ in range(m):
    u, v = map(int, input().split())
    u -= 1
    v -= 1
    graph1[u * 3 + 0].append(v * 3 + 1)
    graph1[u * 3 + 1].append(v * 3 + 2)
    graph1[u * 3 + 2].append(v * 3 + 0)

s, t = map(int, input().split())
s -= 1
t -= 1
s = s * 3
t = t * 3

from heapq import heappush, heappop


def dijkstra(graph: list, n: int, start: int, INF: int = float('inf')) -> list:
    # graph[node] = [(cost, to)]
    dist = [INF] * n
    num = [0] * n

    dist[start] = 0
    heap = [(0, start)]
    while heap:
        _, v_from = heappop(heap)
        for v_to in graph[v_from]:
            dist_cand = dist[v_from] + 1
            if dist_cand < dist[v_to]:
                dist[v_to] = dist_cand
                heappush(heap, (dist[v_to], v_to))
    return dist
    # dist = [costs to nodes]


INF = 10**10
dist = dijkstra(graph1, n * 3, s, INF=INF)
if dist[t] == INF:
    print(-1)
else:
    print(dist[t] // 3)


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

int main(){

	int N, A, B;
	int ans=0;
	cin >> N >> A >> B;
	for(int i = 1; i <= N; i++)
	{
		int k = i, t=0;
		while(k > 0){
			t += k % 10;
			k /= 10;
		}
		if(t>=A && t <= B) ans+=i;
	}
	cout << ans << endl;
	
	return 0;
}

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

int main(){
    int k,a,b;  cin >> k >> a >> b;
    for(int i = a; i <= b; i++){
        if(i%k == 0){
            cout << "OK" << endl;
            return 0;
        }
    }
    cout << "NG" << endl;
}


Measured memory_bytes: 3592
#include <iostream>
#include <array>

using namespace std;

string ExpectTommorowWeather(string today) {
    const int weather_num = 3;
    array<string, weather_num> weather_list = { "Sunny", "Cloudy", "Rainy" };
    string ret = "Can not predict.";

    for(int i = 0; i < weather_list.size(); ++i) {
        if(today.compare(weather_list.at(i)) == 0) {
            ret = weather_list[(i + 1) % weather_num];
            break;
        }
    }
    return ret;
}

int main() {
    string today;
    cin >> today;

    cout << ExpectTommorowWeather(today) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <limits>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <stdio.h>
#include <map>
#include <utility>
#include <queue>
using namespace std;
#define rep(i, n) for (int i =0; i < (int)(n); i++)
typedef pair<int, string> P;



int main() {

	string s, t;
	cin >> s >> t;

	int n = s.size();
	int ans = 0;
	rep(i, n) {
		if (s[i] != t[i]) {
			ans++;
		}
	}
	cout << ans;
}

Measured memory_bytes: 3840
n, m = [ int(v) for v in input().split() ]
num_list = [ int(v) for v in input().split() ]
match_table = [2,5,5,4,5,6,3,7,6]
match_table_2 = [ [] for i in range(8) ]
for i in num_list:
    match_table_2[match_table[i-1]].append(i)

match_table_2 = [ (max(match_table_2[i]), i) for i in range(8) if match_table_2[i] != [] ]
match_list, figure_list = zip(*match_table_2)
k = len(match_list)

dp_list = [ 0 for i in range(n+1) ]

for i in range(n+1):
    index_list = [ i - j for j in figure_list ]
    candidate_list = []
    for j in range(k):
        if index_list[j] > 0 and dp_list[index_list[j]] > 0:
            candidate_list.append(dp_list[index_list[j]] * 10 + match_list[j])
        elif index_list[j] == 0:
            candidate_list.append(match_list[j])
    if candidate_list != []:
        dp_list[i] = max(candidate_list)

print(dp_list[-1])

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

int main(){
	int n,m;
	int mat[100][100];
	int vec[100];
	cin >> n >> m;
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			cin >> mat[i][j];
		}
	}
	for(int j=0;j<m;j++){
		cin >> vec[j];
	}
	for(int i=0;i<n;i++){
		int total = 0;
		for(int j=0;j<m;j++){
			total += mat[i][j]*vec[j];
		}
		cout << total << endl;
	}
	return 0;
}



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

using namespace std;

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

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

	string s;
	cin >> s;

	for(int i = 0; i < k; ++i) {
		if(*min_element(s.begin(), s.end()) == *max_element(s.begin(), s.end())) {
			break;
		}
		string t = s;
		reverse(t.begin(), t.end());
		string x = s + t;
		
		vector<string> tmp;
		for(int i = 0; i < n; ++i) {
			tmp.emplace_back(x.substr(i, n));
		}
		s = *min_element(tmp.begin(), tmp.end());
		reverse(s.begin(), s.end());
	}

	reverse(s.begin(), s.end());

	cout << s << '\n';

	return 0;
}

Measured memory_bytes: 40320
s=input()
n=len(s)+1
dp=[-1]*n
count=0
for i in range(n-1):
    if s[i]=='>':
        count+=1
    else:
        break
dp[0]=count
buf=dp[0]
for i in range(n-2):
    if s[i]=='>' and s[i+1]=='<':
        dp[i+1]=0
        continue
    if s[i]=='<' and s[i+1]=='<':
        dp[i+1]=dp[i]+1
        continue
    if s[i]=='<' and s[i+1]=='>':
        count=0
        for j in range(i+1,n-1):
            if s[j]=='>':
                count+=1
            else:
                break
        dp[i+1]=max(dp[i]+1,count)
        buf=count
        continue
    if s[i]=='>' and s[i+1]=='>':
        dp[i+1]=buf-1
        buf-=1
        continue
if s[n-2]=='>':
    dp[n-1]=dp[n-2]-1
else:
    dp[n-1]=dp[n-2]+1
print(sum(dp))


Measured memory_bytes: 51692
let ts = [| 1; 1; 1; 2; 1; 2; 1; 5; 2; 2; 1; 5; 1; 2; 1; 14; 1; 5; 1; 5; 2; 2; 1; 15; 2; 2; 5; 4; 1; 4; 1; 51 |]

let () = Printf.printf "%d\n" @@ Array.get ts @@ Scanf.scanf "%d\n" @@ pred

Measured memory_bytes: 4480
from bisect import bisect_left, bisect_right
while True:
    n, m = map(int, input().split())
    if n == m == 0:
        break
    a = list(map(int, input().split()))
    w = list(map(int, input().split()))
    Set = set()
    def go(i, weight):
        if i == m:
            Set.add(weight)
            return
        go(i + 1, weight)
        go(i + 1, weight + w[i])
        go(i + 1, weight - w[i])
    go(0, 0)
    ans = False
    for i in a:
        if i not in Set:
            if ans == False:
                ans = set(abs(s - i) for s in Set)
            else:
                ans = set(s for s in ans if i + s in Set or i - s in Set)
    if ans == False:
        print(0)
        continue
    elif len(ans) == 0:
        print(-1)
        continue
    else:
        print(min(ans))


Measured memory_bytes: 14156
#include "bits/stdc++.h"
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define mFOR(i, a, b) for (int i = a; i > b; i--)
#define MP make_pair
#define PB push_back
#define ALL(v) v.begin(), v.end()
#define N 100007
#define INF 1000000007
using namespace std;

typedef long long ll;

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll fceil(ll a, ll b) { return (a % b == 0 ? a / b : a / b + 1); }
int main()
{
   int a, b;
   cin >> a >> b;
   cout << (a ^ b) << endl;
   return 0;
}


Measured memory_bytes: 256
process.stdin.resume()
process.stdin.setEncoding('utf8')
var g_input = ''
process.stdin.on('data', function(chunk) {
    g_input += chunk
})
process.stdin.on('end', function() {
    main(g_input.split(/\r?\n/))
})
function main(input){
  let ans = 0
  //console.log(input)
  input[0] = input[0].split(' ')
  let D = input[0][1]
  for(let i=1;i<input.length;i++){
    input[i] = input[i].split(' ')
    let x = Number(input[i][0])
    let y = Number(input[i][1])
    let k = Math.sqrt(x**2 +y**2)
    //console.log(`${x} ${y} ${k}`)
    //console.log(`${D} ${k}`)
    
    if(k<=D)ans++
  }
  console.log(ans)
}

Measured memory_bytes: 100328
#include <bits/stdc++.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iostream>
#include <bitset>
#include <cassert>
#include <queue>
#include <random>
#include <stack>
#include <iomanip>
#include <math.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define repf(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define repr(i, a, b) for (ll i = (ll)a; i > (ll)b; i--)
#define repv(x, arr) for (auto &x : arr)
#define all(v) (v).begin(), (v).end()
#define vec(name, num) vector<ll> name((num), 0);
#define mp(a, b) make_pair(a, b)
#define pb(x) push_back(x)
#define F first
#define S second
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int> vii;
typedef vector<vii> vvii;
const ll mod = 1e9 + 7;
const int infi = 2147483600;
const ll infl = 1e17;

int main()
{
    ll n, m;
    cin >> n >> m;
    set<ll> color[n];
    vector<pair<ll, pll>> eds(m);
    rep(i,m){
        ll p, q, c;
        cin >> p >> q >> c;
        p--;
        q--;
        color[p].insert(c);
        color[q].insert(c);
        eds[i] = mp(c, mp(p, q));
    }
    map<pll, ll> col_idx;
    ll v_num = 0;
    rep(i,n){
        col_idx[mp(0, i)] = v_num;
        v_num++;
        for(auto c:color[i]){
            col_idx[mp(c, i)] = v_num;
            v_num++;
        }
    }
    vector<map<ll, ll>> edges(v_num);
    rep(i,n){
        for (auto c:color[i]){
            edges[col_idx[mp(c, i)]][col_idx[mp(0,i)]] = 0;
        }
    }
    rep(i,m){
        ll c = eds[i].F, p = eds[i].S.F, q = eds[i].S.S;
        edges[col_idx[mp(c, p)]][col_idx[mp(c, q)]] = 0;
        edges[col_idx[mp(0, p)]][col_idx[mp(c, q)]] = 1;
        edges[col_idx[mp(c, q)]][col_idx[mp(c, p)]] = 0;
        edges[col_idx[mp(0, q)]][col_idx[mp(c, p)]] = 1;
    }
    vll dist(v_num, infl);
    dist[col_idx[mp(0, 0)]] = 0;
    set<ll> check;
    check.insert(col_idx[mp(0, 0)]);
    while (!(check.empty())){
        ll now = *check.begin();
        check.erase(now);
        for (auto p:edges[now]){
            ll nex = p.F, d = p.S;
            if (dist[nex]>dist[now]+d){
                dist[nex] = dist[now] + d;
                check.insert(nex);
            }
        }
    }
    if (dist[col_idx[mp(0,n-1)]]==infl){
        cout << -1 << endl;
    }
    else{
        cout << dist[col_idx[mp(0,n-1)]] << endl;
    }
}


Measured memory_bytes: 167040
#include <stdio.h>

int main(void){
    char line[1001];
    int i,sum;
    for(;sum=0,i=0,scanf("%s",line),line[0] != '0';){
        while(line[i])
            sum+=line[i++]-'0';
        printf("%d\n",sum);
    }
    return 0;
}



Measured memory_bytes: 2112
#include <bits/stdc++.h>
#define l_ength size
using ll = long long;
const ll inf = (1<<30);
const ll mod = 998244353;
using namespace std;

ll __pow( ll a, int b ){
	ll ans = 1;
	int i = 0;
	while( (1<<i) <= b ){
		if( b&(1<<i) ){
			ans *= a;
			ans %= mod;
		}
		a *= a;
		a %= mod;
		i++;
	}
	return ans%mod;
}
	
int main(){
	int n; cin >> n;
	vector<ll> d(n);
	fill_n( d.begin(), n, 0 );
	int distmax = 0;
	for( int i = 0; i < n; ++i ){
		int k; cin >> k;
		if( i == 0 && k != 0 ){
			cout << 0 << endl;
			return 0;
		}
		++d[k];
		distmax = max(distmax, k);
	}
	if( d[0] != 1 ){
		cout << 0 << endl;
		return 0;
	}
	ll ans = 1;
	for( int i = 1; i <= distmax; ++i ){
		ans *= (__pow(d[i-1], d[i]))%mod;
		ans %= mod;
	}
	cout << ans%mod << endl;
}

Measured memory_bytes: 1152
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
int main()
{
	int n,k;
	while(~scanf("%d%d",&n,&k))
	{
		int x[110];
		for(int i=0;i<n;++i)
		{
			scanf("%d",&x[i]);
		}
		int sum = 0;
		for(int i=0;i<n;++i)
		{
			sum+=min(x[i],k-x[i]);
		}
		printf("%d\n",sum*2);
	}
}

Measured memory_bytes: 256
import math
from math import gcd,pi,sqrt
INF = float("inf")
MOD = 10**9 + 7

import sys
sys.setrecursionlimit(10**6)
import itertools
import bisect
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]


def main():
    n = i_input()
    sum = 0
    for i in range(1,n+1):
        if i%3 != 0 and i%5 != 0:
            sum += i
    print(sum)



if __name__=="__main__":
    main()


Measured memory_bytes: 66976
L, N = list(map(int, input().split()))
X = [int(input()) for i in range(N)]

ans0 = X[0]
# 0, -1, 1, -2, ...
i = 0
j = N-1
direc = 1 # direction: left->1, right->-1
while i!=j:
    direc *= -1
    ans0 += L+X[i]-X[j]
    if direc==-1:
        i += 1
    elif direc==1:
        j -= 1
if N%2==0:
    i = N//2
    j = N//2
else:
    i = N//2
    j = N//2+1
tmp_ans = ans0
for k in range(N-1):
    tmp_ans += -L-2*X[k]+X[i]+X[j]
    if i==j:
        j += 1
    else:
        i += 1
    ans0 = max(ans0, tmp_ans)
 
 
''' Start at X[N-1] '''
''' In the case when turn first '''
ans1 = L-X[N-1]
i = 0
j = N-1
direc = -1 # direction: left->1, right->-1
while i!=j:
    direc *= -1
    ans1 += L+X[i]-X[j]
    if direc==-1:
        i += 1
    elif direc==1:
        j -= 1
if N%2==0:
    i = (N-2)//2
    j = (N-2)//2
else:
    i = (N-2)//2
    j = (N-2)//2+1
tmp_ans = ans1
for k in reversed(range(1, N)):
    tmp_ans += -L+2*X[k]-X[i]-X[j]
    if i==j:
        i -= 1
    else:
        j -= 1
    ans1 = max(ans1, tmp_ans)
 
print(max(ans0, ans1))
 

Measured memory_bytes: 11072
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(b);i>(a);--i)
#define eper(i,a,b) for(int i=((int)(a));i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF (1<<30)-1
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

string s, t;
int dp[1010][1010];
int n, m;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
    cin >> s >> t;
    n = s.size(), m = t.size();
    erep(i, 0, n) erep(j, 0, m) dp[i][j] = INF;
    erep(i, 0, n) dp[i][0] = i;
    erep(i, 0, m) dp[0][i] = i;
    erep(i, 1, n) {
        erep(j, 1, m) {
            int cost = s[i-1] == t[j-1] ? 0 : 1;
            dp[i][j] = min(dp[i-1][j-1] + cost, min(dp[i][j-1] + 1, dp[i-1][j] + 1));
        }
    }
    cout << dp[n][m] << endl;
    return 0;
}


Measured memory_bytes: 7148
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <algorithm>
using namespace std;

#define forn(i, n) for(int i = 0; i < (int)(n); i++)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define forab(i, a, b) for(int i=(a);i<(b);++i)
#define foreach(i, n) for (__typeof(n.begin()) i = n.begin(); i != n.end(); ++i)
#define sqr(x) ((x)*(x))
#define clr(a, b) memset(a, b, sizeof(a))
#define MP make_pair
#define PB push_back
#define SZ(a) ((int)a.size())
#define all(a) (a).begin(),(a).end()
#define inf 0x3f3f3f3f
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
const double eps = 1e-8;
int dcmp(double x) { if (x < -eps) return -1; else return x > eps;}
#define se(x) cout<<#x<<" = "<<x<<endl

#ifdef CHEN_PC
#define debug(...) printf(__VA_ARGS__)
#else
#define debug(...)
#endif

const int N = 100010;
const int mod = 1000000007; // 10^9+7
int n;
int m;
char s[N];
char t[N];

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

ll solve() {
	int g = gcd(n, m);
	ll len = (ll)n * m / g;
	map<ll, char> dic;
	ll pos = 0;
	forn (i, n) {
		dic[pos] = s[i];
		pos += len / n;
	}

	pos = 0;
	forn (i, m) {
		if (dic.find(pos) != dic.end() && dic[pos] != t[i]) {
			return -1;
		}
		pos += len / m;
	}
	return len;
}

int main(int argc, char *argv[]) {
#ifdef CHEN_PC
	freopen("A.in", "r", stdin);
#endif

	while (scanf("%d%d", &n, &m) != EOF) {
		scanf("%s%s", s, t);
		ll ret = solve();
		printf("%lld\n", ret);
	}
	return 0;
}



Measured memory_bytes: 6144
#include <iostream>

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

	int x_0 = A % B;
	int x = x_0;
	int i = 1;

	do
	{
		if ( x == C ){
			i = 0;
			break;
		}

		x = ( x + A ) % B;

	}	
	while ( x != x_0 );

	if ( i == 0 ){
		std::cout << "YES" << std::endl;
	}else{
		std::cout << "NO" << std::endl;
	}

	return 0;
}

Measured memory_bytes: 256
# B
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())

a = (10 - A) % 10
b = (10 - B) % 10
c = (10 - C) % 10
d = (10 - D) % 10
e = (10 - E) % 10

print(A+B+C+D+E+a+b+c+d+e-max([a,b,c,d,e]))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int K, S;
    cin >> K >> S;

    int ans = 0;

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

Measured memory_bytes: 256