akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <cmath>

using namespace std;
typedef long long ll;
//typedef unsigned long long ll;

#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define sz(x) ll(x.size())
//typedef pair<ll, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = LONG_LONG_MAX / 100;
//const ll INF = (1ll << 31) - 1;
//const ll INF = 1e15;
const ll MINF = LONG_LONG_MIN;
//const int INF = INT_MAX / 10;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
//typedef pair<int, int> P;
//typedef pair<double, double> P;

bool contain(set<P> &s, P a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
const int mod = 1000000007;
typedef priority_queue<long long, vector<long long>, greater<long long>> PQ_ASK;


void print_line(vector<string> &line) {
    if (line.size() == 0ll) {
        cout << endl;
        return;
    }
    for (ll i = 0; i < line.size(); i++) {
        cout << line[i];
        if (i == line.size() - 1) cout << endl;
        else cout << ' ';
    }
}

typedef int Weight;

struct Edge {
    int src, dst;
    Weight weight;

    Edge(int src, int dst, Weight weight) :
            src(src), dst(dst), weight(weight) {}
};

bool operator<(const Edge &e, const Edge &f) {
    return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
           e.src != f.src ? e.src < f.src : e.dst < f.dst;
}

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

typedef vector<Weight> Array;
typedef vector<Array> Matrix;

bool visit(const Graph &g, int v, vector<int> &order, vector<int> &color) {
    color[v] = 1;
    for (auto e: g[v]) {
        if (color[e.dst] == 2) continue;
        if (color[e.dst] == 1) return false;
        if (!visit(g, e.dst, order, color)) return false;
    }
    order.push_back(v);
    color[v] = 2;
    return true;
}

bool topologicalSort(const Graph &g, vector<int> &order) {
    int n = g.size();
    vector<int> color(n);
    rep(u, n) if (!color[u] && !visit(g, u, order, color))
            return false;
    reverse(order.begin(), order.end());
    return true;
}


int main() {
    int v, e;
    cin >> v >> e;

    Graph g(v);

    rep(i, e) {
        int s, t;
        cin >> s >> t;
        Edge edge(s, t, 1);

        g[s].push_back(edge);
    }
    vector<int> order;
    topologicalSort(g, order);

    for (int a :order) cout << a << endl;

}



Measured memory_bytes: 4180
/**
ABC080
2019/02/11/ 解説AC
**/
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v; return v;}

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector< vector<int> > Mat;
typedef tuple<int, int, int, int> T;

const int MOD = (int)1e9+7;
const int INF = (int)1e9;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

int N, C;
int s[100000], t[100000], c[100000];
int sm[200002];
int tt[200002];

int main(){
    ios::sync_with_stdio(false);
	cin.tie(0);
    
    scanf("%d%d", &N, &C);
    for(int i = 0; i < N; i++) scanf("%d%d%d", &s[i], &t[i], &c[i]);

    for(int i = 1; i <= C; i++){
        for(int j = 0; j < 200002; j++) tt[j] = 0;
        for(int j = 0; j < N; j++){
            if(c[j] == i){
                tt[s[j]*2-1]++;
                tt[t[j]*2]--;
            }
        }
        for(int j = 1; j < 200002; j++) tt[j] += tt[j-1];
        for(int j = 0; j < 200002; j++){
            if(tt[j] > 0){
                sm[j]++;
            }
        }
    }
    int mx = 0;
    for(int j = 0; j < 200002; j++) if(mx < sm[j]) mx = sm[j];
    printf("%d\n", mx);

    return 0;
}

Measured memory_bytes: 3072
#include <bits/stdc++.h>
 
using namespace std;
 
#define MAX_H 110
#define MAX_W 110
typedef long long ll;
 
ll H,W,L;
char field[MAX_H][MAX_W];
const int dx[4] = {-1,0,1,0};
const int dy[4] = {0,-1,0,1};
 
char getDir(int x){
    if(x == 0) return 'W'; 
    if(x == 1) return 'N'; 
    if(x == 2) return 'E'; 
    if(x == 3) return 'S'; 
}
 
int getDir(char ch){
    if(ch == 'W') return 0; 
    if(ch == 'N') return 1; 
    if(ch == 'E') return 2; 
    if(ch == 'S') return 3; 
}
 
bool inField(int x,int y){
    return (0 <= x && x < W && 0 <= y && y < H);
}
 
void solve(int x,int y,int dir){
    int d[MAX_H][MAX_W][4];
    memset(d,-1,sizeof(d));
    d[y][x][dir] = 0;
 
    while(L > 0){
	int nx = x + dx[dir],ny = y + dy[dir];
	if(!inField(nx,ny) || field[ny][nx] == '#'){
	    int ndir = (dir+1) % 4;
	    if(d[y][x][ndir] == -1){
		d[y][x][ndir] = d[y][x][dir];
	    }else{
		int diff = d[y][x][dir]-d[y][x][ndir];
		if(diff > 0 && L >= diff){
		    L %= diff;
		}
	    }
	    if(L != 0){
		dir = ndir;
	    }
	}else{
	    if(d[ny][nx][dir] == -1){
		d[ny][nx][dir] = d[y][x][dir]+1;
		L--;
	    }else{
		L--;
		int diff = d[y][x][dir]+1-d[ny][nx][dir];
		if(diff > 0 && L >= diff){
		    L %= diff;
		}
	    }
	    x = nx; y = ny;
	}
    }
    cout << y+1 << " " << x+1 << " " << getDir(dir) << endl;
}
 
bool check(char ch){
    if(ch == '.' || ch == '#'){
	return false;
    }
    return true;
}
 
int main(){
    int sx,sy,dir;
    while(true){
	cin >> H >> W >> L;
	if(H == 0 && W == 0 && L == 0){
	    break;
	}
	for(int i = 0 ; i < H ; i++){
	    for(int j = 0 ; j < W ; j++){
		cin >> field[i][j];
		if(check(field[i][j])){
		    sx = j; sy = i;
		    dir = getDir(field[i][j]);
		    field[i][j] = '.';
		}
	    }
	}
	solve(sx,sy,dir);
    }
    return 0;
}

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

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

    sort(a.begin(), a.end());
    int b;
    if(n%2==1){
        b = a[n/2];
    }else{
        b = (a[n/2] + a[n/2-1])/2;
    }

    ll ans=0;
    rep(i,n){
        ans += (ll)abs(a[i] - b);
    }

    cout << ans << endl;

	return 0;
}

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

