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

#define int long long int
#define ff first
#define ss second
#define pb push_back
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const int mod = 1e9 + 7;
const int cmod = 998244353;
const int N = 3e5 + 5;
const int inf = 1e18 + 2;


void solve(int Case) {
    int n , x , m ;
    cin >> n >> x >> m ;
    set<int> M ;
    M.insert(x) ;
    vector<int> v , s;
    v.push_back(x) ;
    int idx = 0;
    while(true) {
        int t = (x * x) % m ;
        if(M.find(t) != M.end()) {
            //cout << x << '\n';
            for(int i = 0 ; i < v.size() ; i ++) {
                if(v[i] == t) {
                    idx = i ;
                    break;
                }
            }
            for(int i = idx ; i < v.size() ;i ++) s.push_back(v[i]);
            break;
        }
        x = t ;
        v.push_back(t);
        M.insert(t) ;
    }
    int sz = 0 , ans = 0 ,sum = 0;
    for(int i = 0 ; i < v.size() ; i ++) {
        sz ++ ;
        sum += v[i] ;
        if(sz == n) {
            cout << sum << '\n';
            return;
        }
    }
    n -= sz ;
    ans += sum ;
    sz = 0;
    sum = 0;
    vector<int> p ;
    for(int i = 0 ; i < s.size() ; i ++) {
        sz ++ ;
        sum += s[i] ;
        if(sz == n) {
            cout << ans + sum << '\n';
            return ;
        }
        p.push_back(sum) ;
    }
    ans += (sum * (n / sz)) + ((n % sz) ? p[(n % sz) - 1] : 0) ;
    cout << ans << '\n';
}
/*
 */

int32_t main()
{
    fastio
    int testcase = 1;
    //cin >> testcase;
    int Case = 1;
    while(testcase --) {
        solve(Case);
    }
    return 0;
}


Measured memory_bytes: 6860
#include<bits/stdc++.h>
using namespace std;
const long long inf=1e9+7;
int n;
long long a[200005];
long long lsum[200005];
int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	for(int i=n;i>=1;i--){
		lsum[i]=a[i]+lsum[i+1];
		lsum[i]%=inf;
	}
	long long ans=0;
	for(int i=1;i<=n;i++){
		ans+=a[i]*lsum[i+1];
		ans%=inf;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 6772
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"

using namespace std;

const int MOD = 1000000007;
//const int MOD = 998244353;

//long long int N, M, K, H, W, L, R;
int N, M, K, H, W, L, R;

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

	cin >> N >> M;
	cout << N + M / 2 << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

#define NIL -1
#define N 25

typedef struct node {
	int p,l,r;
} Node;

Node T[N];

void printPre(u) {
	if (u == NIL) return;
	printf(" %d",u);
	printPre(T[u].l);
	printPre(T[u].r);

	return;
}

void printIn(u) {
	if (u == NIL) return;
	printIn(T[u].l);
	printf(" %d",u);
	printIn(T[u].r);

	return;
}

void printPo(u) {
	if (u == NIL) return;
	printPo(T[u].l);
	printPo(T[u].r);
	printf(" %d",u);

	return;
}

int main() {
	int i,n;
	int id, root,l,r;

	scanf("%d", &n);

    for (i = 0; i < n; i++)
        T[i].p = NIL;
    for (i = 0; i < n; i++) {
        scanf("%d %d %d",&id,&l,&r);
        T[id].l = l;
        T[id].r = r;
        if (l != NIL) T[l].p = id;
        if (r != NIL) T[r].p = id;
    }

	for (i = 0; i < n;i++) {
		if (T[i].p == NIL) {
			root = i;
			break;
		}
	}

	printf("Preorder\n");
	printPre(root);
	printf("\nInorder\n");
	printIn(root);
	printf("\nPostorder\n");
	printPo(root);
	printf("\n");

	return 0;
}

Measured memory_bytes: 616
(let ((n (read))
      (a (make-array 1 :element-type 'integer
                       :initial-element 0
                       :adjustable t
                       :fill-pointer 1))
      (ans 100000)
      temp)
     (dotimes (i n)
       (vector-push-extend (+ (aref a i) (read)) a))
     (dotimes (i n)
       (setf ans (min ans (abs (- (aref a n) (* 2 (aref a i)))))))
     (princ ans))


Measured memory_bytes: 16104
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    int n,k;
    cin >> n >> k;
    vector<int>snuke(n+1);
    int answer = 0;
    REP(i,n+1)snuke[i]=0;
    REP(i,k){
        int d;
        cin >> d;
        REP(j,d){
            int a;
            cin >> a;
            snuke[a]++;
        }
    }
    FOR(i,1,n+1)if(snuke[i]==0)answer++;
    cout << answer << endl;
    return 0;
}

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

int main(void){
    int a=0 ,i=0,j=0;
    bool flag = true;
    scanf("%d",&a);
    int *c;        /* 割り振られた領域のアドレスを格納するためのint型のポインタipを宣言 */
        c = (int *)malloc(a * sizeof(int));  /* メモリ領域の確保 */

    for(i=0;i<a;i++){
        scanf("%d",&c[i]);
    }
    
    int count = 0;
    flag = true;
    int min = c[0];
    for(i=0;i<a;i++){
        flag = true;
        //前回値のminと比べる
        if(c[i]>min){
            //flag = false;
            continue;                
        }
        min = c[i];
        count += 1;
        /*
        //i番目の数より前の数字にそれより大きいものがないか確認する
        for(j=0;j<=i;j++){
            if(c[i]>c[j]){
                flag = false;
                break;
            }
        }
        
        if(flag){
            count += 1;
        }
        */
    }
    printf("%d",count);
    free(c);
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
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; }
// template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

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

