akhauriyash/Code-Regression huggingface dataset:
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <limits>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

int64_t powmod(int64_t x, int64_t n, int64_t mod) {
	int64_t ret = 1;
	while (n > 0) {
		if (n & 1) (ret *= x) %= mod;
		(x *= x) %= mod;
		n >>= 1;
	}
	return ret;
}



int main() {
	string s; cin >> s;
	int cnt = 0;
	LL ans = 0;
	for (int i = 0; i < s.size(); i++) {
		int len = s.size() - i - 1;
		if (s[i] == '1') {
			ans += powmod(2, cnt,MOD)*powmod(3, len,MOD);
			ans = (ans + MOD) % MOD;
			cnt++;
		}
	}

	ans += powmod(2, cnt, MOD);
	ans = (ans + MOD) % MOD;

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;

struct UnionFind {
    vector<int> par;
    vector<int> siz;

    UnionFind(int n) : par(n), siz(n, 1) {
        for (int i = 0; i < n; i++) par[i] = i;
    }

    int root (int i) {
        while (par[i] != i) {
            i = par[i] = par[par[i]];
        }
        return i;
    }
    bool marge(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

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

    int size(int i) {
        return siz[root(i)];
    }
};

int main() {
    int n, m;
    cin >> n >> m;
    int edge_list[55][2];
    rep(i,m) {
        int u, v;
        cin >> u >> v;
        u--, v--;
        edge_list[i][0] = u;
        edge_list[i][1] = v;
    }
    int ans = 0;
    rep(i,m) {
        UnionFind uf(n);
        rep(j,m) {
            if (i == j) continue;
            int u = edge_list[j][0];
            int v = edge_list[j][1];
            uf.marge(u, v);
        }
        if (!uf.is_same(edge_list[i][0], edge_list[i][1])) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define MAX 1000000000000000
#define all(v) v.begin(),v.end()
#define rep(i,a,b) for(i=(ll)a;i<(ll)b;i++)
#define revrep(i,a,b) for(i=(ll)a;i>=(ll)b;i--)
#define ii pair<ll,ll>
#define MP make_pair
#define pb push_back
#define f first
#define se second
#define ll long long int
#define vi vector<ll>
ll modexp(ll a,ll b){ ll res = 1; while(b > 0){  if(b & 1) res = (res * a);  a = (a * a);  b/=2;  }  return res; }
#define rs resize
long long readLI(){  register char c;  for(c = getchar(); !(c>='0' && c<='9'); c = getchar());  register long long a=c-'0';
    for(c = getchar(); c>='0' && c<='9'; c = getchar())
        a = (a<<3)+(a<<1)+c-'0';
    return a;
}
const ll N = 100009;
ll n,i,a,ans;
map<ll,ll> m;
int main()
{
    std::ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin>>n;
    rep(i,0,n) cin>>a,m[a]++;
    for(auto &it: m){
        if(it.se > it.f) ans += it.se - it.f;
        if(it.se < it.f) ans += it.se;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 6272
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
using namespace std;
bool r = false;
string str;
int tant(int count,int size) {
	if (count == size) {
		r = true;
		return 0;
	}
	if (r) {
		return 0;
	}
	if (str.substr(count, 5) == "erase") {
		if (count + 5 == size) {
			r = true;
			return 0;
		}
		if (str[count + 5 ] == 'r') {
			if (count + 6 == size) {
				r = true;
				return 0;
			}
			return tant(count + 6, size);
		}
		return tant(count + 5,size);
	}
	if (str.substr(count, 5) == "dream") {
		if (count + 5 == size) {
			r = true;
			return 0;
		}
		if (count + 6 == size) {
			return 0;
		}
		if (str.substr(count, 7) == "dreamer") {
			if (count + 7 == size) {
				r = true;
				return 0;
			}
			if (str[count + 7] != 'a') {
				return tant(count + 7,size);
			}
		}
		return tant(count + 5, size);
	}
	return 0;
}
int main() {
	cin >> str;
	tant(0,str.size());
	cout << (r ? "YES" : "NO");
	return 0;
}

Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  
  vector<int> L(N);
  for(int i=0; i<N; i++) cin >> L[i];
  
  sort(L.begin(), L.end());
  
  int count =0;
  
  for(int i=0; i<N; i++){
    for(int j=i+1; j<N; j++){
      for(int k=j+1; k<N; k++){
        if( L[i] != L[j] && L[j]!=L[k] && L[i]+L[j] > L[k]){
            count ++;
        }
      }
    }
  }
  
  cout << count << endl;
  

}

Measured memory_bytes: 3632
// Aizu 2372: IkaNumber
// 2017.10.30 bal4u@uu

#include <stdio.h>

#define INF 0x7fffffff
#define M 1000000007

void multiply(int f[2][2], int m[2][2])
{
	unsigned long long x, y, z, w;
	
	x =  (unsigned long long)f[0][0]*m[0][0] + (unsigned long long)f[0][1]*m[1][0];
	y =  (unsigned long long)f[0][0]*m[0][1] + (unsigned long long)f[0][1]*m[1][1];
	z =  (unsigned long long)f[1][0]*m[0][0] + (unsigned long long)f[1][1]*m[1][0];
	w =  (unsigned long long)f[1][0]*m[0][1] + (unsigned long long)f[1][1]*m[1][1];
 
	f[0][0] = (int)(x % M);
	f[0][1] = (int)(y % M);
	f[1][0] = (int)(z % M);
	f[1][1] = (int)(w % M);
}

void power(int f[2][2], int n)
{
	int m[2][2] = {{1,1},{1,0}};
	if( n == 0 || n == 1) return;
	power(f, n >> 1);
	multiply(f, f);
	if (n & 1) multiply(f, m);
}

int fib(int n)
{
	int f[2][2] = {{1,1},{1,0}};
//	if (n == 0) return 0;
	power(f, n-1);
	return f[0][0];
}
 
int main()
{
    unsigned long long K, l, r, m;
	int a, b;

	scanf("%llu", &K);

	l = 0;
	if (K < INF) r = K; else r = INF;
    while (l+1 < r) {
        m = (l + r) >> 1;
        if (m * (m + 1) < K) l = m; else r = m;
    }
	K -= l * (l + 1);
    a = (int)((l<<1) + (K-1)/r + 1);

    if (K > r) K -= r;
    if (K <= (r+1)>>1) b = (int)((K<<1) - 1);
    else b = (int)(r - (r & 1) - (((K - ((r+1)>>1) - 1))<<1));

	printf("%d\n", (int)(((long long)fib(a-b+2)*fib(b+1)) % M));
	return 0;
}

Measured memory_bytes: 1816
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>



int main()
{
	int N,A[100000],i;
	scanf("%d", &N);
	for (i = 0; i < N; i++) scanf("%d", &A[i]);
	int B[100000];
	
	
	for (i = 0; i < N; i++) {
		B[A[i] - 1] = i + 1;
	}
	for (i = 0; i < N; i++) printf("%d ", B[i]);
	
}






Measured memory_bytes: 1536
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
const int N=2e6 + 5;
int a[N],b[N],rt[N*20],ls[N*20],rs[N*20],sum[N*20],vis[N*20];

int id;
void build(int &o,int l,int r){
	o=++id;
	sum[o]=0;
	if(l==r) return;
	int m=(l+r)>>1;
	build(ls[o],l,m);
	build(rs[o],m+1,r);
}

void update(int &o,int l,int r,int last,int pos,int val){
	o=++id;
	ls[o]=ls[last];
	rs[o]=rs[last];
	sum[o]=sum[last]+val;
	if(l==r) return;
	int m=(l+r)>>1;
	if(pos<=m)
        update(ls[o],l,m,ls[last],pos,val);
	else
        update(rs[o],m+1,r,rs[last],pos,val);
}
int query(int pos,int root,int l,int r){
	if(l==r)
        return sum[root];
	int m=(l+r)>>1;
	if(m>=pos)
        return sum[rs[root]]+query(pos,ls[root],l,m);
	else
        return query(pos,rs[root],m+1,r);
}

int main(){
	int n,q,l,r,k;
    memset(vis,0,sizeof(vis));
    scanf("%d%d",&n,&q);
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    id=0;
    build(rt[0],1,n);
    for(int i=1;i<=n;i++){
        if(!vis[a[i]])//如果a[i]还未出现过
            update(rt[i],1,n,rt[i-1],i,1);
        else{//如果a[i]已经出现了
            int pos=vis[a[i]];
            int temp;
            update(temp,1,n,rt[i-1],pos,-1);
            update(rt[i],1,n,temp,i,1);
        }
        vis[a[i]]=i;
    }
    while(q--){
        scanf("%d%d",&l,&r);
        int num=query(l,rt[r],1,n);
        printf("%d\n",num);
    }
	return 0;
}


Measured memory_bytes: 409816
from collections import Counter


def resolve():
    N = int(input())
    A = list(map(int, input().split()))

    O = Counter(A[::2])
    E = Counter(A[1::2])

    most_O = O.most_common(2)
    most_E = E.most_common(2)
    # 番兵
    most_O.append((0, 0))
    most_E.append((0, 0))

    cnt = 0
    # key comp
    if most_O[0][0] == most_E[0][0]:
        # value
        res1 = most_O[0][1] + most_E[1][1]
        res2 = most_O[1][1] + most_E[0][1]
        cnt = max(res1, res2)
    else:
        cnt = most_O[0][1] + most_E[0][1]

    # 数字が少ないものを書き換える為、Nで引く
    print(N - cnt)


if __name__ == "__main__":
    resolve()


Measured memory_bytes: 23140
//start of jonathanirvings' template v3.0.3 (BETA)

#include <bits/stdc++.h>
using namespace std;

typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
typedef pair<string,string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef vector<LL> vl;
typedef vector<vl> vvl;

double EPS = 1e-9;
int INF = 1000000005;
long long INFF = 1000000000000000005LL;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};

#ifdef TESTING
  #define DEBUG fprintf(stderr,"====TESTING====\n")
  #define VALUE(x) cerr << "The value of " << #x << " is " << x << endl
  #define debug(...) fprintf(stderr, __VA_ARGS__)
#else
  #define DEBUG 
  #define VALUE(x)
  #define debug(...)
#endif

#define FOR(a,b,c) for (int (a)=(b);(a)<(c);++(a))
#define FORN(a,b,c) for (int (a)=(b);(a)<=(c);++(a))
#define FORD(a,b,c) for (int (a)=(b);(a)>=(c);--(a))
#define FORSQ(a,b,c) for (int (a)=(b);(a)*(a)<=(c);++(a))
#define FORC(a,b,c) for (char (a)=(b);(a)<=(c);++(a))
#define FOREACH(a,b) for (auto &(a) : (b))
#define REP(i,n) FOR(i,0,n)
#define REPN(i,n) FORN(i,1,n)
#define MAX(a,b) a = max(a,b)
#define MIN(a,b) a = min(a,b)
#define SQR(x) ((LL)(x) * (x))
#define RESET(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ALL(v) v.begin(),v.end()
#define ALLA(arr,sz) arr,arr+sz
#define SIZE(v) (int)v.size()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr,sz) sort(ALLA(arr,sz))
#define REVERSEA(arr,sz) reverse(ALLA(arr,sz))
#define PERMUTE next_permutation
#define TC(t) while(t--)

inline string IntToString(LL a){
  char x[100];
  sprintf(x,"%lld",a); string s = x;
  return s;
}

inline LL StringToInt(string a){
  char x[100]; LL res;
  strcpy(x,a.c_str()); sscanf(x,"%lld",&res);
  return res;
}

inline string GetString(void){
  char x[1000005];
  scanf("%s",x); string s = x;
  return s;
}

inline string uppercase(string s){
  int n = SIZE(s); 
  REP(i,n) if (s[i] >= 'a' && s[i] <= 'z') s[i] = s[i] - 'a' + 'A';
  return s;
}

inline string lowercase(string s){
  int n = SIZE(s); 
  REP(i,n) if (s[i] >= 'A' && s[i] <= 'Z') s[i] = s[i] - 'A' + 'a';
  return s;
}

inline void OPEN (string s) {
  #ifndef TESTING
  freopen ((s + ".in").c_str (), "r", stdin);
  freopen ((s + ".out").c_str (), "w", stdout);
  #endif
}

//end of jonathanirvings' template v3.0.3 (BETA)

int cost[503][503];
int aktif[503][503];
int n;

void upd(int x,int y)
{
  REP(d,4)
  {
    int xx = x + dirx[d];
    int yy = y + diry[d];
    if (0 <= xx && xx < n && 0 <= yy && yy < n)
    {
      if (cost[xx][yy] > cost[x][y] + aktif[x][y])
      {
        cost[xx][yy] = cost[x][y] + aktif[x][y];
        upd(xx,yy);
      }
    }
  }
}

int main()
{
  scanf("%d",&n);
  REP(i,n) REP(j,n) aktif[i][j] = 1;
  REP(i,n) REP(j,n)
  {
    cost[i][j] = min(min(i,n-i-1),min(j,n-j-1));
  }
  int risan = 0;
  REP(i,n*n)
  {
    int a;
    scanf("%d",&a);
    --a;
    int x = a / n;
    int y = a % n;
    risan += cost[x][y];
    aktif[x][y] = 0;
    upd(x,y);
  }
  printf("%d\n",risan);
  return 0;
}











Measured memory_bytes: 20908
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  // CODE FESTIVAL 2017 qual A C - Palindromic Matrix
  // 4 : H/2 * W/2
  // 2 : H%2 * W/2 + H/2 * W%2
  // 1 : H%2 * W%2
  int H, W; cin >> H >> W;
  vector<string> a(H);
  REP(i, H){
    cin >> a[i];
  }
  
  vector<int> res(3, 0);
  res[0] = (H/2) * (W/2);
  res[1] = (H%2) * (W/2) + (H/2) * (W%2);
  res[2] = (H%2) * (W%2);
  
  vector<int> alp(26, 0);
  REP(i, H){
    REP(j, W){
      alp[a[i][j] - 'a']++;
    }
  }

  vector<int> ans(3, 0);
  REP(i, 26){
    ans[0] += alp[i] / 4; alp[i] %= 4;
    ans[1] += alp[i] / 2; alp[i] %= 2;
    ans[2] += alp[i];
  }
  
  if(ans[0] < res[0]){
    cout << "No" << endl;
    return 0;
  }else if(ans[0] > res[0]){
    ans[1] += (ans[0] - res[0]) * 2;
  }
  if(ans[1] < res[1]){
    cout << "No" << endl;
    return 0;
  }
  
  cout << "Yes" << endl;
}


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

int main() {
  int n,l=0,count=0,f=0;
  cin >> n;
  int r=n-1;
  vector<char> c(n);
  for(int i=0;i<n;i++) cin >> c.at(i);
  while(f==0){
    if(l>=r) break;
    if(c.at(l)=='W' && c.at(r)=='R'){
      count++;
      l++;
      r--;
    }
    else if(c.at(l)=='R') l++;
    else if(c.at(r)=='W') r--;
  }
  cout << count;
}


Measured memory_bytes: 3568
import java.io.*
import java.util.*
import java.lang.Math.*


fun main() {
    val N = rd.readInt()
    val A = rd.readIntArray()
    assert(A.size == N)

    // A[i]+A[j] == j - i
    // i + A[i] == j - A[j]

    val mp = mutableMapOf<Int, Int>()

    var ans = 0L
    for (i in 0 until N) {
        ans += mp[i - A[i]] ?: 0
        mp[i+A[i]] = (mp[i+A[i]] ?: 0) + 1
    }

    println(ans)
}


//val rd = debug.Reader("abc", "166", "e", "sample-1")
val rd = Reader()
fun main(args: Array<String>) {
    Thread(null, MainThread(), "mainThread", 128 * 1024 * 1024).start()
}


const val MOD = 1_000_000_007L; const val INF = Int.MAX_VALUE/2; const val LINF = Long.MAX_VALUE/2
const val EPS = 1e-9; fun DBLEQ(a: Double, b: Double): Boolean {return abs(a - b) < EPS}
data class IntPair(val first: Int, val second: Int)
data class To(val idx: Int, val cost: Long)
fun <T>edge(V: Int): Array<ArrayList<T>> { return Array(V){ArrayList<T>()} }
val errPrintln: (Any) -> Unit = { msg -> System.err.println(msg) }
class MainThread : Runnable {
    override fun run() { main() }
}
class Reader {
    private val br = BufferedReader(InputStreamReader(System.`in`))
    val readString: () -> String = { br.readLine() }
    val readInt: () -> Int = { br.readLine().toInt() }
    val readLong: () -> Long = { br.readLine().toLong() }
    val readIntArray: () -> IntArray = { br.readLine().split(' ').map { it.toInt() }.toIntArray() }
    val readLongArray: () -> LongArray = { br.readLine().split(' ').map { it.toLong() }.toLongArray() }
    val readListInt: () -> List<Int> = { br.readLine().split(' ').map { it.toInt() } }
    val readListLong: () -> List<Long> = { br.readLine().split(' ').map { it.toLong() } }
}


Measured memory_bytes: 72264
#include <iostream>

using namespace std;
using ull = unsigned long long;

#define Rep(i, n) for(ull i = 0; i < (ull)(n); ++i)
#define For(i, s, n) for(ull i = s; i < (ull)(n); ++i)

int main() {
  ull N, D;
  cin >> N >> D;
  ull dd = D * D;
  ull answer = 0;
  Rep(i, N) {
    ull x, y;
    cin >> x >> y;
    if (x * x + y * y <= dd) answer++;
  }
  cout << answer << endl;
  return 0;
}


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

#define repi(i, a, b) for(int i = (int)(a); i < (int)(b); ++i)
#define rep(i, n) repi(i, 0, n)
#define all(x) (x).begin(), (x).end()

const bool DEBUG = false;

int H, W;
vector<string> S;

inline void input() {
  if(DEBUG) cout << "input()" << endl;
  cin >> H >> W;
  rep(i, H) {
    string x;
    cin >> x;
    S.push_back(x);
  }
}

inline vector<vector<int>> solve_LC() {
  if(DEBUG) cout << "solve_LC()" << endl;
  vector<vector<int>> LC(H, vector<int>(W));
  for (int i = 0; i < H; i++) {
    LC[i][0] = S[i][0] == '.';
    for (int j = 1; j < W; j++) {
      if(S[i][j] == '#') {
        LC[i][j] = 0;
      } else {
        LC[i][j] = LC[i][j-1]+1;
      }
    }
  }
  return LC;
}

inline vector<vector<int>> solve_RC() {
  if(DEBUG) cout << "solve_RC()" << endl;
  vector<vector<int>> RC(H, vector<int>(W));
  for (int i = 0; i < H; i++) {
    RC[i][W-1] = S[i][W-1] == '.';
    for (int j = W-2; j >= 0; j--) {
      if(S[i][j] == '#') {
        RC[i][j] = 0;
      } else {
        RC[i][j] = RC[i][j+1]+1;
      }
    }
  }
  return RC;
}

inline vector<vector<int>> solve_DC() {
  if(DEBUG) cout << "solve_DC()" << endl;
  vector<vector<int>> DC(H, vector<int>(W));
  for (int j = 0; j < W; j++) {
    DC[0][j] = S[0][j] == '.';
    for (int i = 1; i < H; i++) {
      if(S[i][j] == '#') {
        DC[i][j] = 0;
      } else {
        DC[i][j] = DC[i-1][j]+1;
      }
    }
  }
  return DC;
}

inline vector<vector<int>> solve_UC() {
  if(DEBUG) cout << "solve_UC()" << endl;
  vector<vector<int>> UC(H, vector<int>(W));
  for (int j = 0; j < W; j++) {
    UC[H-1][j] = S[H-1][j] == '.';
    for (int i = H-2; i >= 0; i--) {
      if(S[i][j] == '#') {
        UC[i][j] = 0;
      } else {
        UC[i][j] = UC[i+1][j]+1;
      }
    }
  }
  return UC;
}

inline int solve() {
  vector<vector<int>> LC = solve_LC();
  vector<vector<int>> RC = solve_RC();
  vector<vector<int>> DC = solve_DC();
  vector<vector<int>> UC = solve_UC();
  int res = 0;

  if(DEBUG) cout << "solve()" << endl;

  rep(i, H) {
    rep(j, W) {
      res = max(res, LC[i][j]+RC[i][j]+DC[i][j]+UC[i][j]);
    }
  }
  return res - 3;
}

inline void Main() {
  // code
  input();
  cout << solve() << endl;
}

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(20);
  Main();
  return 0;
}


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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}
ll nextLong() { ll x; scanf("%lld", &x); return x;}

int main2() {
  int H = nextInt();
  int W = nextInt();
  int D = nextInt();

  pair<int,int> p[H*W + 1];
  REP(h, H) REP(w, W) {
    int x = nextInt();
    p[x] = {h, w};
  }

  vector<ll> acc(H*W+10);
  for (int i = 1; i <= H*W; i++) {
    if (i - D <= 0) {
      acc[i] = 0;
    } else {
      acc[i] = acc[i - D] + abs(p[i-D].first - p[i].first) + abs(p[i-D].second - p[i].second);
    }
  }

  // REP(i, H*W) cout << p[i+1] << endl;
  // REP(i, H*W) cout << acc[i+1] << endl;


  int Q = nextInt();
  REP(_, Q) {
    int from = nextInt();
    int to = nextInt();

    // int ans = 0;
    // while (from != to) {
    //   ans += abs(p[from].first - p[from + D].first) + abs(p[from].second - p[from + D].second);
    //   from += D;
    // }
    int ans = acc[to] - acc[max(0, from)];
    printf("%d\n", ans);
  }

  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}

Measured memory_bytes: 2560
import java.util.*;
public class Main 
{
	public static void main(String[] args) 
	{
		Scanner sc = new Scanner(System.in);
		int S = sc.nextInt();
		int h = S / 3600;
		S %= 3600;
		int m = S / 60;
		System.out.printf("%d:%d:%d\n", h, m, S % 60);
	}
}

Measured memory_bytes: 17332
#include<bits/stdc++.h>
#define int long long
#define REP(i,a,n) for(int i=a;i<(n);i++)
#define REP_sz(i,s) for(int i=0;i<s.size();i++)
#define RE return
#define FILL(a,b) memset(a,b,sizeof(a))
#define SO(a) sort(all(a))
#define pb push_back
#define sz(a) a.size()
#define V vector
#define ld long double
#define viit(a) vector<int>::iterator a
#define msit1(a) map<string,int>::iterator a
#define miit(a) map<int,int>::iterator a
#define msit2(a) map<int,string>::iterator a
#define IT iterator
#define FOR(i,a,n) for(int i=a;i<=(n);i++)
#define B(s) s.back()
#define all(a) a.begin(),a.end()
#define ER1(a) a.erase(a.begin())
#define ER0(a) a.erase(a.end())
#define pii pair<int,int>
#define pause system("PAUSE")
#define cls system("CLS")
using namespace std;
signed main()
{
	ios::sync_with_stdio(0);
    cin.tie(0);
	int n,m;
	cin>>n>>m;
	V<int>a(n);
	REP(i,0,n)cin>>a[i];
	cout<<(n-m)/(m-1)+((n-m)%(m-1)? 2:1);
    return 0;
}


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

void init(vector<int>&L, int x) {
	for (int i = 0;i < x;i++) {
		L[i] = i;
	}
	return;
}

int root(int x, vector<int>&L) {
	if (L[x] == x)
		return x;
	return L[x] = root(L[x],L);
}

void unite(int x, int y, vector<int>&L) {
	L[root(y,L)] = root(x,L);
	return;
}

int main() {
	int N, K, L;
	cin >> N >> K >> L;
	vector<int> Lnet(N);
	vector<int> Rnet(N);
	init(Lnet, N);
	init(Rnet, N);
	int a, b;
	for (int i = 0;i < K;i++) {
		cin >> a >> b;
		a--;b--;
		if (a < b) swap(a, b);
		unite(a, b, Lnet);
	}
	for (int i = 0;i < L;i++) {
		cin >> a >> b;
		a--;b--;
		if (a < b) swap(a, b);
		unite(a, b, Rnet);
	}
	map<pair<int, int>, int> M;
	
	for (int i = 0;i < N;i++) {
		a = root(i,Lnet);
		b = root(i,Rnet);
		if (M.count({a,b})) {
			M[{a, b}]++;
		}
		else {
			M.insert({ {a,b},1 });
		}
	}
	for (int i = 0;i < N;i++) {
		a = Lnet[i];
		b = Rnet[i];
		cout << M[{a, b}] << " ";
	}
}

Measured memory_bytes: 13568
#include <bits/stdc++.h>
typedef long long ll;
#define mod 1000000007
#define INF 1000000000
#define endl "\n"
#define all(s) s.begin(),s.end()
#define pb push_back
#define uno unordered_map
#define pi 3.1415926536
#define dig(a) fixed<<setprecision(a)
#define w(zz) int zz; cin>>zz; while(zz--)
#define foreach(var,i) for(auto i = var.begin();i!=var.end();i++)
#define fast() ios_base::sync_with_stdio(false); cin.tie(NULL);
ll power(ll a, ll n) {ll res = 1; while (n) {if (n % 2) {res *= a;} n >>= 1; a *= a;} return res;}
ll powerm(ll a, ll n, ll m) {ll res = 1; while (n) {if (n % 2) {res = (res * a) % m;} n >>= 1; a = (a * a) % m;} return res;}
using namespace std;
int main(){
	fast();
	int n,x,t;
	cin>>n>>x>>t;
	int q = n/x;
	if(n%x){
		cout<<(q+1)*t<<endl;
		return 0;
	}
	cout<<q*t<<endl;
	return 0;
}

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

using namespace std;

int main ()

{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    string word;
    bool check1 = true, check2 = true, check3 = true;
    cin >> word;
    int n = (word.length()-1)/2;
    for ( int i = 0, j = word.length()-1; i < n; i++, j-- )
    {
        if(word[i] != word[j])
        {
            cout << "No\n";
            return 0;
        }
        if ( word[i] != word[n-1-i] )
        {
            cout << "No\n";
            return 0;
        }
        if ( word[j] != word[n+1+i] )
        {
            cout << "No\n";
            return 0;
        }
    }
    cout << "Yes\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define sz(x) (int)x.size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
typedef vector<int> vi;
typedef long long ll;
typedef double db;

const int N = 105;
int	n;
char a[N], b[N];

int main(){
	scanf("%d", &n);
	scanf("%s%s", a, b);
	int ans = 2 * n;
	for (int i = 0; i < n; i++) {
		int f = 1;
		for (int j = i; j < n; j++) {
			if (a[j] != b[j - i]) {
				f = 0;
				break;
			}
		}
		if (f) ans = min(ans, n - i + i * 2);
	}
	printf("%d\n", ans);
	return 0;
}


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

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) # VariableName
#define LOG(x) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<endl;
#define LOG2(x,y) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<endl;
#define LOG3(x,y,z) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
#define LOG4(w,x,y,z) if(DEBUG)cout<<TO_STRING(w)<<"="<<w<<" "<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;

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; }

