akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll;
const int N = 5e5 + 5;

int n, Q;
int c[N];
int block;
struct Query{
	int l, r, id;
	ll ans ;
}q[N];
bool cmp(Query x, Query y) {
	if((x.l - 1) / block + 1 == (y.l - 1) / block + 1) return x.r < y.r;
	return (x.l - 1) / block + 1 < (y.l - 1) / block + 1 ;
}
bool cmp2(Query x, Query y) {
	return x.id < y.id ;
}

int cnt[N];
int tot;

void upd(int pos, int v) {
    if (v == 1) {
        if (++cnt[c[pos]] == 1) {
            ++tot;
        }
    } else {
        if (--cnt[c[pos]] == 0) {
            --tot;
        }
    }
}

void run() {
    cin >> n >> Q;
    block = (int)sqrt(n) ;
    for (int i = 1; i <= n; i++) {
        cin >> c[i];
    }
    for (int i = 1; i <= Q; i++) {
        int l, r;
        cin >> l >> r;
        q[i] = Query{l, r, i, 0};
    }
    sort(q + 1, q + Q + 1, cmp);
	int l = 1, r = 0 ;
	for(int i = 1; i <= Q; i++) {
		for(; r < q[i].r; r++) upd(r + 1, 1) ;
		for(; r > q[i].r; r--) upd(r, -1) ;
		for(; l > q[i].l; l--) upd(l - 1, 1) ;
		for(; l < q[i].l; l++) upd(l, -1) ;
		q[i].ans = tot ;
	}
	sort(q + 1, q + Q + 1, cmp2);
	for (int i = 1; i <= Q; i++) {
        cout << q[i].ans << '\n';
	}
}

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


Measured memory_bytes: 19392
#include<stdio.h>
#include<stdlib.h>
#include<string>
#include<iostream>
using namespace std;

struct  Node
{
	int key;
	Node *right, *left, *parent;
};

Node *root, *NIL;

Node * find(Node *u, int k) {
	while (u != NIL && k != u->key)
	{
		if (k < u->key) u = u->left;
		else u = u->right;
	}
	return u;
}

void insert(int k) {
	Node *y = NIL;
	Node *x = root;
	Node *z;

	z = (Node *)malloc(sizeof(Node));
	z->key = k;
	z->left = NIL;
	z->right = NIL;

	while (x != NIL)
	{
		y = x;
		if (z->key < x->key)
		{
			x = x->left;
		}
		else
		{
			x = x->right;
		}
	}
	z->parent = y;
	if (y == NIL)
	{
		root = z;
	}
	else if (z->key < y->key)
	{
		y->left = z;
	}
	else
	{
		y->right = z;
	}
}

void inorder(Node *u) {
	if (u == NIL) return;
	inorder(u->left);
	printf(" %d", u->key);
	inorder(u->right);
}

void preorder(Node *u) {
	if (u == NIL) return;
	printf(" %d", u->key);
	preorder(u->left);
	preorder(u->right);
}

int main() {
	int n, i, x;
	string com;
	scanf("%d", &n);
		for (i = 0; i < n; i++)
		{
			cin >> com;
			if (com[0] == 'f')
			{
				scanf("%d", &x);
				Node *t = find(root, x);
				if (t != NIL) printf("yes\n");
				else printf("no\n");
			}
			else if (com == "insert") {
				scanf("%d", &x);
				insert(x);
			}
			else if (com == "print")
			{
				inorder(root);
				printf("\n");
				preorder(root);
				printf("\n");
			}
		}
		
return 0;
}

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

int main(){
  int n, m,c;
  cin >> n >> m >> c;

  vector<int> B(m);
  for(int i=0;i<m;i++){
    cin >> B[i];
  }

  int cnt=0;
  for(int i=0;i<n;i++){
    vector<int> a(m);
    int sum=c;
    for(int j=0;j<m;j++){
      cin >> a[j];
      sum+=a[j]*B[j];
    }
      if(sum>0) cnt++;
  }
  cout<< cnt<<endl;
  return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-

import sys
import math


debug = False

def log(text):
    if debug:
        print(text)

def parse_input(lines_as_string = None):

    global debug
    lines = []
    if lines_as_string is None:
        debug = False
        # for line in sys.stdin:
        #     lines.append(line)
        lines.append(input())
    else:
        debug = True
        lines = [e for e in lines_as_string.split("\n")][1:-1]

    (x, y, z) = [e for e in lines[0].split(' ')]

    return (x, y, z)


def solve(x, y, z):
    a, b, c = x, y, z 
    a, b, c = b, a, c
    a, b, c = c, b, a
    
    return ' '.join([a, b, c])
    


def main():
    # 出力
    result = solve(*parse_input())
    if isinstance(result, list):
        for r in result:
            print("%s" % r, sep='')
    else:
        print("%s" % result, sep='')

if __name__ == '__main__':

    main()
	

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

int main()
{
	int h,w;
	string s[50];
	cin>>h>>w;
	for(int i=0;i<h;i++) cin>>s[i];
	
	int dx[8]={-1,-1,-1,0,0,1,1,1},dy[8]={-1,0,1,-1,1,-1,0,1};
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			if(s[i][j]=='.'){
				int v=0;
				for(int k=0;k<8;k++){
					int vh=i+dx[k],vw=j+dy[k];
					if(vh<0||h<=vh) continue;
					if(vw<0||w<=vw) continue;
					if(s[vh][vw]=='#') v++;
				}
				s[i][j]=v+'0';
			}
		}
	}
	
	for(int i=0;i<h;i++) cout<<s[i]<<endl;
	
	return 0;
}


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

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define REP(i,a) for(int i = 0; i < (a); ++i)

typedef long long LL;
typedef unsigned long long ULL;
typedef unsigned int UI;

using namespace std;


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

	s[3] = '8';

	cout << s << endl;

    return 0;
}

Measured memory_bytes: 256
import math
def resolve():
    S = input()
    N = len(S)
    pre = S[0:math.floor((N-1)/2)]
    post = S[math.floor((N+3)/2 - 1):]
    if S == S[::-1] and pre == pre[::-1] and post == post[::-1]:
        print('Yes')
    else:
        print('No')


if __name__ == "__main__":
    resolve()

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

