akhauriyash/Code-Regression huggingface dataset:
// 解説見た
#include <bits/stdc++.h>
typedef long long lint;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

int main() {
    lint n,a,b; cin >> n >> a >> b;
    vector<int> h(n);
    rep(i,n) cin >> h[i];
    lint ok = 1e9;
    lint ng = 0;
    while (abs(ok-ng) > 1) {
        lint mid = (ok+ng)/2;
        lint d = b*mid;
        lint cnt = 0;
        rep(i,n) {
            if (h[i]-d > 0) cnt += ((h[i]-d) + (a-b) - 1) / (a-b);
        }
        if (cnt <= mid) ok = mid;
        else ng = mid;
    }
    cout << ok << endl;
}

Measured memory_bytes: 3772
//Use valgrind once if the submission doesn't go through. It can detect uninitialized variables and see where they could be an issue.
#include <bits/stdc++.h>
#include <numeric>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

int main(){

	ios_base::sync_with_stdio(false);
    	cin.tie(NULL);

	int s,t,d;
	cin>>d>>t>>s;
	if(s*t<d){
		cout<<"No"<<endl;
	}
	else{
		cout<<"Yes"<<endl;
	}
}


Measured memory_bytes: 3636
#include<iostream>
using namespace std;
int main(){ 
	int A,B,C,K,i,t;
	cin>>A>>B>>C>>K;
	if(A<B){
		t=A;
		A=B;
		B=t;
	}
	if(A<C){
		t=A;
		A=C;
		C=t;
	}
	for(i=0;i<K;i++){
		A=A*2;
	}
	cout<<A+B+C<<endl;
	return 0;
}


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

int main() {
  int a, b;
  cin >> a >> b;
  int ans = 0;
  if(b % a == 0) ans = a + b;
  else ans = b - a;
  cout << ans << endl;
}

Measured memory_bytes: 3576
import math

a, b, x = map(int, input().split())

sakaime = a * a * b / 2

if x > sakaime:
    try:
        tan = a / (2 * (b - (x / (a ** 2))))
    except:
        tan = float('inf')
else:
    tan = 2 * x / (a * (b**2))

ans = math.degrees(math.atan(tan))

if ans >= 0:
    print(90-ans)

Measured memory_bytes: 3060
#define DEBUG 0

/**
 * File    : B.cpp
 * Author  : Kazune Takahashi
 * Created : 5/22/2019, 4:46:16 PM
 * Powered by Visual Studio Code
 */

#include <iostream>
#include <iomanip>   // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple>
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set>
#include <functional>
#include <random> // auto rd = bind(uniform_int_distribution<int>(0, 9), mt19937(10101010));
#include <chrono> // std::chrono::system_clock::time_point start_time, end_time;
// start = std::chrono::system_clock::now();
// double elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end_time-start_time).count();
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

typedef long long ll;

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

// const int C = 1e6+10;
// const ll M = 1000000007;

int N;
int H[100];