lli nex(char c){
    return c-'a';
}

void func(std::string S_A, std::string S_B, std::string S_C){

    lli aCnt=0,bCnt=0,cCnt=0;
    lli now = 0;
    while(1){
        lli nex;
        LOG(now);
        if(now==0){
            
            if(aCnt >= S_A.size()){
                cout<<'A'<<endl;
                return;
            }
            nex = (S_A[aCnt]-'a');
            aCnt++;
        }
        else if(now==1){
            
            if(bCnt >= S_B.size()){
                cout<<'B'<<endl;
                return;
            }
            nex = (S_B[bCnt]-'a');
            bCnt++;
        }
        else{
            
            if(cCnt >= S_C.size()){
                cout<<'C'<<endl;
                return;
            }
            nex = (S_C[cCnt]-'a');
            cCnt++;
        }
        now = nex;
    }

}

int main(){
    // cout << fixed << setprecision(5);

    std::string S_A;
    std::cin >> S_A;
    std::string S_B;
    std::cin >> S_B;
    std::string S_C;
    std::cin >> S_C;
    func(S_A, S_B, S_C);
    return 0;
}


Measured memory_bytes: 3636
#include <cstdio>
#include <limits>
#include <cassert>
#include <functional>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <iterator>
#include <queue>
#include <utility>