n,k,q = map(int, input().split())
d = [0] * (n+1)
for _ in range(q):
    x = int(input())
    d[x] += 1

for i in range(1, n+1):
    if 0 < k - q + d[i]:
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 4680
/* 
   AOJ 1179
   Millennium
   2015.4.26
 */

int calc(int year, int month, int day)
{
  int days = 0, small_month = 19, large_month = 20, small_year = large_month * 5 + small_month * 5, large_year = large_month * 10, i;

  for(i = year + 1; i < 1000; i++)
    {
      if(i % 3 == 0)
	{
	  days += large_year;
	}
      else
	{
	  days += small_year;
	}
    }
  
  if(year % 3 == 0)
    {
      days += large_month * (10 - month);
      days += large_month - day + 1;
      return days;
    }
  else
    {
      for(i = month + 1; i <= 10; i++)
	{
	  if(i % 2 == 0)
	    {
	      days += small_month;
	    }
	  else
	    {
	      days += large_month;
	    }
	}
  
      if(month % 2 == 0)
	{
	  days += small_month - day + 1;
	}
      else
	{
	  days += large_month - day + 1;
	}
    }

  return days;
}

#include<stdio.h>
int main(void)
{
  int n, i, year, month, day, days_from_birthday;
  scanf("%d", &n);
  for(i = 0; i < n; i++)
    {
      scanf("%d %d %d", &year, &month, &day);
      days_from_birthday = calc(year, month, day);
      printf("%d\n", days_from_birthday);
    }
  return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
#define MAXK 100001
bool win[MAXK];
int main() {
    memset(win, false, sizeof(win));
    int n, k;
    cin >> n >> k;
    int a[n + 1];
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    for (int i = 1; i <= k; i++) {
        for (int j = 1; j <= n; j++) {
            if (i >= a[j]) {
                win[i] += !win[i - a[j]];
            }
        }
    }
    if (win[k]) {
        cout << "First" << endl;
    }
    else {
        cout << "Second" << endl;
    }
    return 0;
}

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

int puzzle[9][9];
bool right(int y,int x){
  for(int i=0;i<9;i++){
    if(y!=i){
      if(puzzle[y][x]==puzzle[i][x]) return false;
    }
    if(x!=i){
      if(puzzle[y][x]==puzzle[y][i]) return false;
    }
  }

  int a=y,b=x;
  while(1){
    if(a%3==0) break;
    a--;
  }
  while(1){
    if(b%3==0) break;
    b--;
  }

  for(int i=a;i<a+3;i++){
    for(int j=b;j<b+3;j++){
      if(i!=y && j!=x){
	if(puzzle[i][j]==puzzle[y][x]){
	  return false;
	}
      }
    }
  }
  return true;
}


int main(){
  int n;
  cin>> n;
  while(n--){
    for(int i=0;i<9;i++){
      for(int j=0;j<9;j++){
	cin>> puzzle[i][j];
      }
    }

    for(int i=0;i<9;i++){
      for(int j=0;j<9;j++){
	if(right(i,j)){
	  cout<< " "<< puzzle[i][j];
	}
	else {
	  cout<< '*'<< puzzle[i][j];
	}
      }
      cout<< endl;
    }
    if(n!=0){
      cout<< endl;
    }
  }
}

Measured memory_bytes: 1160
import copy
N = int(input())
keta = 1
n = copy.deepcopy(N)
flag = True
while flag:
    if n-1 >= 26**keta:
        n -= 26**keta
        keta += 1
    else:
        flag = False
for i in range(1, keta):
    N -= 26**i
alph = 'abcdefghijklmnopqrstuvwxyz'
ans = []
ans.append(alph[(N%26)-1])
for i in range(1, keta):
    num = (N-1)//(26**i)
    if num ==0:
        ans.append("a")
    else:
        ans.append(alph[(num%26)])
ans.reverse()
print("".join(ans))

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

// よく愛用しています
template <class T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }

const int MAX_N = 110000;
int dp[MAX_N]; // dp[i] が i についての答え

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

    // 初期化
    for (int i = 0; i < MAX_N; ++i) dp[i] = N; // INF
    dp[0] = 0;
    priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > > que;
    que.push(make_pair(0, 0));

    // Dijkstra 法
    while (!que.empty()) {
        int cur = que.top().first; // 現在の距離
        int v = que.top().second; // 現在のノード
        que.pop();

        // Dijkstra 法でよくやる枝刈り
        if (cur > dp[v]) continue;

        for (int pow6 = 1; v + pow6 <= N; pow6 *= 6) {
            int nv = v + pow6; // 遷移先
            if (chmin(dp[nv], dp[v] + 1)) que.push(make_pair(dp[nv], nv));
        }
        for (int pow9 = 1; v + pow9 <= N; pow9 *= 9) {
            int nv = v + pow9; // 遷移先
            if (chmin(dp[nv], dp[v] + 1)) que.push(make_pair(dp[nv], nv));
        }
    }

    cout << dp[N] << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

template<class T,uint mod>
struct RollingHash_{
	vector< uint > hashed, power;

	inline uint mul(uint a, uint b){
		return a*(unsigned long long)b%mod;
	}
	RollingHash_(){}
	RollingHash_(T s, uint base = 10007) {
		int sz = (int) s.size();
		hashed.assign(sz + 1, 0);
		power.assign(sz + 1, 0);
		power[0] = 1;
		for(int i = 0; i < sz; i++) {
			power[i + 1] = mul(power[i], base);
			hashed[i + 1] = mul(hashed[i], base) + s[i];
			if(hashed[i + 1] >= mod) hashed[i + 1] -= mod;
		}
	}

	uint get(int l, int r){
		uint ret = hashed[r] + mod - mul(hashed[l], power[r - l]);
		if(ret >= mod) ret -= mod;
		return ret;
	}
};

typedef pair<uint,uint>Hash;

