akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>

//fast(?) Input
#define buf_sz 1<<24
char buf[buf_sz];
unsigned int nextint(){
	static int id = 0;
	if(id == 0)read(0, buf, buf_sz);
	unsigned int res = 0;
	while(id<buf_sz && buf[id]<'0' || '9'<buf[id])id++;
	while(id<buf_sz && '0'<=buf[id] && buf[id]<='9'){
		res *= 10;
		res += buf[id++] - '0';
	}if(id>=buf_sz)exit(1);
	return res;
}

int d[] = {[0 ... 1<<18] -1};
int find(int x){
	if(d[x] < 0) return x;
	return d[x] = find(d[x]);
}
bool unite(int x, int y){
	x = find(x); y = find(y);
	if(x == y)return false;
	if(d[x] > d[y]){
		int tmp = x;
		x = y;
		y = tmp;
	}
	d[x] += d[y];
	d[y] = x;
	return true;
}
bool same(int x, int y){return find(x) == find(y);}
int size(int x){return -d[find(x)];}

char out[buf_sz];
int out_sz = 0;
int main(){
	nextint();
	int Q = nextint();
	while(Q--){
		if(nextint() == 1){
			out[out_sz++] = same(nextint(), nextint())?49:48;
			out[out_sz++] = 10;
		}else {
			unite(nextint(), nextint());
		}
	}
	write(1, out, out_sz);
	return 0;
}

Measured memory_bytes: 4596
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;
class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		Set<Integer> set = new HashSet<>();
		int a,b,c,d,i,s =0;
		a=sc.nextInt();
		b=sc.nextInt();
		c=sc.nextInt();
		d=sc.nextInt();
		for(i=0;i<a;i++) {
			if(d == 0)break;
			d--;
			s++;
		}
		for(i=0;i<b;i++) {
			if(d == 0)break;
			d--;
		}
		for(i=0;i<c;i++) {
			if(d == 0)break;
			d--;
			s--;
		}
		System.out.println(s);
	}	
}


Measured memory_bytes: 35772
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

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

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }
#define INF 1LL<<60

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    REP(i, N) cin >> A[i];

    map<ll, ll> sum;
    sum[A[0]]++;
    ll ans = 0;
    FOR(j, 1, N-1) {
        if(j - A[j] >= 0)
        ans += sum[j-A[j]];
        sum[j + A[j]]++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 17520
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll mod = 1e9 + 7;
#define pival 3.14159265359
#define pll pair<ll,ll>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pqq priority_queue
#define all(a) a.begin(), a.end()
#define sz(a) (ll)(a.size())
#define endl '\n'
ll power(ll x, ll y, ll p)
{ 
    ll res = 1;  
    x = x % p;
    while (y > 0) { 
        if (y & 1) res = (res * x) % p; 
        y = y >> 1;
        x = (x * x) % p;   
    } 
    return res; 
}
const ll MAX = 20;
ll arr[1 << MAX];
pair <pll,pll> F[1 << MAX];
pair <pll,pll> rec(ll ind) {
	if (F[ind].fi.fi != 0) return F[ind];
	set <pll, greater<pll>> ans;
	ans.insert({arr[ind], ind});
	for (ll i = 0; i < MAX; i++) {
		if (ind & (1 << i)) {
			pair<pll,pll> temp = rec(ind ^ (1 << i));
			ans.insert(temp.fi);
			ans.insert(temp.se);
		}
	}
	auto it = ans.begin();
	auto it2 = it;
	it2++;
	return F[ind] = {*it, *it2};
}
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
 	ll n;
 	cin >> n;   
 	ll end = (1 << n); 
 	for (ll i = 0; i < end; i++) {
 		cin >> arr[i];
 	}
 	F[0] = {{arr[0], 0}, {-1, -1}};
 	rec(end - 1);
 	ll ans = 0;
 	for (ll i = 1; i < end; i++) {
 		ll temp = i;
 		vector <ll> pris;
 		while (temp > 0) {
 			pris.pb(temp % 2);
 			temp /= 2;
 		}
 		ans = max(ans, F[i].fi.fi + F[i].se.fi);
 		cout << ans << endl;
 	}
	return 0;
}

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