using namespace std;

struct S {
    string F;
    int z;
    int t;
    S(const string& F, int z, int t) : F(F), z(z), t(t) {}
};

map<string, int> ANSWER;
void init() {
    string init = "01234567";
    ANSWER[init] = 0;
    queue<S> Q;
    Q.push(S(init, 0, 0));
    vector<int> d[8];
    for (int i = 0; i < 8; i++) {
        if (i % 4 != 0) d[i].push_back(-1);
        if (i % 4 != 3) d[i].push_back(1);
        if (i / 4 == 0) d[i].push_back(4);
        else d[i].push_back(-4);
    }
    while (!Q.empty()) {
        S s = Q.front(); Q.pop();
        int z = s.z;
        int t = s.t;
        for (int i = 0; i < d[z].size(); i++) {
            int nz = z + d[z][i];
            if (nz < 0 || nz >= 8) continue;
            string nF = s.F;
            swap(nF[z], nF[nz]);
            if (ANSWER.count(nF)) continue;
            ANSWER[nF] = t + 1;
            Q.push(S(nF, nz, t + 1));
        }
    }
}

string F;
bool input() {
    F = "";
    for (int i = 0; i < 8; i++) {
        int x; cin >> x;
        if (cin.fail()) return false;
        F.push_back(x + '0');
    }
    cin.ignore(numeric_limits<streamsize>::max(), '\n');
    return true;
}