int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, m, k; cin >> n >> m >> k;
    vector<ll> a(n); rep (i, n) cin >> a[i];
    vector<ll> b(m); rep (i, m) cin >> b[i];
    vector<ll> sum_a(n + 1), sum_b(m + 1);
    rep (i, n) sum_a[i + 1] = sum_a[i] + a[i];
    rep (i, m) sum_b[i + 1] = sum_b[i] + b[i];
    ll ok = -1, ng = n + m + 1;
    while (ng - ok > 1) {
        int med = (ng + ok) / 2;
        bool okk = false;
        rep (i, med + 1) {
            int j = med - i;
            if (i > n || j > m) continue;
            if (sum_a[i] + sum_b[j] <= k) okk = true;
        }
        if (okk) ok = med;
        else ng = med;
    }
    cout << ok << "\n";
    return 0;
}

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

typedef long long int ll;
typedef pair<ll, ll> P;

const ll mod = 1e9+7;
const ll INF = 2e9;
const double PI = 3.1415926535;

ll p[51];

int main(void){
    ll n; cin >> n;
    ll c = 0;
    for(ll i = 1;i <= n;i++){
        ll p;
        cin >> p;
        if(p != i)c++;
    }
    if(c < 3)printf("YES\n");
    else printf("NO\n");
	return 0;
}

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

using namespace std;

int ans[26];

int main(){
  for(int i=0;i<26;i++)ans[i] = 50000;
  int n; cin >> n;
  for(int i=0;i<n;i++){
    string s; cin >> s;
    map<int, int> freq;
    for(int i=0;i<s.length();i++) freq[s[i]-'a'] += 1;
    for(int i=0;i<26;i++){
      ans[i] = min(ans[i], freq[i]);
    }
  }
  for(int i=0;i<26;i++){
    for(int e=0;e<ans[i];e++){
      cout << (char)('a' + i);
    }
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <utility>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <cmath>

#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define itrep(i,x) for(auto i=(x).begin(); i!=(x).end();i++)
#define Sort(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define vec vector
#define INF (int)1e9
#define INFL 1e18
#define MOD 1000000007
#define pb push_back
#define MP make_pair
#define PI 3.1415926535
typedef long long int ll;
typedef std::pair<int,int> P;
int D=1;
int dx[4]={0,1,0,-1},dy[4]={-1,0,1,0};

using namespace std;

int main(){
    string a,b,c;
    cin>>a>>b>>c;
    if(a[a.size()-1]==b[0]&&b[b.size()-1]==c[0])cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    
    return 0;
}

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

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int x, a, b;
    cin >> x >> a >> b;
    if (b - a <= 0) {
        cout << "delicious" << '\n';
    } else if (b - a <= x) {
        cout << "safe" << '\n';
    } else {
        cout << "dangerous" << '\n';
    }
    return 0;
}


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

using namespace std;

int main(){
    long long int n,w;
    cin>>n>>w;

    int v[n+1][100005];

    int data[n+1][3];

    for(int i=1; i <=n; i ++){
        cin>>data[i][1]>>data[i][2];
    }

    v[1][data[1][2]]=data[1][1];

    for(int i=0; i <=n; i ++){
        for(int j=1; j <=100004; j ++){
            v[i][j]=-1;
        }
    }
    
    v[1][data[1][2]]=data[1][1];
    
    for(int i=2; i <=n; i ++){
        for(int j=1; j <=100004; j ++){
            long long int a = INT_MAX,b=INT_MAX;
            if(v[i-1][j]!=-1)a=v[i-1][j];
            if(j>=data[i][2] && v[i-1][j-data[i][2]]!=-1)b=v[i-1][j-data[i][2]] + data[i][1];
            
            if(a==INT_MAX && b==INT_MAX)v[i][j]=-1;
            else {
               
                long long int c = min(a,b);
                if(c<=w)v[i][j]=c;
                else v[i][j] = -1;
                
            }
            
            
        }
    }
    
    // for(int i=1; i <=n; i ++){
    //     for(int j=0; j <=100; j +=10){
    //         cout<<v[i][j]<<" ";
    //     }
    //     cout<<endl;
    // }
    
    for(int j=100004; j >=0; j --){
        if(v[n][j]!=-1){
            cout<<j<<endl;
            return 0;
        }
    }
    


}

Measured memory_bytes: 39680
#include <cstdio>

template<typename _T>
void read( _T &x )
{
	x = 0;char s = getchar();int f = 1;
	while( s > '9' || s < '0' ){if( s == '-' ) f = -1; s = getchar();}
	while( s >= '0' && s <= '9' ){x = ( x << 3 ) + ( x << 1 ) + ( s - '0' ), s = getchar();}
	x *= f;
}

template<typename _T>
void write( _T x )
{
	if( x < 0 ){ putchar( '-' ); x = ( ~ x ) + 1; }
	if( 9 < x ){ write( x / 10 ); }
	putchar( x % 10 + '0' );
}

int K, A, B;

int main()
{
	read( K ), read( A ), read( B );
	if( A % K == 0 || B % K == 0 ) { puts( "OK" ); return 0; }
	if( A / K == B / K ) { puts( "NG" ); return 0; }
	puts( "OK" );
	return 0;
}

Measured memory_bytes: 1456
#include <stdio.h>
int main()
{
  int i, n;
  char ch;
 n = 'A'-'a';
 while(1){
   scanf("%c",&ch);
   if('a' <= ch && ch <= 'z'){
     ch += n;
   } else if('A' <= ch && ch <= 'Z'){
     ch -= n;   
   } 
   printf("%c",ch);
   if(ch == '\n')break;  
 }
 return 0;
}

Measured memory_bytes: 524
#include <bits/stdc++.h>
using namespace std;
int main(){
	string s;
	cin>>s;
	for(int i = 1; i < s.size(); ++i){
		if(s[i] == s[i - 1]){
			cout<<"Bad"<<endl;
			return 0;
		}
	}
	cout<<"Good"<<endl;
	return 0;
}


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

typedef long long ll;
typedef pair<ll, ll> pll;

#define m0(x) memset(x, 0, sizeof(x))
#define all(x) x.begin(), x.end()
#define rep(i, n) for(int i = 0; i < (n); i++)
#define asort(x) sort(all(x));
#define dsort(x, t) sort(x.begin(), x.end(), greater<t>());
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define MINS(m, s) m.insert(make_pair(s, 1));
#define MFIN(m, s) m.find(s) != m.end()
#define INF (1 << 29)
const int mod = 1000000007;

int main(){
    int L, R, d, cnt;
    cnt = 0;
    vector<int> v;   
    cin >> L >> R >> d;
    for (int i = L; i <=R; i++) {
        if(i % d == 0){
            cnt++;
        }
    }
    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 3620
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt(), m = in.nextInt();
		int s = 0;
		for (int i = 0; i < m; i++) s += in.nextInt();
		System.out.println(s>n? -1 : n-s);
	}
}