int main(){

    string S;
    cin >> S;

    int n = S.length();
    string ans = "";
    rep(i, n) ans += "x";

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string.h>
#include <math.h>
#include <stdio.h>
#include <deque>
//#include "D:\C++\test_lib_projects\testlib.h"
using namespace std;
#define ll long long
#define pii pair<int,int>

bool debug=true;
/*
   Write In New Computer
    By XiaoGeNintendo
	     gwq2017
	Type:
*/

/*
void fo(int id){
	freopen((toString(id)+".txt").c_str(),"w",stdout);
}
*/

int a,b,c;
set<int> v;
int main(int argc,char* argv[]){
	cin>>a>>b>>c;
	for(int i=a;i<a+c && i<=b;i++){
		v.insert(i);
	}
	for(int i=b;i>b-c && i>=a;i--){
		v.insert(i);
	}
	
	for(set<int>::iterator it=v.begin();it!=v.end();it++){
		cout<<*it<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
long long int n,a[100002],z,zs;
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
      cin>>a[i];
    sort(a+1,a+n+1);
    z=1;
    for(int i=2;i<=n;i++)
    {
        if(a[i]==a[i-1])z=(z+1)%2;
        else zs+=z,z=1;
    }
    if(z%2)zs++;
    cout<<zs<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<vector>

using namespace std;

int main(){
	int N,Q,l,r;
	int i,ans;
	char flag=0;
	string S;

	cin >> N >> Q;
	cin >> S;

	vector<int> counter(N);
	int ac_counter=0;

	for(i=0;i<N;++i){
		if(S[i]=='C' && flag){
			++ac_counter;
		}
		if(S[i]=='A'){
			flag=1;
		}else{
			flag=0;
		}
		counter[i]=ac_counter;
	}

	for(i=0;i<Q;++i){
		cin >> l >> r;
		--l;--r;
		ans=counter[r]-counter[l];
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include <fstream>
#include <algorithm>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <math.h>
using namespace std;
 
#define pb push_back
#define f first
#define s second
#define endl '\n'
#define EPS 1e-9
#define PI acos(-1)
 
using ll = unsigned long long;
using pll = pair<ll,ll>;
using ii = pair<int,int>;
using vi = vector<int>;
using vii = vector<ii>;
using vll = vector<ll>;
using ui = unsigned int;


int main() {
    ofstream out("output.txt");
    ios_base::sync_with_stdio(false);
    
    int a,b,c;
    cin>>a>>b;

    int arr[4];
    for(int i =1;i<=3;i++){
        arr[i] = 0;
    }
    arr[a] = a;
    arr[b] = b;

    if(arr[1] == 0) cout<<1<<endl;
    else if(arr[2] == 0) cout<<2<<endl;
    else if(arr[3] == 0) cout<<3<<endl;

    return 0;
}   


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long                                    // long long省略
#define pb push_back                                    // push_back省略
#define mp make_pair                                    // make_pair省略
#define fi first                                        // first省略
#define se second                                       // second省略
#define itn int                                         // int誤字保険
#define count cout                                      // cout誤字保険
#define vecotr vector                                   // vector誤字保険
#define ednl endl                                       // endl誤字保険
#define opt() cin.tie(0); ios::sync_with_stdio(false)   // 入出力速度改善

#define rep(i,l,r) for(ll i=(l);i<(r);i++)               // 範囲[l, r)で刻み1のfor文(順方向)
#define repp(i,l,r,k) for(ll i=(l);i<(r);i+=(k))         // 範囲[l, r)で刻みkのfor文(順方向)
#define rrep(i,l,r) for(ll i=(r-1);i>=(l);i--)           // 範囲[l, r)で刻み1のfor文(逆方向)
#define rrepp(i,l,r,k) for(ll i=(r-1);i>=(l);i-=(k))     // 範囲[l, r)で刻みkのfor文(逆方向)
#define all(x) (x).begin(), (x).end()                   // vectorのポインタ位置指定用
#define max(p,q)((p)>(q)?(p):(q))                       // max拡張
#define min(p,q)((p)<(q)?(p):(q))                       // min拡張
#define bit(n,m)(((n)>>(m))&1)                          // 変数nのm番目のbitを取り出す

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int dy[]={0, 1, 0, -1};                                 // 4方向近傍
int dx[]={1, 0, -1, 0};                                 // 4方向近傍

int main(){
    ll n,m,c;cin>>n>>m>>c;
    ll b[m];rep(i,0,m)cin>>b[i];
    ll a[n][m];rep(i,0,n)rep(j,0,m)cin>>a[i][j];
    ll ans=0;
    rep(i,0,n){
        ll sum=0;
        rep(j,0,m)sum+=b[j]*a[i][j];
        if(sum>-c)ans++;
    }
    cout << ans << ednl;
   
}


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

int main() {
    int n;
    cin >> n;
    vector<int> s(n);
    for (auto& e : s) cin >> e;
    int ans = accumulate(begin(s), end(s), 0);
    if (ans % 10 == 0) {
        sort(begin(s), end(s));
        auto itr = find_if(begin(s), end(s), [](auto a) { return a % 10 != 0; });
        ans = itr != end(s) ? ans - *itr : 0;
    }
    cout << ans << endl;
}


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

#define FOR(i,l,r) for(int i = (int) (l);i < (int) (r);i++)
template<typename T> bool chmax(T& a,const T& b){ return a < b ? (a = b,true) : false; }
template<typename T> bool chmin(T& a,const T& b){ return b < a ? (a = b,true) : false; }
typedef long long ll;

int N;
ll A,B;
vector<ll> H;

ll f(ll m)
{
	ll res = 0;
	FOR(i,0,N){
		ll h = H [i] - B * m;
		if(h <= 0) continue;
		res += (h + (A - B - 1)) / (A - B);
	}
	return res;
}

int main()
{
	scanf("%d%lld%lld",&N,&A,&B);
	H.assign(N,0);
	FOR(i,0,N){
		scanf("%lld",&H [i]);
	}

	ll ok = 1e10,ng = 0,mid;
	while(ok - ng > 1){
		mid = (ok + ng) / 2;
		if(f(mid) <= mid){
			ok = mid;
		}
		else{
			ng = mid;
		}
	}
	printf("%lld\n",ok);

	return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) ((int)(x).size())
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{
    int N; cin>>N;
    string ans;
    while(N)
    {
        int r=N%2;
        if(r<0) r+=2;
        ans=(char)('0'+r)+ans;
        N=(N-r)/(-2);
    }
    if(ans=="") ans="0";
    cout<<ans<<endl;
}


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

using namespace std;

int main(int argc, char *argv[]) {
	int N;
	cin >> N;
	vector<int> points;
	int point;
	for (int i = 0; i < N; i++) {
		cin >> point;
		points.push_back(point);
	}

	sort(points.begin(), points.end());
	int answer = (*(points.end() - 1) - *(points.begin()));
	cout << answer << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
typedef long long ll;
long long MOD = 1e9 + 7;
const long long INF = 1LL << 60;
using namespace std;

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

// dp[i][j] :=
// i番目までの商品を、重さがj以下になるように選んだ時の価値の最大値
ll dp[110][100100] = {0};

int main() {
  int n, w_limit;
  cin >> n >> w_limit;

  int w[n + 1];
  int v[n + 1];
  repi(i, 1, n + 1) { cin >> w[i] >> v[i]; }

  repi(i, 1, n + 1) {
    repi(j, 0, w_limit + 1) {
      if (j >= w[i]) {
        // i番目の商品を選べる場合
        chmax(dp[i][j], dp[i - 1][j - w[i]] + v[i]);
        chmax(dp[i][j], dp[i - 1][j]);
      }

      // i番目の商品を選べない場合
      chmax(dp[i][j], dp[i - 1][j]);
    }
  }

  cout << dp[n][w_limit] << endl;
  return 0;
}


Measured memory_bytes: 79360
#include <bits/stdc++.h>
#define fastIO (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define precise(i) fixed << setprecision(i)
using namespace std;

int main() {
    fastIO;

    string s;
    cin >> s;

    int l = 0, r = 0;
    for (int i = 0; i < (int)s.size(); ++i) {
        if (s.at(i) == 'A') {
            l = i;
            break;
        }
    }

    for (int i = (int)s.size() - 1; i >= 0; --i) {
        if (s.at(i) == 'Z') {
            r = i;
            break;
        }
    }

    cout << r - l + 1 << endl;
}

Measured memory_bytes: 3732
#include <cstdio>
#include <limits>
#include <cmath>
#include<iostream>
#include<string>
#include <vector>
#include<algorithm>
using namespace std;


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

	double x = (double)(a + b) / 2;
	
	cout << ceil(x) << endl;
	return 0;
}

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

using namespace std;

const int SIZE = 1e6;
const int k = 2;
int n, A[SIZE + 10];
int cnt = 0, m;
vector<int> G;

void insertionSort(int g) {
    for (int i = g; i < n; i++) {
        int v = A[i], j = i - g;
        while (j >= 0 && A[j] > v) {
            A[j + g] = A[j];
            j -= g;
            cnt++;
        }
        A[j + g] = v;
    }
}

int sizeOfG() {
    int res = 0, g = 1;
    while (g <= n) {
        g = k * g + 1;
        res++;
    }
    return res;
}

void shellSort() {
    m = sizeOfG();
    
    int g = 1;
    for (int i = 0; i < m; i++) {
        G.push_back(g);
        g = k * g + 1;
    }

    reverse(G.begin(), G.end());
    for (int i = 0; i < m; i++) {
        insertionSort(G[i]);
    }
}

int main() {
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &A[i]);
    }

    shellSort();

    printf("%d\n", m);
    for (int i = 0; i < m; i++) {
        if (i) putchar(' ');
        printf("%d", G[i]);
    }
    putchar('\n');
    printf("%d\n", cnt);
    for (int i = 0; i < n; i++) {
        printf("%d\n", A[i]);
    }
    return 0;
}


Measured memory_bytes: 7152
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using ll = long long;
using namespace std;

int main() {
    char a;
    cin >> a;
    char ans = 'a';

    if(isupper(a)) {
        ans = 'A';
    }
    cout << ans << endl;
}

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

using namespace std;
typedef long long ll;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, m, n) for (ll i = m; i < n; i++)

int main(int argc, char const *argv[])
{
    string s;
    cin >> s;
    string target = "keyence";
    ll n = s.length();
    REP(i, n)
    {
        FOR(j, i + 1, n + 1)
        {
            if (s.substr(0, i + 1) + s.substr(j, n - j) == target)
            {
                cout << "YES" << endl;
                return 0;
            }
        }
    }
    cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 256
# coding: utf-8

import itertools

data_set = []
answer = []

while (1):
    n,x = map(int, input().split())
    if (n == 0 and x == 0):
        break
    data_set.append([n,x])

for d in data_set:
    num = list(range(d[0] + 1))[1:]
    counter = 0
    for i in itertools.combinations(num, 3):
        if (sum(i) == d[1]):
            counter += 1
    answer.append(counter)
    
for ans in answer:
    print(ans)

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

#include <iostream>
#include <vector>
// #include <map>
// #include <string>
#include <algorithm>
// #include <numeric>
// #include <limits>

using namespace std;

struct Point {
	int x;
	int y;
};

using PolygonalLine = vector<Point>;

vector<PolygonalLine> lines;

void print(PolygonalLine line) {
	cout << "+ " << line.size() << endl;
	for (auto point : line) {
		cout << "  " << point.x << " " << point.y << endl;
	}
}

void rotate(PolygonalLine& line, int a, int b, int c, int d) {
	for (auto& point : line) {
		int x = point.x;
		int y = point.y;
		point.x = a * x + b * y;
		point.y = c * x + d * y;
	}
}

void rotate(PolygonalLine& line, int angle) {
	if (angle == 180) {
		rotate(line, -1, 0, 0, -1);
	} else if (angle == 270) {
		rotate(line, 0, 1, -1, 0);
	} else if (angle == 90) {
		rotate(line, 0, -1, 1, 0);
	}
}

void shift(PolygonalLine& line) {
	int x = line[0].x;
	int y = line[0].y;
	for (auto& point : line) {
		point.x -= x;
		point.y -= y;
	}
}

// align to line[1].x > line[0].x
void align(PolygonalLine& line) {
	if (line[1].x - line[0].x > 0) {
	} else if (line[1].x - line[0].x < 0) {
		rotate(line, 180);
	} else if (line[1].y - line[0].y > 0) {
		rotate(line, 270);
	} else if (line[1].y - line[0].y < 0) {
		rotate(line, 90);
	}
	shift(line);
}

void inputLine() {
	PolygonalLine line;
	int m;
	cin >> m;
	// std::cout << "debug m " << m << std::endl; // debug
	line.resize(m);
	for (int i = 0; i < m; i++) {
		Point point;
		cin >> point.x >> point.y;
		// std::cout << "debug point " << point.x << " " << point.y << std::endl; // debug
		line[i] = point;
	}
	align(line);
	lines.push_back(line);
}

bool isSame(const Point& p1, const Point& p2) {
	return p1.x == p2.x and p1.y == p2.y;
}

bool isSame(const PolygonalLine& l1, const PolygonalLine& l2) {
	if (l1.size() != l2.size()) {
		return false;
	}
	for (size_t i = 0; i < l1.size(); i++) {
		if (isSame(l1[i], l2[i]) == false) {
			return false;
		}
	}
	return true;
}

void solve(int n) {
	lines.clear();
	for (int i = 0; i < n + 1; i++) {
		inputLine();
	}
	PolygonalLine rev_line = lines[0];
	reverse(rev_line.begin(), rev_line.end());
	align(rev_line);
	for (size_t i = 1; i < lines.size(); i++) {
		// print(lines[i]); // debug
		if (isSame(lines[0], lines[i]) or isSame(rev_line, lines[i])) {
			cout << i << endl;
		}
	}
	cout << "+++++" << endl;
}

int main() {
	int n;
	cin >> n;
	while (n != 0) {
		// std::cout << "debug n " << n << std::endl; // debug
		solve(n);
		cin >> n;
	}
	// std::cout << "\e[38;5;0m\e[48;5;40m --- end ---  \e[m" << std::endl; // debug
	return 0;
}

Measured memory_bytes: 3060
#include<iostream>
#include<string>
using namespace std;
int main() {
	string s;
	cin >> s;
	for (int i = 0; i < s.size()-1; i++) {
		if (s.substr(i,2) == "AC") {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef complex<double> xy_t; 
xy_t p[101];
char c;
double x, y;
double sum;
int n;
int main()
{
	sum=0.0;
	cin >> n;
	for(int i=1; i<=n; i++)
	{
		cin >> x >> y;
		p[i]=xy_t(x, y);
	}
	p[n+1]=p[1];
	for(int i=1; i<=n; i++)
	{
		sum+=(conj(p[i])*p[i+1]).imag()/2;
	}
	cout << fixed << setprecision(1) << abs(sum) << endl;
	return 0;
}

Measured memory_bytes: 3280
#include <iostream>
#include <stdio.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <set>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <bitset>
#include <stack>
#include <queue>
#include <ctype.h>

typedef long long int lli;
#define rep(i,s,N) for(int i=s;i<N;i++)
#define MOD 1000000007
#define more(a,b) (((a)>(b))?(a):(b))
#define less(a,b) (((a)<(b))?(a):(b))
using namespace std;


int main(void)
{
	int N, M; cin >> N >> M;
	vector<int> p(M);
	vector<string> S(M);
	rep(i, 0, M)cin >> p[i] >> S[i];

	vector<bool> AC(N, false);
	vector<int> WA(N, 0);
	rep(i, 0, M) {
		if (!AC[p[i] - 1]) {
			if (S[i] == "WA")WA[p[i] - 1]++;
			else AC[p[i] - 1] = true;
		}
	}
	int cor = 0, pen = 0;
	rep(i, 0, N) {
		if (AC[i]) {
			cor++;
			pen += WA[i];
		}
	}

	cout << cor << " " << pen << endl;

	return 0;
}


Measured memory_bytes: 6528
#include <stdio.h>

int main(){
  char s;
  int num_r = 0;
  int num_b = 0;
  int ret;
  while(1){
    ret = scanf("%c",&s);
    if(ret == EOF) break;
    if(s == '0') num_r++;
    else if(s == '1') num_b++;
  }
  
  int answer = 2*num_r;
  if(num_r > num_b) answer = 2*num_b;
  
  printf("%d\n",answer);
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#define rep(i,n) for(int i = 0; i < (n); ++i)
typedef long long ll;
using namespace std;


int main() {
  int wa[105000];
  bool ac[105000];
  
  int rwa = 0;
  int rac = 0;
  int n,m; 
  cin >> n >> m;
  rep(i,m){ 
    wa[i] = 0;
    ac[i] = false;
  }
  rep(i,m){
    int a; 
    string b;
    cin >> a >> b;
    if(ac[a] == true){continue;}
    else{
      if(b == "AC"){
        ac[a] = true;
        rac++; 
        rwa += wa[a];
      } else {
        ++wa[a];
      }
    }
  }
  cout << rac << ' ' << rwa << endl;
}


Measured memory_bytes: 768
#include <stdio.h>
long long a [100010];
int main (){
int n;
scanf("%d",&n);
for(int i=0;i<n;i++) scanf("%lld",&a[i]);
int zero =0;
for(int i=0;i<n;i++)if(a[i]==0) zero ++;
if(zero >0){
// a[i] contains 0
printf("0\n");
return 0;
}
long long prod =1;
for(int i=0;i<n;i++){
if(a[i ] <=1000000000000000000/ prod ){
// This condition is equivalent to prod*a[i] <=10ˆ18
prod *=a[i];
}else{
printf("-1\n");
return 0;
}
}
printf("%lld\n",prod );
}


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

int main() {
  string n;
  cin >> n;
  int s = 0;
  for (auto e : n) {
    s += e - '0';
  }
  cout << (s < 2 ? 10 * s : s) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
const int iINF = 100100100;
vector<int> divisor(int n) {
    vector<int> ret;
    for (int i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    sort(ret.begin(), ret.end());
    return ret;
}

int main()
{
  int n,tmp;
  cin >> n;
  vector<int> vec;
  map<int, int> mp;
  rep(i,n) {
    cin >> tmp;
    vec.push_back(tmp);
  }
  sort(vec.begin(),vec.end());
  if (vec[0] == 1) {
    if (vec[1] == 1)	cout << 0 << endl;
    else cout << 1 << endl;
    return 0;
  }
  vector<int> dev;
  int ans = 0;
  bool search = true;
  bool ok = true;
  rep(i,n) {
    dev = divisor(vec[i]);
    ok = true;
    search = true;
    if (i < n - 1) {
      if (vec[i] == vec[i + 1]) {
        search = false;
        ok = false;
      }
      else search = true;
    }
    if (search) {
      rep(j,dev.size()) {
        if (auto itr = mp.find(dev[j]); itr != mp.end()) {
          ok = false;
          break; 
        }
      }
    }
    if (ok) ++ans;
    mp[vec[i]]++;
  }
  cout << ans << endl;
 
  return 0; 
}

Measured memory_bytes: 13416
def read():
    N = int(input().strip())
    S = str(input().strip())
    return N, S

def rotN(N, S):
    T = []
    for s in S:
        c = ord(s) - ord('A')
        c = (c + N) % 26
        T.append(chr(c + ord('A')))
    return ''.join(T)

def solve(N, S):
    return rotN(N, S)

if __name__ == '__main__':
    inputs = read()
    output = solve(*inputs)
    print("%s" % output)

Measured memory_bytes: 39792
#!/usr/bin/env python3
import sys
read = sys.stdin.buffer.read

K, S = map(int, read().split())
count = 0

for x in range(K + 1):
    for y in range(K + 1):
        z = S - x - y
        if 0 <= z <= K:
            count += 1

print(count)


Measured memory_bytes: 2940
X=int(input())
if X >= 400 and X<=599:
    print(8)
elif X>=600 and X<=799:
    print(7)
elif X>=800 and X<=999:
    print(6)
elif X>=1000 and X<=1199:
    print(5)
elif X>=1200 and X<=1399:
    print(4)
elif X>=1400 and X<=1599:
    print(3)
elif X>=1600 and X<=1799:
    print(2)
elif X>=1800 and X<=1999:
    print(1)

Measured memory_bytes: 9196
//
// Created by Tzyark on 2018/9/19.
//
#include <iostream>
using namespace std;
int main() {
    int a, b, c;
    cin >> a >> b >> c;
    if (a+b==c || a+c==b || b+c==a) cout << "Yes\n";
    else cout << "No\n";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fastIO ios::sync_with_stdio(0), cin.tie(0)
#define endl '\n'
#define ft first
#define sd second
#define pb push_back
#define pob pop_back()
#define pf push_front
#define pof pop_front()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin, (x).rend()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<char,char> pcc;
typedef pair<double,double> pdd;
typedef pair<long long,long long> pll;
// scanf("%d %d %d %d",&w,&b,&d,&s); %lld
// printf("%d\n" ,points);
// const double PI=acos(-1);

int main(){
    cout << fixed << setprecision(10);
    int w,h,x,y;
    bool m;
    double rta;
    cin >> w >> h >> x >> y;
    m=w==x*2 && h==y*2;
    rta=(1.0*w*h)/2;
    cout << rta << " " << m << endl;
    return 0;
}


Measured memory_bytes: 3732
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Scanner;

public class Main {

    private static Scanner scan = new Scanner(System.in);

    public static void main(String[] args) {
	int N = Integer.parseInt(scan.next());
	List<X> xList = new ArrayList<X>(N);
	List<X> yList = new ArrayList<X>(N);
	
	for (int i = 0; i < N; i++) {
	    xList.add(new X(Integer.parseInt(scan.next()), i));
	    yList.add(new X(Integer.parseInt(scan.next()), i));
	}
	Collections.sort(xList);
	Collections.sort(yList);

	List<Edge> list = new ArrayList<Edge>();
	for (int i = 0; i < N-1; i++) {
	    list.add(new Edge(xList.get(i).index, xList.get(i+1).index, Math.abs(xList.get(i).x - xList.get(i+1).x)));
	    list.add(new Edge(yList.get(i).index, yList.get(i+1).index, Math.abs(yList.get(i).x - yList.get(i+1).x)));
	}
	Collections.sort(list);

	UnionFind uf = new UnionFind(N);
	int total = 0;
	for(Iterator<Edge> itr = list.iterator(); itr.hasNext();) {
	    Edge e = itr.next();
	    int idx1 = e.from;
	    int idx2 = e.to;

	    if(uf.root(idx1) != uf.root(idx2)) {
		uf.connect(idx1, idx2);
		total += e.cost;
	    }
	}
	
	System.out.println(total);
	scan.close();
    }
}

class X implements Comparable<X> {
    int x;
    int index;

    X(int x, int index) {
	this.x = x;
	this.index = index;
	}

    @Override
    public int compareTo(X o) {
	return x - o.x;
    }
}

class Edge implements Comparable<Edge>{
    int from;
    int to;
    int cost;

    Edge(int from, int to, int cost) {
	this.from = from;
	this.to = to;
	this.cost = cost;
	}

    @Override
    public int compareTo(Edge o) {
	return cost - o.cost;
    }
    
}

class UnionFind {
    int[] uni;

    UnionFind(int N) {
	uni = new int[N];
	for (int i = 0; i < N; i++) {
	    uni[i] = -1;
	}
    }

    int root(int a) {
	if(uni[a] < 0) return a;
	else return uni[a] = root(uni[a]);
    }

    boolean connect(int a, int b) {
	a = root(a);
	b = root(b);

	if(a == b) return false;
	if(uni[a] > uni[b]) {
	    int tmp = a;
	    a = b;
	    b = tmp;
	}
	uni[a] += uni[b];
	uni[b] = a;
	return true;
    }
    
}


Measured memory_bytes: 67008
n, q = map(int, input().split())
s = input()
l_r = [ list(map(int, input().split())) for _ in range(q) ]

memo = [0] * (n+1)


for i in range(n):
    if s[i:i+2] == 'AC':
         memo[i+1] = memo[i] + 1
    else:
         memo[i+1] = memo[i]

for l,r in l_r:
    print(memo[r-1]-memo[l-1])

Measured memory_bytes: 29704
#include<cstdio>
#include<cstring>
using namespace std;
int main(){
    int x,y;
    while(scanf("%d%d",&x,&y),x,y){
        int data=0;
        int q = 0;
        data = x+y;
        for(int i = 1;i <= 4; i++){
            scanf("%d%d",&x,&y);
            if(data < x+y){
                data = x+y;
                q = i;
            }
        }
        printf("%c %d\n",q+65,data);
    }
    return 0;
}

Measured memory_bytes: 1028
import copy

def dfs(a, b, c, d, A, N, M, Q):
    ans = 0
    if len(A) == 0:
        s = 1
    else:
        s = A[-1]
    A.append(0)
    if len(A) == N:
        for v in range(s, M+1):
            A[-1] = v
            ans_q = 0
            for q in range(Q):
                if (A[b[q]] - A[a[q]]) == c[q]:
                    ans_q += d[q]
            ans = max(ans_q, ans)
    else:
        for v in range(s, M+1):
            A[-1] = v
            ans = max(dfs(a, b, c, d, copy.copy(A), N, M, Q), ans)
    return ans

N, M, Q = [int(a) for a in input().split()]
a = []
b = []
c = []
d = []
A = []

for q in range(Q):
    in_ = [int(a) for a in input().split()]
    a.append(in_[0]-1)
    b.append(in_[1]-1)
    c.append(in_[2])
    d.append(in_[3])

ans = dfs(a,b,c,d,A,N,M,Q)
print(ans)

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

int main(){
    int n;
    cin>>n;
    int A[n],B[n],C[n-1];
    for(int i=1;i<=n;i++)
        cin>>A[i];
    for(int i=1;i<=n;i++)
        cin>>B[i];
    for(int i=1;i<=n-1;i++)
        cin>>C[i];
    //cout<<C[0]<<endl;
    int sum=0,last=-1;
    for(int i=1;i<=n;i++){
        if(A[i]==last+1){
            //cout<<C[last]<<" ";
            sum+=C[last];
        }
        //cout<<B[A[i]]<<" ";
        sum+=B[A[i]];
        last=A[i];
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
vector<int> transform(int N, vector<int> A, vector<int> p) {
	vector<int> ans(N);
	for (int i = 0; i < N; ++i) {
		ans[i] = A[p[i]];
	}
	return ans;
}
int main() {
	int N;
	cin >> N;
	vector<int> A(N), B(N), p(N), q(N);
	for (int i = 0; i < N; ++i) cin >> A[i], p[i] = i;
	for (int i = 0; i < N; ++i) cin >> B[i], q[i] = i;
	sort(q.begin(), q.end(), [&](int i, int j) { return B[i] < B[j]; });
	A = transform(N, A, q);
	B = transform(N, B, q);
	sort(p.begin(), p.end(), [&](int i, int j) { return A[i] < A[j]; });
	bool flag = true;
	for (int i = 0; i < N; ++i) {
		if (A[p[i]] > B[i]) {
			flag = false;
			break;
		}
	}
	if (!flag) {
		cout << "No" << endl;
	}
	else {
		int pos = 0, cnt = 0;
		while (cnt == 0 || pos != 0) {
			++cnt;
			pos = p[pos];
		}
		if (cnt < N) {
			cout << "Yes" << endl;
		}
		else {
			bool ans = false;
			for (int i = 1; i < N; ++i) {
				if (A[p[i]] <= B[i - 1]) {
					ans = true;
					break;
				}
			}
			cout << (ans ? "Yes" : "No") << endl;
		}
	}
	return 0;
}

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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

int N;
int A[100100];

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

    std::cin >> N;

    int pn = 0, nn = 0;

    for(int i=0;i<N;++i){
        std::cin >> A[i];

        if(A[i] >= 0){
            pn += 1;
        }else{
            nn += 1;
        }
    }

    std::sort(A, A + N);

    if(pn > 0 && nn > 0){
        int mx = 0;

        for(int i=0;i<N;++i){
            mx += std::abs(A[i]);
        }

        std::cout << mx << std::endl;

        int cur = A[0];

        for(int i=nn+1;i<N;++i){
            std::cout << cur << " " << A[i] << std::endl;
            cur -= A[i];
        }
        
        std::cout << A[nn] << " " << cur << std::endl;
        A[nn] -= cur;
        
        for(int i=1;i<nn;++i){
            std::cout << A[nn] << " " << A[i] << std::endl;
            A[nn] -= A[i];
        }
    }else if(pn > 0){
        int mx = -A[0];
        
        for(int i=1;i<N;++i){
            mx += A[i];
        }

        std::cout << mx << std::endl;

        int cur = A[0];

        for(int i=2;i<N;++i){
            std::cout << cur << " " << A[i] << std::endl;
            cur -= A[i];
        }

        std::cout << A[1] << " " << cur << std::endl;
    }else if(nn > 0){
        int mx = A[N - 1];

        for(int i=0;i<N-1;++i){
            mx += -A[i];
        }

        std::cout << mx << std::endl;

        int cur = A[N-1];

        for(int i=0;i<N-1;++i){
            std::cout << cur << " " << A[i] << std::endl;
            cur -= A[i];
        }
    }
}


Measured memory_bytes: 2304
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
//#define mt make_tuple
//typedef tuple<double,int,double> tp;
//typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-7;
Def inf=sizeof(Def)==sizeof(long long)?2e18:1e9;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
	int n,m,k;
	cin>>n>>m>>k;
	rep(i,n+1)rep(j,m+1){
		if(k==i*j+(n-i)*(m-j)){
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
}








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

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

   vector<pair<int, pair<int, int>>> YCP(M);
   vector<int> Pcount(N + 1);
   vector<pair<int, int>> ID(M + 1);

   rep(i, 1, M + 1) {
     int p, y;
     cin >> p >> y;
     YCP.at(i - 1).first = y;
     YCP.at(i - 1).second.first = i;
     YCP.at(i - 1).second.second = p;
   }

   sort(YCP.begin(), YCP.end());

   rep(i, 0, M) {
     Pcount.at(YCP.at(i).second.second)++;
     ID.at(YCP.at(i).second.first).first = YCP.at(i).second.second;
     ID.at(YCP.at(i).second.first).second = Pcount.at(YCP.at(i).second.second);
   }

   rep(i, 1, M + 1) {
     cout << setw(6) << setfill('0') << ID.at(i).first;
     cout << setw(6) << setfill('0') << ID.at(i).second << endl;
   }
 }


Measured memory_bytes: 3840
#include<cstdio>
#include<algorithm>
#define MAXN 200006
using namespace std;
int n,q,a[MAXN],sum[MAXN],vis[MAXN],ans,p,x;
int main()
{
	scanf("%d%d",&n,&q);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	for(int i=1;i<=n;i++)
		sum[a[i]]++;
	for(int i=1;i<=n;i++)
	{
		for(int j=max(1,i-sum[i]+1);j<=i;j++)
			vis[j]++;
	}
	for(int i=1;i<=n;i++)
		if(!vis[i]) ans++;
	for(int i=1;i<=q;i++)
	{
		scanf("%d%d",&p,&x);
		int y=a[p];
		sum[y]--;
		if(y-sum[y]>0)
		{
			vis[y-sum[y]]--;
			if(!vis[y-sum[y]]) ans++;
		}
		a[p]=x;
		if(x-sum[x]>0)
		{
			if(!vis[x-sum[x]]) ans--;
			vis[x-sum[x]]++;
		}
		sum[x]++;
		printf("%d\n",ans);
	}
}

Measured memory_bytes: 3840
MOD = 10**9+7
l = input()

dp = [2, 1]
for i in range(1, len(l)):
    x, y = dp
    if l[i] == '1':
        x, y = 2*x%MOD, (x + 3*y%MOD)%MOD
    else:
        x, y = x, 3*y%MOD
    dp = [x, y]
print(sum(dp)%MOD)


Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define Repr(i, n, a) for (int i = (n); i >= (a); i--)
#define rep(i, n) Rep(i, 0, n)
#define repr(i, n) Repr(i, n, 0)
#define all(a) a.begin(), a.end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

int cnt[100010];

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

    int n, k;
    cin >> n >> k;
    rep(i, n)
    {
        int a, b;
        cin >> a >> b;
        cnt[a] += b;
    }
    int num = 0;
    rep(i, 100010)
    {
        num += cnt[i];
        if (num >= k)
        {
            cout << i << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, pair<ll, ll> > P3;
const ll MOD = 1000000007;
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;
const int MAX_N = int(1e5 + 5);
const double EPS = 1e-10;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define ALL(v) (v).begin(), (v).end()

string s[405];
ll h, w;

P rec(int i, int j){
    char c = s[i][j];
    s[i][j] = 'x';
    P res = {0,0};
    if(c=='#')res.first++;
    else res.second++;
    REP(k,4){
        int ni = i+di[k], nj = j+dj[k];
        if(ni<0 || ni>=h)continue;
        if(nj<0 || nj>=w)continue;
        if(s[ni][nj]=='x')continue;
        if(c != s[ni][nj]){
            P tmp = rec(ni,nj);
            res.first += tmp.first;
            res.second += tmp.second;
        }
    }
    return res;
}


int main() {
    ll ans = 0;
    cin >> h >> w;
    REP(i,h) cin >> s[i];
    REP(i,h){
        REP(j,w){
            if(s[i][j]!='x'){
                P tmp = rec(i,j);
                ans += tmp.first*tmp.second;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 20480
#include<stdio.h>

//線形探索
int search(int A[], int n, int key) {
    int i = 0;
    A[n] = key;
    while ( A[i] != key ) i++;
    return i != n;
}

int main() {
    int i, n, A[10000+1], q, key, sum = 0;

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

    scanf("%d", &q);
    for ( i = 0; i < q; i++ ) {
      scanf("%d", &key);
      if ( search(A, n, key) ) sum++;
    }
printf("%d\n", sum);

return 0;
}


Measured memory_bytes: 2112
#include <stdio.h>

#define MAX 50001

int makePrimeTable( int * table )
{
        int i, j;
        for ( i = 0 ; i < MAX ; i++ ) {
                table[i] = 0;
        }

        for ( i = 2 ; i < MAX ; i++ ) {
                if ( table[i] == 0 ) {
                        for ( j = 2 ; i * j < MAX ; j++ ) {
                                table[i*j] = 1;
                        }
                }
        }
        return 0;
}


int main()
{
        int n, i, j, cnt;
        int ptable[MAX];
        makePrimeTable( ptable );
        while ( scanf( "%d", &n ) == 1 ) {
                cnt = 0;
                if ( n == 0 ) {
                        break;
                } else {
                        for ( i = 2 ; i <= n / 2 ; i++ ) {
                                if ( ptable[i] == 0 && ptable[n-i] == 0 ) {
                                        cnt++;
                                }
                        }
                        printf( "%d\n", cnt );
                }
        }
        return 0;
}



Measured memory_bytes: 2000
n=int(input())
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
b=prime_factorize(n) 
print(f'{n}: ',end="")
print(*b)


Measured memory_bytes: 5608
N, K = map(int, input().split())
vH = list(map(int, input().split()))

INF = float("inf")
head = [INF,] * (K-1)
vH = head + vH
dp = head + [0,]

for i in range(K, N+K-1):
    dp.append(min(dp[-k] + abs(vH[i] - vH[i-k]) for k in range(1,K+1)))

print(dp[-1])


Measured memory_bytes: 62816
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=5005;
ll k,q,d[N],a[N];
int main()
{
    scanf("%lld%lld",&k,&q);
    for(ll i=0;i<k;i++) scanf("%lld",&d[i]);
    while(q--)
    {
        ll n,x,mod;
        scanf("%lld%lld%lld",&n,&x,&mod);
        if(n<=k)
        {
            a[0]=x%mod;
            for(int i=1;i<n;i++)
                a[i]=(a[i-1]+d[i-1])%mod;
            int ans=0;
            for(int i=0;i<n-1;i++)
                if(a[i]<a[i+1]) ans++;
            printf("%d\n",ans);
            continue;
        }
        ll sum=0;
        for(ll i=0;i<k;i++) sum+=d[i]%mod;
        ll s=x%mod+(n-1)/k*sum;
        ll t=(n-1)%k;
        for(ll i=0;i<t;i++)
            s+=d[i]%mod;
        ll ans=n-1-s/mod;
        for(ll i=0;i<k;i++)
            if(d[i]%mod==0)
            {
                ll sum=(n-1-i)/k-((n-1-i)%k==0);
                ans-=sum;
                if(i<n-1) ans--;
            }
        printf("%lld\n",ans);
    }
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const ll inf =1LL << 62;
const ll mod=1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b,const ll &mod) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b,const ll &mod) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b,const ll &mod) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b,const ll &mod) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
random_device rd;
mt19937 mt(rd());
uniform_int_distribution<int> dice(1,6);
uniform_real_distribution<double> score(0.0,10.0);

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

    int n; cin >> n;
    string in; cin >> in;

    int res = 0;
    rep(loop, 2){
        int lsum = 0, rsum = 0;
        vi ls2i = {n - 1}, rs2i = {0};
        rep(i, n){
            if(in[i] == '>'){
                rsum++;
                rs2i.emplace_back(i);
            }
        }
        rrep(i, n){
            if(in[i] == '<'){
                lsum++;
                ls2i.emplace_back(i);
            }
        }
        if((int)ls2i.size() >= 1) ls2i[0] = ls2i[1];

        rsum = 0;
        rep(i, n){
            if(in[i] == '<'){
                lsum--;
                continue;
            }
            rsum++;

            int cur = 0;
            if(rsum <= lsum){
                int r = ls2i[lsum - rsum + 1];
                cur = r + 1;
            }
            else {
                int l = rs2i[rsum - lsum];
                cur = n - l;
            }

            chmax(res, cur);
        }

        reverse(_all(in));
        for(auto& e : in){ if(e == '>') e = '<'; else if(e == '<') e = '>'; }
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 3784
n,k = map(int,input().split())
a = list(map(int,input().split()))

next = [[0]*n for _ in range(60)]

for v in range(n):
    next[0][v] = a[v]-1
for d in range(60-1):
    for v in range(n):
        next[d+1][v] = next[d][next[d][v]]
        
v = 0
for d in range(60):
    if k>>d&1:
        v = next[d][v]
        
print(v+1)

Measured memory_bytes: 182008
#include<stdio.h>
int main(void){
   int a[500], count, i, j, n, key;
   scanf("%d", &n);
   while ( n ) {
    for ( i = 0; i < 2 * n; i++ ) {
        a[i] = 0;
    }
       key = 0;
       for ( i = 0; i < n; i++ ) {
           scanf("%d", &a[i]);
       }
       while ( 1 ) {
           count = 0;
           for ( i = 0; i < n; i++ ) {
               for ( j = 0; j < n; j++ ) {
                   if ( a[i] == a[j] ) a[i + n]++;
                   /*printf("a\n");*/
               }
               if ( a[i + n] == a[i] ) count++;
           }
           if ( count == n ) break;
           for ( i = 0; i < n; i++ ) {
               a[i] = a[i + n];
               a[i + n] = 0;
           }
           /*printf("%d", a[0]);
           for( i = 1; i < n; i++ ) {
               printf(" %d", a[i]);
           }
           printf("\n");*/
   
           key++;
        }
        printf("%d\n", key);
        printf("%d", a[0]);
        for( i = 1; i < n; i++ ) {
            printf(" %d", a[i]);
        }
        printf("\n");
        scanf("%d", &n);
    }
   return 0;
}

Measured memory_bytes: 1732
h,w=map(int,input().split())
s=[]
for _ in range(h):
    s.append(list(input()))

dx=[-1,-1,-1,0,0,1,1,1]
dy=[1,0,-1,1,-1,1,0,-1]

for i in range(h):
    for j in range(w):
        if s[i][j]=="#":
            continue

        count=0
        for k in range(8):
            di=i+dx[k]
            dj=j+dy[k]

            if (di<0)|(di>h-1):
                continue
            if (dj<0)|(dj>w-1):
                continue

            if s[di][dj]=="#":
                count+=1

        s[i][j]=str(count)

for _ in range(h):
    print("".join(s[_]))

Measured memory_bytes: 3188
#include <bits/stdc++.h>
//登録しよう！→ https://www.youtube.com/channel/UCRXsI3FL_kvaVL9zoolBfbQ
using namespace std;
using ll = long long;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}//a,bの最大公約数(gcd)を求める
ll lcm(ll a,ll b){return abs(a*b)/gcd(a,b);}//a,bの最小公倍数(lcm)を求める
vector<ll> enum_div(ll n){vector<ll> ret;for(int i=1 ; i*i<=n ; i++){if(n%i == 0){ret.push_back(i);if(i!=1 && i*i!=n)ret.push_back(n/i);}}ret.push_back(n);return ret;}
//↑nの約数を求める
vector<bool> IsPrime; void sieve(size_t max){if(max+1 > IsPrime.size())IsPrime.resize(max+1,true);IsPrime[0] = false;IsPrime[1] = false;for(size_t i=2; i*i<=max; ++i)if(IsPrime[i])for(size_t j=2; i*j<=max; ++j)IsPrime[i*j] = false;}
//↑エラトステネスの篩で素数を求める
#define roundup(divisor,dividend) (divisor + (dividend - 1)) / dividend //切り上げ割り算
#define all(x) (x).begin(),(x).end() //xの初めから終わりまでのポインタ
#define size_t ll //size_tは自動でllに変換される
#define pb(x) push_back(x)
#define gre greater //sortを降順にする
#define pri_queue priority_queue //優先度付きキュー
#define syo(x) fixed << setprecision(x) //iostreamで小数をx桁表示

void solve(long long N){
  double a = roundup(N,2);
  double ans = a/(double)N;
  cout << syo(10) << ans << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    solve(N);
}


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

int main(){
    string s;
    long long int k;
    cin >> s;
    cin >> k;
    
    long long int count = 0;
    int index_s = 0;
    for(int i = 1; i < s.length(); i++){
        if(s[i] != s[index_s]){
            count += (i-index_s)/2;
            index_s = i;
        }
    }
    
    long long int res = 0;
    if(index_s == 0){
        res = s.length() * k / 2;
    }else{
        if(s[0] != s[s.length() - 1]){
            count += (s.length() - index_s)/2;
            res = count * k;
        }else{
            long long int a, b;
            for(a = 0; s[a] == s[0]; a++);
            for(b = 0; s[s.length()-b-1] == s[0]; b++);
            count -= a/2;
            res = count * k;
            res += a/2;
            res += b/2;
            res += (a+b)/2 * (k-1);
        }
    }
    
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void) {
    int a, b, n, s[200], f[200];
    int flag = 0;
    int i, j;
    scanf("%d %d", &a, &b);
    scanf("%d", &n);
    for (i = 0; i < n; i++) {
        scanf("%d %d", &s[i], &f[i]);
    }

    for (i = 0; i < n; i++) {
        if (b <= s[i] || f[i] <= a) {
            continue;
        } else {
            flag = 1;
            break;
        }
    }
    if (flag) {
        printf("1\n");
    } else {
        printf("0\n");
    }
    return 0;
}


Measured memory_bytes: 2104