void solve() {
    cout << ANSWER[F] << endl;
}

int main() {
    init();
    while (input()) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3468
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')


class CombMod:

    def __init__(self, N, MOD=10**9 + 7):

        N = N + 1
        inv = [0] * N
        fact = [0] * N
        fact_inv = [0] * N

        inv[0] = 0
        inv[1] = 1
        for n in range(2, N):
            q, r = divmod(MOD, n)
            inv[n] = inv[r] * (-q) % MOD

        fact[0] = 1
        for n in range(1, N):
            fact[n] = n * fact[n - 1] % MOD

        fact_inv[0] = 1
        for n in range(1, N):
            fact_inv[n] = fact_inv[n - 1] * inv[n] % MOD

        self.fact = fact
        self.fact_inv = fact_inv
        self.inv = inv

    def comb(self, n, r, mod=10**9 + 7):
        return self.fact[n] * self.fact_inv[r] % mod * self.fact_inv[n - r] % mod

    def perm(self, n, r, mod=10**9 + 7):
        return self.fact[n] * self.fact_inv[n - r] % mod


def main():

    N, M = in_nn()
    mod = 10**9 + 7
    c = CombMod(M)

    ans = c.perm(M, N)
    for k in range(1, N + 1):
        ans -= (-1)**(k - 1 % 2) * c.comb(N, k) * c.perm(M - k, N - k)
        ans %= mod

    ans *= c.perm(M, N)
    ans %= mod

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 80328
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC043BeTogether
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            int[] a = new int[N];
            string[] vals = Console.ReadLine().Split(' ');
            int mina, maxa;
            mina = int.MaxValue;
            maxa = int.MinValue;
            for(int i=0; i < N; i++)
            {
                a[i] = int.Parse(vals[i]);
                if (a[i] > maxa)
                    maxa = a[i];
                if (a[i] < mina)
                    mina = a[i];
            }

            int minCost = int.MaxValue;
            for(int i= mina; i <= maxa; i++)
            {
                int cost = 0;
                for(int j=0; j < N; j++)
                {
                    cost += (a[j] - i) * (a[j] - i);
                }
                if (cost < minCost)
                    minCost = cost;
            }

            Console.WriteLine(minCost);
        }
    }
}