using namespace std;

typedef long long ll;

int main(){
ll A,B,Q; cin >> A >> B >> Q;
  vector<ll> s(A); vector<ll> t(B); vector<ll> x(Q);
  for(ll i = 0; i < A; i++){
    cin >> s[i];}
  for(ll j = 0; j < B; j++){
    cin >> t[j];}
  // s and t have already been sorted
 
for(ll l = 0; l < Q; l++){
  ll x ; cin >> x;
  
  ll j = lower_bound(s.begin(),s.end(),x) - s.begin();
  ll k = lower_bound(t.begin(),t.end(),x) - t.begin();
  ll sum = 1LL << 60;
  sum = min(sum,min((abs(t[k] - s[j]) + abs(s[j] - x)),(abs(s[j] - t[k]) + abs(t[k] - x)) ) );
  if( k > 0){
  sum = min(sum,min((abs(t[k-1] - s[j]) + abs(s[j] - x)),(abs(s[j] - t[k-1]) + abs(t[k-1] - x))));}
  if( j > 0){
  sum = min(sum,min((abs(t[k] - s[j-1]) + abs(s[j-1] - x)),(abs(s[j-1] - t[k]) + abs(t[k] - x))));}
  if( k > 0 && j > 0){
  sum = min(sum,min((abs(t[k-1] - s[j-1]) + abs(s[j-1] - x)),(abs(s[j-1] - t[k-1]) + abs(t[k-1] - x))));}

cout << sum << endl;}

return 0;}


Measured memory_bytes: 3712
#include<iostream>
#include<map>
#include<cmath>

using namespace std;
const int N = 1e5+5;
typedef long long ll;
const ll mod = 998244353;
ll a[N];
map<ll,ll>ma;

ll ksm(ll a,ll b){
	ll res=1;
	while(b){
		if(b&1) res=res*a%mod;
		a=a*a%mod;
		b>>=1;
	}
	return res;
}

int main(){
	ll n;
	cin>>n;
	bool flag=0;
	for(ll i=1;i<=n;i++){
		cin>>a[i];
		ma[a[i]]++;
		if(i==1){
			if(a[i]!=0) flag=1;
		}
		else {
			if(a[i]>n-1) flag=1;
		}
	}
	if(ma[0]>1) flag=1;
	for(ll i=1;i<=n-1;i++){
		if(ma[i]>0&&ma[i-1]==0) flag=1;
//		if(ma[i]==0) break;
	}
	ll ans=1;
	if(flag) cout<<0<<endl;
	else {
		for(ll i=1;i<=n-1;i++){
		if(ma[i]&&ma[i-1]) ans=ans*ksm(ma[i-1],ma[i])%mod;
			else break;
		}
		cout<<ans%mod<<endl;
	}
	
	
	return 0;
}

Measured memory_bytes: 7296
<?php 
  fscanf(STDIN, "%s", $S);
  fscanf(STDIN, "%d", $K);
  $ans=0;
  $one=0;
  $count=0;

  for($i =0; $i < strlen($S);$i++){
    if(substr($S, $i, 1) == 1){
        $one++;
    }else{
      $count = $i;
      break;
    }
  }

  if($K <= $one) $ans =1;
  else $ans = substr($S, $count, 1);
   
  echo $ans;
 ?>

Measured memory_bytes: 4604
import javax.swing.plaf.basic.BasicInternalFrameTitlePane;
import  java.io.*;
import  java.math.*;
import java.nio.Buffer;
import java.sql.SQLSyntaxErrorException;
import  java.util.*;
import  java.text.*;
import java.util.regex.Pattern;
import java.util.stream.Collectors;


public class Main {
    public static boolean gcd(int a,int b){
        if(a==1||b==1){
            return false;
        }
        while(1>0){
            int t = a%b;
            if(t == 0){
                break;
            }
            else{
                a=b;
                b=t;
            }

        }
        if(b>1)	return true;
        else{
            return  false;
        }
    }

    public static void main(String[] args) {
        Scanner cin = new Scanner(System.in);
        int a=cin.nextInt();
        int b=cin.nextInt();
        int c=cin.nextInt();
        System.out.println(c+" "+a+" "+b);
    }
}

Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;

// template {{{  0 
// using {{{ 1
using ll = long long int;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;
// }}} 1
// definition {{{ 1
// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)
#define Scll(x) scanf("%lld", &x)
#define Scll2(x,y) scanf("%lld%lld", &x, &y)
#define Scll3(x,y,z) scanf("%lld%lld%lld", &x, &y, &z)
#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2
// constants {{{ 2
#define EPS (1e-7)
#define INF (2e9)
#define PI (acos(-1))
// }}} 2
// systems {{{ 2
#define Repe(x,y,z) for(ll x = z; x < y; x++)
#define Rep(x,y) Repe(x,y,0)
#define RRepe(x,y,z) for(ll x = y-z-1; x >= 0; x--)
#define RRep(x,y) RRepe(x,y,0)
// }}} 2
// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n")
#define YESNO(a) (a)?printf("YES\n"):printf("NO\n")
// }}} 2
// }}} 1
// input {{{ 1
// }}} 1
// }}} 0

int main() {

    int A,V,B,W;
    int T;
    Scd2(A,V);
    Scd2(B,W);
    Scd(T);

    ll v = V-W;
    bool ok = true;
    if( v > 0 ){
        ll l = abs(A-B);
        if( v*T < l ) ok = false;
    }else{
        ok = false;
    }

    YESNO(ok);

    return 0;
}



