akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
// #include <boost/multiprecision/cpp_int.hpp> 

#define gc getchar//_unlocked
#define pc putchar//_unlocked
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define pp pair<int,int>
#define ppl pair<ll,ll>
#define bigint boost::multiprecision::cpp_int
#define finp ios_base::sync_with_stdio(0);cin.tie(0);
#define bc __builtin_popcountll
#define afor(i,a,b) for(int i=a;i<=b;++i)
#define bfor(i,a,b) for(int i=a;i>=b;--i)
#define vi vector<int>
#define vpp vector<pp>
#define vll vector<ll>
#define fr first
#define se second

using namespace std;
using namespace __gnu_pbds;

char putnb[20];
void putn(ll n) {if(!n)pc('0');if(n<0)pc('-'),n=0-n;int pi=0;while(n)putnb[pi++]=(n%10)+'0',n/=10;while(pi)pc(putnb[--pi]);}
void sci(int *x) {register char c = gc();*x = 0;for(; (c<48)||(c>57);c = gc());for(; (c>47)&&(c<58);c = gc())*x = (int)((((*x)<<1) + ((*x)<<3)) + c - 48);}
void scll(ll *x)  {register char c = gc();*x = 0;for(; (c<48)||(c>57);c = gc());for(; (c>47)&&(c<58);c = gc())*x =  (ll)((((*x)<<1) + ((*x)<<3)) + c - 48);}
ll fp(ll a,ll b,ll c) {if(b==0)return 1%c; if(b==1)return a%c; ll ret=fp(a,b/2,c); ret=(ret*ret)%c; if(b&1)ret=(ret*a)%c; return ret;}

const ll mod=1e9 +7;
const ll mod2=1999999973;
const ll inf=1e18;
const int infs=1e9 + 1000;
const int N=100000;
const long double PI = acos(-1);

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;



int main()
{
  finp;
 int t;
 cin>>t;
 while(t--)
 {
  ll a,b,c,d;
  cin>>a>>b>>c>>d;
  if(a < b)cout<<"No\n";
  else if(a%b > c)cout<<"No\n";
  else if(d < b)cout<<"No\n";
  else 
  {
    //a%b <= c
    //d >= b

    if(d%b==0 || c>=(b-1))cout<<"Yes\n";
    else
    {
      ll rem = c+1 - (a%b);
      ll step = __gcd(b,d%b);
      ll tar;
      if(rem%step == 0)tar = rem/step;
      else tar = rem/step + 1;

      ll xx = (tar*step + a%b)%b;

      if(xx > c)cout<<"No\n";
      else cout<<"Yes\n";
    } 
  }
 } 
return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#include <fstream>
#include <random>
#include <map>
#include <unordered_map>
#include <cstdlib>
#include <functional>
#include <random>
#include <time.h>
#include <chrono>
#include <sstream>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define mod 1000000007
#define sort(s) sort(s.begin(), s.end());
#define reverse(s) reverse(s.begin(), s.end());
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
using namespace std;
int POW(int x, int y) { return int(pow(double(x), double(y))); }
double log(double a, double b) { return log(b) / log(a); }

unsigned int randxor()
{
	static unsigned int x = 123456789, y = 362436069, z = 521288629, w = 88675123;
	unsigned int t;
	t = (x ^ (x << 11)); x = y; y = z; z = w; return(w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}






int main() {
	int a,b,c;
	cin >>a>>b>>c;
	cout << min(b / a, c) << endl;




	


	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, to) for (int i = 0; i < (to); i++)
#define rrep(i, to) for (int i = (to) - 1; i >= 0; i--)
#define repf(i, from, to) for (int i = (from); i < (to); i++)
#define all(v) v.begin(), v.end()
#define unless(cond) if (!(cond))
using namespace std;
using ll = long long;
template <typename T>
using V = vector<T>;
template <typename T, typename U>
using P = pair<T, U>;

int main() {
  int n;
  V<int> fibo;

  cin >> n;
  fibo.resize(n + 1);

  fibo[0] = fibo[1] = 1;

  repf(i, 2, n + 1) {
    fibo[i] = fibo[i - 1] + fibo[i - 2];
  }

  cout << fibo[n] << endl;
}



Measured memory_bytes: 3080
#include <algorithm>
#include <bitset>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define MOD (1000000007l)
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)

using namespace std;

void solve() {
  ll k, q;
  cin >> k >> q;
  vector<ll> d(k);
  rep (i, k) cin >> d[i];

  // TODO
  rep (i, q) {
    ll n, x, m;
    cin >> n >> x >> m;
    n--;
    vector<ll> tmp = d;
    rep (j, k) tmp[j] %= m;

    ll inc = 0;
    rep (j, k) if (tmp[j] > 0) inc++;
    inc *= n / k;
    rep (j, n % k) if (tmp[j] > 0) inc++;

    ll sum = 0;
    rep (j, k) sum += tmp[j];
    sum *= n / k;
    rep (j, n % k) sum += tmp[j];
    sum += x % m;

    ll shuukai = sum / m;

    ll ans = inc - shuukai;
    cout << ans << endl;
  }
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  cout << fixed;
  solve();
  return 0;
}


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

void testCase() {    
    
}

ll M = 1e9 +7;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll n,k;
    cin >> n >> k;
    ll ans = 0;
    for (ll i = k; i <= n; i++) {
        ans += n*(n+1)/2 - (n-i)*(n-i+1)/2 - (i-1)*i/2 + 1;
        ans %= M;
    }
    ans += 1;
    ans %= M;
    cout << ans << "\n";
}
