Measured memory_bytes: 11092
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(void){
    int a,b,k;
    cin>>a>>b>>k;
    if(2*k>=b-a+1){
        for(int i=a;i<=b;i++){
            cout<<i<<endl;
        }
    } else {
        for(int i=a;i<a+k;i++){
            cout<<i<<endl;
        }
        for(int i=b-k+1;i<=b;i++){
            cout<<i<<endl;
        }
    }
    return 0;
}


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

int main(void){
    char s[4]; 
    int count = 0, ans = 0;

    scanf("%s", s);

    for(int i = 0; i < 3; i++){
        if(s[i] == 'R'){
            count++;
            if(count > ans){
                ans = count;
            }
        }else{            
            count = 0;
        }
    }

    printf("%d\n", ans);

    return 0;

} 


Measured memory_bytes: 3756
// Package main provides
//
// File:  d.go
// Author: ymiyamoto
//
// Created on Fri Jan 11 02:34:07 2019
//
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

const mod = 1e9 + 7

var dp map[int]int

func fact(n int) int {
	if v, ok := dp[n]; ok {
		return v
	}

	dp[n] = (n * fact(n-1)) % mod
	return dp[n]
}

func pow(a, b int) int {
	if b == 0 {
		return 1
	} else if b%2 == 0 {
		return pow((a*a)%mod, b/2) % mod
	}

	return (a * pow((a*a)%mod, b/2)) % mod
}