Measured memory_bytes: 3660
#include <iostream>
#include <algorithm> 
#include <cstring>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <vector>
#include <stack>
#include <queue>
const int INF=0x3f3f3f3f;
const int MOD=1e9+7;
const double eps=1e-7;
typedef long long ll;
#define vi vector<int> 
#define si set<int>
#define pii pair<int,int> 
#define pi acos(-1.0)
#define pb push_back
#define mp make_pair
#define lowbit(x) (x&(-x))
#define sci(x) scanf("%d",&(x))
#define scll(x) scanf("%lld",&(x))
#define sclf(x) scanf("%lf",&(x))
#define pri(x) printf("%d\n",(x))
#define rep(i,j,k) for(int i=j;i<=k;++i)
#define per(i,j,k) for(int i=j;i>=k;--i)
#define mem(a,b) memset(a,b,sizeof(a)) 
using namespace std;
int dp[505][505],ans[505][505],n,m,q;
int main()
{
	mem(dp,0),mem(ans,0);
	scanf("%d%d%d",&n,&m,&q);
	rep(i,0,m-1)
	{
		int l,r;
		sci(l),sci(r);
		rep(j,r,n)dp[l][j]++;
	}
	per(r,n,1)
	{
		ans[r][r]=dp[r][r];
		per(l,r-1,1)
		{
			ans[l][r]=ans[l+1][r]+dp[l][r];
		}
	}
	rep(j,0,q-1)
	{
		int l,r;
		sci(l),sci(r);
		pri(ans[l][r]);
	}
	return 0;
}

Measured memory_bytes: 2944
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
using namespace std;

int n, a, b;
int fenv, snuv, pathv;

vector<int> g[100005];
int used[100005];

// fennec
void bfs() {
    queue<pair<int, int> > que;
    pair<int, int> tmp;
    que.push(make_pair(0, 1));
    que.push(make_pair(n-1, 2));

    used[0] = 1;
    used[n-1] = 2;

    while (!que.empty()) {
        tmp = que.front();
        que.pop();
        int si = g[tmp.first].size();

        for (int i = 0; i < si; ++i) {
            if (!used[g[tmp.first][i]]) {
                que.push(make_pair(g[tmp.first][i], tmp.second));
                used[g[tmp.first][i]] = tmp.second;
            }
        }
    }
}



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

    cin >> n;
    for (int i = 0; i < n-1; ++i) {
        cin >> a >> b;
        a--; b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    bfs();

    for (int i = 0; i < n; ++i) {
        if (used[i] == 1) {
            fenv++;
        }
        else if (used[i] == 2) {
            snuv++;
        }
    }

    if (fenv > snuv) {
        cout << "Fennec" << endl;
    }
    else {
        cout << "Snuke" << endl;
    }

    return 0;
}


Measured memory_bytes: 6400
def isOp(c):
    if c in ('+', '-', '*', '/'):
        return True
    return False

def cal(num1, num2, op):
    if op == '+':
        return num1 + num2
    elif op == '-':
        return num1 - num2
    elif op == '*':
        return num1 * num2
    else:
        return num1 / num2

if __name__ == '__main__':
    infos = input().split(' ')
    stack = []
    for f in infos:
        if isOp(f):
            num2 = stack.pop(-1)
            num1 = stack.pop(-1)
            stack.append(cal(num1, num2, f))
        else:
            stack.append(int(f))
    print(stack.pop())


Measured memory_bytes: 5596
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define MAX 1000000000
#define PI 3.14159265359
int dx[] = {1,0,-1,0};
int dy[] = {0,-1,0,1};
const ll INF = 10010010010001;
vector<vector<bool>> graph;
vector<bool> reached;
ll MOD = 1000000007;


int main(){
    int r;
    cin >> r;
    cout << (r*r*PI)/(1*1*PI) << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<ll,pll> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-11;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};
const int DX[8]={-1,0,1,0,-1,-1,1,1},DY[8]={0,-1,0,1,-1,1,-1,1};

const int NPrime=3000000;
bool prime[NPrime+1];
vi EnumeratePrime(){
	fill(prime+2,prime+NPrime+1,true);
	vi a;
	for(int i=2;i<=NPrime;i++) if(prime[i]){
		a.emplace_back(i);
		for(int j=2*i;j<=NPrime;j+=i) prime[j]=0;
	}
	return a;
}
int n;

string s;

int main(){
	while(1){
		cin>>n;
		if(n==0) break;
		int res=inf;
		for(int i=0;i*i*i<=n;i++) for(int j=0;i*i*i+j*j<=n;j++){
			res=min(res,i+j+n-i*i*i-j*j);
		}
		cout<<res<<endl;
	}
}


Measured memory_bytes: 3020
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <stack>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
using namespace std;
typedef long long ll;
#define free  freopen ("input.txt", "r", stdin);freopen ("output.txt", "w", stdout);
#define Fast  ios::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define mp make_pair
#define F first
#define S second

bool vowel(char che)
{
    if (che == 'A' || che == 'E' || che == 'I' || che == 'O' || che == 'U' || che == 'Y')
        return true;
    else
        return false;
}

const int N = 2e5+5;
const int mod = 998244353;
ll a[N], l[N], r[N], b[N], c[N], d, dp[N], dis, pr[N];
pair <ll, ll> p[N];
char o;
bool mark[N], h;
string s, s1;
stack <int> st;
set <ll> st1, st2;
deque <int> dq;
vector <int> vt, vs, vm;
//int a1[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};


int main()
{
    Fast
    ll t = 0, n, m = 0, k = 0, f = 0, sum = 0, ans = 0, n1 = 0;
    cin >> n >> n1;
    ll mn = 1e6;
    for (int i = 0; i < n1; i++){
        cin >> p[i].F >> p[i].S;
        mn = min (mn, p[i].F);
    }
    sort (p, p+n1);
    dp[mn+1] = 1;
    pr[mn+1] = 2;
    for (int i = 1; i <= mn; i++){
        pr[i] = 1;
    }
    for (int i = mn+2; i <= n; i++){
        ll mx = 0;
        for (int j = 0; j < n1; j++){
            mx = max(mx, p[j].F);
            if (p[j].S >= mx ){
                dp[i] += pr[i-mx]-pr[max(ll(0),i-p[j].S-1)];
                dp[i] %= mod;
            }
            mx = max(p[j].S, mx);
         }
        pr[i] = pr[i-1] + dp[i];
        pr[i] %= mod;
    }
    cout << (dp[n]+mod)%mod << endl;
}


Measured memory_bytes: 6740
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<int, P> E;
#define MOD (1000000007ll)
#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	b += MOD;
	a += b;
	a %= MOD;
}