template<class T>
struct RollingHash{
	RollingHash_<T,998244353>RH1;
	RollingHash_<T,1000000007>RH2;
	
	RollingHash(T s){
		RH1=RollingHash_<T,998244353>(s);
		RH2=RollingHash_<T,1000000007>(s);
	}

	Hash get(int l,int r){
		return make_pair(RH1.get(l,r),RH2.get(l,r));
	}
};

char S[600000],T[600000];
int nx[1200000],prv[1200000];
bool used[1200000];

int main(){
	scanf("%s%s",S,T);
	string s=S,t=T;
	while(s.size()<t.size())s+=S;
	string ss=s+s;
	RollingHash<string>rh1(ss),rh2(t);
	memset(nx,-1,sizeof(nx));
	memset(prv,-1,sizeof(prv));
	rep(i,s.size()){
		Hash h1=rh1.get(i,i+t.size()),h2=rh2.get(0,t.size());
		if(h1==h2){
			nx[i]=(i+t.size())%s.size();
			prv[nx[i]]=i;
		}
	}
	int Max=0;
	rep(i,s.size()){
		if(used[i])continue;
		if(prv[i]!=-1)continue;
		int x=i;
		int cnt=0;
		while(1){
			used[x]=true;
			if(nx[x]==-1)break;
			x=nx[x];
			cnt++;
		}
		Max=max(Max,cnt);
	}
	rep(i,s.size()){
		if(!used[i]){
			puts("-1");return 0;
		}
	}
	cout<<Max<<endl;
}

Measured memory_bytes: 54552
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	int n; scanf("%d", &n); std::vector<int> h(n);
	for(int i = 0; i < n; i++) scanf("%d", &h[i]);
	
	int ans = 0, tmp = 0;
	for(int i = 0; i < n; i++) {
		ans = std::max(ans, tmp);
		if(i == n - 1) break;

		if(h[i] >= h[i + 1]) tmp++;
		else tmp = 0;
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 640
import math
import fractions
import sys
#入力:N(int:整数)
def input1():
	return str(input())

#入力:N,M(int:整数)
def input2():
	return map(int,input().split())

#入力:[n1,n2,...nk](int:整数配列)
def input_array():
	return list(map(str,input().split()))


s=list(str(input()))
len_s=len(s)
count=0
for i in range(len_s):
	if s[i]!=s[-(i+1)]:
		s[i]=s[-(i+1)]
		count+=1
	else:
		continue
print(count)







Measured memory_bytes: 5048
import sys
def input(): return sys.stdin.readline().strip()


def main():
    S = input()
    N = len(S)
    if S == '1' * N or S == '0' * N:
        print(N)
        return
    left = N // 2
    right = N
    while right - left > 1:
        mid = (left + right) // 2
        if S[(N - mid):mid] == '1' * (2 * mid - N) or S[(N - mid):mid] == '0' * (2 * mid - N):
            left = mid
        else:
            right = mid
    print(left)

if __name__ == "__main__":
    main()


Measured memory_bytes: 67248
#include <algorithm>
#include <cmath>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define loop(i, x, n) for (int i = (x); i < (n); i++)
#define all(v) (v).begin(), (v).end()
#define int long long
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 1e18;
template<typename T> void cmax(T &a, T b) { a = max(a, b); }
template<typename T> void cmin(T &a, T b) { a = min(a, b); }

signed main() {
  int a, b;
  cin >> a >> b;
  vector<int> tow;
  loop(i, 1, 1000) {
    int h = i * (i + 1) / 2;
    tow.push_back(h);
  }
  int ans = 0;
  rep(i, tow.size() - 1) {
    int left = tow[i] - a;
    int right = tow[i + 1] - b;
    if (0 <= left && 0 <= right && (left == right)) {
      ans = tow[i] - a;
      break;
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;

int main(){
	vector<int> a = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	int k;
	cin >> k;
	cout << a.at(k - 1) << endl;
	return 0;
}



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

int main(){
    long long n, m;
    cin >> n >> m;
    vector<long long> ac = vector<long long>(112345, 0);
    vector<long long> penalty = vector<long long>(112345, 0);
    REP(i, m){
        long long p;
        string s;
        cin >> p >> s;
        p--;
        if(ac[p] == 1){

        }else{
            if(s.compare("AC") == 0){
                ac[p] = 1;
            }else if(s.compare("WA") == 0){
                penalty[p]++;
            }else{
                assert(false);
            }
        }
    }


    long long total_ac = accumulate(ac.begin(), ac.end(), 0LL);
    // long long total_wa = accumulate(penalty.begin(), penalty.end(), 0LL);
    long long total_wa = 0;
    REP(i, penalty.size()){
        if(ac[i] == 1){
            total_wa += penalty[i];
        }
    }
    printf("%lld %lld\n", total_ac, total_wa);
    // cout << total_ac << " " << total_wa << endl;
    return 0;
}

Measured memory_bytes: 2048
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner cin = new Scanner(System.in);
        int N = cin.nextInt();
        long[] a = new long[N * 3];
        for (int i = 0; i < N * 3; i++) {
            a[i] = cin.nextLong();
        }

        Arrays.sort(a);

        long sum = 0;
        for (int i = N; i < N * 3; i += 2) {
            sum += a[i];
        }

        System.out.println(sum);
    }
}


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

    using namespace std;
    
    int main()
    {
    	int n;
    	cin >> n;
    	int dp[3][n];
    	cin >> dp[0][0];
    	cin >> dp[1][0];
    	cin >> dp[2][0];
    	
    	for(int i=1; i<n; i++){
    		int a;
    		int b;
    		int c;
    		cin >> a;
    		cin >> b;
    		cin >> c;
    		dp[0][i]=max(dp[1][i-1], dp[2][i-1])+a;
    		dp[1][i]=max(dp[2][i-1], dp[0][i-1])+b;
    		dp[2][i]=max(dp[0][i-1], dp[1][i-1])+c;
    	}
    	cout << max(dp[0][n-1], max(dp[1][n-1], dp[2][n-1])) << endl;
        
    	return 0;
    }

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

int main(){
  int n;
  cin>>n;
  string s;
  cin>>s;


  vector<vector<int>>dp(5005, vector<int> (5005));
  for (int i=n-1; i>=0; i--){
    for (int j=n-1; j>=0; j--){
      if (s[i]!=s[j]) dp[i][j]=0;
      else{
        dp[i][j]=dp[i+1][j+1]+1;
      }
    }

  }
int ans=0;

  for (int i=0;i<n;i++){
    for (int j=i+1;j<n;j++){

    int temp=min(dp[i][j],(j-i));
    if (temp>ans)ans=temp;

  }

  }
  cout<<ans;

}


Measured memory_bytes: 98812
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <cmath>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <complex>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <list>
#include <unordered_map>

using namespace std;

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

	int cost = 0;
	cost = a + 0.5*b;

	std::cout << cost << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,a,b) for(int i=(a),_end_=(b);i<=_end_;i++)
#define DREP(i,a,b) for(int i=(a),_end_=(b);i>=_end_;i--)
#define EREP(i,a) for(int i=start[(a)];i;i=e[i].next)
template<class T>inline void chkmax(T &a,T b){ if(a<b)a=b;}
template<class T>inline void chkmin(T &a,T b){ if(a>b)a=b;}
#define fi first
#define se second
#define mkr(a,b) make_pair(a,b)
inline int read()
{
	int sum=0,p=1;char ch=getchar();
	while(!(('0'<=ch && ch<='9') || ch=='-'))ch=getchar();
	if(ch=='-')p=-1,ch=getchar();
	while('0'<=ch && ch<='9')sum=sum*10+ch-48,ch=getchar();
	return sum*p;
}

const int maxn=2e5+20;

int n,q,sta,stb,x[maxn];
ll s[maxn];

struct Fenwick_Tree {
	int rev;
	ll s[maxn];
	Fenwick_Tree(int _rev=0){ rev=_rev;}
	inline void Clear(){ memset(s,63,sizeof(s));}

	inline void Add(int x,ll d){ for(x=rev?n-x+1:x;x<=n;x+=x&(-x))chkmin(s[x],d);}

	inline ll Sum(int x){ ll res=1ll<<60; for(x=rev?n-x+1:x;x;x-=x&(-x))chkmin(res,s[x]); return res;}
}A(0),B(1);

inline void init()
{
	n=read();q=read(); sta=read(); stb=read();
	REP(i,1,q)x[i]=read();
}

ll dp[maxn];
ll ans=1ll<<60;

inline void doing()
{
	A.Clear(); B.Clear();
	x[0]=sta; 
	REP(i,2,q)s[i]=s[i-1]+abs(x[i]-x[i-1]);
	dp[0]=abs(x[1]-stb); A.Add(sta,dp[0]-sta); B.Add(sta,dp[0]+sta);
	REP(i,1,q)
	{
		dp[i]=s[i]+min(x[i+1]+A.Sum(x[i+1]) , -x[i+1] + B.Sum(x[i+1]));
		A.Add(x[i],-s[i+1]-x[i]+dp[i]); B.Add(x[i],-s[i+1]+x[i]+dp[i]);
		chkmin(ans,dp[i]+s[q]-s[i+1]);
	}
}

int main()
{

	init();
	doing();
	swap(sta,stb); doing();
	printf("%lld\n",ans);
	return 0;
}



Measured memory_bytes: 7296
#include<bits/stdc++.h>
#define LL long long
#define PII pair<int, int>
#define MP make_pair
#define PB push_back
#define FF first
#define SS second
using namespace std;
template<typename T> inline void gmax(T &x, T y){x = x > y ? x : y;}
template<typename T> inline void gmin(T &x, T y){x = x < y ? x : y;}
const int MAXN = 300010;
int n, ans;
char s[MAXN];
int pre[MAXN];
int main(){
	scanf("%d", &n);
	scanf("%s", s);
	ans = n;
	for(int i = 1; i <= n; i++) pre[i] = pre[i - 1] + (s[i - 1] == 'W');
	for(int i = 0; i < n; i++) gmin(ans, pre[i] + n - 1 - i - (pre[n] - pre[i + 1]));
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 1664
import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int x = sc.nextInt();
        long count = 0;
        int[] array = new int[n];

        for (int i = 0; i < n; i++) {
            array[i] = sc.nextInt();
        }

        for (int i = 0; i < n - 1; i++) {
            int sum = array[i] + array[i + 1];
            if (sum > x) {
                int gap = sum - x;
                if (gap > array[i + 1]) {
                    array[i] -= gap - array[i + 1];
                    array[i + 1] = 0;
                } else {
                    array[i + 1] -= gap;
                }
                count += gap;
            }
        }

        System.out.println(count);
    }
}