func combination(n, k int) int {
	if n < 0 || k < 0 || n < k {
		return 0
	}
	if n == 0 && k == 0 {
		return 1
	}

	return (((fact(n) * pow(fact(k), mod-2)) % mod) * pow(fact(n-k), mod-2)) % mod
}

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()

	arr := make([]int, n+1)
	for i := range arr {
		arr[i] = nextInt()
	}

	var sameValue int
	m := map[int]int{}
	for i := range arr {
		if _, ok := m[arr[i]]; ok {
			sameValue = arr[i]
			break
		} else {
			m[arr[i]]++
		}
	}

	isCount := true
	num := -1
	for i := range arr {
		if sameValue == arr[i] {
			isCount = !isCount
		}
		if isCount {
			num++
		}
	}

	dp = make(map[int]int)
	dp[0] = 1
	for i := 1; i <= n+1; i++ {
		fmt.Println((combination(n+1, i) - combination(num, i-1) + mod) % mod)
	}
}


Measured memory_bytes: 22656
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int (i)=(m);(i)<(n);++(i))
#define rREP(i,m,n) for(int (i)=(n)-1;(i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;
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;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

int main() {
	init();

	int N; cin >> N;
	vector<int>h(N);
	rep(i, 0, N)cin >> h[i];
	int ans = 0;
	h.push_back(0);
	while (1) {
		bool is = false;
		int x = INF, cnt = 0;
		rep(i, 0, N + 1) {
			if (h[i] == 0) {
				if (is) {
					rep(j, 0, i) {
						if (h[j] != 0)h[j] -= x;
					}
					ans += x;
					break;
				}
				else cnt++;
			}
			else {
				is = true;
				chmin(x, h[i]);
			}
		}
		if (cnt == N+1)break;
	}
	cout << ans << "\n";

	return 0;
}

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

int main(){
	int sx, sy, tx, ty;
	cin >> sx >> sy >> tx >> ty;
	int dx = tx - sx, dy = ty - sy;
	string ans;
	rep(dx)
		ans += "R";
	rep(dy)
		ans += "U";
	rep(dx)
		ans += "L";
	rep(dy+1)
		ans += "D";
	rep(dx+1)
		ans += "R";
	rep(dy+1)
		ans += "U";
	ans += "LU";
	rep(dx+1)
		ans += "L";
	rep(dy+1)
		ans += "D";
	ans += "R";
	cout << ans << endl;
	return 0;
} 

Measured memory_bytes: 256
//Author: Fuadul Hasan(fuadul202@gmail.com)
//BSMRSTU,Gopalganj
#include<bits/stdc++.h>
using namespace std;int tc = 1;
#define happy ios::sync_with_stdio(false);
#define coding  cin.tie(0);
#define F first
#define S second
#define mp make_pair
#define ll long long
#define Pi atan(1)*4
#define pb  push_back
#define vpr vector<pr> 
#define pr pair<int, int> 
#define vi std::vector<int>
#define vll std::vector<ll>
#define YES printf("YES\n");
#define NO printf("NO\n");
#define Yes printf("Yes\n");
#define No printf("No\n");
#define all(n) n.begin(),n.end()
#define point(x) setprecision(x)
#define Test printf("Case %d: ",tc++);
#define Unique(c) (c).resize(unique(all(c))-(c).begin())
#define vout(v) for (auto z: v) cout << z << ""; cout << endl;

#define error(args...) {vector<string>_v=split(#args,',');err(_v.begin(),args);cout<<endl;}
vector<string> split(const string &s, char c) {vector<string>v; stringstream ss(s); string x;
while (getline(ss, x, c))v.emplace_back(x); return move(v);} void err(vector<string>::iterator it) {}
template<typename T, typename... Args>void err(vector<string>::iterator it, T a, Args...args) {
cout << it->substr((*it)[0] == ' ', it->length()) << " = " << a << " "; err(++it, args...);}