int main(void){
	int n,i,t,cost,time,ans=INF;
	cin >> n >> t;
	for(i=0; i<n; ++i){
		cin >> cost >> time;
		if(time > t){
			continue;
		}
		ans = min(ans,cost);
	}
	if(ans==INF){
		cout << "TLE" << endl;
	}else{
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int a,b;
    cin>>a>>b;
    int p=a+b;
    int m=a-b;
    int l=a*b;
    if(p>=m&&p>=l)
        cout<<p;
    else if(m>=p&&m>=l)
        cout<<m;
    else
        cout<<l;
    return 0;
}


Measured memory_bytes: 256
import sys
from bisect import *
from collections import *
from copy import deepcopy
from datetime import *
from heapq import *
from itertools import *
# from math import *
from operator import *
from pprint import *

sys.setrecursionlimit(10**8)

input = sys.stdin.readline

def main():
    """ main """
    N = int(input())
    graph = [set() for _ in range(N)]
    for i in range(N):
        S = input().rstrip()
        for j in range(N):
            if S[j] == '1':
                graph[i].add(j)
    # graphには頂点iにつながっている頂点が入っている
    # graphの適当な点から初めて、取れるだけ列挙していく
    ans = -1
    for i in range(N):
        visited = {i}
        cur_points = {i}
        tmp = 1
        # 全て訪問し終えるまで
        while len(visited) < N:
            next_points = set()
            # 現在のポイントからまだ言っていないところを全列挙
            for point in cur_points:
                next_points |= graph[point]
            next_points -= cur_points
            # 次のポイントないで繋がりがあるものはないか
            link_checker = False
            for point in next_points:
                if graph[point] & next_points:
                    link_checker = True
                    break
            # 繋がりがあればここはダメ。次の頂点から始める
            if link_checker:
                break
            # 繋がりがないなら、cur_pointsを更新して次へ
            visited |= next_points
            cur_points = next_points
            tmp += 1
        else:
            ans = max(ans,tmp)

    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 5616
#!/usr/bin/env python3
import sys
import numpy as np


def solve(S: str):
    if S=='Sunny':
        print('Cloudy')
    elif S=='Cloudy':
        print('Rainy')
    else:
        print('Sunny')
    return


# 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)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 12416
#include <bits/stdc++.h>
#define rep(i,l,r) for(int i=(l);i<=(r);++i)
#define per(i,r,l) for(int i=(l);i<=(r);++i)
using namespace std;
typedef long long ll;
ll a[600][600];
int n,m,q,l,r;
int main(){
	scanf("%d%d%d",&n,&m,&q);
	rep(i,1,m){scanf("%d%d",&l,&r),a[l][r]++;}
	rep(i,1,n) rep(j,1,n) a[i][j]+=a[i][j-1]; 
	rep(i,1,q){
		scanf("%d%d",&l,&r);
		ll ans=0;
		rep(j,l,r) ans+=a[j][r];
		printf("%lld\n",ans);
	}
	return 0;
}

Measured memory_bytes: 3328
/* ex 7_1
   Rikuta */

#include <stdio.h>
//point型の構造体を定義
typedef struct point
{   
    //中身はint型が二つ,x座標,y座標
    int x_elem;
    int y_elem;
}point;

//プロトタイプ宣言
point shift_point(point p_past, point p_now);

int main(void)
{
    //point型の座標配列を準備
    point coordinates[4];

    //入力
    scanf("%d%d%d%d", &coordinates[0].x_elem, &coordinates[0].y_elem, &coordinates[1].x_elem, &coordinates[1].y_elem);
    
    for (int i = 2; i <= 3; i++)
    {   
        //shift_point関数を用いて，3,4番目の座標を計算
        coordinates[i] = shift_point(coordinates[i - 2], coordinates[i - 1]);
        
        //計算した座標を出力
        printf("%d %d ", coordinates[i].x_elem, coordinates[i].y_elem);
    }

    //改行
    printf("\n");
    return 0;
}

//point型を返す，引数としてpointを二つもつ関数の定義
point shift_point(point p_past, point p_now)
{
    //次の点の宣言
    point nextpoint;

    //次の点のx,y座標の計算
    nextpoint.x_elem = p_now.x_elem - (p_now.y_elem - p_past.y_elem);
    nextpoint.y_elem = p_now.y_elem + (p_now.x_elem - p_past.x_elem);

    //次の点を返す
    return nextpoint;
}


Measured memory_bytes: 1668
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define int long long
#define endl '\n'
#define pi 3.14159265
int mod=10;
int p(int a,int b)
{
    int res=1;
    while(b)
    {
        if(b%2!=0)
            res*=a;
        res%=mod;
        a*=a;
        a%=mod;
        b/=2;
    }
    return res; 
}
int32_t main()
{
    IOS;
    int n;
    cin>>n;
    vector<int> v(n);
    for(int i=0;i<n;i++)
        cin>>v[i];
    sort(v.begin(),v.end());
    int x=v[n/2-1];
    int y=v[n/2];
    cout<<y-x;
}   

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

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

constexpr int dx[8] = { 1,1,0,-1,-1,-1,0,1 };
constexpr int dy[8] = { 0,1,1,1,0,-1,-1,-1 };


using namespace std;

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

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


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n; cin >> n;
	vi v(n);
	REP(i, n)cin >> v[i];
	int sum = 0;
	
	REP(i, n)sum += v[i];
	int ans = sum;
	REP(i, n) {
		int tmp = 0;
		REP(j, i + 1)tmp += v[j];
		chmin(ans, abs(tmp - (sum - tmp)));
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;

//vector string deque break continue
#define forn(i, s, f) for (int i = (int)s; i < (int)f; i++)
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair <int, int>
#define fs first
#define sc second
#define pf push_front
#define pb push_back
#define pop_f pop_front
#define pop_b pop_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()

int gcd(int a, int b) {
    if (!a)
        return b;
    return gcd(b % a, a);
}

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    int a, b;
    cin >> a >> b;
    cout << 1LL * a * b / gcd(a, b);
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define endl '\n'
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define mod 1000000007
#define FASTIO ios::sync_with_stdio(0); cin.tie(0);
#define REP(i,a,b) for(int i=a;i<b;i++)
#define maxx 1000001
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

ll bigmod(ll a,ll b){
   if(b==0) return 1%mod;
   ll x=bigmod(a,b/2);
   x=(x*x)%mod;
   if(b%2) x=(x*a)%mod;
   return x;
}

int main(){
    FASTIO
    ll n,tot,sub,add,ans;
    cin>>n;
    tot=bigmod(10,n);
    add=bigmod(8,n);
    sub=bigmod(9,n);
    sub=(2*sub)%mod;
    ans=(tot-sub+add+mod)%mod;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3632
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
cnt = 0
for i  in range(N):
  if A[i] >= B[i]:
      cnt += B[i]
  elif A[i+1]+A[i] <= B[i]:
      cnt += A[i+1]+A[i]
      A[i+1] = 0
  elif A[i]<B[i] and A[i+1]+A[i] >= B[i]:
      cnt +=B[i]
      A[i+1] = A[i+1]-(B[i]-A[i])


print(cnt)


Measured memory_bytes: 18752
#include <cstdio>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iterator>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define debug(x)  cout << #x << " = " << (x) << endl;

using namespace std;

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

    if (h == 1 || w == 1) {
        cout << 1 << endl;
        return 0;
    }
    if (h % 2 == 0) {
        long long tate = h / 2;
        cout << tate * w << endl;
    } else {
        long long tate1 = h / 2 + 1;
        long long tate2 = tate1 - 1;

        if (w % 2 == 0) {
            cout << tate1 * (w / 2) + tate2 * (w / 2) << endl;
        } else {
            long long yoko1 = w / 2 + 1;
            long long yoko2 = yoko1 - 1;
            cout << tate1 * yoko1 + tate2 * yoko2 << endl;
        }
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353

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

ll dp[2222][2222];

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

	ll n;cin >> n;
	vector<P> a(n);
	REP(i, n) {
		cin >> a[i].FI;
		a[i].SE = i;
	}

	sort(ALL(a), greater<P>());

	REP(i, n+1){
		REP(j, n+1){
			if(i + j >= n)continue;
			ll left = i;
			ll right = n - 1 - j;
			ll id = a[i+j].SE;
			ll c = a[i+j].FI;
			dp[i+1][j] = max(dp[i+1][j], dp[i][j] + c * abs(id - left));
			dp[i][j+1] = max(dp[i][j+1], dp[i][j] + c * abs(id - right));
		}
	}

	ll ans = 0;
	REP(i, n)REP(j, n)if(i + j == n)ans = max(ans, dp[i][j]);
	cout << ans << endl;

	return 0;
}


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

#include <cctype>
#include <cstdio>

int main(){
    char ch;
    
    while(1){
    scanf("%c",&ch);
        if(isalpha(ch)){
            if(islower(ch)){
            printf("%c",toupper(ch));
            }else if(isupper(ch)){
            printf("%c",tolower(ch));
            }
        }else{
            printf("%c",ch);
        }
    if(ch == '\n') break;
    }
    return 0;
    
}


Measured memory_bytes: 3156
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define f(i,n) for(int i=0;i<n;i++)
#define pb push_back
int mod=1e9+7;
int gcd (int a, int b) {
   while (b) {
        a %= b;
        swap(a, b);
    }
    return a;
}
ll fast(ll a,ll n){
	a%=mod;
	ll res=1;
	while(n>0){
		if(n&1)res=res*a%mod;
		a=a*a%mod;
		n>>=1;
	}
	return res;
}
int digit_sum(int a){
	int sum=0;
	while(a){
		sum+=a%10;
		a/=10;
	}
	return sum;
}
	// vector<int> v;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	string s,t;
	cin>>s>>t;
	int dp[s.size()+1][t.size()+1];

	f(i,s.size()+1){dp[i][0]=0;}
	f(j,t.size()+1){dp[0][j]=0;}
	for(int i=1;i<=s.size();i++){
		for(int j=1;j<=t.size();j++){
			if(s[i-1]==t[j-1]){dp[i][j]=1+dp[i-1][j-1];}
			else {
				if(dp[i-1][j]>dp[i][j-1]){
				dp[i][j]=dp[i-1][j];
				// dp[i][j]=dp[i-1][j];
				}
				else {
				dp[i][j]=dp[i][j-1];
				// dp[i][j]=dp[i][j-1];s
				}

			}
		}
	}
	// string ans=" ";
	int index=dp[s.size()][t.size()];
	// cout<<index<<endl;
	// char lcs[ind];
    // lcs[ind]='\0';
int m=s.size();
int n=t.size();
	char lcs[index+1];
   lcs[index] = '\0'; // Set the terminating character

   // Start from the right-most-bottom-most corner and
   // one by one store characters in lcs[]
   int i = m, j = n;
   while (i > 0 && j > 0)
   {
      // If current character in X[] and Y are same, then
      // current character is part of LCS
      if (s[i-1] == t[j-1])
      {
          lcs[index-1] = s[i-1]; // Put current character in result
          i--; j--; index--;     // reduce values of i, j and index
      }

      // If not same, then find the larger of two and
      // go in the direction of larger value
      else if (dp[i-1][j] > dp[i][j-1])
         i--;
      else
         j--;
   }

	cout<<lcs<<endl;
	return 0;
}



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

int main() {
  int n;
  cin >> n;
  ll ans = 1;
  vector<ll> a(n);
  rep(i,n) cin >> a[i];
  sort(a.begin(),a.end());
  if(a[0]==0) {
    cout << 0 << endl;
    return 0;
  }

  ll pre=0;
  rep(i,n) {
    ans *= a[i];
    if(ans>INF||ans<pre) {
      cout << -1 << endl;
      return 0;
    }
    pre = ans;
  }

  cout << ans << endl;
}


Measured memory_bytes: 4052
integer(16)::n,m,i,j,q,r
integer(16),allocatable::p(:),y(:),a(:),b(:),c(:)
read*,n,m
allocate(p(m),y(m),a(m))
do i = 1,m
  read*,p(i),y(i)
  a(i) = i
end do
	
call HeapsortTri(M,p,a,y)
q = 1;r = 1
do
  do 
    if(r+1 > m)exit
    if(p(r+1)/=p(r))exit
	r = r+1
  end do
  j = r-q+1
  allocate(b(j),c(j))
  b(1:j) = y(q:r)
  c(1:j) = a(q:r)
  
  call HeapsortPair(J,b,c)
  
  do i = 1,j
    b(i) = i
  enddo
  y(q:r) = b(1:j)
  a(q:r) = c(1:j)
  q = r+1
  r = r+1
  deallocate(b,c)
  if(r>m)exit
end do
	
call heapsorttri(m,a,p,y)
	
do i = 1,m
  print"(i12.12)",p(i)*1000000+y(i)
end do

contains
subroutine HeapsortTri(n,array,array2,array3)
  implicit none
!ここの入力は状況に応じて変更すること
  integer(16),intent(in) :: n
  integer(16),intent(inout) :: array(1:n),array2(1:n),array3(1:N)
  integer(16)::i,k,j,l
  integer(16):: t,t2,t3

  l=n/2+1
  k=n
  do while(k /= 1)
     if(l > 1)then
        l=l-1
        t=array(L)
        t2=array2(L)
        t3=array3(L)
     else
        t=array(k)
        t2=array2(k)
        t3=array3(k)
        array(k)=array(1)
        array2(k)=array2(1)
        array3(k)=array3(1)
        k=k-1
        if(k == 1) then
           array(1)=t
           array2(1)=t2
           array3(1)=t3
           exit
        endif
     endif
     i=l
     j=l+l
     do while(j<=k)
        if(j < k)then
           if(array(j) < array(j+1))j=j+1
        endif
        if (t < array(j))then
           array(i)=array(j)
           array2(i)=array2(j)
           array3(i)=array3(j)
           i=j
           j=j+j
        else
           j=k+1
        endif
     enddo
     array(i)=t
     array2(i)=t2
     array3(i)=t3
  enddo
  return
end subroutine HeapsortTri


subroutine HeapsortPair(n,array,array2)
  implicit none
!ここの入力は状況に応じて変更すること
  integer(16),intent(in) :: n
  integer(16),intent(inout) :: array(1:n),array2(1:n)
  integer(16)::i,k,j,l
  integer(16):: t,t2

  l=n/2+1
  k=n
  do while(k /= 1)
     if(l > 1)then
        l=l-1
        t=array(L)
        t2=array2(L)
     else
        t=array(k)
        t2=array2(k)
        array(k)=array(1)
        array2(k)=array2(1)
        k=k-1
        if(k == 1) then
           array(1)=t
           array2(1)=t2
           exit
        endif
     endif
     i=l
     j=l+l
     do while(j<=k)
        if(j < k)then
           if(array(j) < array(j+1))j=j+1
        endif
        if (t < array(j))then
           array(i)=array(j)
           array2(i)=array2(j)
           i=j
           j=j+j
        else
           j=k+1
        endif
     enddo
     array(i)=t
     array2(i)=t2
  enddo
  return
end subroutine HeapsortPair
end

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

    int cur = 1;
    for(int i = 2; i <= n; i++){
        cout << cur << " " << i << endl;
        if(s[i - 1] == '1'){
            cur = i;
        }
    }
}


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

char s[105];
char s1[105];
char s2[105];
char s3[105];
int dp[105][2];
int cal(char s[])
{
	memset(dp,0x3f,sizeof(dp));
	dp[1][0]=0,dp[1][1]=1;
	int n=strlen(s+1);
	for(int i=2;i<=n;i++)
	{
		if(s[i]==s[i-1])
		{
			dp[i][1]=dp[i-1][0]+1;
			dp[i][0]=dp[i-1][1];
		}
		else
		{
			dp[i][1]=min(dp[i-1][0],dp[i-1][1])+1;
			dp[i][0]=min(dp[i-1][0],dp[i-1][1]);
		}
	}
	return min(dp[n][0],dp[n][1]);
}
int main()
{
	int k,flg=true;
	scanf("%s",s+1);
	scanf("%d",&k);
	int n=strlen(s+1);
	for(int i=1;i<=n;i++) if(s[i]!=s[1]) flg=false;
	if(flg) return !printf("%lld\n",1LL*n*k/2);
	if(k==1) return !printf("%lld\n",1LL*cal(s));
	int s1len=0,s2len=0,s3len=0;
	for(int i=2;i<=n;i++)
	{
		if(s[i]!=s[i-1])
		{
			for(int j=1;j<i;j++) s1[++s1len]=s[j];
			for(int j=i;j<=n;j++) s2[++s2len]=s[j];
			for(int j=i;j<=n;j++) s3[++s3len]=s[j];
			for(int j=1;j<i;j++) s3[++s3len]=s[j];
			break;
		}
	}
	printf("%lld\n",1LL*cal(s1)+1LL*(k-1)*cal(s3)+cal(s2));
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;
using msi=map<string,int>;
using mii=map<int,int>;
using pii=pair<int,int>;
using vlai=valarray<int>;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1e9
#define EPS 1e-9
#define MOD 1000000007
void bulk(){}template<class H,class...T>void bulk(H&h,T&...t){cin>>h;bulk(t...);}
#define get(...) ll __VA_ARGS__; bulk(__VA_ARGS__);
int main(){
	get(n);ll a=1;
	range(i,1,n+1){
	    a=a*i%MOD;
	}
	cout<<a<<endl;
	return 0;
}


Measured memory_bytes: 384
// Binary Search Tree II
#include <stdio.h>
#include <stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;

Node root, nil;

// 木から key の値を持つノードを探す //
Node treeSearch(Node x, int k){
  if(x == nil || k == x->key) return x;
  if(k < x->key) treeSearch(x->left, k);
  else treeSearch(x->right, k);
}

// ノード x から最小の key を探す //
Node treeMinimum(Node x){
  while(x->left != nil)x = x->left;
  return x;
}

// ノード x から最大の key を探す //
Node treeMaximum(Node x){
  while(x->right != nil)x = x->right;
  return x;
}

//  二分探索木へkを挿入 //
void insert(int k){
  Node y = nil; // x の親
  Node x = root; // T の根
  Node z;
  
  //z->parent = y;
  z = (Node)malloc(sizeof(struct node));
  z->key = k;
  z->left = nil;
  z->right = nil;

  while(x != nil){
    y = x;   // 親を設定
    if(z->key < x->key)x = x->left; // 左の子へ移動
    else x = x->right;            // 右の子へ移動
  }
  z->parent = y;

  if(y == nil)root = z; // T が空の場合
  else if(z->key < y->key)y->left = z; // z を y の左の子にする
  else y->right = z; // z を y の右の子にする
}

// 再帰を使って中間順巡回(Inorder)で表示
void printInorder(Node u){
  if(u == nil)return;
  printInorder(u->left);
  printf(" %d", u->key);
  printInorder(u->right);
}

// 再帰を使って先行順巡回(Preorder)で表示
void printPreorder(Node u){
  if(u == nil)return;
  printf(" %d", u->key);
  printPreorder(u->left);
  printPreorder(u->right);
}

int main(){
  int n, i, x;
  char com[20];
  Node t;
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != nil ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      printInorder(root);
      printf("\n");
      printPreorder(root);
      printf("\n");
    }
  }

  return 0;
}


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