int main()
{
  cin >> N;
  for (auto i = 0; i < N; i++)
  {
    cin >> H[i];
  }
  int M = 0;
  int ans = 0;
  for (auto i = 0; i < N; i++)
  {
    if (M <= H[i])
    {
      ans++;
      M = H[i];
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
N,K=map(int,input().split())
S=[0]*(10**5+1)
for _ in range(N):
  a,b=map(int,input().split())
  S[a]+=b
x=0
i=0
while x<K:
  x=x+S[i]
  i=i+1
print(i-1)

Measured memory_bytes: 5748
import java.util.*;
public class Main {
    public static void main(final String[] args) {
        final Scanner sc = new Scanner(System.in);
        final String s = sc.next();
        final int si1 = Integer.parseInt(s.substring(0, 2));
        final int si2 = Integer.parseInt(s.substring(2, 4));
        Boolean isYyMm = (1 <= si2 && si2 <= 12);
        Boolean isMmYy = (1 <= si1 && si1 <= 12);
        if (isYyMm && isMmYy) {
            System.out.print("AMBIGUOUS");
        } else if (isYyMm) {
            System.out.print("YYMM");
        } else if (isMmYy) {
            System.out.print("MMYY");
        } else {
            System.out.print("NA");
        }
    }
}


Measured memory_bytes: 21588
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1e18;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
const int MX = 200005;
typedef v(string) vs;

string fa(string s) {
  int n = sz(s);
  vi a, b;
  rep(i,n) {
    if (s[i] == 'a') a.pb(i);
    else b.pb(i);
  }
  vi is(n);
  rep(i,sz(a)) is[a[i]] = i;
  rep(i,sz(b)) is[b[i]] = i;
  string res;
  rep(i,n) {
    if (s[i] == 'b') continue;
    res += "ab";
    i = b[is[i]];
  }
  return res;
}
string fb(string s) {
  int n = sz(s);
  vi a, b;
  rep(i,n) {
    if (s[i] == 'a') a.pb(i);
    else b.pb(i);
  }
  vi is(n);
  rep(i,sz(a)) is[a[i]] = i;
  rep(i,sz(b)) is[b[i]] = i;
  string res;
  rep(si,sz(b)) {
    string now;
    rep(i,n) if (is[i] >= si) now += s[i];
    maxs(res,now);
  }
  return res;
}
string f(string s) {
  if (s[0] == 'a') return fa(s);
  return fb(s);
}

int main() {
  int n;
  scanf("%d",&n);
  n <<= 1;
  string s;
  cin>>s;
  int cnt = 0;
  string ns;
  vs t;
  rep(i,n) {
    if (s[i] == 'a') ++cnt; else --cnt;
    ns += s[i];
    if (!cnt) t.pb(f(ns)), ns = "";
  }
  string ans;
  drep(i,sz(t)) {
    string now = t[i]+ans;
    maxs(ans,now);
  }
  cout<<ans<<endl;
  return 0;
}






















Measured memory_bytes: 384
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{
    char a[3],b[3];
    while(scanf("%s %s",a,b)==2)
    {
        if(a[0]==b[0])
            printf("H\n");
        else
            printf("D\n");
    }
    return 0;
}


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

int main() {
  long N; cin >> N;
  long min = N - 1;
  for (int i = (int) sqrt((double) N); i >= 1; i--) {
    long j = N / i;
    if (i * j == N) {
      min = (i - 1) + (j - 1);
      break;
    }
  }
  cout << min << endl;
}

Measured memory_bytes: 256
import sys


def query(S):
    print(S)
    sys.stdout.flush()
    return input()


def main():
    N = int(input())
    base = query(0)
    if base == "Vacant":
        return
    lo = 1
    hi = N-1
    while lo < hi:
        mid = (lo+hi) // 2
        ans = query(mid)
        if ans == "Vacant":
            return
        if (mid % 2 == 0 and ans == base) or \
           (mid % 2 == 1 and ans != base):
            lo = mid + 1
        else:
            hi = mid
    query(lo)


if __name__ == "__main__":
    main()


Measured memory_bytes: 38852
h,w,k = list(map(int,input().split()))
c = []
ans = 0

for i in range(h):
  c.append(list(input()))

for i in range(2 ** h):
  for j in range(2 ** w):
    now = 0
    for x in range(h):
      for y in range(w):
        if not (i >> x) & 1 and not (j >> y) & 1 and c[x][y] == '#':
          now += 1
    if now == k:
      ans += 1

print(ans)
          



Measured memory_bytes: 9108
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define pye cout << "Yes" << endl;
#define pno cout << "No" << endl;
#define prin(num) cout << num << endl;
#define sprin(str) cout << "str" << endl;
#define INF 1000000000
#define MOD 1000000007LL
#define MAX 100001
#define NIL -1
#define WHITE 0
#define GRAY 1
#define BLACK 2
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PA;
typedef priority_queue<ll> PQ;
typedef pair<double, double> doup;
//typedef vector<ll> vec;
//typedef vector<vec> mat;


int main() {
    ll N, A;
    ll x[50];
    cin >> N >> A;
    ll i, j, k;
    ll dp[N+1][N+1][N*A+1];
    for(i=0; i<N; i++)
        cin >> x[i];
    
    for(i=0; i<=N; i++) {
        for(j=0; j<=N; j++) {
            for(k=0; k<=N*A; k++) {
                dp[i][j][k]=0;
            }
        }
    }
    dp[0][0][0]=1;
    
    for(i=0; i<N; i++) {
        for(j=0; j<N; j++) {
            for(k=0; k<N*A; k++) {
                dp[i+1][j][k]+=dp[i][j][k];
                if(k+x[i]<=N*A)
                    dp[i+1][j+1][k+x[i]]+=dp[i][j][k];
            }
        }
    }
    ll ans=0;
    for(j=1; j<=N; j++) {
        ans+=dp[N][j][j*A];
    }
    
    prin(ans);
}



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

using namespace std;

int v[21];

int main() {

  int n, l, ans = 0;
  cin >> n;
  for(int i = 1;i <= n;i++){
    cin >> v[i];
  }
  for(int i = 1;i <= n;i++){
    cin >> l;
    if(v[i] > l){
      ans += v[i] - l;
    }
  }
  cout << ans;
  return 0;
}


Measured memory_bytes: 3620
s = input()
t = input()
ans = 10**10
l = len(s) - len(t) + 1
for i in range(l):
  tans = 0
  for j in range(len(t)):
    if s[i+j] != t[j]:
      tans += 1
  ans = min(ans, tans)
print(ans)

Measured memory_bytes: 9032
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
#![macro_use]

use std::cmp::*;
use std::collections::*;
use std::io::prelude::*;
use std::mem::*;
use std::num::*;
use std::slice::*;

const MOD: isize = 1_000_000_007;

fn main() {
    let (K, N): (usize, usize) = (read(), read());
    let mut A: Vec<usize> = (0..N).map(|_| read()).collect();

    let mut B: Vec<usize> = vec![];
    for i in 0..N {
        B.push(K + &A[i]);
    } // size 2n
    A.append(&mut B);
    let mut ans = std::usize::MAX;
    for i in 0..N {
        ans = min(ans, A[i + N - 1] - A[i]);
    }
    println!("{}", ans);
}
fn read<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let next: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    next.parse().ok().unwrap()
}


Measured memory_bytes: 11376
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<n; ++i)
#define rep1(i, n) for (int i=1; i<=n; ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
constexpr ll  MOD = (1e9+7);
constexpr int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
constexpr int lcm(int a, int b) { return a / gcd(a, b) * b; }

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;
}
ll factorial(ll n, ll m=2) {
    // calculate n!
    m = max(2LL, m);
    ll rtn = 1;
    for (ll i=m; i<=n; i++) {
        rtn = (rtn * i) % MOD;
    }
    return rtn;
}
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
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;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    int cnt = 0;
    rep(i, n) {
        int a; cin >> a;
        int tmp = 0;
        while (a%2==0) tmp++, a/=2;
        cnt += tmp;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int grid[105][105];
int main(){
	int n , m , k;
	cin>>n>>m>> k;
	vector<int>vi;
	for(int i= 0; i < k ; i++){
		int x ;cin>>x;
		vi.push_back(x);
	}
	int curr = 0 ,cnt = 0;
	for(int i =0 ; i < m ; i++){
		if(i%2==0){
			for(int j = 0; j < n ;j++){
				grid[j][i] = curr+1;
				cnt++;
				if(cnt == vi[curr]){
					curr++;
					cnt = 0;
				}
			}
		}else{
			for(int j = n-1 ; j >= 0; j--){
				grid[j][i] = curr+1;
				cnt++;
				if(cnt == vi[curr]){
					curr++;
					cnt = 0;
				}			
			}
		}
	}
	for(int i = 0; i < n; i++){
		for(int j = 0;j < m ;j++){
			cout<<grid[i][j]<<" ";
		}
		cout<<endl;
	}
	return 0;
}



Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,K;
    cin >> N >> K;
    vec<int> P(N);
    bool ok = false;
    for(auto& x:P){
        cin >> x;
        x--;
    }
    vec<ll> C(N);
    for(auto& x:C){
        cin >> x;
        ok |= x>0;
    }
    if(!ok){
        cout << *max_element(C.begin(),C.end()) << "\n";
        return 0;
    }
    auto calc = [&](int s){
        int now = s;
        int c = 0;
        int k = K;
        vec<ll> A;
        while(true){
            int ne = P[now];
            c++;
            A.push_back(C[ne]);
            if(ne==s) break;
            now = ne;
        }
        ll ans0 = 0;
        ll a = 0;
        for(int i=0;i<min(k,c);i++){
            a += A[i];
            ans0 = max(ans0,a);
        }
        if(k<c) return ans0;
        ll sum = accumulate(A.begin(),A.end(),0LL);
        ll n = k/c;
        assert(n>=1);
        ll ans = (sum>0? sum*(n-1):0);
        k -= c*(n-1);
        ll ma = 0,v = 0;
        for(int i=0;i<k;i++){
            v += A[i%c];
            ma = max(v,ma);
        }
        ans += ma;
        return max(ans0,ans);
    };

    ll ans = 0;
    for(int i=0;i<N;i++) ans = max(ans,calc(i));
    cout << ans << "\n";
}

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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFやMODの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const ll MOD = 1000000007;