const int M = 1e9 + 7;
const ll  Inf = (ll)2e18 + 5;
const int N   = 2e5 + 5;
ll vis[N],res[N];

int solve() 
{
	//happy coding

	ll n;
	cin>>n;
	string ret ;
	ll prob = 1;
	ll cnt = 0;
	while(1){
		prob *= 26;
		cnt++;
		if (prob >= n) break;
		n-=prob;
	}
	--n;
	for(int i =0;i<cnt;i++){
		ret += (char)('a'+n%26);
		n/=26;
	}

	reverse(all(ret));
	vout(ret);

	
	return 0;
}
int main(){
	int test = 1;
  	//scanf("%d", &test);
  	while (test--)solve();return 0;
}


Measured memory_bytes: 3604
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<ctime>
#include<cstdlib>
#include<sys/time.h>
#include<cstring>
#include<cmath>
using namespace std;
typedef long long ll;
inline int ri()
{
	register int x=0;register bool f=0;register char ch=getchar();
	while(ch>'9'||ch<'0'){if(ch=='-')f=1;ch=getchar();}
	while(ch<='9'&&ch>='0'){x=x*10+ch-'0';ch=getchar();};
	return f?-x:x;
}
void wi(int x)
{
	if(x<0)	x=-x,putchar('-');
	if(x>9)	wi(x/10);
	putchar('0'+x%10);
}
const int N=2e5+7;
int a[N],b[N],aa[N],bb[N];
int main()
{
	int n=ri(),i,k,l1,l2,r1,r2,t=1,ans=0,sum;
	for(i=1;i<=n;i++)	a[i]=ri();
	for(i=1;i<=n;i++)	b[i]=ri();
	for(k=0;k<=28;k++,t*=2)
	{
		for(i=1;i<=n;i++)	aa[i]=a[i]%(2*t);
		for(i=1;i<=n;i++)	bb[i]=b[i]%(2*t);
		sort(bb+1,bb+1+n);sum=0;
		for(i=1;i<=n;i++)
		{
			l1=lower_bound(bb+1,bb+1+n,t-aa[i])-bb;
			r1=lower_bound(bb+1,bb+1+n,2*t-aa[i])-bb-1;
			l2=lower_bound(bb+1,bb+1+n,3*t-aa[i])-bb;
			r2=lower_bound(bb+1,bb+1+n,4*t-aa[i])-bb-1;
			sum+=r2-l2+1+r1-l1+1;
		}
		if(sum&1)	ans|=t;
	}
	wi(ans);putchar('\n');
	return 0;
}


Measured memory_bytes: 3328
n=int(input())
c=[0,0,0,0]

for i in range(n):
  a=input()
  if a=="AC":
    c[0]+=1
  if a=="WA":
    c[1]+=1
  if a=="TLE":
    c[2]+=1
  if a=="RE":
    c[3]+=1

print("AC x "+str(c[0])+"\nWA x "+str(c[1])+"\nTLE x "+str(c[2])+"\nRE x "+str(c[3]))

Measured memory_bytes: 9144
# 初期入力
N,K = (int(x) for x in input().split(" "))
R,S,P = (int(x) for x in input().split(" "))
ten_janken_dic ={"R":R,"S":S,"P":P} #じゃんけんの役ごとの点を辞書
ten_janken_sort =sorted(ten_janken_dic.items(),key=lambda x: x[1])
T =input()

#合計点と高橋君が出す手を同時進行
sum_janken = 0 # 合計点
takahasi = [] # 高橋君が出す手,K回前の手も出せる＝すべて勝つとした場合
for i in T:
    if i =="r":
        sum_janken += P #6
        takahasi.append("P")
    elif i == "s":
        sum_janken += R #8
        takahasi.append("R")

    elif i == "p":
        sum_janken += S #7
        takahasi.append("S")
takahasi_mae =[]
from copy import deepcopy
takahasi_mae = deepcopy(takahasi)

# K回前の手は出せない        
for i,v in enumerate(takahasi[K:]):
    if v ==takahasi[(i+K)-K]:
        sum_janken -= ten_janken_dic[v]
        x = ["R","S","P"]
        if takahasi[(i+K)-K] in x:
            x.remove( takahasi[(i+K)-K] ) #K回前の手を消す
        if i+K+K < len(takahasi):    
            if takahasi[i+K+K] in x:
                x.remove( takahasi[i+K+K] ) #K回後の手を消す
        if len(x) ==1:
            takahasi[i+K] =x[0]
        elif x[0]==ten_janken_sort[2][0] or x[1] ==ten_janken_sort[2][0] : #高い点を選ぶ
            takahasi[i+K] =ten_janken_sort[2][0]
        else:
            takahasi[i+K] =ten_janken_sort[1][0] #2番目に高い点のキー（点順でソートしてある）
print(sum_janken)

Measured memory_bytes: 6128
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