#include <math.h>
#include <stdlib.h>


#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

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

//INT_MAX	2,147,483,647 = 2*1.0e9

const int INF = 2e9;

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
   int n, m; cin >> n >> m;
   //vector<vector<bool>> c(m, vector<bool>(n, false));
   vector<int> c(m,0);
   vector<int> a(m);
   for(int i = 0; i < m; i++){
       int bt; cin >> a[i] >> bt;
       for(int j = 0; j < bt; j++){
           int ct; cin >> ct;
           ct--;
           c[i] += (1 << ct);
       }
   }

    int maxP = (1 << n);
   vector<int> dp(maxP,INF);
   dp[0] = 0;

   for(int i = 0; i < n; i++){
       for(int j = 0; j < m; j++){
           if((c[j]>>i)&1){
               for(int k = 0; k < maxP; k++){
                   int cur = k|c[j];
                   dp[cur] = min(dp[cur], dp[k]+a[j]);
               }
           }
       }
   }

   if(dp[maxP-1] == INF) cout << -1 << endl;
   else cout << dp[maxP-1] << endl;

   return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int a[1000000];
int main(){
    int k;
    scanf("%d",&k);
    a[0]=7%k;
    for(int i=1;i<k;i++)a[i]=(a[i-1]*10+7)%k;

    for(int i=0;i<k;i++)if(a[i]==0){
        printf("%d\n",i+1);
        return 0;
    }
    printf("-1\n");
}