Measured memory_bytes: 51856
#include <bits/stdc++.h>
			using namespace std;
			#define pll pair<ll,ll>
			typedef long long ll;
			#define mod 1000000007
			#define fi first
			#define se second
			#define mp make_pair
			#define pb push_back
			#define INF 1e15
			
			
			int main()
			{
				map<string,ll> m;
				ll n;
				cin>>n;
				ll ans=0;
				for(ll i=0;i<n;i++)
				{
					string s;
					cin>>s;
					m[s]++;
					ans=max(ans,m[s]);
				}
				vector<string> res;
				for(auto i:m)
				{
					if(i.se==ans)
						res.pb(i.fi);
						
					
				}
				sort(res.begin(),res.end());
				for(ll i=0;i<res.size();i++)
					cout<<res[i]<<endl;
			}


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

using namespace std;

string a,b,c;

int main(){
	string s,p;
	getline(cin, s);
	getline(cin, p);
	while(s.size()<=200){
		s = s + s; 
	}
	if(s.find(p)!= string::npos){
		printf("Yes\n");
	}else{
		printf("No\n");
	}	
}


Measured memory_bytes: 3212
#include<stdio.h>
#include<string.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

#define M 1046527
#define NIL (-1)
#define L 14

char H[M][L];

int getChar(char ch){
    if(ch == 'A') return 1;
    else if(ch == 'C') return 2;
    else if(ch == 'G') return 3;
    else if(ch == 'T') return 4;
    else return 0;
}