Measured memory_bytes: 39552
#include<iostream>

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

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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) begin(r),end(r)
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)
#define vvl(v,w,h,init) vector<vector<ll>> v(w,vector<ll>(h,init))
#define mp(a,b) make_pair(a,b)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using pii = pair<int,int> ;
using pll = pair<ll,ll> ;
using pdl = pair<double,ll> ;

const int mod = 1000000007;
constexpr int inf = ((1<<30)-1)*2+1 ;
constexpr double PI = acos(-1.0) ;
double eps = 1e-6 ;
const int dy[] = {-1,0,1,0,1,-1,1,-1};
const int dx[] = {0,-1,0,1,1,-1,-1,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}


double calc(int r1,int r2){
  return sqrt((r1+r2)*(r1+r2) - (r1-r2)*(r1-r2));
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  stringstream ss;
  ll w;
  while(getline(cin,s)){
    ss.clear();
    ss << s;
    ss >> w;
    vector<ll> v(12);
    ll n = 0,k;
    while(ss >> k){
      v[n] = k;
      ++n;
    }
    vector<vector<double>> dp(1 << n,vector<double>(n,1e9));
    bool f = false;
    rep(i,n){
      dp[1 << i][i] = v[i];
    }
    double ans = 10000000.0;
    REP(i,1,(1 << n)){
      REP(j,0,n){
        if(i & (1 << j)) continue;
        ll nxt = i | (1 << j);
        REP(k,0,n){
          if((i & (1 << k)) == 0) continue;
          double bw = 0;
          if(nxt == (1 << n)-1){
            bw += v[j];
          }
          bw += calc(v[k],v[j]);
          dp[nxt][j] = min(dp[nxt][j],bw + dp[i][k]);
        }
      }
    }
    rep(i,n){
      ans = min(ans,dp[(1 << n)-1][i]);
    }
    if(ans <= w){
      cout << "OK" << endl;
    }
    else{
      cout << "NA"<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 3496
D = int(input())
C = list(map(int, input().split()))
S = [list(map(int, input().split())) for _ in range(D)]

N = 26
L = [0] * N
for d in range(1, D + 1):
    mx = -10**18
    nx = -1

    for i, (c, l) in enumerate(zip(C, L)):
        r = c * (d - l) - S[d - 1][i]
        if mx < r:
            mx = r
            nx = i

    L[nx] = d
    print(nx + 1)


Measured memory_bytes: 9240
N,K = map(int,input().split())
X = list(map(int,input().split()))
x_n = [0] + sorted([-x for x in X if x < 0])
x_p = [0] + sorted([x for x in X if x >= 0])
size_n,size_p = len(x_n), len(x_p)
ans = 2 * 10**10
for i in range(K+1):
	if i < size_n and K-i < size_p:
		ans = min(ans, x_n[i] + x_p[K-i] + min(x_n[i], x_p[K-i]))
print(ans)

Measured memory_bytes: 14252
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <iostream>
#include <vector>
#include <queue>
#include <unordered_map>
#include <random>
#include <stack>
#include <set>
#include <unordered_set>

#define bug(x) cout<<"zdongdebug1: "<<x<<endl;
#define bug2(x, y) cout<<"zdongdebug2: "<<x<<" "<<y<<endl;
#define bug3(x, y, z) cout<<"zdongdebug3: "<<x<<" "<<y<<" "<<z<<endl;
using namespace std;
typedef long long ll;
const int maxn = 200005;
const int mod = 1000000007;

int main() {
#ifdef suiyuan2009
  freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
  //freopen("/Users/suiyuan2009/CLionProjects/icpc/output.txt", "w", stdout);
#endif
  int n,m;
  cin>>n>>m;
  ll ret = 0;
  for(int i=m;i<=n+1;i++){
    ll l = (0 + i-1) * (ll)(i)/2;
    ll r = (n + (n-i+1))*(ll)(i)/2;
    ret += r -l+1;
    ret %=mod;
  }
  cout<<ret<<endl;
  return 0;
}

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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { cout << #a << " = " << a << endl; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }

typedef long long ll;
int const inf = 1<<29;

constexpr int MOD = 1e9+7;

int main() {

  int N; cin >> N;
  ll A[N], B[N];
  rep(i, N) cin >> A[i];
  rep(i, N) cin >> B[i];

  int L = -inf;
  ll pat[N]; zero(pat);
  rep(i, N) {
    if(L < A[i]) {
      pat[i] = 1;
      L = A[i];
    } else if(L > A[i]) {
      cout << 0 << endl; exit(0);
    }
  }

  int R = -inf;
  rep(i, N) {
    if(R < B[N-1-i]) {
      if(pat[N-1-i] && A[N-1-i] != B[N-1-i]) { cout << 0 << endl; exit(0); }
      pat[N-1-i] = 1;
      R = B[N-1-i];
    } else {
      if(pat[N-1-i] && A[N-1-i] > B[N-1-i]) { cout << 0 << endl; exit(0); }      
    }
  }

  if(L != R) { cout << 0 << endl; exit(0); }

  ll ans = 1;
  rep(i, N) {
    if(!pat[i]) {
      pat[i] = min(A[i], B[i]);
    }
    ans *= pat[i];
    ans %= MOD;
  }

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

Measured memory_bytes: 2688
#include <bits/stdc++.h>
using namespace std;
void out(int a,int b){cout << a << ' ' << b << '\n';}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    int n=1;
    while((n<<1)<=N) n<<=1;
    if (n==N){cout << "No" << '\n'; return 0;}
    cout << "Yes" << '\n';
    if (N&1){
        for (int i=2;i<=N;i+=2){
            out(1,i); out(i,i+1);
            out(1,i+1+N); out(i+1+N,i+N);
        }
        out(1+N,3);
    } else {
        int m=N^n;
        out(N,n); out(n,m); out(m,N+N);
        out(N+N,n+N); out(n+N,m+N);
        out(m+N,m+N+1); out(m+N+1,n+N+1);
        out(n+N,n+1); out(n+1,m+1);
        out(m+N,1); out(m+N+1,1+N);
        for (int i=2;i<=N;i+=2){
            if (i==N||i==n||i==m) continue;
            out(1,i); out(i,i+1);
            out(1,i+1+N); out(i+1+N,i+N);
        }
    }
}

Measured memory_bytes: 2304
import numpy as np


MOD = 10**9 + 7
def powmod(mat, n, mod):
    result = np.eye(len(mat), dtype=np.int64)
    while n > 0:
        if n & 1:
            result = np.dot(result, mat) % mod
        mat = np.dot(mat, mat) % mod
        n >>= 1
    return result


H, W, K = [int(elem) for elem in input().split()]
trans_mat = np.zeros((W, W), dtype=np.int64)
initial_vec = np.zeros(W, dtype=np.int64)
initial_vec[0] = 1

for i in range(2**(W - 1)):
    flag = False
    for pos in range(W - 2):
        if (i >> pos & 1) and (i >> (pos + 1) & 1):
            flag = True
    if flag:
        continue
    for pos in range(W):
        if pos == 0:
            if i & 1:
                trans_mat[0, 1] += 1
            else:
                trans_mat[0, 0] += 1
        elif pos == W - 1:
            if (i >> W - 2) & 1:
                trans_mat[W - 1, W - 2] += 1
            else:
                trans_mat[W - 1, W - 1] += 1
        else:
            if (i >> (pos - 1)) & 1:
                trans_mat[pos, pos - 1] += 1
            elif (i >> pos) & 1:
                trans_mat[pos, pos + 1] += 1
            else:
                trans_mat[pos, pos] += 1

powed_mat = powmod(trans_mat, H, MOD)
print(np.dot(powed_mat, initial_vec)[K - 1] % MOD)


Measured memory_bytes: 19664
import java.util.Scanner;
import java.lang.Math;
class Main {
    public static void main (String[] args) {
        Scanner sc = new Scanner(System.in);
        double r = sc.nextDouble();
        double a = r*r*Math.PI;
        double b = 2*r*Math.PI;
        System.out.println(String.format("%.6f", a) + " " + String.format("%.6f", b));
    }
}


Measured memory_bytes: 28120
program prob3
    implicit none
    character(len=200005) :: s 
    integer :: ans
    character(len=2) :: tmp
    integer :: i

    read(*,*) s
    
    ans = 1
    tmp = s(1:1)
    do i = 2, len_trim(s)
        if(tmp == s(i:i)) then
            tmp = "aa"
        else if(tmp == "aa") then
            tmp = "ab"
            ans = ans + 1
        else
            tmp = s(i:i)
            ans = ans + 1
        end if
    end do
    
    
    write(*,*) ans
    stop
contains
end program prob3

Measured memory_bytes: 1084
N = int(input())
A = list(map(int, input().split()))
B = [0]*N
for i in range(N):
    B[i] = A[i] - i
B.sort()

res = 0
x = B[N//2]

for i in range(N):
    res += max(x - B[i], -x + B[i])

print(res)

Measured memory_bytes: 26128
#include <iostream>
#include <cstring>
#include <utility>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <iomanip>
using namespace std;
typedef long long ll;

int main() {
  int n;
  cin >> n;
  vector<double> p(n);
  for (int i = 0; i < n; i++) {
    cin >> p[i];
  }
  vector<vector<double>> dp(n, vector<double>(n+1));
  dp [0][0] = 1 - p[0];
  dp [0][1] = p[0];
  for (int i = 1; i < n; i++) {
    dp[i][0] = (1-p[i]) * dp[i-1][0];
  }
  for (int i = 1; i < n; i++) {
    for (int j = 1; j <= i + 1; j++) {
      dp[i][j] = dp[i-1][j]* (1-p[i]) + dp[i-1][j-1] * p[i];
    }
  }
  double ans = 0;
  for (int j = n/2 + 1; j <= n; j++) {
    ans += dp[n-1][j];
  }
  cout << setprecision(10) << ans << endl;
}

Measured memory_bytes: 70656
import sys
input = sys.stdin.readline

class WarshallFloyd:
    def __init__(self,n):
        self.v = n
        self.d = []
        for i in range(n):
            self.d.append([1e100]*n)
            self.d[i][i] = 0

    def path(self,x,y,c):
        if x == y:
            return False
        self.d[x][y] = c
        self.d[y][x] = c
        return True

    def build(self):
        for k in range(self.v):
            for i in range(self.v):
                for j in range(self.v):
                    self.d[i][j] = min(self.d[i][j], self.d[i][k] + self.d[k][j])
        return self.d

n,m,l = map(int,input().split())
wf = WarshallFloyd(n)
for i in range(m):
    a,b,c = map(int,input().split())
    wf.path(a-1,b-1,c)
d = wf.build()

wf = WarshallFloyd(n)
for i in range(1,n):
    for j in range(i):
        if d[i][j] <= l:
            wf.path(i,j,1)

ans = wf.build()

q = int(input())
for i in range(q):
    s,t = map(int,input().split())
    if ans[s-1][t-1] == 1e100:
        print(-1)
    else:
        print(ans[s-1][t-1] - 1)


Measured memory_bytes: 127580
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)){
			int s = sc.nextInt();
			if(s >=0 && s <86400) {
				int second = s % 60;
				s = s / 60;
				int minute = s % 60;
				int hour = s / 60;
				System.out.println(String.format("%d:%d:%d",hour,minute,second));			
			}
		}
	}
}

Measured memory_bytes: 26236
#include <bits/stdc++.h>
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF=1e18;
static const ll MAX=101010;
static const ll MOD=1e9+7;
static const ll LOGN=55;

class unionFind {
public:
  vector<ll> data;
  
  unionFind(ll size) {
    data.assign(size, -1);
  }
  
  bool same(ll x, ll y) {
    return find(x)==find(y);
  }
  
  void unite(ll x, ll y) {
    x=find(x);
    y=find(y);
    if(x==y) return;
    if(data[x]>data[y]) swap(x, y);
    data[x]+=data[y];
    data[y]=x;
  }
  
  ll find(ll k) {
    if(data[k]<0) return k;
    return data[k]=find(data[k]);
  }
  
  ll size(ll k) {
    return -data[find(k)];
  }
  
};


int main(void) {
  ll N, M;
  cin >> N >> M;
  ll i;
  ll x[MAX];
  ll d[MAX];
  
  for(i=0; i<M; i++) cin >> x[i];
  sort(x, x+M);
  
  for(i=0; i<M-1; i++) d[i]=x[i+1]-x[i];
  sort(d, d+M-1);
  
  ll ans=0;
  for(i=0; i<M-N; i++) ans+=d[i];
  pt(ans);
  
  
}






Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define allR(v) v.rbegin(), v.rend()
#define PRINT(v) for (auto x : (v)) cout <<x <<" " ; cout <<endl;
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
typedef pair<int,int> Pi;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
const int inf = 1001001001;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
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;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m=numeric_limits<T>::max()){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }

template<class T> struct edge { int to; T cost;};


int main() {
  string s; cin >>s;
  ll res = 0;
  ll bs = 0;
  rep(i, s.size()){
    if (s[i] == 'B') bs++;
    else res += bs;
  }
  cout <<res <<endl;
}

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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};

int main()
{
    string s;
    cin>>s;
    int n=s.size();
    vector<int> c(3);
    for (int i = 0; i < n; i++)
    {
        c[s[i]-'a']++;
    }
    sort(all(c));
    if(c[2]-c[0]>1) cout<<"NO"<<endl;
    else cout<<"YES"<<endl;
    
    return 0;
}

Measured memory_bytes: 512
class UnionFind

  def initialize(n)
    @parents = Array.new(n, -1) # if negative value means size
  end

  def unite(a, b)
    a = root(a)
    b = root(b)

    return false if a == b

    a, b = b, a if -@parents[a] < -@parents[b]
    @parents[a] += @parents[b] # if negative value means size
    @parents[b] = a
    true
  end

  def root(a)
    @parents[a] < 0 ? a : (@parents[a] = root(@parents[a]))
  end

  def same?(a, b)
    root(a) == root(b)
  end

  def size(a)
    -@parents[root(a)]
  end
end

def make_edges(towns, edges)
  a, b, i = towns[0]
  (1 ... towns.size ).each do |k|
    c, d, j = towns[k]
    cost = [(a-c).abs, (b-d).abs].min
    edges << [cost, i, j]
    a, b, i = c, d, j
  end