Measured memory_bytes: 3648
#include <iostream>
#include <fstream>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <set>

using std::vector;
template<typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); }
template<typename T, typename... Args> void ndarray(vector<T> &vec, int len, Args... args) { vec.resize(len); for (auto &v : vec) ndarray(v, args...); }
constexpr long long MOD = 1000000007;

int main() {
    //std::ifstream in("in01.txt");
    //std::cin.rdbuf(in.rdbuf());
    
    int n;
    std::cin >> n;
    
    //末尾3文字が何か覚えておく必要がある
    //dp[n][l3][l2][l1]
    //ln : 0:"A" 1:"C" 2:"G" 3:"T"
    vector<vector<vector<vector<long long>>>> dp;
    ndarray(dp, n+1, 4, 4, 4);
    
    dp[0][3][3][3] = 1;
    
    for (int i = 0; i < n; i++) {
        for (int l3 = 0; l3 < 4; l3++) {
            for (int l2 = 0; l2 < 4; l2++) {
                for (int l1 = 0; l1 < 4; l1++) {
                    for (int add = 0; add < 4; add++) {
                        if (l2 == 0 && l1 == 2 && add == 1) continue; //agc
                        if (l2 == 0 && l1 == 1 && add == 2) continue; //acg
                        if (l2 == 2 && l1 == 0 && add == 1) continue; //gac
                        if (l3 == 0 && l2 == 2 && add == 1) continue; //axgc
                        if (l3 == 0 && l1 == 2 && add == 1) continue; //agxc
                        dp[i+1][l2][l1][add] += dp[i][l3][l2][l1];
                        dp[i+1][l2][l1][add] %= MOD;
                    }
                }
            }
        }
    }
    long long ans = 0;
    for (int l3 = 0; l3 < 4; l3++) {
        for (int l2 = 0; l2 < 4; l2++) {
            for (int l1 = 0; l1 < 4; l1++) {
                ans += dp[n][l3][l2][l1];
                ans %= MOD;
            }
        }
    }
    std::cout << ans << std::endl;
    
    return 0;
}


Measured memory_bytes: 384
#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)-1;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
using namespace std;
typedef long long ll;
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;}

int n, a[100005];
ll ans;
int main() {
 ios::sync_with_stdio ( false );
 cin.tie ( 0 );
    cin >> n;
    rep(i, 0, n) cin >> a[i];
    ll sum = 0, cnt1 = 0, cnt2 = 0;
    rep(i, 0, n) {
        sum += a[i];
        if (i%2) {
            if (sum <= 0) {
                cnt1 += abs(sum) + 1;
                sum = 1;
            }
        } else {
            if (sum >= 0) {
                cnt1 += sum + 1;
                sum = -1;
            }
        }
    }
    sum = 0;
    rep(i, 0, n) {
        sum += a[i];
        if (i%2) {
            if (sum >= 0) {
                cnt2 += abs(sum) + 1;
                sum = -1;
            }
        } else {
            if (sum <= 0) {
                cnt2 += abs(sum) + 1;
                sum = 1;
            }
        }
    }
    cout << min(cnt1, cnt2) << endl;
    return 0;
}


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

#define rep(i,n) for(ll i=0;(i)<(ll)n;(i)++)
const long long INF = 100000000000;
using mint = modint998244353;
int main(){
  int n,m; cin >> n >> m;
  vector<mint> a(n),b(m);
  rep(i,n){
    int tmp; cin >> tmp;
    a[i] = tmp;
  }
  rep(i,m){
    int tmp; cin >> tmp;
    b[i] = tmp;
  }
  auto res = convolution(a,b);
  for(auto it = res.begin(); it != res.end(); it++){
    if(it != res.begin()) cout << " ";
    cout << it -> val();
  }
  cout << endl;
}


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