long long getKey(char str[]){
    long long sum = 0, p = 1;
    for(int i = 0; i < strlen(str); i++){
        sum += p*(getChar(str[i]));
        p *= 5;
    }
    return sum;
}

int h1(int key){ return key % M; }
int h2(int key){ return 1 + (key % (M - 1)); }

int find(char str[]){
    long long key, h;
    key = getKey(str);
    for(int i = 0;; i++){
        h = (h1(key) + i*h2(key)) % M;
        if(strcmp(H[h],str) == 0) return 1;
        else if(strlen(H[h]) == 0) return 0;
    }
    return 0;
}

int insert(char str[]){
    int key,h;
    key = getKey(str);
    for(int i = 0;; i++){
        h = (h1(key) + i*h2(key)) % M;
        if(strcmp(H[h],str) == 0) return 1;
        else if(strlen(H[h]) == 0){
            strcpy(H[h],str);
            return 0;
        }
    }
    return 0;
}

int main(){
    int n;
    scanf("%d", &n);
    char com[9], str[L];

    for(int i = 0; i < M; i++){
        H[i][0] = '\0';
    }
    
    for(int i = 0; i < n; i++){
        scanf("%s %s", com,str);
        if(com[0] == 'i'){
            insert(str);
        }else if(com[0] == 'f'){
            if(find(str)){
                printf("yes\n");
            }else{
                printf("no\n");
            }
        }
    }

    return 0;

}


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

int ans = 0;
vector<vector<int>> board;

void input(int H)
{
  board.clear();
  board.resize(5, vector<int>(10, 0));
  for (int row = H - 1; row >= 0; row--)
  {
    rep(col, 5)
    {
      cin >> board.at(col).at(row);
    }
  }
}

pair<int, int> find(int row)
{
  int start = -1, last = -1, cnt = 0;
  rep(col, 5)
  {
    if (board.at(col).at(row) == 0)
    {
      start = -1;
      last = -1;
      cnt = 0;
      continue;
    }
    if (board.at(col).at(row) == last)
    {
      cnt++;
    }
    else
    {
      if (cnt >= 3)
      {
        break;
      }
      start = col;
      last = board.at(col).at(row);
      cnt = 1;
    }
  }
  return make_pair(start, cnt);
}

void change(pair<int, int> p, int row)
{
  int start, cnt;
  tie(start, cnt) = p;
  if (start == -1 || cnt < 3)
  {
    return;
  }
  ans += board.at(start).at(row) * cnt;
  for (int col = start; col < start + cnt; col++)
  {
    board.at(col).at(row) = -1;
  }
}

void update()
{
  rep(col, 5)
  {
    vector<int> new_col(10, 0);
    int index = 0;
    rep(i, 10)
    {
      if (board.at(col).at(i) == -1)
      {
        continue;
      }
      if (board.at(col).at(i) == 0)
      {
        break;
      }
      new_col.at(index) = board.at(col).at(i);
      index++;
    }
    board.at(col) = new_col;
  }
}

void solve()
{
  ans = 0;
  rep(i, 10)
  {
    rep(row, 10)
    {
      change(find(row), row);
    }
    update();
  }
  cout << ans << endl;
}

int main()
{
  while (1)
  {
    int H;
    cin >> H;
    if (!H)
      break;
    input(H);
    solve();
  }
}


Measured memory_bytes: 3148
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s,t;cin>>s>>t;
  int a=s.size(),b=t.size();
  int dp[a+1][b+1];
  for(int i=0;i<=a;i++)for(int j=0;j<=b;j++)dp[i][j]=0;
  for(int i=1;i<=a;i++){
    for(int j=1;j<=b;j++){
      if(s[i-1]==t[j-1])dp[i][j]=dp[i-1][j-1]+1;
      else{
       dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
      }
    }
  }
  vector<char>v;
  int x=b,y=a;
  for(;;){
    if(x==0||y==0)break;
    if(s[y-1]==t[x-1]){
      v.push_back(s[y-1]);
      x--;y--;
    }
    else{
      if(dp[y][x]==dp[y-1][x])y--;
      else x--;
    }
  }
  reverse(v.begin(),v.end());
  for(int i=0;i<v.size();i++)cout<<v[i];
  cout<<endl;
}
  
                 

Measured memory_bytes: 35456
#include <bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
#define eps 1e-9

typedef long long ll;

using namespace std;

const ll inf = 1e18;
const ll mod = 1e9+7;
const int N = 1e5+5;
//int a[N];

int main()

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

    int a, b;

    cin >> a >> b;

    cout << (a-1)*(b-1);

    return 0;
}


Measured memory_bytes: 256
chk = [
    (1,2,3),
    (4,5,6),
    (7,8,9),
    (1,4,7),
    (2,5,8),
    (3,6,9),
    (1,5,9),
    (3,5,7)
    ]
while True:
    s = "0"
    s += raw_input()
    if s[1]=='0':
        break
    s += raw_input()+raw_input()
    judge = "NA"
    for ch in chk:
        if s[ch[0]]==s[ch[1]]==s[ch[2]]:
            if s[ch[0]]=='b':
                judge = "b"
                break
            elif s[ch[0]]=='w':
                judge = "w"
                break
    print judge

Measured memory_bytes: 4236
#include<iostream>
#include<sstream>
#include<ios>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<deque>
#include<map>
#include<string>
#include<numeric>
#include<set>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using vi = vector<int>;
using vl = vector<long>;
using vc = vector<char>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<long>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
using pll = pair<long, long>;
using vpii = vector<pii>;
using vpll = vector<pll>;

int main(){
  long N;
  cin >> N;
  string S, T;
  cin >> S >> T;

  rep(i, N) cout << S[i] << T[i];

  cout << endl;
  
  return 0;
}

Measured memory_bytes: 256
s = input()

flag = 0
if len(s) == 2 and s[0] == s[1]:
    print('1 2')
    flag = 1
for i in range(len(s)-2):
    if s[i] == s[i+1]:
        print(i+1, i+2)
        flag = 1
        break
    if s[i] == s[i+2]:
        print(i+1, i+3)
        flag = 1
        break

if not flag:
    print('-1 -1')