end

n = gets.to_s.to_i
towns = Array.new(n){|i| gets.to_s.split.map{|t| t.to_i } << i }

edges = []

towns.sort_by!{|(x, y)| x }
make_edges(towns, edges)

towns.sort_by!{|(x, y)| y }
make_edges(towns, edges)

ans = 0
uft = UnionFind.new(n)
edges.sort_by!{|cost, _, _| cost }
edges.each do |cost, i, j|
  ans += cost if uft.unite(i, j)
end

puts ans

Measured memory_bytes: 35904
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 3005;
int64_t dp[MAXN][MAXN];

int main()
{
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++)
  {
    cin >> A.at(i);
  }
  for (int l = N - 1; l >= 0; l--)
  {
    for (int r = l; r < N; r++)
    {
      if (l == r)
        dp[l][r] = A.at(l);
      else
        dp[l][r] = max(A.at(l) - dp[l + 1][r], A.at(r) - dp[l][r - 1]);
    }
  }
  cout << dp[0][N - 1] << endl;
}


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

int main() {
    int N, M;
    cin >> N;
    vector<string> s(N);
    for (int i = 0; i < N; i++) {
        cin >> s.at(i);
    }
    cin >> M;
    vector<string> t(M);
    for (int i = 0; i < M; i++) {
        cin >> t.at(i);
    }
    vector<int> count(N, 0);

    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            if (s.at(i).compare(s.at(j)) == 0) count.at(i)++;
        }
        for (int j = 0; j < M; j++) {
            if (s.at(i).compare(t.at(j)) == 0) count.at(i)--;
        }
    }

    int max = 0;
    string result;
    for (int i = 0; i < N; i++) {
        if (count.at(i) > max) {
            max = count.at(i);
        }
        result = s.at(i);
    }
    if (max < 0) cout << 0 << endl;
    else cout << max << endl;
}


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