Measured memory_bytes: 5628
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>

#define int long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
#define PB push_back
#define MP make_pair
#define FST first
#define SND second
#define SZ(a) (signed)((a).size())
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;

const int MOD = 1000000007;

#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")"  << " " << __FILE__ << endl;

signed main(void) {
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed, ios::floatfield);
    cout.precision(10);
    cin.tie(0);

    VS s(3);
    REP(i, 3) {
        cin >> s[i];
    }

    REP(i, 3) {
        cout << s[i][0];
    }
    cout << endl;

    return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;

int main() {
    int n,x;
    cin >> x >> n;
    int ans = (x >= n) ? 10 : 0;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <queue>

#ifndef U_L_LONG
typedef unsigned long long ULLONG;
#endif
#ifndef L_LONG
typedef long long LLONG;
#endif
template <class _T> static _T tp_abs(const _T& a) {
	//	usage:  tp_abs<type name>(a);
	return ((a < 0) ? (a * -1) : a);
}
template <class _T> static _T tp_min(_T a, _T b) {
	return a < b ? a : b;
}
template <class _T> static _T tp_max(_T a, _T b) {
	return a > b ? a : b;
}
template<class _T> static void get1int(_T& a) {
	const char* fmt = " %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld";
	}

	if (scanf(fmt, &a) < 0) {
		printf("g1int Error\n");
	}
}
template<class _T> static void get2int(_T& a, _T& b) {
	const char* fmt = " %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld";
	}

	if (scanf(fmt, &a, &b) < 0) {
		printf("g2int Error\n");
	}
}
template<class _T> static void get3int(_T& a, _T& b, _T& c) {
	const char* fmt = " %d %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld %lld";
	}

	if (scanf(fmt, &a, &b, &c) < 0) {
		printf("g3int Error\n");
	}
}
static void getstring(char* buff) {
	if (scanf(" %s", buff) < 0) {
		printf("getstr error!\n");
	}
}