Measured memory_bytes: 3188
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main(){
    int x,n;
    cin>>x>>n;
    int p[n];
    for(int i=0;i<n;i++){
        cin>>p[i];
    }
    bool flag=true,flag2=true;
    int ans=0;
    for(int i=0;i<=n+1||flag2;i++){
        int s=x-i;
        flag=true;
        for(int j=0;j<n;j++){
            if(p[j]==s){
                flag=false;
                break;
            }
        }
        if(flag&&flag2){
            ans=s;
            flag2=false;
        }
        flag=true;
        s=x+i;
        for(int j=0;j<n;j++){
            if(p[j]==s){
                flag=false;
                break;
            }
        }
        if(flag&&flag2){
            ans=s;
            flag2=false;
        }
    }
    cout<<ans<<"\n";
    return(0);
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e18
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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;

signed main()
{
    int n;
    cin >> n;
    set<char> st;
    for (int i = 0; i < n; i++)
    {
        char a;
        cin >> a;
        st.insert(a);
    }
    if(st.size()==3){
    cout << "Three" << endl;
    }
    else{
        cout << "Four" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int n,a[110]={0};
	scanf("%d",&n);
	for(int i = 1; i <= n; i++){
		cin >> a[i];
	}
	unsigned long long int dp[110][21]={{0}};
	dp[1][a[1]]=1;
	for(int i = 2; i < n; i++){
		for(int j = 0; j <= 20; j++){
			if(j + a[i] <= 20){
				dp[i][j] += dp[i-1][j+a[i]];
			}
			if(j - a[i] >= 0){
				dp[i][j] += dp[i-1][j-a[i]];
			}
		}
	}
	printf("%lld\n",dp[n-1][a[n]]);
	return 0;
}

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

#define ALL(a) (a).begin(), (a).end()
#define ll long long

using namespace std;

signed main(){
	int n,k; cin >> n >> k;
	vector<int> a(n);
	for(auto &e : a)cin >> e;
	sort(ALL(a));
	vector<int> ans;
	for(int i = 0; i <= n-k; i++){
		ans.push_back(a[i+k-1] - a[i]);
	}
	sort(ALL(ans));
	cout << ans[0] << endl;


	return 0;
}



Measured memory_bytes: 1276
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
const int MOD = 998244353;
const int MX = 100005;
int n, x;
ll ans;
ll exp(ll b, ll n){
	ll res = 1;
	for(; n; n/=2,(b*=b)%=MOD) if(n%2) (res *= b) %= MOD;
	return res;
}
ll fact[MX] = {1}, invf[MX];
void setcomb(int n){
	for(int i = 1; i <= n; i++) fact[i] = (fact[i-1] * i) % MOD;
	invf[n] =  exp(fact[n] ,MOD-2);
	for(int i = n; i > 0; i--) invf[i-1] = (invf[i] * i) % MOD;
}
inline ll comb(int a, int b){return fact[a] * invf[a-b] % MOD * invf[b] % MOD;}

int main(){
	scanf("%d%d", &n, &x);
	setcomb(n);
	rep(i,n+1) rep(j,n+1-i){
		int s = i + j*2, k = s - x;
		if(k < 0) ans += comb(n,i+j) * comb(i+j,i) % MOD;
		else if(k&1 && (k+1 <= j || !i)){
			ans += comb(n,i+j) * comb(i+j-min(k+1,j),i) % MOD;
		}
	}
	printf("%lld\n", ans % MOD);
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int n;
  scanf("%d",&n);
  int l[n];
  for(int i=0;i<n;i++)scanf("%d",&l[i]);
  for(int i=0;i<n;i++){
    for(int j=n-1;j>i;j--){
      if(l[j]<l[j-1]){
        int tmp = l[j];
        l[j]=l[j-1];
        l[j-1]=tmp;
      }
    }
  }
  int ans=0;
  for(int i=0;i<n-2;i++){
    for(int j=i+1;j<n-1;j++){
      for(int k=j+1;k<n;k++){
        ans+=(l[i]+l[j]>l[k]);
      }
    }
  }
  printf("%d",ans);
}


Measured memory_bytes: 128
import java.io.*;
import java.util.*;

public class Main {
	FastScanner in;
	PrintWriter out;

	void solve() {
		int h = in.nextInt();
		int w = in.nextInt();
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				if (in.next().equals("snuke")) {
					char c = (char) ('A' + j);
					out.println(c + "" + (i + 1));
				}
			}
		}
	}

	void run() {
		try {
			in = new FastScanner(new File("object.in"));
			out = new PrintWriter(new File("object.out"));

			solve();

			out.close();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
	}

	void runIO() {

		in = new FastScanner(System.in);
		out = new PrintWriter(System.out);

		solve();

		out.close();
	}

	class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner(File f) {
			try {
				br = new BufferedReader(new FileReader(f));
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			}
		}

		public FastScanner(InputStream f) {
			br = new BufferedReader(new InputStreamReader(f));
		}

		String next() {
			while (st == null || !st.hasMoreTokens()) {
				String s = null;
				try {
					s = br.readLine();
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (s == null)
					return null;
				st = new StringTokenizer(s);
			}
			return st.nextToken();
		}

		boolean hasMoreTokens() {
			while (st == null || !st.hasMoreTokens()) {
				String s = null;
				try {
					s = br.readLine();
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (s == null)
					return false;
				st = new StringTokenizer(s);
			}
			return true;
		}

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

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}
	}

	public static void main(String[] args) {
		new Thread(null, new Runnable() {
			public void run() {
				new Main().runIO();
			}
		}, "1", 1 << 26).start();
	}
}

Measured memory_bytes: 8584
fun main(args: Array<String>) {
    arc097d()
}

fun arc097d() {
    val (n, m) = readLine()!!.split(' ').map { it.toInt() }
    val pList = readLine()!!.split(' ').map { it.toInt() - 1 }
    val xyList = (1..m).map { readLine()!!.split(' ').map { it.toInt() - 1 } }

    val uf = UnionFind(n)
    xyList.forEach { uf.unite(it[0], it[1]) }

    val answer = pList.mapIndexed { index, i -> if (uf.isSame(index, i)) 1 else 0 }.sum()

    println(answer)
}

private class UnionFind(vectors: Int) {
    private val parent = IntArray(vectors) { it }
    private val size = LongArray(vectors) { 1L }

    fun root(x: Int): Int {
        if (x == parent[x]) return x

        val xr = root(parent[x])
        parent[x] = xr
        return xr
    }

    fun unite(x: Int, y: Int) {
        val xr = root(x)
        val yr = root(y)
        if (xr == yr) return

        if (size[xr] >= size[yr]) {
            size[xr] += size[yr]
            parent[yr] = xr
        } else {
            size[yr] += size[xr]
            parent[xr] = yr
        }
    }

    fun isSame(x: Int, y: Int): Boolean = root(x) == root(y)

    fun size(x: Int): Long = size[root(x)]
}


Measured memory_bytes: 84932
#include<stdio.h>

int main(){
  int i,j,n,q,count=0,S[10000],T[500];

  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&S[i]);
  scanf("%d",&q);
  for(i=0;i<q;i++) scanf("%d",&T[i]);

  for(j=0;j<q;j++){
    for(i=0;i<n;i++){
      if(S[i]==T[j]){
	count++;
	break;
      }
    }
  }

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

  return 0;
}