int main() {
  int x;
  cin >> x;
  ll ans = x / 500 * 1000;
  x %= 500;
  ans += x / 5 * 5;
  cout << ans << endl;
}


Measured memory_bytes: 256
import sys
import os

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

MOD = 10 ** 9 + 7


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    S = iss()
    key = ['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT']
    print(7 - key.index(S))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
    ll n;
    cin>>n;
    int len=0;
    ll val=0;
    while(val<n){
        len++;
        val+=(ll)(pow(26,len)+0.5);
    }
    if(len==1){
        cout<<char(n+'a'-1)<<endl;
        return 0;
    }
    vector<char>ans(len);
    for(ll i=0;i<len;i++){
        ll op=0;
        if(n<=26){
            ans[i]=char(n+'a'-1);
            continue;
        }
        ll v=0;
        for(ll j=1;j<=len-1-i;j++){
            v+=(ll)(pow(26,j)+0.5);
        }
        ll e=v;
        while(n>e){
            op++;
            e+=(ll)(pow(26,len-1-i)+0.5);
        }
        n=v-(e-n);
        ans[i]=char(op+'a'-1);
    }
    for(auto i:ans)cout<<i;
    return 0;
}


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

int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<int>> map(M, vector<int>(2));
  for (int i = 0; i < M; i++){
    for(int j = 0; j < 2 ; j++) cin >> map.at(i).at(j);
  }
  
  
  vector<int> ans(N);
  for (int i = 1; i < N + 1 ; i++){
    int count = 0;
    for ( int j = 0 ; j < M; j++){
      for (int k = 0; k < 2 ; k++){
        if ( i == map.at(j).at(k)) count++;
      }
    }
    cout << count << endl;
  }  
}//main

Measured memory_bytes: 256
/*
これを入れて実行
g++ code.cpp
./a.out
*/

#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <stack>

using namespace std;
typedef long long ll;
typedef long double ld;

int dy4[4] = { -1, 0, +1, 0 };
int dx4[4] = { 0, +1, 0, -1 };
int dy8[8] = { -1, -1, 0, 1, 1, 1, 0, -1 };
int dx8[8] = { 0, 1, 1, 1, 0, -1, -1, -1 };

const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;

bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
	return f.second > s.second;
}

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

ll lcm(ll a, ll b){
	return a / gcd(a, b) * b;
}

ll nCr(ll n, ll r){
	if (r == 0 || r == n){
		return 1;
	}
	else if (r == 1){
		return n;
	}
	return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}

ll nPr(ll n, ll r){
	r = n - r;
	ll ret = 1;
	for (ll i = n; i >= r + 1; i--) ret *= i;
	return ret;
}

//-----------------------ここから-----------

int main(void){
	int n;
	cin >> n;

	vector<int> a(n);

	for (int i = 0; i < n; i++) cin >> a[i];

	int odd = 0;

	for (int i = 0; i < n; i++){
		if (a[i] % 2 != 0){
			odd++;
		}
	}

	if (odd > 0){
		cout << "first" << endl;
	}
	else {
		cout << "second" << endl;
	}
}



Measured memory_bytes: 640
# ABC172　C - Walking Takahashi
X,K,D=map(int,input().split())

X=abs(X)
q=X//D
if q>K:
    print(X-K*D)
else:
    if (K-q)%2==0:
        print(X-q*D)
    else:
        print(-X+(q+1)*D)


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

using namespace std;

void solve()
{
	string s;
	cin >> s;
	if(s.back() == 's')
		cout << s+"es";
	else
		cout << s+"s";
}


int main() {
    int t;
    // cin>>t;
	// while(t--)
		solve();
	return 0;

}