static void ABC096C_GridReplacing();

#if 1
int main()
{
	ABC096C_GridReplacing();
	fflush(stdout);
	return 0;
}
#endif

static bool ABC096C_bfs(char grid[51][51], int nowH, int nowW, int H, int W)
{
	if (grid[nowH][nowW] != '#') return true;

	bool enable = false;
	int dh[] = { 1, 0, -1, 0 };
	int dw[] = { 0, 1, 0, -1 };

	std::queue<std::pair<int, int>> bp;
	bp.push(std::pair<int, int>(nowH, nowW));
		
	while (!bp.empty()) {
		std::pair<int, int> pt = bp.front(); bp.pop();

		for (int i = 0; i < 4; i++) {
			int nh = pt.first + dh[i];
			int nw = pt.second + dw[i];
			if ((nh < H) && (nh >= 0) && (nw < W) && (nw >= 0) && (grid[nh][nw] == '#')) {
				enable = true;
				grid[nh][nw] = '.';
				bp.push(std::pair<int, int>(nh, nw));
			}
		}
	}
	if (enable) grid[nowH][nowW] = '.';
	
	return enable;
}

static void ABC096C_GridReplacing()
{
	int H, W;
	get2int(H, W);

	char grid[51][51] = { 0 };

	for (int h = 0; h < H; h++) {
		getstring(grid[h]);
	}

	const char* ans = "Yes\n";
	for (int h = 0; h < H; h++) {
		for (int w = 0; w < W; w++) {
			if ((grid[h][w] == '#') && (!ABC096C_bfs(grid, h, w, H, W))) {
				ans = "No\n";
			}
		}
	}

	printf(ans);
}


Measured memory_bytes: 256
n,k = map(int,input().split())
s = input()
ans = ''

for p in range(len(s)):
  if p == k - 1:
    if s[p] == 'A':
      ans += 'a'
    elif s[p] == 'B':
      ans += 'b'
    elif s[p] == 'C':
      ans += 'c'
  else:
    ans += s[p]
    
print(ans)

Measured memory_bytes: 9164
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;
const long long MOD=1e09+7;