Measured memory_bytes: 2104
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main(){
    int n1,n2;
    cin >> n1;
    vector<int>a1(n1);
    for(int i = 0;i < n1;++i){
        cin >> a1[i];
    }

    cin >> n2;
    vector<int>a2(n2);
    for(int i = 0;i < n2;++i){
        cin >> a2[i];
    }
    cout << lexicographical_compare(a1.begin(),a1.end(),a2.begin(),a2.end()) << endl;
}



Measured memory_bytes: 3116
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N = I()
    BA = []
    for _ in range(N):
        A, B = LI()
        BA.append((B, A))

    BA.sort()
    ans = BA[0][0] + BA[0][1]
    print(ans)

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 23860
#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 pb push_back
#define ALL(obj) (obj).begin(), (obj).end()

using namespace std;
struct UnionFind {
  vector<int> par;
  vector<int> rank;
  vector<int> num;
  
  UnionFind(int N) : par(N),rank(N),num(N) {
        for(int i = 0; i < N; i++){ 
          par[i] = i;
          rank[i] = 0;
          num[i] = 1;
        }
   }
   
  void init(int N){
        for(int i = 0; i < N; i++){ 
          par[i] = i;
          rank[i] = 0;
          num[i] = 1;
        }
  }
  
  int root(int x) {
    if (par[x] == x) return x;
    return par[x] = root(par[x]);
  }
  
  int ranker(int x){
    x = root(x);
    return rank[x];
  }
  
  int number(int x){
    x = root(x);
    return num[x];
   }
  
  void unite(int x, int y){
    int rx = root(x);
    int ry = root(y);
    if ( rx == ry ) return;
    if ( rank[rx] < rank[ry] ){
      par[rx] = ry;
      num[ry] += num[rx];
      num[rx] = 0;
    } else {
      par[ry] = rx;
      num[rx] += num[ry];
      num[ry] = 0;
      if ( rank[rx] == rank[ry] ) rank[rx]++;
    }
   }
  
  bool same(int x, int y){
    return root(x) == root(y);
  }
};

int n,m;
vector<int> A(55),B(55);
UnionFind tree(55);

int main(){
    cin >> n >> m;
    rep(i,m) cin >> A[i] >> B[i];
    int ct = 0;
    rep(i,m){
        tree.init(55);
        rep(j,m) if(i != j) tree.unite(A[j],B[j]);
        if(!tree.same(A[i],B[i])) ct++;
    } 
    cout << ct << endl;
}


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

// aを常に小さい値にする　大きい値にする
template<class T> bool chmin(T &a, T b){
    if(a>b) {
        a = b;
        return true;
    }
    return false;

}
template<class T> void chmax(T &a, T b){ if(a<b) a = b; }

// 二分探索 前方のindexを返すもの（自分自身を含む） 前方: -INF側のこと
template<class T> int former(const vector<T> &v, T x){
    return upper_bound(v.begin(), v.end(), x) - v.begin() -1; // upper_bound : keyより大きい要素の内の一番左側のイテレータを返す
}
// 二分探索 後方のindexを返すもの（自分自身を含む）後方: INF側のこと
template<class T> int latter(const vector<T> &v, T x){
    return lower_bound(v.begin(), v.end(), x) - v.begin(); // lower_bound : key以上の要素の内の一番左側のイテレータを返す
}

/*
 *
 * */

int main() {

    int N;
    cin >> N;
    string S[N];
    rep(i,N) cin >> S[i];

    map<std::string,int> counter;

    rep(i,N) counter[S[i]] = 0;

    rep(i,N) counter[S[i]] += 1;

    int count = 0;
    for(map<string, int>::iterator itr = counter.begin(); itr != counter.end(); ++itr)
    {
        // 処理(下例ではキーと値を出力)
//        cout << "Key: " << itr->first << ", Value: " << itr->second << endl;
        count++;
    }
    cout << count << endl;
}

Measured memory_bytes: 25424
// template version 1.9

// varibable settings {{{
using namespace std;
#include <iostream>
#include <bits/stdc++.h>

#define int long long
const int INF=1e18;
const int MOD=1e9+7;
#define infile "../test/sample-1.in"
int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};
#define fi first
#define se second

// }}}

// define basic macro {{{
#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 _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)(b-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(i,a) for (auto&& i : a)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
template<class T> inline void chmax(T &a, const T &b) { if(a < b) a = b; }
template<class T> inline void chmin(T &a, const T &b) { if(a > b) a = b; }

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;
template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;

// dump macro
#ifdef PCM
  #include "dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;
// }}}

int p[500001];