Measured memory_bytes: 3628
#include <iostream>

using namespace std;

int main() {

	int S;
	
	cin >> S;
	
	if((0 < (S/100)) && ((S/100) < 13)){
		if((0 < (S%100)) && ((S%100) < 13)){
			cout << "AMBIGUOUS" << "\n";
		}
		else
		{
			cout << "MMYY" << "\n";
		}
	}
	else if((0 < (S%100)) && ((S%100) < 13)){
		cout << "YYMM" << "\n";
	}
	else{
		cout << "NA" << "\n";
	}

	return 0;
}

Measured memory_bytes: 256
# encoding: utf-8
N = int(input())
W = list([input() for i in range(N)])

ans = "Yes"

for i, Wi in enumerate(W):
    # rule 1
    if W.count(Wi) > 1:
        ans = "No"
        break
    # rule 2
    if i == 0:
        hdr = Wi[-1]
        continue
    # i > 0
    if Wi[0] != hdr:
        ans = "No"
        break
    hdr = Wi[-1]

print(ans)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define MOD (int)1e9+(int)7
#define INF 2147483647
typedef long long ll;
typedef unsigned long long ull;

//dark power
//#define int ll
//define Error、大抵は、セミコロン忘れとか、Defineは関係ない
/*
vector<int> d(100000);
vector<int> b(100000);
class UnionFind{
	public:
	UnionFind(signed n){rep(i,n){d[i]=i;b[i]=0;}}
	signed find(signed x){
		if(d[x]==x){
			return x;
		}else{
			return d[x]=find(d[x]);
		}
	}
	UnionFind(signed n){rep(i,n){d[i]=i;b[i]=0;}}
	void unite(signed x,signed y){
		x=find(x);
		y=find(y);
		if(x==y)return;
		if(b[x]<b[y]){
			d[x]=y;
		}else{
			d[y]=x;
			if(b[x]==b[y])b[x]++;
		}
	}
	bool same(signed x,signed y){return (find(x)==find(y));}
};
*/
signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n=0;
	cin>>n;
	if(n<1200)cout<<"ABC"<<endl;
	else if(n<2800)cout<<"ARC"<<endl;
	else cout<<"AGC"<<endl;
//	int m,n;
//	cin>>n>>m;
//	vector<string> a(n);
//	vector<string> b(m);
//
//	rep(i,n)cin>>a[i];
//	rep(i,m)cin>>b[i];
//
//	rep(i,n-m+1)rep(j,n-m+1){
//		rep(k,m)rep(l,m)if(a[i+k][j+l]!=b[k][l])goto BB;
//		cout<<"Yes"<<endl;
//		return 0;
//BB:
//		continue;
//	}
//	cout<<"No"<<endl;
//
//
	return 0;
}


Measured memory_bytes: 256
#include "stdio.h"
#include "string.h"
#define min(a,b) (a<b?a:b)
#define swap(a,b) (a^=b,b^=a,a^=b)
int cmp(char const *a,char const *b){
	int i;
	int len = min(strlen(a),strlen(b));
	for(i=0;i<len;i++){
		if(a[i] > b[i])return 1;
		else if(a[i] < b[i])return 0;
	}
	return strlen(a) > strlen(b);
}
int str_swap(char *a,char *b){
	int i=0;
	for(i=0;i<31;i++)swap(a[i],b[i]);
}
int main()
{
	int page;
	char tmp[31];
	char table[101][31]={{0}};
	int pg[101][101] = {{0}};	//ツペツーツジツ篠ゥツ妥個づ個配ツ療ア
	int top[101] = {0};			//ツつサツづェツつシツづェツづ個ペツーツジツ氾板債格ツ納ツつキツづゥツ陛渉青板づ個凝ウツつォツ静ヲツ督ェ
	int n = 0;
	
	int i,j,k,l,m;
	while(~scanf("%s %d\n",tmp,&page)){
		for(i=0;i<100;i++){
			if(table[i][0] == '\0'){
				strcpy(table[i],tmp);
				pg[i][top[i]++] = page;
				n++;
				break;
			}
			if(strcmp(tmp,table[i])==0){
				pg[i][top[i]++] = page;
				break;
			}
		}
	}
	for(i=0;i<n;i++){
		for(j=0;j<top[i];j++){
			for(k=0;k<top[i]-1;k++){
				if(pg[i][k] > pg[i][k+1])
					swap(pg[i][k],pg[i][k+1]);
			}
		}
	}
	for(i=0;i<n;i++){
		for(j=0;j<n-1;j++){
			if(cmp(table[j],table[j+1])){
				for(k=0;k<100;k++)swap(pg[j][k],pg[j+1][k]);
				str_swap(table[j],table[j+1]);
				swap(top[j],top[j+1]);
			}
		}
	}
	for(i=0;i<n;i++){
		printf("%s\n",table[i]);
		for(j=0;j<top[i];j++)
			printf("%s%d",j?" ":"",pg[i][j]);
		puts("");
	}
	return 0;
}

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