const long mod = 1000000007;
long fact(long n) {
  return n == 0 ? 1 : n * fact(n - 1) % mod;
}

long mpow(long b, long e) {
  if (e == 0) return 1;
  if (e % 2 == 1) return b * mpow(b, e - 1) % mod;
  long t = mpow(b, e / 2);
  return t * t % mod;
}

long inv(long n) {
  return mpow(n, mod - 2);
}

long sub(int m, int n) {
  return fact(m + n) * inv(fact(m) * fact(n) % mod) % mod;  
}

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  long sum = (
    sub(a, b)
    - sub(a, d + 1)
    - sub(c + 1, b)
    + sub(c + 1, d + 1)
    + 4 * mod
    ) % mod;
  cout << sum << endl;
}

Measured memory_bytes: 31488
class Dice():
    def __init__(self, nums):
        self.nums = nums
        self.top, self.front, self.right = 0, 1, 2

    def __eq__(self, dice):
        for x in "NNNNEEE":
            dice.move(x)
            for _ in range(4):
                dice.move("ESW")
                if self.nums[self.top] == dice.nums[dice.top] and \
                        self.nums[self.front] == dice.nums[dice.front] and \
                        self.nums[self.right] == dice.nums[dice.right] and \
                        self.nums[5 - self.top] == dice.nums[5 - dice.top] and \
                        self.nums[5 - self.front] == dice.nums[5 - dice.front] and \
                        self.nums[5 - self.right] == dice.nums[5 - dice.right]:
                    return True
        return False

    def move(self, op):
        for c in op:
            if c == 'N':
                self.top, self.front = self.front, 5 - self.top
            elif c == 'S':
                self.top, self.front = 5 - self.front, self.top
            elif c == 'E':
                self.top, self.right = 5 - self.right, self.top
            else:
                self.top, self.right = self.right, 5 - self.top

n = int(input())
ans = "Yes"
dices = []
dices.append(Dice([int(n) for n in input().split()]))
for _ in range(n - 1):
    new_dice = Dice([int(n) for n in input().split()])
    for dice in dices:
        if dice == new_dice:
            ans = "No"
            break
    dices.append(new_dice)
print(ans)

Measured memory_bytes: 7836
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
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 ll INF = 1LL << 60;
const int MAX = 1000000010;
const ll MOD = 1000000007;
const double PI = acos(-1);

int main() {
    int a, b; cin >> a >> b;
    if (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0) {
        cout << "Possible" << endl;
    } else {
        cout << "Impossible" << endl;
    }
    return 0;
}

Measured memory_bytes: 3552
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;
int main() {
  int a,b,c,d,e,k;
  cin >> a >> b >> c >> d >> e >> k;
  
  int maxdis = e-a;
  
  if (maxdis <= k) {
    cout << "Yay!" << endl;
  }
  else {
    cout << ":(" << endl;
  }
}

Measured memory_bytes: 256
import math
N = int(input())
TA = [list(map(int, input().split())) for i in range(N)]