int main() {
	string s;
	cin >> s;
	string a = s.substr(0, 2), b = s.substr(2, 4);
	if ("01" <= a && a <= "12") {
		if ("01" <= b && b <= "12") {
			cout << "AMBIGUOUS" << endl;
		} else {
			cout << "MMYY" << endl;
		}
	} else {
		if ("01" <= b && b <= "12") {
			cout << "YYMM" << endl;
		} else {
			cout << "NA" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define fileio freopen("in.in", "r", stdin),freopen("out.out", "w", stdout);
#define ll long long int
#define FF first
#define SS second
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<long long int,long long int>
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d\n",x)
#define plld(x) printf("%lld\n",x)
#define pss printf
#define MOD 1000000007
#define INF 1e18
#define eps 0.00001
#define endl '\n'
#define debug(n1) cout<<n1<<endl
const int N = 1e5;  // limit for array size
ll n;  // array size

/*template<typename T>
using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rand(int l, int r){
    uniform_int_distribution<int> uid(l, r);
    return uid(rng);
}
*/
int main(){
	int n;cin>>n;
	ll h[n];
	int c=0,ans=0;
	for(int i=0;i<n;i++){
		cin>>h[i];
	}
	
	for(int i=1;i<n;i++){
		if(h[i]<=h[i-1]){
			c++;
		}
		else{
			ans=max(ans,c);
			c=0;
		}
	}
	
	ans=max(ans,c);
	cout<<ans<<endl;
	return 0;
	
}

Measured memory_bytes: 1024
N = int(input())
a = list(map(int, input().split()))
s = 0

for i in range(N):
	x = 0
	while True:
		if a[i] % 2 == 0:
			x += 1
			a[i] = int(a[i] // 2)
		else:
			break
	s += x

print(s)

Measured memory_bytes: 4148
[n, q] = [int(i) for i in input().split()]
s = input() + '_'
l = [[int(j) - 1 for j in input().split()] for i in range(q)]

cnt = 0
num = []
for i in range(len(s) - 1):
    if (s[i:i + 2] == 'AC'):
        cnt += 1
        num.append(cnt)
    else:
        num.append(cnt)
for i in l:
    temp = num[i[1]] - num[i[0]]
    if i[1] - i[0] > 0:
        if (s[i[0]:i[0] + 2] == 'AC'):
            temp += 1
        if (s[i[1]:i[1] + 2] == 'AC'):
            temp -= 1 
    print(temp)


Measured memory_bytes: 24472
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e18l+5;

int main(){
    int n,W;
    cin>>n>>W;
    
    vector<ll> dp(100001,INF); //min weight at value = i.
    dp[0]=0;
    for(int i=0; i<n; ++i){
        int w,v;
        cin>>w>>v;
        for(int va=100001-v; va>=0; --va){
            dp[va+v]=min(dp[va+v],dp[va]+w);
        }
    }
    int ans=0;
    for(int i=0; i<100001; ++i){
        if(dp[i]<=W) ans=max(ans,i);
    }

    cout<<ans;
    
}

Measured memory_bytes: 4044
#include<iostream>
#include<string>
#include<math.h>
using namespace std;


int main(){

int A,B;

cin>>A>>B;

int card[]=  {1,2,3,4,5,6,7,8,9,10,11,12,13};

if(A==1){
    A=14;
}

if(B==1){
    B=14;
}
//cout<<"A"<<A;
//cout<<"B"<<B;
if(A>B){
    cout<<"Alice"<<endl;
}

else if(A<B){

    cout<<"Bob"<<endl;

}

else if(A==B){

    cout<<"Draw"<<endl;
}




return 0;

}

Measured memory_bytes: 256
N,M = map(int,input().split())
k_1 = []
k_2 = []
for i in range(M):
  l,r = map(int,input().split())
  k_1.append(l)
  k_2.append(r)
if max(k_1)<=min(k_2):
  print(min(k_2)-max(k_1)+1)
else:
  print(0)

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

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

  vector<int > a(N);
  for ( int i = 0; i < N; i++ ) {
    cin >> a.at(i);
  }

  int K, sum, M;
  vector<int > b(N);
  for ( int i = N; i > 0; i-- ) {
    K = N/i;
    sum = 0;
    if ( i > N/2 ) {
      b.at(i-1) = a.at(i-1);
    } else {
      for ( int j = 2; j <= K; j++ ) {
        sum += b.at(i*j-1);
        // cout << sum << endl;
      }
      if ( sum%2 == a.at(i-1) ) {
        b.at(i-1) = 0;
      } else {
        b.at(i-1) = 1;
      }
    }
    // cout << b.at(i-1) << " " << i << endl;
  }

  vector<int > ans;
  for ( int i = 1; i <= N; i++ ) {
    if (b.at(i-1)) ans.push_back(i);
  }
  M = ans.size();
  cout << M << endl;
  for ( int i = 0; i < M; i++ ) {
    if ( i < M - 1 ){
      cout << ans.at(i) << " ";
    } else {
      cout << ans.at(i) << endl;
    }
  }

  return 0;
}


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

#define MAX 10000

void rec(char *str)
{
    int temp;
    char *tok;

    tok = strtok(NULL, " ");
    if(tok == NULL) return;
    temp = atoi(tok);
    rec(str);
    printf("%d ", temp);
    return;
}

void first_rec(char *str)
{
    int temp;
    char *tok;

    tok = strtok(str, " ");
    temp = atoi(tok);
    rec(str);
    printf("%d\n", temp);
    return;
}

int main(void)
{
    int n;
    char str[MAX];

    scanf("%d%*c", &n);
    fgets(str, MAX, stdin);

    first_rec(str);

    return 0;
}

Measured memory_bytes: 612
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
int main() {
  int x;
  cin >> x;
  x-=400;
  int ans=8;
  while(x>=200){
    x-=200;
    ans--;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3636
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <algorithm>
#include <functional>
#include <deque>
#include <cctype>
#include <ctime>
#include <cstdlib>
#include <iomanip>
using namespace std;

int main(){
    int n;
    cin >> n;
    vector<string> v;
    for(int i = 0; i < n; ++i){
        string w;
        cin >> w;
        v.push_back(w);
    }
    bool flg = true;
    for(int i = 0; i < n-1; ++i){
        if(v[i][v[i].size()-1]!=v[i+1][0]) flg = false;
    }
    sort(v.begin(), v.end());
    for(int i = 0; i < n-1; ++i){
        if(v[i]==v[i+1]) flg = false;
    }
    if(flg) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 888
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <climits>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cassert>

using namespace std;

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

const ll MOD = ll(1e9 + 7);
const ll INF = LLONG_MAX;
const ll MAX_N = ll(1e3) + 5;
const double EPS = 1e-8;
const double PI = 3.14159265359;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)

int main() {
    ll n,m,a[8][1002]{},ans = -1;
    cin >> n >> m;
    REP(i,n){
        ll x,y,z;
        cin >> x >> y >> z;
        REP(j,8){
            a[j][i] += j&1?x:-x;
            a[j][i] += j&2?y:-y;
            a[j][i] += j&4?z:-z;
        }
    }
    REP(j,8){
        ll t=0;
        sort(a[j],a[j]+n);
        reverse(a[j],a[j]+n);
        REP(i,m){
            t+=a[j][i];
        }
        ans = max(ans,t);
    }
    cout << ans << endl;
    return 0;
}


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

int main() {
    int64_t X;
    std::cin >> X;

    int64_t p = 100, y = 0;
    while (true) {
        if (p >= X) {
            break;
        }

        p += p / 100;
        ++y; 
    }

    std::cout << y << std::endl;

    return 0;
}


Measured memory_bytes: 3612
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = (ll)(1e9+7);
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(int)(n); (i)++)
int dx[4]={ 1,0,-1,0 };
int dy[4]={ 0,1,0,-1 };

int A, B, M;
int a[100000], b[100000];
int Am = INT_MAX;
int Bm = INT_MAX;

signed main(){
    cin >> A >> B >> M;
    rep(i, A){
        cin >> a[i];
        Am = min(Am, a[i]);
    }
    rep(i, B){
        cin >> b[i];
        Bm = min(Bm, b[i]);
    }
    int ans = Am + Bm;
    rep(i, M){
        int x, y, c;
        cin >> x >> y >> c;
        ans = min(ans, a[x-1]+b[y-1]-c);
    }
    cout << ans << endl;
}

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

int N;
int A[100010];
int main()
{
    cin >> N;
    for (int i = 0; i < N; i++)
    {
        scanf("%d", &A[i]);
    }

    bool increase = true;
    bool updated = true;
    int cnt = 0;
    for (int i = 0; i < N ; i++)
    {   
        while(i+1 < N && A[i] == A[i+1]) i++;
        
        if (i+1 < N && A[i] < A[i + 1])
        {
            while(A[i]<=A[i+1]){
                i++;
            } 
            
        }
        else if (i+1 < N && A[i] > A[i + 1])
        {
            while(A[i] >= A[i+1]) i++;
        }

        cnt++;
    }

    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
#define MAXN 100
#define MAXT 1000000000000000000
long long int GCD(long long int a,long long int b)
{
  if(b==0) {
    return a;
  }
  else {
    return GCD(b,a%b);
  }
}
long long int LCM(long long int a,long long int b)
{
  long long int g=GCD(a,b);
  return a / g * b;
}
  
int main(int argc,char const* argv[])
{
  vector<long long int> t;
  long long int tmpt;
  long long int ans=1;
  int n,i;
  
  cin >> n;
  for(i=0;i<n;i++)
    {
      cin >> tmpt;
      t.push_back(tmpt);
    }
  for(i=0;i<n;i++)
    {
      ans=LCM(ans,t[i]);
    }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(A) (A).begin(),(A).end()
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define P pair<ll,ll>
const ll mod = 1e9+7;
const ll INF = 2e12;
const int inf = -1*((1<<31)+1);
 
using namespace std;

struct edge{
	int to;
	int cost;
};

void dijkstra(ll S,vector<vector<ll>> &dist,vector<vector<edge>> &g){
	priority_queue<P,vector<P>,greater<P>> q;
	dist[S][0] = 0;
	q.push(P(0,S));
	//コスト0でSから開始する
	while(!q.empty()){
		P now = q.top();q.pop();
		ll c  = now.first;//(スタート地点からの移動回数)%3
		ll v  = now.second;//今いる頂点
		if(dist[v][c%3]<c){
			cout << v << " " << c << endl;
			continue;
		}
		for(int i=0;i<g[v].size();i++){//今いる頂点から行ける辺について
			edge nextedge = g[v][i];//次の辺 (to,cost)を持つ
			if(dist[nextedge.to][(c+1)%3]>dist[v][c%3]+nextedge.cost){
				dist[nextedge.to][(c+1)%3]=dist[v][c%3]+nextedge.cost;
				q.push(P(c+1,nextedge.to));
			}
		}
	}
}
int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll N,M,S,T;
	cin >> N >> M;
	vector<vector<ll>> dist(N,vector<ll>(3,INF));
	//dist[i][j]:= 頂点iにj歩目で行くのにかかる最短コスト
	vector<vector<edge>> g(N);
	rep(i,M){
		int a,b;
		cin >> a >> b;
		a--;b--;
		g[a].push_back({b,1});

	}
	cin >> S >> T;
	S--;T--;
	dijkstra(S,dist,g);
	cout << (dist[T][0] != INF?dist[T][0]/3:-1) << endl;
}

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

#define int long long
typedef pair<int, int> P;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

/*
ifstream ifs("in.txt");
ofstream ofs("out.txt");
#define cin ifs
#define cout ofs
//*/

signed main() {
    vector<int> prime;
    for (int i = 2; i < 5555; i++) {
        bool flag = true;
        for (int j = 2; j <= sqrt(i); j++) {
            if (i % j == 0) flag = false;
        }
        if (flag && i % 5 == 1) prime.push_back(i);
    }
    int N;
    cin >> N;
    for (int i = 0; i < N; i++) cout << prime[i] << " ";
}

Measured memory_bytes: 256
use proconio::input;
use std::collections::HashMap;

fn gcd(a:usize, b:usize) -> usize {
  if a == 0 {
    return b
  }
  gcd(b % a, a)
}

fn factorize(mut n:usize) -> HashMap<usize, bool> {
  let base_n = n;
  let mut map: HashMap<usize, bool> = HashMap::new();
  let mut index = 2;
  while index * index <= base_n {
    while n % index == 0 {
      map.insert(index, true);
      n /= index;
    }
    index += 1;
  }
  if n != 1 {
    map.insert(n, true);
  }
  map
}

fn main() {
  input! {
    a: usize,
    b: usize
  }
  
  println!("{}", factorize(gcd(a,b)).keys().len() + 1);
}

Measured memory_bytes: 2192
n=int(input())
s=input()
ans=300000
l=[0]
r=[0]
for i in s:
  if i=="W":
    l.append(1)
    r.append(0)
  else:
    l.append(0)
    r.append(1)
l.append(0)
r.append(0)
for i in range(1,n+2):
  l[i]+=l[i-1]
for i in range(n,-1,-1):
  r[i]+=r[i+1]
for i in range(1,n+1):
  ans=min(ans,l[i-1]+r[i+1])
print(ans)

Measured memory_bytes: 29092
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e9+7;
int mod = 998244353;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main() {
    int N;
    cin >> N;
    string S = "";
    while(N != 0) {
        N--;
        S+=(char)(N%26+'a');
        N/=26;
    }
    for(int i = S.size()-1; i >= 0; i--) {
        cout << S[i];
    }
    cout << endl;
}

Measured memory_bytes: 3620
#include <stdio.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <cmath>
//#include <unordered_map>
//#include <unordered_set>
//#include <boost/container/static_vector.hpp>
//#include <boost/unordered_set.hpp>
//#include <boost/unordered_map.hpp>
//#include <unistd.h>

//#include <cv.h>
//#include <highgui.h>
#include <stdlib.h>
#include <string>

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

const int MAX_N = 100050;
int N;
int A[MAX_N];

main(int argc, char **argv) {
    std::cin >> N;
    for (int i = 1; i <= N; i++) {
        std::cin >> A[i];
    }
    
    int ret = A[1];

    for (int i = 2; i <= N; i++) {
        ret = gcd(ret, A[i]);
    }
    
    std::cout << ret << std::endl;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define vi vector<int>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pi 3.141592653589793238
#define eb emplace_back
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define zip(i,a,b) for(int i=a;i<b;i++)
#define rzip(i,a,b) for(int i=a;i>=b;i--)
#define ll unsigned int
#define test int t;cin>>t; while(t--)
#define um unordered_map
#define en '\n'
#define us unordered_set
typedef pair<int, int>     pii;
typedef pair<char, int>    pci;
typedef pair<char, char>   pcc;
typedef vector<pii>       vii;
typedef long double ld;
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(),v.rend()
#define sz(x) (int)x.size()
#define INF (1e18+5)
#define inf (1e9+5)
#define mod 1000000007


void __print(int x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
// You should only debug a pair of simple data types. For example,
// the debug won't work if one of pair's elements is collection type
// (std::vector, std::map, std::set...).
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif


// bool check_prime(int n)  return whether a number is prime or not O(sqrt(N));
// int BE(int x,int n,int m)  return x^n%m; O(logN);
// void sieve()  from number 1-1000001 saare prime store kar lega  in bool is_prime[1000001] array
// vector<int> z_array(string s)  return vector which is Z-array of string s;
// vector<int> lps(string s)      return vector which is lps array of string s;
// int power(int x,int n) return x^n; O(logN);
// using_ordered_set (template for using ordered set , replace first 2 lines of this page with this code..);
const int gf = 1e6 + 9;

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(0);
#ifndef ONLINE_JUDGE
	if (fopen("input.txt", "r"))
	{
		freopen ("input.txt" , "r" , stdin);
		freopen ("output.txt" , "w" , stdout);
	}
#endif
	//_______________________________-code starts-_______________________________________________

	int n;
	cin >> n;
	vi add, sub;

	zip(i, 0, n)
	{
		int x, y;
		cin >> x >> y;
		add.pb(x + y);
		sub.pb(x - y);
	}
	int ans = *max_element(all(add)) - *min_element(all(add));
	sort(all(sub));
	int var = sub[sz(sub) - 1] - sub[0];
	ans = max(ans, var);
	cout << ans << en;




	return 0;
}




Measured memory_bytes: 6692
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
using namespace std;
#define int long long


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

    int n,m; cin >> n >> m;
    vector<int> a(n),b(n),c(m),d(m);
    for(int i= 0;i < n;i ++){
        cin >> a.at(i) >> b.at(i);
    }
    for(int i = 0;i < m;i ++){
        cin >> c.at(i) >> d.at(i);
    }

    int dis,ans;

    for(int i = 0;i < n;i ++){
        dis = 1000000000;

        for(int j = 0;j < m;j ++){
            if(abs(a.at(i)-c.at(j)) + abs(b.at(i)-d.at(j)) < dis){
                dis = abs(a.at(i)-c.at(j)) + abs(b.at(i)-d.at(j));
                ans = j;
            }
        }

        cout << ans+1 << endl;
    }
}



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

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

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

int main() {
  ll N, K;
  cin >> N >> K;
  vector<ll> A(N);
  rep(i, N) cin >> A[i];
  vector<ll> F(N);
  rep(i, N) cin >> F[i];

  sort(all(A));
  sort(all(F), greater<ll>());

  ll r = LINF;
  ll l = -1;

  while (r - l > 1) {
    ll c = (r + l) / 2;
    ll shugyo = 0;

    rep(i, N) {
      ll multi = A[i] * F[i];
      if (multi <= c)
        continue;
      multi -= c;
      multi = (multi + F[i] - 1) / F[i];
      shugyo += multi;
    }
    if (shugyo <= K) {
      r = c;
    } else {
      l = c;
    }
  }
  cout << r << endl;
}

Measured memory_bytes: 3328
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
using namespace std;
const int mod = 1000000007;
#define ll long long


int main()
{
	int N;
	ll an = 1;
	cin >> N;
	for (int i = 1; i <= N; i++) {
		an *= i;
		an %= mod;
	}
	cout << an << endl;
}


Measured memory_bytes: 256
#include <iostream>
#define FOR(i,a,b) for(int i=a;i<b;i++)
using namespace std;

int main() {
	// your code goes here
	int n;cin>>n;
	int a[n],dp[n];
	FOR(i,0,n)cin>>a[i];
	FOR(i,0,n)dp[i]=-1;
	dp[0]=0;
	dp[1]=abs(a[1]-a[0]);
	FOR(i,2,n){
		dp[i]=min(dp[i-2]+abs(a[i]-a[i-2]),dp[i-1]+abs(a[i]-a[i-1]));
	}
//	FOR(i,0,n)cout<<dp[i]<<" ";
	cout<<dp[n-1]<<endl;
	return 0;
}

Measured memory_bytes: 4312
#include <iostream>
#include <cmath>
using namespace std;
const int N = 2e5 + 500;
int dp[N], a[N], n;
int main(){
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> a[i];
	dp[2] = abs(a[2] - a[1]);
	for(int i = 3; i <= n; i++){
		dp[i] = min(dp[i - 2] + abs(a[i] - a[i - 2]), dp[i - 1] + abs(a[i] - a[i - 1]));
	}
	cout << dp[n] << endl;
}

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

int main()
{
    int k, x;
    cin >> k >> x;
    for (int i = x - k + 1; i < x; i++)
        cout << i << " ";
    cout << x << " ";
    for (int i = x + 1; i < x + k; i++)
        cout << i << " ";
    return 0;
}


Measured memory_bytes: 3644
import sys
stdin = sys.stdin

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

from bisect import bisect_left

dic = dict()

n = ni()
a = []
for _ in range(n):
    a.append(ni())
    
b = sorted(a)

for i, ai in enumerate(a):
    dic[ai] = (i, bisect_left(b,ai))
    
cnt = 0
for ord1, ord2 in dic.values():
    if ord1%2 != ord2%2:
        cnt += 1
        
print(cnt // 2)

Measured memory_bytes: 28204
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#include<list>
#include<unordered_map>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
// #define int ll
using namespace std;
const int INF (1 << 30);
const ll LLINF (1LL << 55LL);
const int MOD = 1000000007;
const int MAX = 510000;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll n,h[100010],cnt=0,ans=0;
    cin>>n;
    rep(i,n){
        cin>>h[i];
    }
    reverse(h,h+n);
    rep(i,n-1){
        if(h[i+1]>=h[i]) cnt++;
        else cnt=0;
        ans=max(cnt,ans);
    }
    cout<<ans<<endl;
    return 0;
}

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

using namespace std;

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


Measured memory_bytes: 256
MOD = 998244353
N = int(input())
D = list(map(int, input().split()))
if D[0] != 0:
    print(0)
    exit()
D_2 = [0]*(max(D)+1)
for i in D:
    D_2[i] += 1
if D_2[0] != 1:
    print(0)
    exit()
ans = 1
for i in range(1,max(D)+1):
    ans *= D_2[i-1]**D_2[i]
    ans %= MOD
print(ans)


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

const int N = 21, MOD = 1e9+7, MASK = 1<<21;
int n, graph[N][N], dp[N][MASK];

void add_self(int& a, int b) {
  a = a + b;
  if (a >= MOD)
    a -= MOD;
}

int f(int boy, int mask) {
  if (boy >= n) return 1;
  if (dp[boy][mask] != -1) return dp[boy][mask];
  int ans = 0;
  for (int girl = 0; girl < n; girl++)
    if (graph[boy][girl] && (mask & (1<<girl)) == 0)
      add_self(ans, f(boy + 1, mask | (1<<girl)));
  return dp[boy][mask] = ans;
}

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

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

  memset(dp, -1, sizeof dp);
  printf("%d\n", f(0, 0));
  return 0;
}


Measured memory_bytes: 172288
//Papers, Please

#include <iostream>
#include <vector>
#include <math.h>
#include <string>
#include <map>
#include <stdio.h>
#include <string.h>
#include <initializer_list>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <queue>
#include <set>
using namespace std;
const int INF = 1 << 29;
int main ()
{
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    for (int i = 0; i < N; i++) {
        if (A[i] % 2 == 0) {
            if (A[i] % 3 != 0 && A[i] % 5 != 0) {
                cout << "DENIED" << endl;
                return 0;
            }
        }
    }
    cout << "APPROVED" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl "\n"
#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

int intceil(int a, int b) {
    return (a + (b - 1)) / b;
}

signed main() {
    cin >> N;
    vi p(N);
    cin >> p;
    REP(i, N) {
        if (p[i] == i + 1) {
            swap(p[i], p[i + 1]);
            ans++;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3780
#include<iostream>
#include<string>
#include<map>
using namespace std;
typedef long long ll;
const int Max = 1e5 + 5;
int lst[Max];

int main()
{
	ll n, k;
	cin >> n >> k;
	ll sum = 0, f;
	map<ll, ll> ma;
	for (int i = 1;i <= n;i++)
	{
		ll a, b;
		scanf("%lld%lld", &a, &b);
		ma[a] += b;
	}
	for (auto i = ma.begin();i != ma.end();i++)
	{
		if (sum + i->second >= k)
		{
			cout << i->first;
			break;
		}
		sum += i->second;
	}
}

Measured memory_bytes: 7156
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,n,s) for(int i = s; i < (n); ++i)
#define rsrep(i,n,s) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<x<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;


int calc(int n) {
    int res = 0;
    while (n) {
        res += n%10;
        n /= 10;
    }
    return res;
}


int main() {
    int n;
    cin >> n;
    
    int ans = INF;
    for (int i = 1; i < n; ++i) {
        ans = min(ans, calc(i)+calc(n-i));
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    private Scanner in = new Scanner(System.in);

    void solve() {
        int n = in.nextInt(); in.nextLine();
        String[] s = new String[n];
        for(int i = 0; i < n; i++) {
            s[i] = in.nextLine();
        }
        int m = in.nextInt(); in.nextLine();
        String[] t = new String[m];
        for(int i = 0; i < m; i++) {
            t[i] = in.nextLine();
        }
        int[] cnt = new int[n];
        for(int i = 0; i < n; i++) {
            int tmp = 0;
            for(int k = 0; k < n; k++){
                if(s[i].equals(s[k])) tmp++;
            }
            for(int k = 0; k < m; k++){
                if(s[i].equals(t[k])) tmp--;
            }
            cnt[i] = tmp;
        }
        int ans = 0;
        for(int i = 0; i < n; i++) {
            ans = Math.max(ans, cnt[i]);
        }
        System.out.println(ans);
    }
    public static void main(String[] args) {
        new Main().solve();
    }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
int check(int t)
{
    return t % 2 == 0; 
}

int main()
{
    int n;
    cin >> n;
    int flag = 1;
    for (int i = 0; i < n; i++)
    {
        int t;
        cin >> t;
        if (check(t))
        {
            if (t % 3 != 0 && t % 5 != 0)
            {
                flag = 0;
            }
        }
    }
    cout << (flag ? "APPROVED" : "DENIED") << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()

int main()
{
  int n;
  cin >> n;
  vector<int> v(n), sum(n);
  for(int i = 0 ; i < n ; i++){
    int a;
    cin >> a;
    v[i] = a;
    sum[i] = a;
    if(i) sum[i] += sum[i - 1];
  }
  int ans = 1e8;
  for(int i = 0 ; i < n ; i++){
    ans = min(ans, abs(sum[n - 1] - sum[i] * 2));
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
N=int(input())
S=input()
R=S.count("R")
G=S.count("G")
B=S.count("B")
count=0
for i in range(N):
    for j in range(i+1,N):
        k=2*j-i
        if k<N and S[i]!=S[j] and S[j]!=S[k] and S[k]!=S[i]:
            count+=1
print(R*G*B-count)

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

//D

int main() {
	// your code goes here
	int h,w,i,j,k,tate[2005][2005]={0},yoko[2005][2005]={0},ans=0;
	char s[2005];
	int g[2005][2005];
	cin >> h >> w;
	for(i=1;i<=h;i++){
		cin >> s;
		for(j=0;j<w;j++){
			if(s[j]=='#') g[i][j+1]=1;
			else g[i][j+1]=0;
		}
	}
	for(i=1;i<=h;i++){
		int start=0,end=-1;
		for(j=1;j<=w;j++){
			if(g[i][j]==0){
				end=j;
			} else {
				yoko[i][j]=0;
				for(k=start+1;k<=end;k++) yoko[i][k]=end-start;
				start=j;
				end=j-1;
			}
		}
		for(k=start+1;k<=end;k++) yoko[i][k]=end-start;
	}
	for(j=1;j<=w;j++){
		int start=0,end=0;
		for(i=1;i<=h;i++){
			if(g[i][j]==0){
				end=i;
			} else {
				tate[i][j]=0;
				for(k=start+1;k<=end;k++) tate[k][j]=end-start;
				start=i;
				end=i-1;
			}
		}
		for(k=start+1;k<=end;k++) tate[k][j]=end-start;
	}
	for(i=1;i<=h;i++){
		for(j=1;j<=w;j++){
			ans=max(ans,tate[i][j]+yoko[i][j]);
		}
	}
	cout << ans-1 << endl;
	return 0;
}

Measured memory_bytes: 47360
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>
#pragma GCC optimize(2)
#define ll long long
using namespace std;
void put(int x){
	if(x<0) {
		putchar('-');
		x*=-1;
	}
	if(x==0) {
		putchar('0');
	}
	int num=0;
	char c[15];
	while(x) {
		c[++num]=(x%10)+48;
		x/=10;
	}
	while(num) {
		putchar(c[num--]);
	}
	putchar('\n');
}
inline void in(int &x){
	char ch=getchar();
	int flag=1;
	while(!(ch>='0'&&ch<='9')) {
		if(ch=='-')
			flag*=-1;
		ch=getchar();
	}
	x=ch-'0';
	ch=getchar();
	while(ch>='0'&&ch<='9') {
		x=((x<<3)+(x<<1))+ch-'0';
		ch=getchar();
	}
	x*=flag;
}
int n;
int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	in(n);
	printf("%d\n",1-n);
	return 0;
}

Measured memory_bytes: 3760
#!python3

iim = lambda: map(int, input().rstrip().split())

def resolve():
    N, M = iim()
    A = list(iim())

    total = sum(A)
    M1, b = divmod(total, 4*M)
    if b == 0:
        M1 -= 1
    num = 0
    for ai in A:
        if ai > M1:
            num += 1
            if num >= M:
                print("Yes")
                return
    print("No")



if __name__ == "__main__":
    resolve()


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

using namespace std;

int main(void){

	int mem, kyogi;
	cin >> kyogi >> mem;
	int money[kyogi];
	int kijun[mem];
	int score[mem];
	//かかる費用を入力
	for(int i = 0; i < kyogi; i++){
		cin >> money[i];
	}
	//審査員の基準を入力
	for(int i = 0; i < mem; i++){
		cin >> kijun[i];
		score[i] = 0;
	}

	for(int i = 0; i < mem; i++){
		for(int j = 0; j < kyogi; j++){
			if(kijun[i] >= money[j]){
				score[j]++;
				break;
			}
		}
	}
	int log, max = 0;
	for(int i = 0; i < mem; i++){
		if(score[i] > max){
			max = score[i];
			log = i;
		}
	}
	cout << log+1 << endl;

}

Measured memory_bytes: 1172
#include <stdio.h>

int main(void) {
	int n, i, dep = 0, cnt = 0;
	char s[300000];
	
	scanf("%d", &n);
	scanf("%s", s);
	
	for (i = 0; i < n; i++)
		if (s[i] == 'W')
			dep++;
		else if (dep > 0)
			dep--, cnt++;
	
	printf("%d\n", cnt);
	
	return 0;
}

Measured memory_bytes: 512
m,d =map(int,input().split())
count = 0
for i in range(1,m+1):
    for j in range(11,d+1):
        if int(str(j)[0])> 1 and int(str(j)[-1]) > 1 and (int(str(j)[0]) * int(str(j)[-1]) == i) :
            count += 1
print (count)


Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
#include<stack>

bool sort_pair( std::pair< int64_t, int64_t > origin, std::pair< int64_t, int64_t > another )
{
    return origin.first > another.first;
}

int main()
{
    int64_t a,b,c,d;
    std::cin>> a;
    std::cin>> b;
    std::cin>> c;
    std::cin>> d;

    if( a - c == 0 )
    {
        std::cout<< 0;
    }
    else
    {
        std::cout<< 1;
    }
}


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

int main(){
    int n, ans=0;
    cin >> n;
    vector<int> b(n-1);
    rep(i,n-1) cin >> b.at(i);
    ans += b.at(0);
    ans += b.at(n-2);

    rep(i, n-2){
        ans += min(b.at(i), b.at(i+1));
    }

    cout << ans << endl;
}

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

string partsorw(bool spe[], int n, string xo){

    bool around0 = false;
    bool aroundn1 = false;
    bool shougen0 = false;
    bool shougenn1 = false;
    bool ok0 = false;
    bool okn1 = false;

    string example = "";

    for(int i = 1; i < n - 1; i++){
        if((spe[i] && xo[i] == 'o') || (!spe[i]) && xo[i] == 'x'){
            spe[i + 1] = spe[i - 1];
        } else{
            spe[i + 1] = !spe[i - 1];
        }
    }
    
    if(spe[n - 1] == spe[1])
        around0 = true;

    if (spe[n - 2] == spe[0])
        aroundn1 = true;

    if((spe[0] && xo[0] == 'o') || (!spe[0] && xo[0] == 'x'))
        shougen0 = true;

    if((spe[n - 1] && xo[n - 1] == 'o') || (!spe[n - 1] && xo[n - 1] == 'x'))
        shougenn1 = true;

    if (around0 == shougen0)
        ok0 = true;

    if (aroundn1 == shougenn1)
        okn1 = true;

    if(ok0 && okn1){
            for (int k = 0; k < n; ++k) {
                if (spe[k]) {
                    example += "S";
                } else {
                    example += "W";
                }
            }
        }

    return example;
}

string sorw(int n, string xo){
    bool speicies[n];
    string TT, TF, FT, FF;
    speicies[0] = true;
    speicies[1] = true;
    TT = partsorw(speicies, n, xo);
    speicies[0] = true;
    speicies[1] = false;
    TF = partsorw(speicies, n, xo);
    speicies[0] = false;
    speicies[1] = true;
    FT = partsorw(speicies, n, xo);
    speicies[0] = false;
    speicies[1] = false;
    FF = partsorw(speicies, n, xo);
    if (TT != ""){
        return TT;
    } else {
        if (TF != ""){
            return TF;
        } else {
            if (FT != ""){
                return FT;
            } else {
                if (FF != ""){
                    return FF;
                } else {
                    return "-1";
                }
            }
        }
    }

}

int main() {
    int N;
    string xoro;
    cin >> N >> xoro;
    string Ans = sorw(N, xoro);
    cout << Ans << endl;
    return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <vector>
#include <string>

using namespace std;
using ll = long long;

#define CIN(T, x) T x; cin >> x;
#define CINS(T, x, N) vector<T> x(N); for(int i = 0; i < (N); i++) { cin >> x.at(i); }

int main() {

    CIN(int, N);
    CIN(int, M);
    CIN(int, C);

    CINS(int, B, M);

    int count = 0;

    for (int i = 0; i < N; i++) {

        CINS(int, A, M);
        int sum = 0;

        for (int j = 0; j < M; j++) {
            sum += A.at(j) * B.at(j);
        }

        if ( sum + C > 0 ) count++;
    }

    cout << count;
    return 0;
}

Measured memory_bytes: 256