int main() {
    string s, t;
    cin >> s >> t;
    sort(s.begin(), s.end());
    sort(t.begin(), t.end(), greater<char>());
    if (s.compare(t) < 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

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

int main() {
  int a,b,c;
  cin >> a >> b >> c;

  int ans=0;
  if (b<c) {
    ans += b*2;
    c -= b;
    if (a<c) {
      ans += a+1;    }
    else {
      ans += c;
    }
  }
  else {
    ans = b+c;
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
def solve():
    N = int(input())
    A = [int(i) for i in input().split()]
    sorted_A = sorted(A, reverse=True)
    cnt = N
    ptr = 0
    is_first = True
    ans = 0
    while cnt > 0:
        ans += sorted_A[ptr]
        if is_first:
            is_first = False
        else:
            ptr +=1
            is_first = True
        cnt -= 1
    print(ans - sorted_A[0])

if __name__ == "__main__":
    solve()

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

const int N = 1e3 + 7;

long long M = 1e9 + 7;
int a[N], b[N], n, m;
long long res = 1;
long long mrk[N * N];
vector <pair <int, int> > v;
int main() {
	cin >> n >> m;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int j = 0; j < m; j++)
		cin >> b[j];
	for (int i = 0; i < n; i++)
		for (int ii = i + 1; ii < n; ii++)
			if (a[ii] == a[i]) {
				cout << "0";
				return 0;
			}
	for (int j = 0; j < m; j++)
		for (int jj = j + 1; jj < m; jj++)
			if (b[jj] == b[j]) {
				cout << 0;
				return 0;
			}
	for (int i = 0; i < n; i++) 
		for (int j = 0; j < m; j++)
			if (a[i] == b[j])
				mrk[a[i]] = 1;
	for (int i = 0; i < n; i++) {
		if (mrk[a[i]])
			continue;
		for (int j = 0; j < m; j++)
			if (b[j] > a[i])
				mrk[a[i]]++;
	}
	for (int j = 0; j < m; j++) {
		if (mrk[b[j]])
			continue;
		for (int i = 0; i < n; i++)
			if (a[i] > b[j])
				mrk[b[j]]++;
	}
	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++)
			v.push_back({i, j});
	sort(v.begin(), v.end(), [](pair <int, int> x, pair <int, int> y) {
		return min(a[x.first], b[x.second]) < min(a[y.first], b[y.second]);		
	});/*
	for (int i = 0; i < v.size(); i++)
		cout << i << " v[i] " << v[i].first << " " << v[i].second << endl;
*/	for (int pnt = n * m; pnt >= 1; pnt--) {
		if (mrk[pnt]) {
			res *= mrk[pnt];
			res %= M;
//			cout << pnt << " RES :::::" << res << " " << mrk[pnt] << endl;
			continue;	
		}
		int l = -1, r = v.size(), md;
		while (r - l > 1) {
			md = (r + l) / 2;
			if (min(a[v[md].first], b[v[md].second]) > pnt)
				r = md;
			else
				l = md;
		}
		res *= (v.size() - r - (n * m - pnt));
		res %= M;
//		cout << pnt << " RES " << res << " R " << r << " " << (v.size() - r - (n * m - pnt)) << endl;
	}
	cout << res;
	return 0;
}








































Measured memory_bytes: 10604
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

int main()
{
  long n, i, j;
  long cnt = 0;
  long cnta = 0;
  long cntb = 0;
  long cntc = 0;
  char s[10000][11];
  scanf("%ld", &n);
  for (i = 0; i < n; i++) {
    scanf("%s", s[i]);
    if (s[i][0] == 'B')
      cnta++;
    if (s[i][strlen(s[i])-1] == 'A')
      cntb++;
    if (s[i][strlen(s[i])-1] == 'A' && s[i][0] == 'B')
      cntc++;
    for (j = 0; j < strlen(s[i])-1; j++) {
      if (s[i][j] == 'A' && s[i][j+1] == 'B')
	cnt++;
    }
  }
  if (max(cnta, cntb) - cntc || cntc == 0)
    printf("%ld\n", cnt + min(cnta, cntb));
  else
    printf("%ld\n", cnt + min(cnta, cntb)-1);
}


Measured memory_bytes: 1144
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;

int main(){
  
  ll N, A, B, C, D, E;
  cin >> N >> A >> B >> C >> D >> E;
  vll city(7, 0);
  city.at(1) = N;
  int counter = 0;
  vector<ll> ninzuu{A, B, C, D, E};
  sort(ALL(ninzuu));
  ll rissoku = ninzuu.at(0);
  cout << 4LL + (N + rissoku - 1) / rissoku << endl;
}


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

int main()
{
    int n, k;
    cin >> n >> k;
    int a[n] = {};
    int dp[n+k] = {};
    for(int i=0; i<n; i++){
        cin >> a[i];
        dp[i] = 4e9;
    }
    dp[0] = 0;
    for(int i=0; i<n; i++){
        for(int j=1; j<=k; j++){
            if(i+j >= n) continue;
            dp[i+j] = min(dp[i] + abs(a[i+j]-a[i]), dp[i+j]);
        }
    }
    cout << dp[n-1] << endl;
    return 0;
}


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


int main()
{
    int n,k;
    cin>>n>>k;vector<int>h(n);int a=0;
    for(int i=0;i<n;i++){
        int p;
        cin>>p;
        if(p>=k)a++;
    }
    cout<<a;
    return 0;
}


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

int compare_int(const void*a,const void*b){
    return *(int*)a - *(int*)b;
}
int factorial(int x) {
    if (x == 0) return 1;
    else {
        int ans = 1;
        for (int i = 1; i <= x; i++) ans *= i;
        return ans;
    }
}
int where(vector<int>& a, int x, int n) {
    int counter = 0;
    for (int i = x+1; i < n; i++) {
        if (a[x] > a[i]) counter += 1;
    }
    return counter;
}
int order(vector<int>& a,int n) {
    int small = 1;
    int ans = 1;
    for (int i = n - 1; i >= 0; i--) {
        ans += where(a,n-1-i,n) * factorial(i);
        if (a[n-1-i] == small) small += 1;
    }
    return ans;
}
int main() {
    int n; cin >> n;
    vi p(n); vi q(n);
    for (int i = 0; i < n; i++) cin >> p[i];
    for (int i = 0; i < n; i++) cin >> q[i];

    int pa = order(p, n); int qa = order(q, n);

    cout << abs(pa - qa) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1001001001
#define LINF 1001001001001001001
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;

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

int main() {
  
  int N;
  cin >> N;
  ll ans = 0;
  for (int A = 1; A <= N; A++) {
    ans += (N - 1) / A;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string str;
  int n=0;
  cin >> str;
  n = (int)str.size();
  int i=0,a=0,b=0;
  while(str[i]==str[(n-3)/2-i] && i != (n-3)/2 && str[i] == str[n-1-i]) i++;
  if(i == (n-3)/2) cout << "Yes" << endl;
  else cout << "No" << endl;
}
  
  
  

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


   
int main(){
 int n;
 cin >> n;
 int x=n*800;
 int y=(n/15)*200;
 cout << x-y << endl;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
#define GET_REP(_1, _2, _3, NAME, ...) NAME
#define rep(...) GET_REP(__VA_ARGS__, irep, _rep)(__VA_ARGS__)
#define rep1(...) GET_REP(__VA_ARGS__, irep1, _rep1)(__VA_ARGS__)
#define _rep(i, n) irep (i, 0, n)
#define _rep1(i, n) irep1(i, 1, n)
#define irep(i, a, n) for (int i = a; i < (int)(n); ++i)
#define irep1(i, a, n) for (int i = a; i <= (int)(n); ++i)
#define rrep(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define rrep1(i, n) for (int i = (int)(n); i >= 1; --i)
#define allrep(X, x) for (auto &&X : x)
#define all(x) (x).begin(), (x).end()
#ifdef LOCAL
  #include "../../Lib/cout_container.hpp"
  #define debug(x) cerr << #x " => " << (x) << endl
#else
  #define debug(x) 0
#endif
using lint = long long;
constexpr int    INF  = 1 << 29;
constexpr lint   INFL = 1LL << 61;
constexpr int    MOD  = (int)1e9 + 7;
constexpr double EPS  = 1e-9;
using namespace std;
namespace { struct INIT { INIT() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } } INIT; }

int main(void) {
  string s;
  cin >> s;
  int mini = INT_MAX;
  rep (x, 2) {
    int cnt = 0, prev = x;
    allrep (c, s) {
      if (c - '0' == prev) ++cnt;
      prev = !prev;
    }
    mini = min(mini, cnt);
  }
  cout << mini << endl;
  return 0;
}

Measured memory_bytes: 512
import Control.Applicative

grading :: Int -> Int -> Int -> String
grading m f r
    | m == -1 || f == -1                   = "F"
    | m + f >= 80                          = "A"
    | m + f >= 65 && m + f < 80            = "B"
    | m + f >= 50 && m + f < 65            = "C"
    | m + f >= 30 && m + f < 50 && r >= 50 = "C"
    | m + f >= 30 && m + f < 50 && r < 50  = "D"
    | otherwise                            = "F"

main :: IO ()
main = do
    [m, f, r] <- (map (read :: String -> Int) . words) <$> getLine
    if (m == -1 && f == -1 && r == -1)
    then return ()
    else do
        putStrLn $ grading m f r
        main

Measured memory_bytes: 4080
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) 
	{
		Scanner scanner = new Scanner(System.in);
		List<Sub> subs = new ArrayList<Sub>();
		
		subs.add(new Sub());
	}

	static class Sub
	{
		int i;
		public Sub()
		{
			Scanner scanner = new Scanner(System.in);
			i = scanner.nextInt();
			System.out.println(i*i*i);
		}
	}
}



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

#define all(v) v.begin(), v.end()
#define mp make_pair
#define EPS (int)1e-9
#define PI acos(-1)
#define endl '\n'
#define pb push_back
#define fi first
#define se second

using namespace std;
using ld = long double;
using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;

const int mod = 1000000007;


int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n;
	cin >> n;

	if(n%10 == 9 or int(n/10) == 9)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;	
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <unordered_map>
#include <cmath>
#include <utility> // pair make_pair
#include <algorithm>
#include <functional>
#include <iomanip>
#include <climits> // LLONG_MAX, LLONG_MIN, INT_MIN, INT_MAX
#include <assert.h>

#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,63,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define ll long long
#define int ll
#define INF INT_MAX/10
#define MOD 1000000007

using namespace std;
using Pi = pair<int, int>;
using Graph = vector<vector<int> >;
using WeightGraph = vector<vector<Pi> >;

set<int> Parents;

struct UnionFind {
  vector<int> par; // 親ノード
  vector<int> rank; // ランク

  UnionFind(int n = 1) {
    init(n);
  }

  void init(int n = 1) {
    par.resize(n);
    rank.resize(n);
    for (int i = 0; i < n; i++) {
      par[i] = i;
      rank[i] = 0;
    }
  }

  int root(int x) {
    if (par[x] == x) {
      return x;
    } else {
      int r = root(par[x]);
      return par[x] = r;
    }
  }

  bool issame(int x, int y) {
    return root(x) == root(y);
  }

  bool merge(int x, int y) {
    x = root(x); y = root(y);
    if (x == y) return false;
    if (rank[x] < rank[y]) swap(x, y); // y is smaller, x is bigger
    if (rank[x] == rank[y]) rank[x]++;
    par[y] = x; // parent of y is x
    return true;
  }
  
};


signed main() {
  int N, M; cin >> N >> M;
  UnionFind Tree(N);
  
  for (int i = 0; i < M; i++) {
    int x, y, z; cin >> x >> y >> z;
    x--; y--;
    if (!Tree.issame(x, y)) {
      Tree.merge(x, y);
    } 
  }

  for (int i = 0; i < N; i++) {
    Parents.insert(Tree.root(i));
  }
  
  cout << Parents.size() <<  endl;
}


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

int main(){
  while(true){
    int a,b;
    char op;
    cin >> a >> op >> b;
    if(op=='+'){
      cout << a+b << endl;
    }
    else if(op=='-'){
      cout << a-b << endl;
    }
    else if(op=='*'){
      cout << a*b << endl;
    }
    else if(op=='/'){
      cout << a/b << endl;
    }
    else{
      break;
    }
  }
}


Measured memory_bytes: 3072
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define FORq(i, m, n) for(int i = m;i <= n;i++)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define PB push_back
#define MP make_pair
#define ARSCD(A,N) REP(i,N){SCD(A[i]);}
#define ARSCD1(A,N) FORq(i,1,N){SCD(A[i]);}
#define PRINTD(n) printf("%d\n",n)
#define PRINTLLD(n) printf("%lld\n",n);
#define DEBUG printf("%s\n","debug")
using namespace std;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef long long ll;
//////////////////////////////////////////////////////

int main(){
	char s[100];
	int ans = 700;
	

	scanf("%s",s);
	
	if (s[0] == 'o') { 
		ans = ans + 100;
	}
	if (s[1] == 'o') { 
		ans = ans + 100;
	}
	if (s[2] == 'o') { 
		ans = ans + 100;
	}
	
	printf("%d\n",ans);
	
	return 0;
}










Measured memory_bytes: 256
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 H = sc.nextInt();
        int W = sc.nextInt();
        int[] A = new int[N];
        int[] B = new int[N];
        for (int i = 0; i < N; i++) {
            A[i] = sc.nextInt();
            B[i] = sc.nextInt();
        }
        long ans = 0;
        for (int i = 0; i < N; i++) {
            if (A[i] >= H && B[i] >= W) ans++;
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 24524
#include <stdio.h>

struct Treasure
{
	int value;
	int weight;
};

int main(void)
{
	int w;
	int n;
	struct Treasure t[1000];
	int case_n = 0;
	
	scanf("%d", &w);
	while (w != 0){
		int i;
		struct Treasure max = {0, 0};
		int suck[1001] = {0};
		
		scanf("%d", &n);
		for (i = 0; i < n; i++){
			int j;
			
			scanf("%d,%d", &t[i].value, &t[i].weight);
			for (j = w - t[i].weight; j >= 0; j--){
				if ((j == 0 || suck[j] > 0) && suck[j + t[i].weight] < suck[j] + t[i].value){
					suck[j + t[i].weight] = suck[j] + t[i].value;
				}
			}
		}
		for (i = 0; i <= w; i++){
			if (suck[i] > max.value){
				max.value = suck[i];
				max.weight = i;
			}
		}
		
		printf("Case %d:\n", ++case_n);
		printf("%d\n%d\n", max.value, max.weight);
		
		scanf("%d", &w);
	}
	
	return 0;
}

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

using namespace std;

template <class T>inline T updmax(T& a, T b) {return a = max(a, b);}
template <class T>inline T updmin(T& a, T b) {return a = min(a, b);}

class Solution {
public:
	void solve() {
		string s;
		cin >> s;
		s[0]++;
		cout << s << "\n";
		
		return;
	};
};

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	Solution solution;
	solution.solve();
	return 0;
}

Measured memory_bytes: 256
#import sys
#input = sys.stdin.readline

def chr2ord(c):
  return ord(c) - ord('a')

N = int(input())
S = []
for i in range(N):
  wk = list(input())
  S.append(wk)

ANS = 0
# A=0として、0<=B<Nをためす。
# こたえはN倍。
for b in range(N):
  cnt = 0
  B = [['X' for _ in range(N)] for _ in range(N)]
  for i in range(N):
    for j in range(N):
      B[i][j] = S[i][(j+b)%N]
  #print(B)
  for i in range(N):
    for j in range(N):
      if B[i][j] == B[j][i]:
        cnt += 1
  
  if cnt == N*N:
    ANS += N
print(ANS)

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

int main(void){
	long long n, m;
	while(cin >> n >> m, n+m){
		vector<pair<int,int> > v(n);
		for(int i= 0; i < n; ++i){
			int a,b;
			cin >> a >> b;
			v.emplace_back(-b, a);
		}
		long long ans = 0;
		sort(v.begin(), v.end());
		for(int i = 0; i < n; ++i){
			long long d = v[i].second;
			long long p = -v[i].first;
			if(m>d){
				m -= d;
			}else if(m==0){
				ans += d*p;
			}else{
				ans += p*(d-m);
				m = 0;
			}
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 3308
import sys

def gcd(a,b):
    mod = a % b
    if mod == 0:
        return b
    return gcd(b, a%b)


n, X = map(int,input().split())
x = sorted(list(map(int, input().split())) + [X])

if len(x) == 2:
    print(x[1]- x[0])
    sys.exit()

xx = [x[i+1] -x[i] for i in range(len(x)-1)]

g = gcd(xx[0],xx[1])

if len(xx) >= 3:
    for i in range(2,n):
        g = gcd(g,xx[i])

print(g)



Measured memory_bytes: 14480
from itertools import permutations

n=int(input())
p=tuple(map(int,input().split()))
q=tuple(map(int,input().split()))

r=list(permutations(range(1,n+1)))				#1~n
																					#permutationsの結果はタプルであらわれる
print(abs(r.index(p) - r.index(q)))

Measured memory_bytes: 8052
#include<stdio.h>
#include<algorithm>
using namespace std;
char str[1200][1200];
int d[1200];
int main(){
	int a;
	while(scanf("%d",&a),a){
	//	for(int i=0;i<a;i++)for(int j=0;j<120;j++)str[i][j]=0;
		for(int i=0;i<a;i++)scanf("%s",str[i]);
		for(int i=0;i<a;i++){
			for(int j=0;str[i][j];j++){
				if('a'<=str[i][j]&&str[i][j]<='z'){
					d[i]=j;
					if(j)str[i][j-1]='+';break;
				}
			}
		}
		for(int i=0;i<a;i++){
			if(d[i]){
				for(int j=i+1;j<a;j++){
					if(d[j]<d[i])break;
					if(d[j]==d[i]){
						for(int k=i+1;k<j;k++)str[k][d[i]-1]='|';
						break;
					}
				}
			}
		}
		for(int i=0;i<a;i++)for(int j=0;str[i][j];j++)if(str[i][j]=='.')str[i][j]=' ';
		for(int i=0;i<a;i++)printf("%s\n",str[i]);
	}
}

Measured memory_bytes: 2180
//Compete against Yourself.
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define pb push_back
#define sz(i) (int)(i.size())
#define F first
#define S second
#define L long double
#define P pair<int, int>
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}
const int N = 5*(int)1e5 + 10;

int n, a[N], k;
int32_t main(){_

   cin>>n>>k;

   map<int, int> M;
   M[0]++;

   vector<int> pref;
   pref.push_back(0);
   for (int i = 1; i <= n; ++i)
   {
      cin>>a[i];
      pref.push_back(pref.back() + a[i]);
   }

   int sum = 0, ans = 0;
   for (int i = 1; i <= n; ++i)
   {
      if(i-k >= 0){
         int yy = pref[i-k] - (i-k);
         yy %= k;
         yy += k; 
         yy %= k;
         M[yy]--;
      }
      sum = pref[i] % k;
      int tt = (sum - i) % k;
      tt += k;
      tt %= k;
      ans += M[tt];
      M[tt]++;
   }
   
   cout<<ans;

   return 0;
}


Measured memory_bytes: 15856
// This file is a "Hello, world!" in C++ language by GCC for wandbox.
#include <iostream>
#include <cstdlib>

int main()
{
    int A, B;
    std::cin >> A >> B;
    
    std::cout << A * B - (A + B - 1) << std::endl;
  
  	return 0;
}

// GCC reference:
//   https://gcc.gnu.org/

// C++ language references:
//   https://msdn.microsoft.com/library/3bstk3k5.aspx
//   http://www.cplusplus.com/
//   https://isocpp.org/
//   http://www.open-std.org/jtc1/sc22/wg21/

// Boost libraries references:
//   http://www.boost.org/doc/


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

int main(){

    int k,a,b;
    cin >> k >> a>>b;
    if (a/k == b/k && a%k != 0) cout << "NG" << endl;
    else cout << "OK" <<endl;

    return 0;
}

Measured memory_bytes: 3624
N = int(input())
A = list(map(int,input().split()))
count = 0

for i in range(N):
    for j in range(N-1,i,-1):
        if A[j] < A[j-1]:
            A[j],A[j-1] = A[j-1],A[j]
            count += 1
print(*A)
print(count)


Measured memory_bytes: 5608
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int main() {
    ll n, t; cin >> n >> t;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    map<ll, ll> mp;
    ll mx = a[n-1];
    for(int i=n-2;i>=0;i--) {
        ll now = mx - a[i];
        if(now > 0) {
            mp[now]++;
        }
        mx = max(mx, a[i]);
    }
    auto it = mp.end();
    it--;
    cout << it->second;
}


Measured memory_bytes: 7296
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define vv vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int> >
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define INF 1000000000
#define eps 1e-7
#define mod 1000000007
#define int ll
using namespace std;

int A[100000+10];
int B[100000+10];
int C[100000+10];

signed main(void) {
    int N; cin>>N;
    rep(i, N) cin>>A[i];
    rep(i, N) cin>>B[i];
    rep(i, N) cin>>C[i];
    sort(A, A+N);
    sort(B, B+N);
    sort(C, C+N);

    int ans=0;
    rep(i, N) { //真ん中
        int U=(int)(lower_bound(A,A+N,B[i])-A);
        int D=N-(int)(upper_bound(C,C+N,B[i])-C);
//        cout <<U<<" "<<D<<endl;
        ans+=U*D;
    }
    cout<<ans<<endl;
    return 0;
}


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

int main() {
    long n;
    cin >> n;
    vector<bool> visited(n,0);
    long u, v, w;
    vector<vector<pair<long,long>>> children(n);
    for (long i=0; i<n-1; i++) {
        cin >> u >> v >> w;
        u--;
        v--;
        children[u].push_back(make_pair(v,w));
        children[v].push_back(make_pair(u,w));
    }
    queue<pair<long,long long>> moves;
    pair<long,long long> curr;
    vector<int> values(n,0); 
    moves.push(make_pair(0,0));
    while (moves.size()>0) {
        curr = moves.front();
        moves.pop();
        if (visited[curr.first]) continue;
        visited[curr.first] = true;
        if (curr.second%2==1) values[curr.first] = 1;
        for (auto i : children[curr.first]) {
            moves.push(make_pair(i.first,i.second+curr.second));
        }
    }
    for (auto i : values) cout << i << endl;
    return 0;
}

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

typedef long long ll;

int digit(int n)
{
    int cnt=0;
    while(n) n/=10,cnt++;
    return cnt;
}

int main()
{
    int n;
    cin>>n;
    int tot=0;
    for(int i=1;i<=n;i++)
    {
        if(digit(i)%2) tot++;
    }
    
    cout<<tot;
}

Measured memory_bytes: 256