x = 1
y = 1
for t, a in TA:
    if x <= t and y <= a:
        x = t
        y = a
    else:
        v = max(-(-x//t), -(-y//a))
        x = v * t
        y = v * a


print(x+y)


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

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

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

    int X,A; cin >> X >> A;

    cout << (X < A?0:10) << endl;

    return 0;

}

Measured memory_bytes: 256
import sys
import collections

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    N = int(input())
    A = [int(x) for x in input().split()]
    aset = list(set(A))
    aset.sort()

    ans = [0] * (10 ** 6 + 1)

    for a in aset:
        for i in range(2, 10 ** 6 + 1):
            if a * i > 10 ** 6:
                break
            ans[a * i] += 1

    res = 0
    c = collections.Counter(A)
    for a in A:
        if ans[a] == 0 and c[a] == 1:
            res += 1

    print(res)



if __name__ == '__main__':
    main()


Measured memory_bytes: 49252
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

//

fn run() {
    input! {
        _n: usize,
        k: usize,
        a: [u32; 3],
        s: chars,
    }
    let mut ans = 0;
    for i in 0..k {
        let mut dp = [0; 3];
        let mut j = i;
        while let Some(&c) = s.get(j) {
            j += k;
            let k = match c {
                'r' => 2,
                's' => 0,
                'p' => 1,
                _ => unreachable!(),
            };
            let mut next = [0; 3];
            for i in 0..3 {
                for j in 0..3 {
                    if i == j {
                        continue;
                    }
                    let mut v = dp[i];
                    if j == k {
                        v += a[k];
                    }
                    next[j] = std::cmp::max(next[j], v);
                }
            }
            dp = next;
        }
        ans += *dp.iter().max().unwrap();
    }
    println!("{}", ans);
}

fn main() {
    run();
}


Measured memory_bytes: 4352
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
using namespace std;

int main() {

  int n;
  cin >> n;
  string s = to_string(n);

  int tmp = 0;
  for(int i=0; i<s.size(); i++){
    tmp += s[i]-'0';
  }

  if( n % tmp == 0 ) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int PS(int x, int y) {
 int c=1;
  rep(i,y) {
    c *=x;
  }
  return c;
}
int main() {
  int a;
  int b;
  cin >>a>>b;
  int counta=0;
  int countb=0;
  rep(i,b) {
    counta+=a*PS(10,i);
  }
  rep(i,a) {
    countb +=b*PS(10,i);
  }
cout << max(counta,countb) << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder190804_D
{
    class Program
    {
        static void Main()
        {
            String input = Console.ReadLine();

            var resList = new List<int>(input.Length);

            char prevC = ' ';
            int count = 0;
            int savedIndex = -1;
            for (int i = 0; i < input.Length; i++)
            {
                char c = input[i];
                resList.Add(0);

                if (prevC == c)
                {
                    count += 1;
                }
                else
                {
                    if (c == 'R')
                    {
                        if (prevC == 'L')
                        {
                            int halfNumL = count / 2;
                            // Rの連続終了地点
                            resList[savedIndex - 1] += halfNumL;
                            // Lの連続開始地点
                            resList[savedIndex] += halfNumL;
                            if (count % 2 != 0)
                            {
                                // 奇数なら１加算
                                resList[savedIndex] += 1;
                            }
                        }
                    }
                    else if (c == 'L')
                    {
                        int halfNumR = count / 2;
                        // Rの連続終了地点
                        resList[i - 1] = halfNumR;
                        if (count % 2 != 0)
                        {
                            // 奇数なら１加算
                            resList[i - 1] += 1;
                        }
                        // Lの連続開始地点
                        resList[i] += halfNumR;

                        savedIndex = i;
                    }
                    count = 1;
                }

                prevC = c;

                if (i == input.Length - 1)
                {
                    int halfNumL = count / 2;
                    // Rの連続終了地点
                    resList[savedIndex - 1] += halfNumL;
                    // Lの連続開始地点
                    resList[savedIndex] += halfNumL;
                    if (count % 2 != 0)
                    {
                        // 奇数なら１加算
                        resList[savedIndex] += 1;
                    }
                }

            }

            string[] res = resList.Select((c) => c.ToString()).ToArray();
            Console.WriteLine($"{string.Join(" ", res)}");
        }
    }
}


Measured memory_bytes: 20320
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define ULL unsigned long long
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<LL,LL>
#define x first
#define y second
#define pi acos(-1)
#define sqr(x) ((x)*(x))
#define pdd pair<double,double>
#define MEMS(x) memset(x,-1,sizeof(x))
#define MEM(x) memset(x,0,sizeof(x))
#define less Less
#define EPS 1e-4
#define arg ARG
#define pdd pair<double,double>
#define cpdd const pdd
int ans[505][505];
void go(vector<int> l,vector<int> r,int level){
    if(r.empty()||l.empty())return;
    for(auto it:l){
        for(auto it2:r){
            ans[it][it2]=ans[it2][it]=level;
        }
    }
    vector<int> tl,tr;
    for(auto it:l){
        if(it&(1<<level)){
            tl.pb(it);
        }
        else{
            tr.pb(it);
        }
    }
    go(tl,tr,level+1);
    tl.clear(),tr.clear();
    for(auto it:r){
        if(it&(1<<level)){
            tl.pb(it);
        }
        else{
            tr.pb(it);
        }
    }
    go(tl,tr,level+1);
}
int main(){
    int n;
    scanf("%d",&n);
    vector<int> l,r;
    for(int i = 1;i<=n;i++){
        if(i&1){
            l.pb(i);
        }
        else{
            r.pb(i);
        }
    }
    go(l,r,1);
    for(int i=1;i<=n;i++){
        for(int j = i+1;j<=n;j++)
            printf("%d ",ans[i][j]);
        printf("\n");
    }
}

Measured memory_bytes: 1536
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String[] s = getString(sc).split("");

		int min = Integer.MAX_VALUE;
		for (int i = 0; i < s.length - 2; i++) {
			int x = Integer.parseInt(s[i] + s[i + 1] + s[i + 2]);
			if (Math.abs(753 - x) < min) {
				min = Math.abs(753 - x);
			}
		}
		System.out.println(min);

	}

	/**
	 * *汎用メソッド<br>
	 * 入力した配列に対する順列を取得
	 *
	 * @param numArray
	 * @return
	 */
	private static List<Integer[]> getPermutation(int[] numArray) {
		List<Integer[]> permutation = new ArrayList<>();
		Integer[] ans = new Integer[numArray.length];
		boolean[] used = new boolean[numArray.length];

		return buildPermutaion(permutation, numArray, ans, used, 0);
	}

	/**
	 * *汎用メソッド(内部)<br>
	 * 入力した配列に対する順列を作成
	 *
	 * @param list
	 * @param numArray
	 * @param ans
	 * @param used
	 * @param depth
	 * @return
	 */
	private static List<Integer[]> buildPermutaion(List<Integer[]> list, int[] numArray, Integer[] ans, boolean[] used,
			int depth) {

		// 全部使い切った時=>できた順列を返す
		if (depth == numArray.length) {
			list.add(ans.clone());
			return list;
		}
		// 使い切っていない場合

		for (int i = 0; i < numArray.length; i++) {
			if (used[i]) {
				continue;
			}
			ans[depth] = numArray[i];
			used[i] = true;
			list = buildPermutaion(list, numArray, ans, used, depth + 1);

			used[i] = false;
		}

		return list;
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をlongで返却
	 *
	 * @return
	 */
	public static long getLong(Scanner sc) {

		return Long.parseLong(sc.next());
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をintで返却
	 *
	 * @return
	 */
	public static int getInt(Scanner sc) {

		return Integer.parseInt(sc.next());
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をStringで返却
	 *
	 * @return
	 */
	public static String getString(Scanner sc) {

		return sc.next();
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をint配列で返却
	 *
	 * @return
	 */
	public static int[] getIntArray(Scanner sc) {
		String line = "";
		// 直前にnext()を実行していると改行コードだけ取ってしまうのでその対策
		while (line.equals("")) {
			line = sc.nextLine();
		}

		String[] strArray = line.split(" ");
		int[] intArray = new int[strArray.length];
		for (int i = 0; i < strArray.length; i++) {
			intArray[i] = Integer.parseInt(strArray[i]);
		}
		return intArray;
	}

}


Measured memory_bytes: 23508
N,Q = map(int, input().split(" "))
sentence = input()

"""
###文章そのままの実装ー＞N,Q によりオーダーが大きくなりすぎる
for i in range(int(Q)):
	count = 0
	l,r = map(int, input().split(" "))
	for j in range(r-l):
		if sentence[l-1+j:l+j+1] == "AC":
			count += 1
	print(count)

"""

###累積和を用いて高速に計算
#予め累積和を計算　クエリで高速回答
#ACACTGC
#0112222
AC_list = [0]*(N)
count = 0
for i in range(N-1):
	if sentence[i : i+2] == "AC":
		count += 1
	AC_list[i+1] = count

for i in range(Q):
	l,r = map(int, input().split())
	print(AC_list[r-1]-AC_list[l-1])

Measured memory_bytes: 6060
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <vector>

typedef long long ll;
using namespace std;

int main()
{
    int n, count = 0;
    cin >> n;

    vector <int> h(n, 0);
    for (int i = 0; i < n; i++) {
        cin >> h[i];
    }

    for (int i = 0; i < n; i++) {
        while (h[i] > 0) {
            count++;
            for (int j = i; j < n; j++) {
                if (h[j] > 0) h[j]--;
                else break;
            }
        }
    }

    cout << count << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
using namespace std;

int main()
{
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int l=a+b, r=c+d;
    if(l>r){
        cout << "Left";
    }else if(l<r){
        cout << "Right";
    }else{
        cout << "Balanced";
    }
    
    return 0;
}

Measured memory_bytes: 384
import java.util.*;
public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
 
   int N = sc.nextInt();
   int[] t = new int[N];
   int[] x = new int[N];
   int[] y = new int[N];
   for(int i=0;i<N;i++)
   {
     t[i] = sc.nextInt();
     x[i] = sc.nextInt();
     y[i] = sc.nextInt();
   }

   int tmpd =0;
   int tmpt =0;
   int tmpx =0;
   int tmpy =0;
   boolean cant = false;
   for(int i=0;i<N;i++) 
   {
     tmpd = Math.abs(tmpx-x[i])+Math.abs(tmpy-y[i]);
     if(tmpd>t[i]-tmpt)
     {
       cant = true;
       break;
     }
     else if((t[i]-tmpt-tmpd)%2==1)
     {
       cant = true;
       break;
     }
     tmpt=t[i];
     tmpx=x[i];
     tmpy=y[i];
   }
   String ans = "Yes";
   if(cant) ans = "No";
   System.out.println(ans);
 }
}

Measured memory_bytes: 90384
#
N = gets.chomp.to_i
V = gets.chomp.split.map(&:to_i)
C = gets.chomp.split.map(&:to_i)
sum = 0
(0..(N-1)).each do |i|
  sum = sum + (V[i] - C[i]) if V[i] > C[i]
end
puts sum

Measured memory_bytes: 1788
use std::io::*;
use std::str::FromStr;

fn main() {
    let a: [usize; 2] = [read(), read()];
    let b: [usize; 2] = [read(), read()];

    let mut dupcnt = 0;
    if a[1] < b[0] || b[1] < a[0] {
    } else {
        let l = if a[0] < b[0] { b[0] } else { a[0] };
        let r = if a[1] < b[1] { a[1] } else { b[1] };

        dupcnt = r - l;
    }

    println!("{}", dupcnt);
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}


Measured memory_bytes: 4352