int main(){
    int N, A, B;
    cin >> N >> A >> B;
    cout << min(A, B) << ' ' << max(0, A+B-N) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define For(i,j,k) for(int i=j;i<=k;++i)
using namespace std;
int read(){
	int x=0,l=1; char ch=getchar();
	while(!isdigit(ch)) {if (ch=='-') l=-1; ch=getchar();}
	while(isdigit(ch)) x=x*10+(ch^48),ch=getchar();
	return x*l;
}
int main(){
	int n=read(),m=read(); if (n>m) swap(n,m);
	if (n==1) {if (m==1) printf("1\n"); else printf("%d\n",m-2);}
	else if (n==2) printf("0\n");
	else printf("%lld\n",(long long)(n-2)*(m-2));
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
const long long M=100000;
using namespace std;
int main(){
	int i=1,j=1,k=0,N;
	int a[M];
	cin>>N;
	for(i;i<M;i++){
		j=i*i;
		if(j<=N)
		{
			a[k]=j;
			k++;
			}
		else{ break;}
	}
	
	cout<<a[k-1]<<endl;	
	return 0;
	}

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

int main() {
  ll N, A, B;
  cin >> N >> A >> B;
  ll ans = (N / (A + B))*A;
  if((N % (A + B)) <= A)
    ans += (N % (A + B));
  else
    ans += A;
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(i, n) for(int i=0; i<=n; i++)
#define repr(i, n) for(int i=n; i>0; i--)
#define REPR(i, n) for(int i=n; i>=0; i--)
const ll INF = 1LL<<60;
const int INT_INF = 1e9;
const ll MOD = 1e9+7;
template<class T> void puts(T x) { std::cout << x << std::endl; }
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; }
using namespace std;

int n, a[200010], b[200010];

int main() {
    cin >> n;
    rep(i, n) cin >> a[i+1];

    for (int i = n; i > 0; i--) {
        b[i] = a[i];
        for (int j = 2; i * j <= n; j++) {
            b[i] += b[i * j];
        }
        b[i] %= 2;
    }

    vector<int> ans;
    for (int i = 1; i <= n; i++) {
        if (b[i]) ans.emplace_back(i);
    }

    cout << ans.size() << endl;
    for (auto x: ans) cout << x << ' ';
    cout << endl;
}


Measured memory_bytes: 3064
#include <bits/stdc++.h>
//----***やべーやつら***----
using namespace std;
#define int long long

//----***型定義***----
using ll = long long;
using P = pair<int,int>;

//----***Like a Pythonista***----
#define REP(ii,jj,nn) for (ll ii=jj;ii<(nn);ii++)
#define RREP(ii,nn,jj) for (ll ii = nn; jj<ii;ii--)
#define each(i,...) for (auto&& i:__VA_ARGS__)
#define ALL(vec) (vec).begin(),(vec).end()
#define sum(...) accumulate(ALL(__VA_ARGS__),0LL)
#define dsum(...) accumulate(ALL(__VA_ARGS__),0.0)
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
template<class T> inline auto max(const T& a){ return *max_element(ALL(a)); }
template<class T> inline auto min(const T& a){ return *min_element(ALL(a)); }
inline ll gcd(ll a,ll b){if(b == 0) return a;return  gcd(b,a%b);}
inline ll lcm(ll a,ll b){ll g = gcd(a,b);return a / g * b;}

//----***定数***----
#define MOD 1000000007
#define INF 100000000000000000
#define EPS 1e-9
const vector<vector<int>> DXY={{-1,0},{1,0},{0,-1},{0,1}};

//----***パーツ***----
#define fi first
#define se second
#define pb push_back
#define re return
#define br break

//----***入出力***---
void print() { std::cout << "\n"; }
template <class T>void print(const T &x) {std::cout << x<<"\n";}
template <class T, class... Args>void print(const T &x, const Args &... args) {std::cout << x << " ";print(args...);}
#define debug(var)  do{std::cerr << #var << " ↓ "<<"\n";view(var);}while(0);
#define dbg cerr<<"🥺🥺🥺🥺🥺🥺"<<endl;
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

//----***初期時読み込み***----
struct initial{initial(){cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(15);};}initial_;

signed main(){
  int A,B;cin>>A>>B;
  int ans=0;
  REP(i,A,B+1){
    int a,b,c,d,e,tmp=i;
    a=tmp%10;tmp/=10;
    b=tmp%10;tmp/=10;
    c=tmp%10;tmp/=10;
    d=tmp%10;tmp/=10;
    e=tmp%10;
    if(a==e&&b==d)ans++;

  }
  print(ans);

}


Measured memory_bytes: 256
#include<cstdio>
#include<utility>
#include<vector>
using namespace std;
typedef pair<int, int> P;

int n, m;
int c[49], depth[50], p[50], ind[50];
long dp[1 << 20];
vector<P> v[50];

void init(int x, int d) {
    depth[x] = d;
    for (int i = 0; i < v[x].size(); i++) {
        if (v[x][i].first != p[x]) {
            p[v[x][i].first] = x;
            init(v[x][i].first, d + 1);
        }
        else ind[x] = i;
    }
}

void lca(int x, int y, int z) {
    if (depth[x] > depth[y]) swap(x, y);
    while (depth[y] > depth[x]) {
        c[v[y][ind[y]].second] |= 1 << z;
        y = p[y];
    }
    while (y != x) {
        c[v[x][ind[x]].second] |= 1 << z;
        x = p[x];
        c[v[y][ind[y]].second] |= 1 << z;
        y = p[y];
    }
}

int main() {
    scanf("%d", &n);
    for (int i = 0; i < n - 1; i++) {
        int a, b;
        scanf("%d %d", &a, &b);
        v[a - 1].emplace_back(b - 1, i);
        v[b - 1].emplace_back(a - 1, i);
    }
    scanf("%d", &m);
    init(0, 0);
    for (int i = 0; i < m; i++) {
        int u, v;
        scanf("%d %d", &u, &v);
        lca(u - 1, v - 1, i);
    }
    
    dp[0] = 1;
    for (int i = 0; i < n - 1; i++) {
        for (int j = (1 << m) - 1; j >= 0; j--) dp[j | c[i]] += dp[j];
    }

    printf("%ld\n", dp[(1 << m) - 1]);
    return 0;
}


Measured memory_bytes: 8448
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<cstdio>
#include<stack>
#include<queue>
#include<fstream>
#include<cstdio>
#include<deque>
#include<iomanip>
#include <numeric>

using namespace std;
#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);(i)--)
#define all(a) (a).begin(),(a).end()
#define reall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
const double pi = acos(-1.0);

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef deque<ll> dll;
#define mod 1e9 + 7;
ll gcd(ll x, ll y)
{
	ll r;
	while ((r = x % y) != 0)
	{
		x = y;
		y = r;
	}
	return y;
}
ll lcm(ll x, ll y)
{
	x /= gcd(x, y);
	y /= gcd(x, y);
	return (x * y);
}

int main()
{
	ios_base::sync_with_stdio(false);

	ll b, c , n, k = 0,ans = 0;
	string s;
	cin >> s;
	if (s[0] != 'A') {
		cout << "WA" << endl;
		return 0;
	}
	if ((s[1] >= 'a') && (s[1] <= 'z'));
	else {
		cout << "WA" << endl;
		return 0;
	}
	REP(i, 2, s.size() - 1) {
		if (s[i] == 'C') k++;
		else {
			if ((s[i] >= 'a') && (s[i] <= 'z')) continue;
			else {
				cout << "WA" << endl;
				return 0;
			}
		}
	}
	if ((s[s.size()-1] >= 'a') && (s[s.size() - 1] <= 'z'));
	else {
		cout << "WA" << endl;
		return 0;
	}
	if (k == 1) cout << "AC\n";
	else puts("WA");
	return 0;
}

Measured memory_bytes: 256