int solve(){
  int n;cin>>n;

  p[0] = 1;
  rep(i, 1, 500002){
    p[i] = p[i-1]*2;
    p[i] %= MOD;
  }
  // dump_1d(p, n+1);

  vi x(n+1, 0);
  rep(i, 1, n+1){
    int a;cin>>a;
    x[i] = x[i-1]^a;
  }
  dump(x);

  vi cumz(n+1, 0);
  rep(i, 1, n+1){
    cumz[i] = cumz[i-1];
    if (x[i]==0) cumz[i]++;
  }
  dump(cumz);

  vi prememo(n+1, -1);
  map<int, int> last;
  rep(i, 1, n+1){
    if (last.find(x[i])!=last.end()){
      prememo[i] = last[x[i]];
    }
    last[x[i]] = i;
  }
  dump(prememo);
  dump(last);

  vi dp0(n+1, 0);
  vi dpx(n+1, 0);

  rep(i, 1, n+1){
    if (prememo[i]==-1){
      dp0[i]=1;
      dpx[i]=1;
    }
    else{
      int pre = prememo[i];
      dump(i, pre);
      if (i<n) dpx[i]+=dpx[pre];  // preから何もとらない
      dpx[i]+=dpx[pre] * (cumz[i-1]-cumz[pre]);
      dpx[i]%=MOD;
      dpx[i]+=dp0[pre];
      dp0[i]+=dpx[pre] * (cumz[i-1]-cumz[pre]);
      dp0[i]%=MOD;
      dp0[i]+=dp0[pre];
      dpx[i]%=MOD;
      dp0[i]%=MOD;
    }
  }
  dump(dpx);
  dump(dp0);

  int res=0;
  if (x[n]==0) res += p[cumz[n]-1];
  each(el, last){
    int v=el.first;
    int i=el.second;
    if (v==0) continue;
    if (i==n){
      res += dpx[i];
      res %= MOD;
    }
    else{
      if (x[n]==0){
        res+=dpx[i];
        res%=MOD;
      }
    }
  }

  cout << res%MOD << endl;

  return 0;
}

signed main() { //{{{
#ifdef INPUT_FROM_FILE
  std::ifstream in(infile);
  std::cin.rdbuf(in.rdbuf());
#endif
  solve();
  return 0;
} //}}}


Measured memory_bytes: 41728
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define X first
#define Y second
const ll MOD = 1e9 + 7;
const int C = 2e5 + 87;
ll f[C], fi[C];
void precalc()
{
    f[0] = f[1] = fi[0] = fi[1] = 1;
    for (int i = 2; i < C; ++i)
        f[i] = i * f[i - 1] % MOD;
    for (int i = 2; i < C; ++i)
        fi[i] = (MOD - MOD / i) * fi[MOD % i] % MOD;
    for (int i = 2; i < C; ++i)
        fi[i] = fi[i] * fi[i - 1] % MOD;
}
ll c(int n,int k)
{
    return f[n] * fi[k] % MOD * fi[n - k] % MOD;
}
ll fun(int x0, int y0, int x1, int y1)
{
    return c(x1 - x0 + y1 - y0, x1 - x0);
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    precalc();
    int H, W, N;
    cin >> H >> W >> N;
    vector<pair<int, int>> vp;
    for (int i = 0; i < N; ++i) {
        int x, y;
        cin >> x >> y;
        vp.emplace_back(x, y);
    }
    vp.emplace_back(H, W);
    sort(begin(vp), end(vp));
    vector<ll> dp(vp.size());
    for (int i = 0; i <= N; ++i)
        dp[i] = fun(1, 1, vp[i].X, vp[i].Y);
    for (int i = 0; i < N; ++i) {
        int x0, y0;
        tie(x0, y0) = vp[i];
        for (int j = i + 1; j <= N; ++j) {
            int x1, y1;
            tie(x1, y1) = vp[j];
            if (x1 >= x0 && y1 >= y0)
                (dp[j] -= dp[i] * fun(x0, y0, x1, y1)) %= MOD;
        }
    }
    cout << (dp.back() % MOD + MOD) % MOD << endl;
}


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

using namespace std;
using LLONG = long long;

int main()
{
    int A, B;
    string S;
    cin >> A >> B >> S;
    for (int i = 1; i <= A + B + 1; ++i)
    {
        char ch = S[i - 1];
        if (i != A + 1)
        {
            if (!('0' <= ch && ch <= '9'))
            {
                cout << "No" << endl;
                return 0;
            }
        }
        else
        {
            if (ch != '-')
            {
                cout << "No" << endl;
                return 0;
            }
        }
    }

    cout << "Yes" << endl;
    return 0;
}

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

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

    //good luck kittu!
    string s; cin>>s;
    if(s[0]==s[1] && s[1]==s[2]) cout<<"No\n";
    else cout<<"Yes\n";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

int main()
{
    int r,c;

    std::cin >> r >> c;

    int *matrix = new int[(r+1)*(c+1)];

    for (int row = 0; row < r; row++)
        for (int col = 0; col < c; col++)
            std::cin >> matrix[row*(c+1)+col];
    
    for (int row = 0; row < r; row++)
    {
        for (int col = 0; col < c; col++)
        {
            matrix[row*(c+1) + c]   += matrix[row*(c+1) + col];
            matrix[r  *(c+1) + col] += matrix[row*(c+1) + col];
            matrix[r  *(c+1) + c]   += matrix[row*(c+1) + col];
        }
    }
    
    for (int row = 0; row < r + 1; row++)
    {
        for (int col = 0; col < c + 1; col++)
        {
            std::cout << matrix[row*(c+1)+col];

            if (col < c) std::cout << " ";
            else         std::cout << std::endl;
        }
    }    

}


Measured memory_bytes: 3076
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;

ll n, h, maxa = 0;
ll a[100000], b[100000];

int main() {
	cin >> n >> h;
	for (int i = 0; i < n; i++) {
		cin >> a[i] >> b[i];
		maxa = max(maxa, a[i]);
	}

	sort(b, b + n);
	int index = 0;
	for (index; index < n; index++) {
		if (b[index] > maxa)break;
	}

	ll bsum = 0;
	for (int i = index; i < n; i++) {
		bsum += b[i];
	}

	ll ans;
	if (h > bsum) {
		ans = n - index + (h-bsum)/maxa;
		if ((h - bsum) % maxa > 0)ans++;
	}
	else {//小さかったら
		ans = 0;
		for (int i = n - 1; i >= index && h > 0; i--) {
			ans++;
			h -= b[i];
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
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;
}

int main()
{
  string s;
  cin >> s;
  cout << s.erase(3) << endl;
}


Measured memory_bytes: 3612