akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main(){
    int n,i1=1,i2=2,i3;
    cin >> n;
    vector<ll> a(n),s(n);
    for(int i = 0;i < n;i ++){
        cin >> a[i];
        if(!i) s[i] = a[i];
        else s[i] = s[i-1] + a[i];
    }
    ll P,Q,R,S,m,M,ans;
    P = a[0];
    Q = a[i1];
    ll sub = 1e15;
    for(int j = 3;j < n;j ++){
        if(abs((s[j-1] - s[1])-(s[n-1] - s[j-1]))<sub){
            R = s[j-1] - s[1];
            S = s[n-1] - s[j-1];
            sub = abs(R-S);
        }else{
            i3 = j-1;
            break;
        }
        i3 = j;
    }
    m = min(min(P,Q),min(R,S));
    M = max(max(P,Q),max(R,S));
    ans = M-m;
    for(int i = 2;i < n-1;i ++){
        i2 = i;
        if(abs((P+a[i1])-(Q+a[i2]-a[i1]))>abs(P-(Q+a[i2]))){
            Q += a[i2];
        }else{
            Q += a[i2];
            sub = abs(P-Q);
            while(1){
                P += a[i1];
                Q -= a[i1];
                if(abs(P-Q)<sub && Q != 0){
                    sub = abs(P-Q);
                }else{
                    P -= a[i1];Q += a[i1];
                    break;
                }
                i1 ++;
            }
        }
        if(abs((R-a[i2]+a[i3])-(S-a[i3]))>abs((R-a[i2])-S)||i3==n-1){
            R -= a[i2];
        }else{
            R -= a[i2];
            sub = abs(R-S);
            while(1){
                R += a[i3];
                S -= a[i3];
                if(abs(R-S)<sub && S != 0){
                    sub = abs(R-S);
                }else{
                    R -= a[i3];S += a[i3];
                    break;
                }
                i3 ++;
            }
        }
        m = min(min(P,Q),min(R,S));
        M = max(max(P,Q),max(R,S));
        //cout << P << "," << Q << "," << R << "," << S << endl;
        if(ans>M-m)ans = M-m;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3456
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<long long>;
using pll = pair<long long, long long>;
#define rep(i,n) for(long long i(0);(i)<(n);(i)++)


void solve(long long N, long long A, long long B){
    if(A > B) {cout << 0 << endl; return;}
    if(N == 1) {
        if(A < B)
            cout << 0 << endl;
        else
            cout << 1 << endl; 
        return;
    }
    if(N == 2) {cout << 1 << endl; return;}
    
    cout << (B-A)*(N-2)+1 << endl;

}

int main(){
    long long N;
    scanf("%lld",&N);
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    solve(N, A, B);
    return 0;
}


Measured memory_bytes: 256
#include<map>
#include <cmath>
#include <cstdio>
#include<string>
#include<iostream>

using namespace std;

#define loop(i,a,b) for(int i=(a); i<int(b);i++)
#define rep(i,b) loop(i,0,b)

double ax[1100];
double ay[1100];

double pi = acos(-1);

int main(){

    double x = 1;
    double y = 1;    

    loop(i,1,1100){
        ax[i] = x;
        ay[i] = y;
        double t = atan(y/x);
        if(x<0) t=-pi+t;
        double dx = cos(t+pi/2);
        double dy = sin(t+pi/2);
        x+=dx;
        y+=dy;
    }

    while(1){
        int x; cin >> x;
        if(x==-1) break;
        x--;
        printf("%.20lf\n%.20lf\n", ax[x], ay[x]);
    }
}

Measured memory_bytes: 1272
fun main(args: Array<String>){
    val k = readLine()
    val num = k!!.toInt()


    var sumGcd = 0
    for(a in 1..num){
        for(b in 1..num){
            for(c in 1..num){
                sumGcd += gcd(gcd(a, b), c)
            }
        }
    }
    println(sumGcd)
}

fun gcd(p: Int, q: Int) : Int{
    if(p % q == 0){
        return q
    }
    return gcd(q, p % q)
}

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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;++A)
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////

ll K,Q;
ll D[5555],Ds[5555],D2[5555],A[5555];
ll N, X, M;
ll i, j, k,ans;

void query(){
    scanf("%lld%lld%lld",&N,&X,&M);
    A[0] = 0;
    Ds[0] = 0;
    fornum(i,0,K){
        D2[i] = D[i] % M;
        Ds[i + 1] = Ds[i] + D2[i];
        A[i + 1] = A[i];
        if(D2[i]==0){
            ++A[i + 1];
        }
    }
    ll n = (N - 1) / K, m = (N - 1) % K;
    ans = N - 1;
    ans -= A[K] * n;
    ans -= A[m];
    ll nd = Ds[K] / M, ndm = Ds[K] % M;
    ans -= n * nd + (X % M + n * ndm + Ds[m]) / M;
    printf("%lld\n", ans);
}

int main(){
    scanf("%lld%lld", &K,&Q);
    fornum(i,0,K){
        scanf("%lld", &D[i]);
    }
    while(Q--)
        query();

    return 0;
}

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

int main(){
    int n,x,y;
    cin >> n >> x >> y;
    x--; y--;
    vector<int> ans(n); //1~(N-1)
  
    //スタート地点全探索
    rep(si,n){
        vector<int> dist(n, INF);
        queue<int> q;
        auto update = [&](int i,int d){
            if(dist[i] != INF) return;
            dist[i] = d;
            q.push(i);
        }; 
        update(si,0);
        while(!q.empty()){
            int i = q.front(); q.pop();
            int d = dist[i];
            if(i-1>=0) update(i-1,d+1);
            if(i+1<n) update(i+1,d+1);
            if(i==x) update(y,d+1);
            if(i==y) update(x,d+1);
        }
        rep(i,n) ans[dist[i]]++;
    }
    for(int i=1;i<n;i++){
        cout << ans[i]/2 << endl;
    }
    return 0;    
}

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

using namespace std;

int main() {

    int N;
    string f[100];
    // bool lrOnStep[2] = {false};
    bool up = true;
    int state = 0;

    while(true) {
        state = 0;
        up = true;
        int ans = 0;
        
        cin >> N;
        if(N==0) {
            break;
        }

        for(int n = 0; n < N; n++) {
            cin >> f[n];
        }

        for(int n = 0; n < N; n++) {
            if(f[n] == "lu" || f[n] == "ru") {
                state++;
            } else {
                state--;
            }
            if(up) {
                if(state == 2) {
                    up = false;
                    ans++;
                }
            } else {
                if(state == 0) {
                    up = true;
                    ans++;
                }
            }

            // if(f[n] == "lu") {
            //     if(lrOnStep[1] && flag) {
            //         ans++;
            //         flag = false;
            //     }
            // } else if(f[n] == "ru") {
            //     if(lrOnStep[0] && flag) {
            //         ans++;
            //         flag = false;
            //     }
            // } else if(f[n] == "ld") {
            //
            // } else if(f[n] == "rd") {
            // }
        }
        cout << ans << endl;
    }


    return 0;
}



Measured memory_bytes: 3156
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

using namespace std;

typedef long long ll;

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

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

int main(void) {
    int A, B, C, D, E;
    cin >> A >> B >> C >> D >> E;

    vector<int> dishes(5);
    dishes[0] = A;
    dishes[1] = B;
    dishes[2] = C;
    dishes[3] = D;
    dishes[4] = E;

    vector<int> ceils(5);
    for (int i = 0; i < 5; i++) {
        ceils[i] = ((dishes[i] + 10 - 1) / 10) * 10;
    }

    vector<int> rems(5);
    for (int i = 0; i < 5; i++) {
        rems[i] = ceils[i] - dishes[i];
    }

    int ans = 0;
    for (int i = 0; i < 5; i++) {
        ans += ceils[i];
    }
    ans -= *max_element(rems.begin(), rems.end());

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
import           Control.Monad
import qualified Data.Array.IO               as IO
import           Data.Bits
import qualified Data.ByteString.Char8       as BS
import           Data.Char
import           Data.Foldable
import           Data.Maybe
import qualified Data.Sequence               as Seq
import qualified Data.Vector.Unboxed         as V
import qualified Data.Vector.Unboxed.Mutable as VM

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine
getIntVec n = V.unfoldrN n (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine

readInteger = fst . fromJust . BS.readInteger
readIntegerList = map readInteger . BS.words
getInteger = readInteger <$> BS.getLine
getIntegerList = readIntegerList <$> BS.getLine

main = do
  n <- getInt
  let ans = sum $ map (\i -> if i `mod` 3 == 0 || i `mod` 5 == 0 then 0 else i) [1..n]
  print ans

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

int main() {
  int N,M;
  vector<string> s_N;
  vector<string> t_M;
  cin >> N;
  for(int i=0;i<N;i++){
    string A;
    cin >> A;
    s_N.push_back(A);
  }
  cin >> M;
  for(int i=0;i<M;i++){
    string A;
    cin >> A;
    t_M.push_back(A);
  }
  int c_max = 0;
  for(int i=0;i<s_N.size();i++){
    int c = 0;
    for(int j=0;j<s_N.size();j++){
      if(s_N.at(i)==s_N.at(j)){
        c++;
      }
    }
    for(int j=0;j<t_M.size();j++){
      if(s_N.at(i)==t_M.at(j)){
        c--;
      }
    }
    if(c_max <= c){
      c_max = c;
    }
  }
  cout << c_max << endl;
}


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

s = input()

i = 1
tmp = s[0]
cnt = 1
while i < len(s):
    if s[i] == tmp:
        if i == len(s) - 1:
            break
        tmp = s[i:i+2]
        i += 2
    else:
        tmp = s[i]
        i += 1

    cnt += 1

print(cnt)


Measured memory_bytes: 3500
//#pragma GCC         optimize("O3")
#include            <bits/stdc++.h>
#include            <ext/pb_ds/assoc_container.hpp>
#include            <ext/pb_ds/tree_policy.hpp>
#define FastIO      ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define pb          push_back
#define mp          make_pair
#define mem(x,i)    memset(x,i,sizeof(x))
#define ff          first
#define ss          second
#define popcount(x) __builtin_popcount(x)
#define all(x)      x.begin(),x.end()
#define Case(t)     for(int ks=1;ks<=t;ks++)
#define fileout     freopen("output.txt","w",stdout)
#define filein      freopen("input.txt","r",stdin)
#define D(x)        cerr<< __LINE__ <<": "<< #x << " = "<<(x) <<'\n';
#define endl        '\n'

using namespace std;
using namespace __gnu_pbds;

using ll  = long long;
using ld  = long double;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using pil = pair<int,ll>;

const int INF    = 0x3f3f3f3f;
const ll LL_INF  = 0x3f3f3f3f3f3f3f3f;
const double PI  = acos(-1);
const double eps = 1e-4;
const int mod    = 1e9+7;
const int mx     = 5e5+5;
template <typename T>  using orderedSet =
    tree<T, null_type, less_equal<T>,
    rb_tree_tag, tree_order_statistics_node_update>;//find_by_order,order_of_key*/

/*------------------------------Graph Moves----------------------------*/
//const int fx[]= {+1,-1,+0,+0};
//const int fy[]= {+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*---------------------------------------------------------------------*/

//ll powmod(ll a,ll b){ll res=1;a%=mod;assert(b>=0);for(; b; b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
/*----------------------BitMask-----------------------------------------*/
//inline int setBit(int N,int pos){return N=N | (1<<pos);}
//inline int resetBit(int N,int pos){return N= N & ~(1<<pos);}
//inline bool checkBit(int N,int pos){return (bool) (N& (1<<pos));}

int main()
{
    int n;
    cin>>n;
    vector<char>v;
    for(int i=0;i<n;i++)
    {
        char c;cin>>c;
        if(v.empty() || v.back()!=c) v.pb(c);
    }
    cout<<v.size()<<endl;
}


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

int main() {
  int N,M,X,Y;
  cin>>N>>M>>X>>Y;
  
  vector<int> data_x;
  vector<int> data_y;
  
  data_x.push_back(X);
  data_y.push_back(Y);
  
  for(int i=0;i<N;i++){
    int p;
    cin>>p;
    data_x.push_back(p);
  }

  for(int i=0;i<M;i++){
    int p;
    cin>>p;
    data_y.push_back(p);
  }
  
  sort(data_x.begin(),data_x.end());
  sort(data_y.begin(),data_y.end());
  
  string ans="No War";
  
  if(data_x.at(N)>=data_y.at(0)) ans="War";
  
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
typedef long long ll;
typedef long double ld;
const long long INF = 1e18;
# define len(x) ((int)(x).size())
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define foreps(i, m, n) for(int i = m;i < n;i++)
# define ALL(x) (x).begin(), (x).end()
# define rall(x) (x).rbegin(), (x).rend()
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 main() {
    string s; cin >> s;

    ll a = 0, ans = 0;
    rep(i, len(s)) {
        if (s.at(i) == 'A') {
            a = i + 1;
            break;
        }
    }

    for (int i = len(s) - 1; i > a; i--) {
        if (s.at(i) == 'Z') {
            ans = ((i + 1) - a) + 1;
            break;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3744
n = int(input())
b = [int(i) for i in input().split()]
b_list = []
for i in range (n-1):
  b_list.append([b[i],i])
b_list.sort()

a_list = []
for i in range(n):
  a_list.append("Yet")

for i in range(n-1):
  idx = b_list[i][1]
  if a_list[idx]=="Yet":
    a_list[idx]=b_list[i][0]
  if a_list[idx+1]=="Yet":
    a_list[idx+1]=b_list[i][0]

print(sum(a_list))

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        if (n > 1 || n < 0) {
            return;
        }
        if (n == 0) {
            System.out.println(1);
        } else {
            System.out.println(0);
        }
    }
}

Measured memory_bytes: 35704
#include"bits/stdc++.h"

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef pair<LL, LL> PLL;
typedef vector<PLL> VPLL;
typedef priority_queue<LL> PQ_DESC;
typedef priority_queue<LL, VL, greater<LL>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;
typedef priority_queue<VL> PQ_DESC_VL;
typedef priority_queue<VL, vector<VL>, greater<VL>> PQ_ASC_VL;
typedef priority_queue<PLL> PQ_DESC_PLL;
typedef priority_queue<PLL, vector<PLL>, greater<PLL>> PQ_ASC_PLL;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
//#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SORT_DESC(c) sort((c).rbegin(),(c).rend())
#define REV(c) reverse((c).begin(), (c).end())
#define SIZE(a) int((a).size())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ROF(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;
const LL INF_LL = (LL)INF*(LL)INF;
const int MOD = 1e9+7;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

LL modpow(LL a, LL n) {
    LL res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

void Main()
{
    int x,y;cin>>x>>y;
    cout<<(x-1)*(y-1)<<endl;
    
	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
    return 0;
}

Measured memory_bytes: 3544
#include <iostream>
#include<algorithm>
using namespace std;
int map[11][11];
int dx[] = { 0, 0, 0, 1, -1, 1, 1, -1, -1, 0, 0, 2, -2 };
int dy[] = { 0, 1, -1, 0, 0, -1, 1, 1, -1, 2, -2, 0, 0 };
int ans;
int total;
void map_make(int x, int y, int size){
	for (int i = 0; i < size * 4 + 1; i++){
		int xx = x + dx[i];
		int yy = y + dy[i];
		if (xx < 0 || xx >= 10 || yy < 0 || yy >= 10) continue;
		map[yy][xx]++;
		ans = max(ans, map[yy][xx]);
		if (map[yy][xx] == 1)total--;
	}
}
int main(){
	int x, y, size;
	char c;
	total = 10 * 10;
	while (cin >> x >> c >> y >> c >> size){
		map_make(x, y, size);
	}
	cout << total << endl;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF=1001001001;
vector<pair<int64_t,int64_t>>prime_factorize(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p; 
}
int main() {
  int N;
  cin>>N;
  vector<int64_t>a(N),b(N);
  for(int i=0;i<N;i++){
    cin>>a[i];
  }
  for(int i=0;i<N;i++){
    cin>>b[i];
  }
  int64_t cntv=0,cnto=0;
  for(int i=0;i<N;i++){
    if(a[i]>b[i]){cntv+=(a[i]-b[i]);}
    if(a[i]<b[i]){cnto+=(b[i]-a[i])/2;}
  }
  if(cnto<cntv){cout<<"No"<<endl;}
  else{cout<<"Yes"<<endl;}

  return 0;
}

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

int main(){
  int64_t n,tmp;
  cin >>n;
  int x=0;
  vector<char>ans;
  while(n){
    n--;
    int tmp1=n%26+(int)'a';
    ans.push_back((char)tmp1);
    x++;
    n/=26;
  }
  
  for(int i=x-1;i>=0;i--){
    cout <<ans.at(i);
  }
  cout <<endl;
}

Measured memory_bytes: 3608
from sys import stdin


def ind_cnv(x,y,xlim):
    return x+y*xlim


if __name__ == "__main__":
    _in = [_.rstrip() for _ in stdin.readlines()]
    W, H, N = list(map(int,_in[0].split(' ')))  # type:list(int)
    x_y_a_arr = []
    for i in range(N):
        _ = list(map(int,_in[i+1].split(' ')))  # type:list(int)
        x_y_a_arr.append(_)
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    colored = [0]*(H*W)
    for x,y,a in x_y_a_arr:
        x -= 1
        y -= 1
        if a==1:
            for _x in range(x+1):
                for _y in range(H):
                    colored[ind_cnv(_x,_y,W)] = 1
        elif a==2:
            for _x in range(x+1,W):
                for _y in range(H):
                    colored[ind_cnv(_x,_y,W)] = 1
        elif a==3:
            for _x in range(W):
                for _y in range(y+1):
                    colored[ind_cnv(_x,_y,W)] = 1
        elif a==4:
            for _x in range(W):
                for _y in range(y+1,H):
                    colored[ind_cnv(_x,_y,W)] = 1
    cnt = colored.count(0)
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(cnt)


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

using namespace std;
typedef long long ll;

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


Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define rep(n) for (int i = 0; i < (n); ++i)
int main()
{
    string s;
    cin >> s;
    bool ok = true;
    rep(s.size())
    {
        if (i % 2 == 0)
        { //奇数
            if (s[i] == 'L')
                ok = false;
        }
        else
        { //偶数
            if (s[i] == 'R')
                ok = false;
        }
    }
    if (ok)
    {
        cout << "Yes";
    }
    else
    {
        cout << "No";
    }
}

Measured memory_bytes: 256
#pragma region include
#include <stdio.h>
#include <string>
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <map>
#include <set>
#pragma endregion
using namespace std;

#pragma region 定数
#define INF_VAL (2147483647 - 1)
#define INF_VAL_MINUS -INFVAL
#pragma endregion

#pragma region マクロ
// 配列の長さを取得する(ただし関数内ではポインタサイズに注意)
#define SIZE_OF_ARRAY(array) sizeof(array) / sizeof(*array)

// for文
#define forn(i, size) for (long long(i) = 0; (i) < (size); (i)++)
#define for0(size) for (long(i) = 0; (i) < (size); (i)++)

// ソート
#define Sort(array, length) sort(array, array + length)
#define SortDESC(array, length, type_name) sort(array, array + length, std::greater<type_name>())

// 配列の最大値、最小値取得
#define MAX_OF_ARRAY(array, length) *max_element(array, array + length)
#define MIN_OF_ARRAY(array, length) *min_element(array, array + length)

// 結果出力系
#define YES                    \
    {                          \
        cout << "YES" << endl; \
        return 0;              \
    }
#define NO                    \
    {                         \
        cout << "NO" << endl; \
        return 0;             \
    }
#define Yes                    \
    {                          \
        cout << "Yes" << endl; \
        return 0;              \
    }
#define No                    \
    {                         \
        cout << "No" << endl; \
        return 0;             \
    }
#pragma endregion

#pragma region Utility
#pragma region 配列要素の合計値を取得
template <typename T>
T getSum(T array[], int length)
{
    T sum = 0;
    for (int i = 0; i < length; i++)
    {
        sum += array[i];
    }
    return sum;
}
#pragma endregion

#pragma region ToString(int)
string ToString(int i)
{
    char buffer[1000];
    sprintf(buffer, "%d", i);
    return string(buffer);
}
#pragma endregion

#pragma region 10進数からN進数(<= 10) へ変換
string convertToN(long n, int base)
{
    string ans = "";
    while (n != 0)
    {
        int temp = n % base; // 1桁取得
        ans = ToString(temp) + ans;
        n /= base;
    }
    return ans;
}
#pragma endregion
#pragma endregion

int main()
{
    // 標準入力から値を取得
    int N;
    cin >> N;

    // 入力数がN個の場合
    int P[N];
    int i = 0;
    forn (i, N)
    {
        cin >> P[i];
    }

    int ans = 0;
    int min = 30000000;
    forn(i, N)
    {
        if (P[i] <= min)
        {
            ans++;
            min = P[i];
        }
    }

    // 結果出力
    printf("%d\n", ans);
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>

#define MOD 1000000007
using ll = long long;
using namespace std;

int main() {
    int N;
    cin >> N;
    vector<int> a(N);
    for (int i = 0; i < N; i++)
    {
        cin >> a[i];
    }
    sort(a.rbegin(), a.rend());
    int A = 0, B = 0;
    for (int i = 0; i < N; i++)
    {
        if (i % 2 == 0) {
            A += a[i];
        }
        else {
            B += a[i];
        }
    }
    cout << A - B << endl;
    return 0;
}

Measured memory_bytes: 256
#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>
#include <cstdlib>
#include <iomanip>
#define rep(i,x) for(ll i=0;i<x;i++)
#define all(a) (a).begin(),(a).end()
using namespace std;
using ld = long double;
using ll = long long;
const ll INF = 10010010010;
typedef pair<ll, ll> P;
using graph = vector<vector<ll>>;
const ll mod = 1000000007;
ll gcd(ll a, ll b) {//a>b
    if (a < b)swap(a, b);
    if (a % b == 0) return b;
    else return gcd(b, a % b);
}/*フィボナッチテンプレ
ll memo[50];
ll fibo(ll n) {
    if (memo[n] != 0)return memo[n];
    if (n <= 1)return memo[n] = n;
    else return memo[n] = fibo(n - 1) + fibo(n - 2);
}
*/
bool isp(ll n) {
    bool res = true;
    for (ll i = 2; i * i <= n; i++) {
        if (n % i == 0) {
            res = false;
            break;
        }
    }
    return res;
}
int main() {
    ll N;
    cin >> N;
    map<ll, ll> num;
    ll n;
    rep(i, N) {
        cin >> n;
        num[n]++;
    }
    bool ans = true;
    ll size = num.size();
    if (N % 2 == 0) {
        rep(i, size) {
            if (num[i * 2 + 1] != 2)ans = false;
        }
    }
    else {
        rep(i, size) {
            if (i == 0) {
                if (num[0] != 1)ans = false;
            }
            else if (num[i * 2] != 2)ans = false;
        }
    }
    if (ans) {
        ll cnt = 1;
        ll kai = N / 2;
        rep(i, kai) {
            cnt *= 2;
            cnt %= mod;
        }
        cout << cnt << endl;
    }
    else cout << "0" << endl;
}

Measured memory_bytes: 6144
def ans(p,q):
    p=p%q
    _q=q

    mods=[p%q]
    score=""
    while True:
        p*=10
        score+=str(p//q)
        p=p%q
        if p in mods:
            break
        else:
            mods.append(p)

    mods=[]
    score2=""
    while True:
        p*=10
        score2+=str(p//q)
        p=p%q
        if p in mods:
            break
        else:
            mods.append(p)
    score2=score2[:-1]
    if score2=="0":
        ans=score[:-1]
    else:
        ans="{0}\n{1}"
        padding=" "*(len(score)-len(score2))+"^"*len(score2)
        ans=ans.format(score,padding)
    return ans


while True:
    try:
        p,q=[int(i) for i in input().split(" ")]
        print(ans(p,q))
    except EOFError:
        break



Measured memory_bytes: 5608
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		while(true){
			int n = stdIn.nextInt();
			if(n==0){
				return;
			}
			int[][] d = new int[n][4];
			for(int i=0;i<n;i++){
				for(int j=0;j<4;j++){
					d[i][j] = stdIn.nextInt();
				}
			}
			// sort
			for(int i=0;i<n;i++){
				int max = i;
				for(int j=i+1;j<n;j++){
					if(d[max][2]<d[j][2]){
						max = j;
					}
				}
				for(int j=0;j<4;j++){
					int tmp = d[i][j];
					d[i][j] = d[max][j];
					d[max][j] = tmp;
				}
			}
			for(int i=0;i<n;i++){
				int max = i;
				for(int j=i+1;j<n;j++){
					if(d[max][2]==d[j][2]&&d[max][3]>d[j][3]){
						max = j;
					}
				}
				for(int j=0;j<4;j++){
					int tmp = d[i][j];
					d[i][j] = d[max][j];
					d[max][j] = tmp;
				}
			}
			for(int i=0;i<n;i++){
				int max = i;
				for(int j=i+1;j<n;j++){
					if(d[max][2]==d[j][2]&&d[max][3]==d[j][3]&&d[max][0]>d[j][0]){
						max = j;
					}
				}
				for(int j=0;j<4;j++){
					int tmp = d[i][j];
					d[i][j] = d[max][j];
					d[max][j] = tmp;
				}
			}
			int pass = 0;
			for(int i=0;i<n;i++){
				if(pass<10){
					int my = 0;
					for(int j=0;j<i;j++){
						if(d[i][1]==d[j][1]){
							my++;
						}
					}
					if(my<3){
						pass++;
						System.out.println(d[i][0]);
					}
				}
				else if(pass<20){
					int my = 0;
					for(int j=0;j<i;j++){
						if(d[i][1]==d[j][1]){
							my++;
						}
					}
					if(my<2){
						pass++;
						System.out.println(d[i][0]);
					}
				}
				else if(pass<26){
					int my = 0;
					for(int j=0;j<i;j++){
						if(d[i][1]==d[j][1]){
							my++;
						}
					}
					if(my==0){
						pass++;
						System.out.println(d[i][0]);
					}
				}
			}
		}
	}
}

Measured memory_bytes: 12000
S = input()
ABC = [0 for i in range(26)]
for i in S:
    ABC[ord(i)-97] += 1
flag = 0
for i in range(26):
    if ABC[i] == 0 and flag == 0:
        print(chr(i+97))
        flag = 1
if flag == 0:
    print("None")


Measured memory_bytes: 3188
import collections

n = int(input())

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

if n == 1: # 1
    print(0)
    exit()

c = collections.Counter(prime_factorize(n))
counts = c.values()
ans = 0

for i in counts:
    x = 0
    for j in range(i):
        x += j + 1
        if i >= x:
            ans += 1
        else:
            break

print(ans)


Measured memory_bytes: 9464
// abc.cpp : 此檔案包含 'main' 函式。程式會於該處開始執行及結束執行。
//

#include <iostream>

int main()
{
	int a, b, c,d[3];
	char we[3];
	d[0] = 0;
	d[1] = 0;
	d[2] = 0;
	b = 0;
	
	
	for (a = 0; a < 3; a++) {
		scanf("%c", &we[a]);
		if (we[a] == 'R') {
			d[a]=1;
			b++;
		}
	}
	if (b == 0) {
		printf("0");
	}
	else if (b == 1) {
		printf("1");
	}
	else if (b == 2) {
		if ((d[0] == 1) && (d[2] == 1)) {
			printf("1");
		}
		else {
			printf("2");
		}
	}
	else {
		printf("3");
	}
	return 0;
}

// 執行程式: Ctrl + F5 或 [偵錯] > [啟動但不偵錯] 功能表
// 偵錯程式: F5 或 [偵錯] > [啟動偵錯] 功能表

// 開始使用的提示: 
//   1. 使用 [方案總管] 視窗，新增/管理檔案
//   2. 使用 [Team Explorer] 視窗，連線到原始檔控制
//   3. 使用 [輸出] 視窗，參閱組建輸出與其他訊息
//   4. 使用 [錯誤清單] 視窗，檢視錯誤
//   5. 前往 [專案] > [新增項目]，建立新的程式碼檔案，或是前往 [專案] > [新增現有項目]，將現有程式碼檔案新增至專案
//   6. 之後要再次開啟此專案時，請前往 [檔案] > [開啟] > [專案]，然後選取 .sln 檔案


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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;

#define INF (1LL << 60)
#define MOD 1000000007

#define REP(i,m,n) for(ll (i)=(m),i_len=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define pb push_back
#define mp make_pair

int main()
{
    ll K, N;
    cin >> K >> N;
    vec A(N);
    REP(i,0,N) cin >> A[i];
    
    vec D(N);
    REP(i,0,N-1) D[i] = A[i+1] - A[i];
    D[N-1] = A[0] + K - A[N-1];
    ll m = INF;
    REP(i,0,N) m = MIN(m,K-D[i]);
    PR(m);

    return 0;
}

/*



*/

Measured memory_bytes: 3328
from itertools import permutations as perm
from collections import deque, Counter as cnt
from collections import defaultdict as dd
from operator import itemgetter as ig
from bisect import bisect_right as bsr
from math import factorial, ceil, floor
import sys
sys.setrecursionlimit(1000000)

# お約束
args = None
INF = float("inf")
MOD = int(1e9 + 7)


def input(*ps):
    if type(ps[0]) is list:
        return [input(*ps[0][:-1]) for _ in range(ps[0][-1])]
    elif len(ps) == 1:
        return ps[0](next(args))
    else:
        return [p(next(args)) for p in ps]


def nlist(n, v):
    if not n:
        return [] if type(v) is list else v
    return [nlist(n[1:], v) for _ in range(n[0])]


def yesno(v, yes="Yes", no="No", upper=False):
    if upper:
        print([yes.upper(), no.upper()][not v])
    else:
        print([yes, no][not v])


def main():
    """エントリーポイント"""
    A, B = input([int, 2])
    print(({1, 2, 3} - {A, B}).pop())


if __name__ == '__main__':
    args = iter(sys.stdin.read().split())
    main()


Measured memory_bytes: 3444
#include<bits/stdc++.h>
#define int long long
#define vi vector<int>
#define pb push_back
#define log(x,b) (log(b)/log(x))
#define rep(i,x,y) for(int i=(x);i<(y);i++)
using namespace std;


int32_t main()
{
    int n,m;
    cin>>n>>m;
    string s[n],t[n];
    for(int i=0;i<n;i++){
        cin>>s[i];
    }
    for(int i=0;i<m;i++){
        cin>>t[i];
    }
    rep(i,0,n-m+1)rep(j,0,n-m+1){
        bool flg=1;
        rep(h,0,m)rep(w,0,m){
            if(s[i+h][j+w]!=t[h][w])flg=0;
        }
        if(flg){
            cout<<"Yes\n";
            return 0;
        }
    }
    cout<<"No\n";

    return 0;
}


Measured memory_bytes: 3608
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.Collections;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */

public class Main {
    public static void main(String[] args) {
        InputStream    inputStream    = System.in;
        OutputStream outputStream = System.out;
        InputReader    in                      = new InputReader(inputStream);
        PrintWriter      out                    = new PrintWriter(outputStream);
        Task                 solver               = new Task();
        solver.solve(1, in, out);
        out.close();
    }

    static class Task {
    	public void solve(int testNumber, InputReader in, PrintWriter out) {
    		double a = in.nextInt();
    		double b = in.nextInt();
    		out.println(Math.round((a + b) / 2));
    	}
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



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

int main(void)
{
  int n;
  cin >> n;
  unsigned int st = 0;
  for (int i = 0; i < n; i++)
  {
    char parentheses;
    int p_num;
    cin >> parentheses >> p_num;
    if (parentheses == '(')
    {
      st += p_num;
    }
    else
    {
      if (st < p_num)
      {
        cout << "NO" << endl;
        return 0;
      }
      else
      {
        st -= p_num;
      }
    }
  }
  if (st == 0)
  {
    cout << "YES" << endl;
  }
  else
  {
    cout << "NO" << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
<?php
list($n, $m) = ints();
for ($i = 0; $i < $m; ++$i) {
    list($u, $v) = ints();
    --$u;
    --$v;
    for ($j = 0; $j < 3; ++$j) {
        $from = $u * 3 + $j;
        $to = $v * 3 + ($j + 1) % 3;
        $g[$from][] = $to;
    }
}
list($s, $t) = ints();
--$s;
--$t;
$s *= 3;
$t *= 3;
// BFS（幅優先探索）：最短経路アルゴリズムとして活用
$q = new SplQueue(); // キューを用意
$dist = array_fill(0, 3 * $n, -1); // 距離を格納する配列（-1の場合はその頂点が未発見）

$dist[$s] = 0; // 始点からの距離格納配列
$q->enqueue($s); // キューに始点を追加

while (!$q->isEmpty()) {
    $v = $q->dequeue();
    if (!isset($g[$v])) continue;
    foreach ($g[$v] as $next_v) {
        if ($dist[$next_v] !== -1) continue; // 発見済み

        $dist[$next_v] = $dist[$v] + 1;
        $q->enqueue($next_v);
    }
}
echo $dist[$t] !== -1 ? $dist[$t] / 3 : -1;
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}


Measured memory_bytes: 145036
#include<bits/stdc++.h>
//#pragma GCC optimize("O3")
//#pragma GCC target ("sse4")
using namespace std;
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define MEM(x,a) memset((x),a,sizeof((x)))
#define F first
#define S second
#define imx INT_MAX
const long long MOD = (long long)(1e9+7);
const long long MMX = (long long)(1e18);
typedef long long LL;
typedef pair<int,int> pii;
int n,ans=imx;
int main()
{
    scanf("%d",&n);
    for(int i=1;i<1000;i++)
    {
        if((360*i)%n==0)
        {
            ans=min(ans,(360*i)/n);
        }
    }
    printf("%d",ans);
}


Measured memory_bytes: 3820
N=io.read"*n"
D=io.read"*n"
X,Y={},{}
for i=1,N do
X[i]=io.read"*n"
Y[i]=io.read"*n"
end
c=0

for i=1,N do
	if(X[i]*X[i]+Y[i]*Y[i]<=D*D)then c=c+1 end
end

print(c)

Measured memory_bytes: 6804
N=int(input())
A=list(map(int, input().split()))
B=[]
B.append(A[0])
for i in range(1,N):
    if A[i]!=B[-1]: B.append(A[i])
i=1
length=len(B)
while i<length-1:
    if B[i]>B[i-1] and B[i]<B[i+1] or B[i]<B[i-1] and B[i]>B[i+1]:
        B.pop(i)
        length-=1
    else:
        i+=1
yen=1000
kabu=0
for i in range(len(B)):
    if len(B)>=2 and B[0]<B[1]:
        if i%2==0 and i<len(B)-1:
            kabu=yen//B[i]
            yen=yen%B[i]
        elif i%2==1:
            yen=yen+kabu*B[i]
    else:
        if i%2==1 and i<len(B)-1:
            kabu=yen//B[i]
            yen=yen%B[i]
        elif i%2==0:
            yen=yen+kabu*B[i]
print(yen)

Measured memory_bytes: 61988
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include <numeric>
#include<map>
#include<unordered_map>
#include <queue>
 
using namespace std;
using ll=long long;
#define rep(i,n)  for(ll i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()
 
int main(){
    string s;
    cin >> s;
    vector<ll> cnt(3, 0);
    rep(i, s.size()){ 
        cnt[s[i]-'a']++;
    }
    sort(ALL(cnt), greater<ll>());
    // cout << cnt[0] << " & " << cnt[1] << " & " << cnt[2] << endl;
    if(cnt[0]==cnt[1]&&cnt[0]-cnt[2]<=1)cout << "YES\n";
    else if(cnt[1]==cnt[2]&&cnt[0]-cnt[1]<=1)cout << "YES\n";
    else cout << "NO\n";
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define ld long double
const int nax=1e5+5;
pair<int,int> arr[nax];
vector<vector<pair<int,pair<int,ll>>>> v(nax);
int vis[nax]={0};
vector<map<int,map<int,int>>> pre(nax);
int level[nax];
int parent[nax];
int dp[nax][20];
struct s{
	int a,b,c,d;
};
int find(int x, int d){
	for(int i=19;i>=0;i--){
		if(d < (1<<i)) continue;
		x=dp[x][i];
		d-=(1<<i);
	}
	return x;
}
void dfs(int ci, int l){
	vis[ci]=1;
	level[ci]=l;
	if(l==0) parent[ci]=ci;
	for(auto x : v[ci]){
		if(vis[x.first]==1) continue;
		parent[x.first]=ci;
		dfs(x.first,l+1);
	}
}
int lca(int a, int b){
	int p=a; int q=b;
	if(level[a] > level[b]){
		p=b; q=a;
	}
	q=find(q,abs(level[a]-level[b]));
	if(p==q) return p;
	for(int i=19;i>=0;i--){
		if(dp[p][i]==dp[q][i]) continue;
		p=dp[p][i];
		q=dp[q][i];
	}
	return dp[p][0];
}
void dfs1(int ci, int sum, int col, int val){
	vis[ci]=1;
	for(auto x : pre[ci]){
		for(auto y: x.second){
			pre[ci][x.first][y.first]=sum-(ll)arr[x.first].second+arr[x.first].first*y.first;
		}
	}
	for(auto x : v[ci]){
		if(vis[x.first]==1) continue;
		arr[x.second.first].first++;
		arr[x.second.first].second+=x.second.second;
		dfs1(x.first,sum+x.second.second,x.second.first,x.second.second);
	}
	if(col != -1){
		arr[col].first--;
		arr[col].second-=val;
	}
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	int n,q;
	cin>>n>>q;
	for(int i=0;i<n-1;i++){
		int a,b,c,d;
		cin>>a>>b>>c>>d;
		a--; b--; c--;
		v[a].push_back({b,{c,d}});
		v[b].push_back({a,{c,d}});
		arr[i]={0,0};
	}

	dfs(0,0);
	for(int i=0;i<n;i++){
		vis[i]=0;
		dp[i][0]=parent[i];
	}
	for(int j=1;j<20;j++){
		for(int i=0;i<n;i++) dp[i][j]=dp[dp[i][j-1]][j-1];
	}
	vector
 query;
	for(int i=0;i<q;i++){
		int a,b,c,d;
		cin>>a>>b>>c>>d;
		a--; c--; d--;
		query.push_back({a,b,c,d});
		pre[c][a][b]=0;
		pre[d][a][b]=0;
		pre[lca(c,d)][a][b]=0;
	}
	dfs1(0,0,-1,-1);
	for(auto x : query){
		cout<<pre[x.c][x.a][x.b]+pre[x.d][x.a][x.b]-2*pre[lca(x.c,x.d)][x.a][x.b]<<"\n";
	}
}


Measured memory_bytes: 69808
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
using namespace std;

const int MOD = 998244353;

int add(int x, int y) {return (x+y) % MOD;}
int mul(int x, int y) {return (x*1ll*y) % MOD;}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int n, s;
	cin >> n >> s;
	int a[n];
	for (int i=0; i<n; i++) cin >> a[i];
	int dp[n+1][s+1];
	memset(dp, 0, sizeof(dp));
	dp[0][0] = 1;
	for (int i=0; i<n; i++) {
		for (int j=0; j<=s; j++) {
			dp[i+1][j] = add(dp[i+1][j], mul(2, dp[i][j]));
			if (j + a[i] <= s) dp[i+1][j + a[i]] = add(dp[i+1][j + a[i]], dp[i][j]);
		}
	}
	cout << dp[n][s];
}

Measured memory_bytes: 38808
use std::fs;
use std::io::{stdin, Read};

macro_rules! parse {
    ($it: ident) => {
        $it.next().unwrap().parse().unwrap()
    };
    ($it: ident,2) => {
        (parse!($it), parse!($it))
    };
    ($it: ident,3) => {
        (parse!($it), parse!($it), parse!($it))
    };
    ($it: ident,4) => {
        (parse!($it), parse!($it), parse!($it), parse!($it))
    };
    ($it: ident, $n: expr) => {
        (&mut $it).take($n).map(|e| e.parse().unwrap()).collect();
    };
}

fn solve(s: &str) {
    let mut it = s.split_whitespace();
    let n: usize = parse!(it);
    let s: Vec<Vec<_>> = (0..n)
        .map(|_| it.next().unwrap().chars().collect::<Vec<char>>())
        .collect();
    let getmod = |x| if x < 0 { x % n + n } else { x % n };
    let mut ret = 0;
    for i in 0..n {
        let mut flag = true;
        for j in 0..n {
            for k in 0..n {
                if s[j][getmod(i + j + k)] != s[(j + k) % n][(i + j) % n] {
                    flag = false;
                }
            }
        }
        if flag {
            ret += n;
        }
    }
    println!("{}", ret);
}

fn main() {
    let mut s = String::new();
    stdin().read_to_string(&mut s).unwrap();
    solve(&s);
}

#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn test_input() {
        let s = "
        ";
        solve(s);
    }
}


Measured memory_bytes: 4352
import java.util.*;

public class Main {
  public static void main(String[] args) {
    @SuppressWarnings("resource")
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int L = sc.nextInt();
    String[] S = new String[N];
    for (int i = 0; i < N; i++) {
      S[i] = sc.next();
    }

    Arrays.sort(S);
    StringBuilder sb = new StringBuilder();
    for (String s : S) {
      sb.append(s);
    }

    System.out.println(sb.toString());
  }
}

Measured memory_bytes: 23892
n,m = map(int,input().split())
l = [list(map(int,input().split())) for _ in range(m)]
g = {}
for i in range(1,n+1):
    g[i] = []
for x,y,z in l:
    g[x].append(y)
    g[y].append(x)

def connected_components(graph):
    seen = set()
    def component(n):
        nodes = set([n])
        while nodes:
            n = nodes.pop()
            seen.add(n)
            nodes |= set(graph[n]) - seen
            yield n
    for n in graph:
        if n not in seen:
            yield component(n)

def print_gen(gen):
    a = [list(x) for x in gen]
    print(len(a))

print_gen(connected_components(g))

Measured memory_bytes: 67532
N,A,B=map(int,input().split())
if abs(A-B)%2==0:
  print(abs(A-B)//2)
else:
  ans=0
  touch=min(min(A,B)-1,N-max(A,B))
  ans+=touch
  ans+=1
  if (abs(A-B)-1)>0:
    ans+=(abs(A-B)-1)//2
  print(ans)


Measured memory_bytes: 3060
from fractions import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import accumulate, product, permutations, combinations

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

    res = 0

    for i in range(N+1):
        res += i
    
    print(res)

if __name__ == '__main__':
    main()

Measured memory_bytes: 10368
from math import ceil
from math import floor
import itertools

s = input()
n = len(s)
t = []

def output(r_cnt, l_cnt):
    global t
    r_num = ceil(r_cnt/2) + floor(l_cnt/2)
    l_num = ceil(l_cnt/2) + floor(r_cnt/2)
    x = [0 for _ in range(r_cnt + l_cnt)]
    x[r_cnt-1] = r_num
    x[r_cnt] = l_num
    t.append(x)


r_cnt = 0
l_cnt = 0
for i in range(n-1):
    if s[i] == 'R':
        r_cnt += 1
    elif s[i] == 'L':
        l_cnt += 1
    if s[i] == 'L' and s[i+1] =='R' or i == n-2:
        if i == n-2:
            l_cnt += 1
        output(r_cnt, l_cnt)
        r_cnt = 0
        l_cnt = 0


t = list(itertools.chain.from_iterable(t))
for i in t:
    print(i, end=' ')

Measured memory_bytes: 9972
#include<iostream>
#include<cstdlib>
#include <cmath>
#include<algorithm>
#include<vector>
#include<string>
#include<unordered_map>
#include <bits/stdc++.h>
using namespace std;

int main()
{      
    int N;
    cin >> N;
    
    int ans = 1000 - N % 1000;
    if(ans == 1000){
        cout << 0 << endl;    
    }
    else{
        cout << 1000 - N % 1000 << endl;
    }
}


Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
stack<int> sta;
int i;
string s;
int ret(char op){
    int a2=sta.top();
    sta.pop();
    int a1=sta.top();
    sta.pop();
    if(s[i]=='+'){
        return a1+a2;
    }
    else if(s[i]=='-'){
        return a1-a2;
    }
    else return a1*a2;
}
int main(){
    getline(cin,s);
    int tmp=0;
    for(i=0;i<s.size();i++){
        if(s[i]==' ' && tmp!=0){
            sta.push(tmp);
            //cout<<" "<<tmp<<endl;
            tmp=0;
        }
        if(s[i]=='+' || s[i]=='-' || s[i]=='*'){
            sta.push(ret(s[i]));
            tmp=0;
        }
        for(char j='0';j<='9';j++){
            if(s[i]==j){
                int a=j-'0';
                tmp*=10;
                tmp+=a;
                //cout<<tmp<<" "<<a<<endl;
            }
        }
    }
    cout<<sta.top()<<endl;
    return 0;
}




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

int solve(int n){
	int ans = 0;

	do{
		ans += (n%10);
		n /= 10;
	}while(n);

	return ans == 1 ? 10 : ans;
}

int main(){
	int n;

	cin>>n;

	auto ans = solve(n);

	cout<<ans<<'\n';

	return 0;
}

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

int main(){

int A, B, C;
cin >> A >> B >> C;

int x = min (A, B);
int y = max (A, B);

    if(x < C && C < y){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;

    }

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/

int N;
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N;

    if ('A' <= N and N <= 'Z') cout << 1 << endl;
    else if ('a' <= N and N <= 'z') cout << 2 << endl;
    else cout << 0 << endl;
}



Measured memory_bytes: 3104