#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,m,n) for(int i=m;i<n;i++)
#define ALL(v) v.begin(), v.end()





int main(){
  
  int a,b;
  cin>>a>>b;
  
  if (a==b){
    cout<<2*a<<endl;
  }
  else {
    cout<<2*max(a,b)-1<<endl;
  }


}












Measured memory_bytes: 256
#include "bits/stdc++.h"
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>

using namespace std;

#ifndef _DEBUG
#define main_ main
#endif
#define FOR(i,s,e) for (int i = int(s); i != int(e); i++)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<bool> vb;

template <typename T>
using keyVal = pair<string, T>;
template<typename T>
bool val_greater(const keyVal<T>& left, const keyVal<T>& right) {
	return left.second > right.second;
}

void init_global() {}

const int Mgn = 5;
const int NM=50, XM=50;
ll dp[NM + Mgn][NM + Mgn][XM*NM + Mgn];

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

	int N, A;  cin >> N >> A;
	vi X(N + Mgn, 0);
	int xMax = 0;
	FOR(i, 1, N + 1) {
		cin >> X[i];
		xMax = max(xMax, X[i]);
	}
	
	dp[0][0][0] = 1;

	FOR(i, 1, N + 1) {
		dp[i][0][0] = 1;

		FOR(j, 1, i + 1) {
			FOR(k, 0, XM*N + 1) {
				if (k >= X[i]) {
					// dp[i][j][k] : The number of ways to choose
					//   j cards whose sum is k from X[0]..X[i]					
					dp[i][j][k] = dp[i-1][j][k] + dp[i-1][j-1][k - X[i]];
				}
				else {
					dp[i][j][k] = dp[i-1][j][k];
				}
			}
		}
	}

	ll ans = 0;
	FOR(j, 1, N + 1) ans += dp[N][j][A*j];

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


Measured memory_bytes: 53504
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
#include <functional>
#include <cctype>

using namespace std;

#define REP(i,n) for(int i = 0; i < (int)n; ++i)

int main()
{
	int room[4][3][10];

	REP(i,4)
		REP(j,3)
			REP(k,10)
				room[i][j][k] = 0;

	int N;
	cin >> N;

	for(int i = 0, b, f, r, v; i < N; i++) {
		cin >> b >> f >> r >> v;
		b--, f--, r--;
		room[b][f][r] += v;
	}

	REP(i,4) {
		if(i > 0) cout << "####################" << endl;
		REP(j,3) {
			REP(k,10)
				cout << ' ' << room[i][j][k];
			cout << endl;
		}
	}
}

Measured memory_bytes: 1160
S = list(input())
ACGT = ['A', 'C', 'G', 'T']
Ans = 0

for i in range(len(S)):
    tmp = 0
    for j in range(i, len(S)):
        if S[j] in ACGT:
            tmp += 1
            Ans = max(Ans, tmp)
            continue
        else:
            break
        
print(Ans)


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
typedef long long int uli;
int main(){
  string s;
  cin>>s;
  int n=s.size();
  vector<int>f(26,0);
  for(int i=0;i<n;i++)f[s[i]-'a']++;
  for(int i=0;i<26;i++)if(f[i]==0){
    cout<<s+string(1,'a'+i)<<endl;
    return 0;
  }
  string w=s;
  if(next_permutation(s.begin(),s.end())){
    string ans=s;
    for(int l=n;l>=1;l--){
      string bet=s.substr(0,l);
      if(bet>w){
        ans=bet;
      }
    }
    cout<<ans<<endl;
  }
  else puts("-1");
  return 0;
}


Measured memory_bytes: 764
a = [0]*9
a[0],a[1],a[2] = map(int,input().split())
a[3],a[4],a[5] = map(int,input().split())
a[6],a[7],a[8] = map(int,input().split())
n = int(input())
ans = [0]*9
for i in range(n):
    b = int(input())
    for j in range(9):
        if b == a[j]:
            ans[j] = 1
if sum(ans[:3]) == 3 or sum(ans[3:6]) == 3 or sum(ans[6:9]) == 3:
    print('Yes')
elif sum(ans[0::3]) == 3 or sum(ans[1::3]) == 3 or sum(ans[2::3]) == 3:
    print('Yes')
elif sum(ans[0::4]) == 3 or sum(ans[2:7:2]) == 3:
    print('Yes')
else:
    print('No') 

Measured memory_bytes: 62044
#include <bits/stdc++.h>
#define int long long int
using namespace std;
template<typename T,typename U> using P=pair<T,U>;
template<typename T> using V=vector<T>;
template<typename T>bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}

template<typename T>auto&operator<<(ostream&s,const vector<T>&v){s<<"[";bool a=1;for(auto e:v){s<<(a?"":" ")<<e;a=0;}s<<"]";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const pair<T,U>&p){s<<"("<<p.first<<","<<p.second<<")";return s;}
template<typename T>auto&operator<<(ostream&s,const set<T>&st){s<<"{";bool a=1;for(auto e:st){s<<(a?"":" ")<<e;a=0;}s<<"}";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const map<T,U>&m){s<<"{";bool a=1;for(auto e:m){s<<(a?"":" ")<<e.first<<":"<<e.second;a=0;}s<<"}";return s;}
#define DUMP(x) cout<<#x<<" = "<<(x)<<endl
#define COUT(x) cerr<<#x<<" = "; cout<<(x)<<endl

struct edge { int to, cost; };

const int INF = 1e18;
const int MOD = 1e9+7;

signed main()
{
   int n; cin >> n;
   string S; cin >> S;
   int Q; cin >> Q;
   vector<int> k(Q);
   for (int i = 0; i < Q; i++) {
      cin >> k[i];
   }

   for (auto K : k) {
      int a = 0, b = 0, c = 0, sum = 0;
      for (int i = 0; i < n; i++) {
         if (i-K >= 0) {
            if (S[i-K] == 'D') {
               a--; c -= b;
            } else if (S[i-K] == 'M') {
               b--;
            }
         }
         if (S[i] == 'D') {
            a++;
         } else if (S[i] == 'M') {
            b++; c += a;
         } else if (S[i] == 'C') {
            sum += c;
         }
      }
      cout << sum << endl;
   }

   return 0;
}


Measured memory_bytes: 1412