akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>

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

using namespace std;

typedef long long int lli;

int main () {
    int N, M, K;
    cin >> N >> M >> K;
    vector<int> D(M);
    vector<int> is(N, -1);
    REP (i, 0, M) {
        cin >> D[i];
        is[D[i] - 1] = i;
    }
    vector<vector<int>> v(N, vector<int>(K));
    REP (i, 0, N) REP (j, 0, K) cin >> v[i][j];
    int size = 1 << M;
    const int inf = 1 << 30;
    vector<int> dp(size, inf);
    queue<int> q;
    q.push(size - 1);
    dp[size - 1] = 0;
    while (q.size()) {
        int t = q.front();
        q.pop();
        REP (i, 0, K) {
            int bt = 0;
            REP (j, 0, M) {
                if ((t >> j) & 1) {
                    int nxt = v[D[j] - 1][i] - 1;
                    if (is[nxt] != -1) {
                        bt |= (1 << is[nxt]);
                    }
                }
            }
            if (dp[bt] > dp[t] + 1) {
                q.push(bt);
                dp[bt] = dp[t] + 1;
            }

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

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

int main(){
    cin.tie(0);
	ios::sync_with_stdio(false);
    string s;
    getline(cin,s);
    cout<<s[0];
    for(int i=0; s[i]; i++) if(s[i]==' ') cout<<s[i+1];
}



Measured memory_bytes: 256
import java.util.*
fun main(args: Array<String>) {
    val reader = Scanner(System.`in`)
    var N = reader.nextLong()
    var str = reader.next()
    var start = 0
    var end = str.length - 1
    var findW = false
    var findR = false
    var count = 0
    do{
        if(str[start] == 'W'){
            findW = true
        }
        else {
            start += 1
        }

        if(str[end] == 'R'){
            findR = true
        }
        else {
            end -= 1
        }

        if(findW && findR){
            count += 1
            findW = false
            findR = false
            start += 1
            end -= 1
        }
    } while(start  < end)

    println(count)
}

Measured memory_bytes: 40836
n = int(input())
a = [int(s) for s in input().split(" ")]
cnt = 0

for i in range(n):
    mi = min(a[i:])
    if a[i] > mi:
        j = a[i:].index(mi)+i
        a[i], a[j] = a[j], a[i]
        cnt += 1

print(" ".join([str(i) for i in a]))
print(cnt)

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

/********************************************************************/
#define M1 1000000007
#define M3 1000000009
#define M2 998244353
#define ll long long
#define pll pair<ll,ll>
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define REPR(i,a,b) for(ll i=b-1;i>=a;i--)
#define forr(i,n) for(ll i=0;i<n;i++)
#define F first
#define S second
#define pb push_back
#define DB pop_back
#define mp make_pair
#define MT make_tuple
#define V(a) vector<a>
#define vi vector<ll>
#define endl '\n'
#define ce(ele) cout<<ele<<' '
#define cs(ele) cout<<ele<<'\n'
#define CASE(t) ll t; cin>>t; while(t--)
#define sor(v) sort(v.begin(),v.end())
#define rev(v) reverse(v.begin(),v.end())

/********************************************************************/
const double pi = 3.1415926535;
ll n, m;
const int mx = 69;
char grid[mx][mx];
ll blocked[mx][mx];
ll vis[mx][mx];
/********************************************************************/
//FAST IO//
void FAST() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}

/********************************************************************/

ll power(ll a, ll b)
{
	ll res = 1;
	for (int i = 1; i <= b; ++i)
		res *= a;

	return res;
}
ll sum(ll x) {
	ll ans = 0;
	while (x > 0) {
		ans += (x % 10);
		x /= 10;
	}
	return ans;
}

bool opp(int x, int y)
{
    return ((x ^ y) < 0);
}

int main()
{
  FAST();
  
    ll n,k;
    cin>>n>>k;
    ll arr[n+1],dp[n+1];
    for(ll i=1;i<=n;i++)
    {
      cin>>arr[i];
    }
    
    dp[1]=0;
    for(ll i=2;i<=n;i++)
    {
    	dp[i]=INT_MAX;
    }
    
    for(ll i=1;i<=n;i++)
    {
    	for(ll j=i+1;j<=i+k && j<=n;j++)
    	{
    		dp[j]=min(dp[j],dp[i]+abs(arr[j]-arr[i]));
    		// ce(dp[j]);
    	}
    	//cout<<endl;
    }
    cout<<dp[n]<<"\n";
  
}

Measured memory_bytes: 1792
public class Main {
    public static void main(String args[]) {
        java.util.Scanner sc = new java.util.Scanner(System.in);
        long h = sc.nextLong();
        long ans = func(h);
        System.out.println(ans);
    }
    public static long func(long x) {
        if (x == 1) return 1;
        return func(x / 2) * 2 + 1;
    }
}

Measured memory_bytes: 23124
#include<stdio.h>

using namespace std;

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

Node* NIL;

void inorder(Node* current){
    if(current == NIL){
        return;
    }

    inorder(current->left);
    printf(" %d", current->key);
    inorder(current->right);
}

void preorder(Node* current){
    if(current == NIL){
        return;
    }

    printf(" %d", current->key);
    preorder(current->left);
    preorder(current->right);
}

int main(){
    int n;
    scanf("%d", &n);

    Node* root = NIL;

    for(int i = 0; i < n; i++){
        char str[7];
        scanf("%s", str);

        if(str[0] == 'i'){
            Node* z = new Node;
            scanf("%d", &z->key);
            z->left = NIL;
            z->right = NIL;

            Node* y = NIL;
            Node* x = root;
            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;
            }
        }
        else{
            inorder(root);
            printf("\n");
            preorder(root);
            printf("\n");
        }
    }
}


Measured memory_bytes: 26128
#include <iostream>
#include <stdio.h>
#include <ctype.h>
#include <bits/stdc++.h>
#include <string>
#include <stdlib.h>
#include <vector>
#include <sstream>
#include <stack>
#include <queue>
#include <cmath>
using namespace std;
long long x, y, z;
bool eve(long long a, long long b, long long c){
	if (a%2==0 && b%2==0 && c%2==0) return true;
	else return false;
}
int main(){
	long long a, b, c;
	long long cal = 0;
	cin >> a >> b >> c;
	if (a == b && b == c && a%2==0){
		cout << -1;
	}
	else if (a==b && b==c){
		cout << 0;
	}
	else{
		while (eve(a, b, c)==true){
		    x = (b+c)/2; y = (a+c)/2; z = (a+b)/2; a = x; b = y; c = z;
		    cal++;
		}
		cout << cal;
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;
import java.util.stream.IntStream;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }

        Set<Integer> set = new HashSet<>();
        int wc = 0;
        for (int i = 0; i < n; i++) {
            int r = a[i] / 400;
            if (r < 8) {
                set.add(r);
            } else {
                wc++;
            }
        }

        long count = set.size();
        long min = Math.max(count, 1);
        long max = count + wc;

        System.out.println(String.format("%d %d", min, max));
    }
}

Measured memory_bytes: 21844
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.StringTokenizer;

public class Main {

	static Main main = new Main();
	static HashMap<String, Item> itemTable = new HashMap<String, Item>();

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = "";

		while (!(line = br.readLine()).equals("0")) {
			int m = 0, n = 0;
			String target;

			n = Integer.parseInt(line);
			for (int i = 0; i < n; i++) {
				Item item = getItemInstance(br.readLine());
				itemTable.put(item.name, item);
			}

			m = Integer.parseInt(br.readLine());
			for (int i = 0; i < m; i++) {
				setRecipe(br.readLine());
			}

			target = br.readLine();
			System.out.println(itemTable.get(target).getMinCost());
		}
	}

	class Item {
		String name;
		int price;
		int recipeCount = 0;
		ArrayList<Item> recipe;

		Item(String name, int price) {
			this.name = name;
			this.price = price;
		}

		int getMinCost() {
			int min = 0;
			if (recipeCount == 0) {
				min = price;
			} else {
				for (Item i : recipe) {
					if (i != null)
						min += i.getMinCost();
				}
			}
			return min < price ? min : price;
		}
	}

	static Item getItemInstance(String info) {
		int n = info.indexOf(' ');
		String name = info.substring(0, n);
		int price = Integer.parseInt(info.substring(n + 1));
		return main.new Item(name, price);
	}

	static void setRecipe(String info) {
		StringTokenizer st = new StringTokenizer(info);
		Item item = itemTable.get(st.nextToken());
		item.recipeCount = Integer.parseInt(st.nextToken());
		item.recipe = new ArrayList<Item>(item.recipeCount);
		while (st.countTokens() > 0) {
			item.recipe.add(itemTable.get(st.nextToken()));
		}
	}
}

Measured memory_bytes: 21464
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e5+7;
int w[N],v[N],dp[N];
main()
{
    int n,W;
    scanf("%lld%lld",&n,&W);
    for(int i=0;i<n;i++)
        scanf("%lld%lld",&w[i],&v[i]);
    for(int i=0;i<n;i++){
        for(int j=W-w[i];j>=0;j--)
            dp[j+w[i]]=max(dp[j+w[i]],dp[j]+v[i]);
    }
    int ans=0;
    for(int i=0;i<=W;i++)
        ans=max(ans,dp[i]);
    printf("%lld\n",ans);
}


Measured memory_bytes: 4528
#include <bits/stdc++.h>
#include <algorithm>
#include <utility>
using namespace std;
int main(){
	string S; 
	cin >> S;
	int N = S.size(); 
	int A[30] = {}; 
	for(int i = 0; i < N; i++){
		A[S.at(i) - 'a'] ++; 
	}
	long long int ans = (long long) N * (N - 1) / 2 + 1; 
	for(int i = 0; i < 26; i++){
		ans -= (long long) A[i] * (A[i] - 1) / 2; 
	}
	cout << ans << endl; 
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define pi acos(-1)
#define mod 1000000007
#define all(x) x.begin(), x.end()
using namespace std;

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

    ll n;
    cin >> n;
    int ans = 1;
    int x = n;
    while(n % 360 != 0){
        n += x;
        ans++;
    }
    cout << ans;
}



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

#define int long long

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a) memset((a), 0, sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF (3e15)

using namespace std;

int N, M, A[105], B[105], C[105], d[105][105], pre[105][105], used[105][105];

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

    cin >> N >> M;

    REPS(i, N) REPS(j, N) {
        d[i][j] = INF;
        used[i][j] = 1;
    }

    REP(i, M) {
        int a, b, c;
        cin >> a >> b >> c;
        d[a][b] = c;
        d[b][a] = c;
        used[a][b] = 0;
        used[b][a] = 0;
        pre[a][b] = a;
        pre[b][a] = b;
    }

    REPS(k, N) REPS(i, N) REPS(j, N) {
        if (d[i][j] > d[i][k] + d[k][j]) {
            d[i][j] = d[i][k] + d[k][j];
            pre[i][j] = pre[k][j];
        }
    }

    set<int> s;
    REPS(i, N) REPS(j, N) {
        for (int k = j; k != i; k = pre[i][k]) {
            int pk = pre[i][k];
            used[k][pk] = 1;
            used[pk][k] = 1;
        }
    }
    int ans = 0;
    REPS(i, N) REPS(j, N) {
        if (used[i][j] == 0) {
            ans++;
        }
    }
    cout << ans / 2 << endl;

    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <tuple>

using namespace std;

int main(){

    int N, A;
    cin >> N >> A;
    int result = N*N - A;

    cout << result << endl;

    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<set>
#include<map>
#include<queue>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);++i)
#define rrep(i,n) for(int (i)=(n)-1;(i)>=0;--i)
#define rep1(i,n) for(int (i)=1;(i)<=(n);++i)
#define rrep1(i,n) for(int (i)=(n);(i)>=1;--i)
#define pb push_back
#define fr first
#define sc second
typedef long long ll;
typedef pair<int,int> P;
typedef pair<long long,long long> LP;
typedef double db;
using namespace std;
ll N,A[300000];
priority_queue<ll> p,q;//でかい方から
ll ans1[300000];
ll ans2[300000];

int main(){
  cin>>N;
  rep(i,3*N) cin>>A[i];
  ll sum1=0,sum2=0;
  rep(i,N){
    q.push(-A[i]);
    sum1+=A[i];
  }
  ans1[N] = sum1;
  for(ll i=N+1;i<2*N+1;i++){// [0,i) [i,3*N)
    ll x = -q.top();
    if(x < A[i-1]){
      sum1 -= x;
      sum1 += A[i-1];
      q.pop();
      q.push(-A[i-1]);
    }
    ans1[i]=sum1;
  }
  rrep(i,N){
    p.push(A[2*N+i]);
    sum2+=A[2*N+i];
  }
  ans2[2*N]=sum2;
  for(ll i=2*N-1; i>=N; i--){
    ll x = p.top();
    if( x > A[i] ){
      sum2 -= x;
      sum2 += A[i];
      p.pop();
      p.push(A[i]);
    }
    ans2[i]=sum2;
  }
  ll ans = -0xfffffffffffffff;
  rep(i,N+1){
    ans = max(ans,ans1[i+N]-ans2[i+N]);
    // cout<<i<<" "<<ans1[i+N]<<" "<<ans2[i+N]<<endl;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 7668
#include <iostream>

using namespace std;

void swap(bool& x,bool&y){
  y^=x;
  x^=y;
  y^=x;
}

int main(){
  bool cups[3]={1,0,0};
  char cup1,c,cup2;
  while(cin>>cup1>>c>>cup2){
    swap(cups[cup1-'A'],cups[cup2-'A']);
  }
  cout<<(char)(cups[1]+cups[2]*2+'A')<<endl;
}

Measured memory_bytes: 1132
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while(true){
int a = sc.nextInt();
int b = sc.nextInt();
if(a==0&&b==0) break;
System.out.println(a<b?a+" "+b:b+" "+a);
}
}
}


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

int multi_first(string s){
  int l = (int)s.size(), ret = 0;
  stack<int> st;
  for(int i = 0; i < l; ++i){
    if(s[i] == '+') continue;
    else if(s[i] == '*'){
      int t = st.top();
      st.pop();
      st.push(t*(s[i+1]-'0'));
      ++i;
    }else{
      st.push(s[i]-'0');
    }
  }
  while(!st.empty()){
    ret += st.top();
    st.pop();
  }
  //cout << "multi_first = " << ret << endl;
  return ret;
}

int left_to_right(string s){
  int l = (int)s.size(), ret = s[0]-'0';
  for(int i = 1; i < l; ++i){
    if(s[i] == '+'){
      ret += s[i+1] - '0';
      ++i;
    }else if(s[i] == '*'){
      ret *= s[i+1] - '0';
      ++i;
    } 
  }
  //cout << "left_to_right = " << ret << endl;
  return ret;
}

int main(){
  string S;
  int N;
  cin >> S >> N;
  if(multi_first(S) == N){
    if(left_to_right(S) == N) cout << 'U' << endl;
    else cout << 'M' << endl;
  }else{
    if(left_to_right(S) == N) cout << 'L' << endl;
    else cout << 'I' << endl;
  }
  return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> aa;
  int count = 0;

  for (int k = 0; k < n; k++) {
    int t;
    cin >> t;
    aa.push_back(t);
    while (t % 2 == 0 && t > 0) {
      count++;
      t /= 2;
    } 
  }
  cout << count << endl;
}

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

int main(){
  int n;
  cin >> n;
  double y = 0;
  rep(i,n){
    double x;
    string u;
    cin >> x >> u;
    if(u=="JPY"){
      y += x;
    }else{
      y += x*380000.0;
    }
  }
  
  cout << setprecision(20) << y << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
 
char str[1005];
char p[1005];
 
int main()
{
    int q, a, b;
    char op[10], *x, *y, c;
     
    scanf("%s%d", str, &q);
    while (q--) {
        scanf("%s%d%d", op, &a, &b);
        if (op[2] == 'i') {             // print
            b++, c = *(str+b), *(str+b) = 0, puts(str+a), *(str+b) = c;
        } else if (op[2] == 'v') {      // reverse
            x = str+a, y = str+b;
            while (x < y) {
                c = *x, *x = *y, *y = c;
                x++, y--;
            }
        } else {                        // replace
            scanf("%s", p);
            x = str+a, y = p;
            while (*y) *x++ = *y++;
        }
    }
    return 0;
}


Measured memory_bytes: 2144
#include <iostream>
using namespace std;
int main()
{
	int a,b,c; int CASE[1000][3];
	while(1)
	{
		cin >> a >> b >> c ; int total=a+b+c;
		if(a==0 && b==0 && c==0) break;
		int N,i,j,k,r; int pnt=0;
		cin >> N ; 
		int* test=new int[total]; for(int n=0;n<total;n++) test[n]=2;
		for(int n=0;n<N;n++)
		{
			cin >> i >> j >> k >> r ;
			if(r==1) test[i-1]=test[j-1]=test[k-1]=1;
			else CASE[pnt][0]=i-1,CASE[pnt][1]=j-1,CASE[pnt++][2]=k-1;
		}
		for(int n=0;n<pnt;n++)
		{
			if(test[CASE[n][0]]==1 && test[CASE[n][1]]==1 && test[CASE[n][2]]==2) test[CASE[n][2]]=0;
			if(test[CASE[n][0]]==1 && test[CASE[n][2]]==1 && test[CASE[n][1]]==2) test[CASE[n][1]]=0;
			if(test[CASE[n][1]]==1 && test[CASE[n][2]]==1 && test[CASE[n][0]]==2) test[CASE[n][0]]=0;
		}
		for(int n=0;n<total;n++)
		cout << test[n] << '\n' ;
	}
}

Measured memory_bytes: 1196
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define PI acos(-1)
typedef  long long ll;
using namespace std;

ll modinv(ll a,ll m){
   ll b=m,u=1,v=0;
   while(b){
      ll t=a/b;
      a-=t*b; 
      swap(a,b);
      u-=t*v; 
      swap(u,v);
   }
   u%=m;
   if(u<0) u+=m;
   return u;
}

ll gcd(ll x,ll y){
   if(y==0) return x;
   else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
   return x/gcd(x,y)*y;
}



int main(){
  string s;
  cin>>s;
  int n=s.size();

  rep(i,n){
     if(s[i]=='?') s[i]='D';       
  }
  rep(i,n){
     cout<<s[i];
  }

   return 0;
}



Measured memory_bytes: 3752
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        FastReader sc = new FastReader();
        PrintWriter out = new PrintWriter(System.out);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int x = sc.nextInt();
        int y = sc.nextInt();
        Integer[] xArr = new Integer[n];
        Arrays.fill(xArr, 0);
        int[] yArr = new int[m];
        for (int i = 0; i < xArr.length; i++) {
            xArr[i] = sc.nextInt();
        }

        for (int i = 0; i < yArr.length; i++) {
            yArr[i] = sc.nextInt();
        }
        Arrays.sort(xArr, (e1, e2) -> e2 - e1);
        Arrays.sort(yArr);

        int tarx = xArr[0];
        int tary = yArr[0];

        for (int i=tarx+1;i <=tary;i++) {
            if (x < i && i <=y) {
                out.println("No War");
                out.flush();
                return;
            }
        }

        out.println("War");

        out.flush();

    }

    static class Toi {
        public int x;
        public int y;

        public Toi(int x, int y) {
            this.x = x;
            this.y = y;
        }

        @Override public boolean equals(Object obj) {
            if (obj == null) {
                return false;
            }

            if (this == obj) {
                return true;
            }

            if (this.getClass() != obj.getClass()) {
                return false;
            }

            Toi toi = (Toi) obj;
            return x == toi.x && y == toi.y;
        }
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

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

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

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

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

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}

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

using namespace std;

typedef vector<int> vi;

#define PB push_back
#define rep(i,x) for(int i=0;i<(x);++i)
#define rep1(i,x) for(int i=1;i<=(x);++i)

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

int a[100002];

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

	rep(i, N) cin >> a[i];

	vi l; l.PB(0); l.PB(0);

	int ma = 0;

	int cnt = 1;

	rep1(i, N - 1) {
		if (a[i] == a[i - 1]) {
			l.PB(cnt);
			cnt = 1;
			chmax(ma, *(l.end() - 1) + *(l.end() - 2) + *(l.end() - 3));
		} else cnt++;
	}
	
	l.PB(cnt);
	chmax(ma, *(l.end() - 1) + *(l.end() - 2) + *(l.end() - 3));

	cout << ma << endl;
}

Measured memory_bytes: 1800
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;
int main() {
  int N,A,B,C,D;
  cin >> N >> A >> B >> C >> D;
  A--;
  B--;
  C--;
  D--;
  string S;
  cin >> S;
  bool ans = true;
  if (C < D) {
    for (int i = A+1; i <= D-2; i++) {
      if (S[i] == '#' && S[i+1] == '#') {
        ans = false;
      }
    }
  } else {
    for (int i = A+1; i <= C-2; i++) {
      if (S[i] == '#' && S[i+1] == '#') {
        ans = false;
      }
    }
    bool ans2 = false;
    for (int i = B-1; i <= D-1; i++) {
      if (i + 2 < N) {
        if ((S[i] == '.' && S[i+1] == '.') && S[i+2] == '.') {
          ans2 = true;
        }
      } 
    }
    if (!ans2) ans = false;
  } 
  
  if (ans) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 644
import java.io.*;
import java.util.*;
public class Main
{
	
	private void solve()throws Exception
	{
		int n=nextInt();
		long ans=0;
		for(int i=1;i<=n;i++)
			ans+=1l*i*(i+1)/2;
		for(int i=1;i<n;i++)
		{
			int u=nextInt();
			int v=nextInt();
			if(u>v)
			{
				int t=u;
				u=v;
				v=t;
			}
			ans-=1l*u*(n-v+1);
		}
		out.println(ans);
	}

	 
	///////////////////////////////////////////////////////////

	public void run()throws Exception
	{
		br=new BufferedReader(new InputStreamReader(System.in));
		st=null;
		out=new PrintWriter(System.out);

		solve();
		
		br.close();
		out.close();
	}
	public static void main(String args[])throws Exception{
		new Main().run();
	}
	BufferedReader br;
	StringTokenizer st;
	PrintWriter out;
	String nextToken()throws Exception{
		while(st==null || !st.hasMoreTokens())
		st=new StringTokenizer(br.readLine());
		return st.nextToken();
	}
	String nextLine()throws Exception{
		return br.readLine();
	}
	int nextInt()throws Exception{
		return Integer.parseInt(nextToken());
	}
	long nextLong()throws Exception{
		return Long.parseLong(nextToken());
	}
	double nextDouble()throws Exception{
		return Double.parseDouble(nextToken());
	}
}

Measured memory_bytes: 54300
x, y = map(int, input().split())
g1 = [1, 3, 5, 7, 8, 10, 12]
g2 = [4, 6, 9, 11]
g3 = [2]

if x in g1 and y in g1:
    print("Yes")
elif x in g2 and y in g2:
    print("Yes")
elif x in g3 and y in g3:
    print("Yes")
else:
    print("No")

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

ll mod=1e9+7;

ll powpow(ll a, ll n){
    ll ret=1;
    while(n>0){
        if(n&1) ret=ret*a%mod;
        a=a*a%mod;
        n>>=1;
    }
    return ret;    
}

ll invmod(ll a){
    return powpow(a,mod-2);
}

int main(){

    int n;
    cin >> n;
    vector<ll> a(n);
    for(int i=0;i<n;i++) cin >> a[i];
    vector<ll> a2(n);
    for(int i=0;i<n;i++){
        a2[i]=a[i]*a[i]%mod;
    }
    ll ans=0;
    ll sum=0;
    ll sum2=0;
    for(int i=0;i<n;i++){
        sum+=a[i];
        sum%=mod;
        sum2+=a2[i];
        sum2%mod;
    }
    //cout << sum << " " << sum2 << endl;
    ans+=((sum*sum)%mod-sum2+mod)%mod;
    ans=(ans*invmod(2)+mod)%mod;
    ans=(ans+mod)%mod;
    cout << ans << endl;
   
    return 0;
}

Measured memory_bytes: 6348
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define pp pop_back
#define in insert
#define ff first
#define ss second
#define  show for(int j=0;j<v.size();j++) cout<<v[j]<<" ";
#define ld long double
#define e endl
#define bc __builtin_popcount
#define MOD 1000000007
#define INT_SIZE 32
#define me(x) memset(x,0,sizeof(x))
ll fast_expo(ll x,ll p)
{if(p==0) return 1;
else if(p%2==0){ ll t=fast_expo(x,p/2)%MOD;return (t*t)%MOD;} else return (x*(fast_expo(x,p-1))%MOD)%MOD;}
int fun1(string s)
{
    int flag=1;
    int len=s.length();
    for(int i=0;i < len ;i++){
        if(s[i] != s[len-i-1]){
            {flag = 0;
            break;}
        }
    }
            return flag;
}
int main()
{
    string s;
    cin>>s;
    int n=s.length();
    if(fun1(s)&&fun1(s.substr(0,(n-1)/2))&&fun1(s.substr((n+3)/2-1)))
        cout<<"Yes";
    else
        cout<<"No";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()

int main() {
  ll A,B,K;
  cin>>A>>B>>K;
  ll C=min(A,B);
  
  while(K>0) {
    if(A%C==0&&B%C==0) {
K--;
    }
    C--;
  }
  
  cout<<C+1<<endl;
}

 
      


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

namespace my_lib
{
ll roundUp(ll a, ll b)
{
    return (a + (b - 1)) / b;
}
} // namespace my_lib

int main()
{
    ll N, D;
    cin >> N >> D;
    cout << my_lib::roundUp(N, (2 * D + 1));
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main
{
    public static void main(String args[])
    {
        Scanner kb = new Scanner(System.in);

        String s1 = kb.nextLine();
        String s2 = kb.nextLine();

        int k = s2.length();
        int min = Integer.MAX_VALUE;

        for(int i = k ; i <= s1.length() ; i++)
        {
            String tmp = s1.substring(i-k,i);
            int t = diff(s2,tmp);
            if(t < min)
                min = t;
        }
        System.out.println(min);

    }
    public static int diff(String s1,String s2)
    {
        int res = 0;

        for(int i = 0 ; i < s1.length() ; i++)
        {
            if(s1.charAt(i) != s2.charAt(i))
            {
                res++;
            }
        }
        return res;
    }
}

Measured memory_bytes: 35956
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;

int gcd(int a, int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int lcm(int a, int b){
    return a/gcd(a,b)*b;
}

#define MAX 100005

signed main(void) {
    vi v(MAX,0);
    loop(i,1,MAX)for(int j = 1; i*j < MAX; j++){
        v[i*j]++;
    }
    vi ans(MAX, 0);
    loop(i,1,MAX)ans[i] = ans[i-1] + (v[i] > 4);
    int n;
    cin >> n;
    while(n--){
        int a;
        cin >> a;
        cout << ans[a] << endl;
    }

}



Measured memory_bytes: 4256
// A.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>

using namespace std;

int main(int argc, char *argv[]) {
	int a, b, c;
	cin >> a >> b >> c;
	int ans = min(b / a, c);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main() {
	int D, E, a, b, c, d, e, f, g, h, i;
	scanf("%d%d%d%d%d%d%d%d%d", &a, &b, &c, &d, &e, &f, &g, &h, &i);
	printf("%s", (b - a == e - d && b - a == h - g && c - b == f - e && c - b == i - h) ? "Yes" : "No");
	return 0;
}

Measured memory_bytes: 128
//#pragma GCC optimize("Ofast,unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,tune=native")
#include<bits/stdc++.h>

using namespace std;

#define all(x) (x).begin(),(x).end()
#define I(x, a) for(auto x : (a))
#define ins insert
#define F(i, l, r) for(auto i = (l); i < (r); i++)
#define DF(i, l, r) for(auto i = (l); i >= (r); i--)
#define E(i, l, r) for(auto i = (l); i <= (r); i++)
#define pb push_back
#define X first
#define Y second
#define mp make_pair
#define ret return
#define brk break
#define cont continue
#define move fjgjgjgjghd

typedef long long ll;
typedef unsigned long long ull;
typedef long double dbl;
typedef pair<int, int> pii;

typedef vector<int> perm;

const int mod = (int)1e9 + 7;
const int N = (int)2e5 + 5;

int n, k;

perm mul(const perm & a, const perm & b){
	perm q(a.size());
	F(i, 0, n)
		q[i] = a[b[i]];
	return q;
}

perm inv(const perm & a){
	perm b(a.size());
	F(i, 0, n)
		b[a[i]] = i;
	ret b;
}

void finish(const perm & p){
	I(x, p)cout << x + 1 << ' ';
	exit(0);
}

int wc[N];
int nxt[N];
int cycle[N];

perm pw(const perm & a, int w){
	if(w == 0){
		vector<int>res(a.size());
		iota(all(res), 0);
		ret res;
	}
//	F(i, 0, n)cerr << a[i] << ' ';
//	cerr << endl;
	vector<int> res(a.size());
	fill(wc, wc + n, 0);
	F(i, 0, n){
		nxt[i] = a[i];
		cycle[i] = 0;
	}
	F(i, 0, n){
		if(wc[i])cont;
		int j = i;
		wc[i] = 1;
		cycle[i] = 1;
		j = nxt[i];
		while(j != i){
			++cycle[i];
			wc[j] = 1;
			j = nxt[j];
		}
	}
	F(i, 0, n){
		if(wc[i] == 2)cont;
		int len = w%cycle[i];
		int j = i;
		F(t, 0, len)j = nxt[j];
		res[i] = j;
		int t = nxt[i];
		wc[i] = 2;
		while(t != i){
			wc[t] = 2;
			j = nxt[j];
			res[t] = j;
			t = nxt[t];
		}
	}
	return res;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	vector<int> p, q;
	cin >> n >> k;
	p.resize(n); q.resize(n);
	F(i, 0, n){
		cin >> p[i];
		--p[i];
	}
	F(i, 0, n){
		cin >> q[i];
		--q[i];
	}
	auto ip = inv(p);
	auto iq = inv(q);
	if(k == 1)finish(p);
	if(k == 2)finish(q);
	int r = k%6;
	auto L = mul(q, ip);
	L = mul(L, iq);
	L = mul(L, p);
	if(r == 0){
		L = pw(L, k/6);
		L = mul(L, p);
		L = mul(L, iq);
		auto R = mul(ip, q);
		R = mul(R, p);
		R = mul(R, iq);
		R = pw(R, k/6 - 1);
		L = mul(L, R);
		finish(L);
	}
	if(r == 1){
		L = pw(L, k/6);
	    auto R = mul(q, p);
		R = mul(R, iq);
		R = mul(R, ip);
		R = pw(R, k/6);
		R = mul(R, p);
		finish(mul(L, R));
	}
	if(r == 2){
		L = pw(L, k/6);
		auto R = mul(q, p);
		R = mul(R, iq);
		R = mul(R, ip);
		R = pw(R, k/6);
		R = mul(R, p);
		R = mul(ip, R);
		R = mul(q, R);
		finish(mul(L, R));
	}
	if(r == 3){
		L = pw(L, k/6);
		L = mul(L, q);
		L = mul(L, ip);
		auto R = mul(ip, q);
		R = mul(R, p);
		R = mul(R, iq);
		R = pw(R, k/6);
		finish(mul(L, R));
	}
	if(r == 4){
		L = pw(L, k/6 + 1);
		L = mul(L, ip);
		auto R = mul(ip, q);
		R = mul(R, p);
		R = mul(R, iq);
		R = pw(R, k/6);
		finish(mul(L, R));
	}
	if(r == 5){
		L = pw(L, k/6 + 1);
		L = mul(L, iq);
		auto R = mul(ip, q);
		R = mul(R, p);
		R = mul(R, iq);
		R = pw(R, k/6);
		finish(mul(L, R));
	}
	assert(0);
	return 0;
}


Measured memory_bytes: 4720
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
const int MOD = 1000000007;
const int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;

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

  int N;
  cin >> N;
  int A[N-1], B[N-1], C[N-1];
  rep(i,N-1){
    cin >> A[i] >> B[i] >> C[i];
  }
  for(int i=0;i<N-1;i++){
    int ans = B[i] + A[i];
    for(int j=i+1;j<N-1;j++){
      if(ans <= B[j]){
        ans = B[j] + A[j];
      }
      else{
        ans = A[j] + C[j]*((ans+C[j]-1)/C[j]);
      }
    }
    cout << ans << endl;
  }
  cout << 0 << endl;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define pb push_back
#define all(v) v.begin(), v.end()
#define bigger (char)toupper
#define smaller (char)tolower
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;
typedef unsigned long long ull;

int main() {
    int N; cin>>N;
    vi v(N);
    rep(i,N) {
        cin>>v[i];
    }
    sort(all(v));
    reverse(all(v));
    int counter=0;
    rep(i,N) counter+=v[i];
    cout<<counter-(v[0]/2)<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(i,n) for(ll i=0;i<n;++i)
#define ocut cout
#define ouct cout
#define itn int

struct Union{
  vector<ll> par;
  Union(ll a){
  par=vector<ll>(a,-1);
  }
  ll find(ll a){
    if(par[a]<0){
      return a;
    }
    else{
      return par[a]=find(par[a]);
    }
  }
  bool same(ll a,ll b){
    return (find(a)==find(b));
  }
  ll size(ll a){
    return -par[find(a)];
  }
  void unite(ll a,ll b){
    ll c=find(a),d=find(b);
    if(c==d)
      return;
    if(size(c)<size(d)){
      swap(c,d);
    }
    par[c]+=par[d];
    par[d]=c;
  }
};
ll euclidean_gcd(ll a, ll b) {
  if(a < b) return euclidean_gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
ll euclidean_lcm(ll a, ll b) {
  return a/euclidean_gcd(a,b)*b;
}
int main(void){
  ll a,b,c,ans=0;
  cin >> a >> b >> c;
  for(ll i=a;i<=b;i++){
    if(i%c==0)ans++;
  }
  cout << ans;
  
}

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

int main(){
    vector<int> a(3);
    int K;
    cin >> a[0] >> a[1] >> a[2];
    cin >> K;

    sort(a.begin(),a.end(), greater<int>());

    int sums = 0;
    sums += a[1] + a[2];
    sums += a[0] * pow(2,K);
    cout << sums << endl;
}

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

int main() {
    int n, a;
    std::cin >> n >> a;
    int temp;
    temp = n % 500;
    if (temp <= a){
        std::cout << "Yes" << std::endl;
    }
    else{
        std::cout << "No" << std::endl;
    }
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.math.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        TreeMap<Integer,Integer> map = new TreeMap<Integer,Integer>();
        int n = sc.nextInt();
        int[] al = new int[n];
        for(int i = 0; i < n; i++){
            al[i] = sc.nextInt();
        }
        long ans = 0;
        long now = 0;
        for(int i = 0; i < n; i++){
            if(al[i] == 0){
                ans += now/2L;
                now = 0;
            }else{
                now += al[i];
            }
        }
        System.out.println(ans+now/2L);
    }
    
}



Measured memory_bytes: 52060
#include <iostream>
#include <vector>
#include <algorithm>
#include <tuple>
using namespace std;

long long N, X[1009], Y[1009], H[1009]; vector<tuple<long long, long long, long long>>vec;

int main() {
    cin >> N; tuple<long long, long long, long long>G = make_tuple(-1, -1, -1);
    for (int i = 1; i <= N; i++) {
        cin >> X[i] >> Y[i] >> H[i];
        if (H[i] >= 1) G = make_tuple(X[i], Y[i], H[i]);
    }
    for (int i = 0; i <= 100; i++) {
        for (int j = 0; j <= 100; j++) {
            long long V = get<2>(G) + abs(get<0>(G) - i) + abs(get<1>(G) - j); bool flag = true;
            for (int k = 1; k <= N; k++) {
                long long VV = V - abs(X[k] - i) - abs(Y[k] - j); VV = max(VV, 0LL);
                if (H[k] != VV) flag = false;
            }
            if (flag == true) vec.push_back(make_tuple(i, j, V));
        }
    }
    if (vec.size() == 1) {
        cout << get<0>(vec[0]) << " " << get<1>(vec[0]) << " " << get<2>(vec[0]) << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
void print_rectangle(int h, int w)
{
    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            printf("#");
        }
        printf("\n");
    }
    printf("\n");
}
int main(void)
{
    int h, w;

    while (1)
    {
        scanf("%d %d", &h, &w);
        if (h == 0 && w == 0) //０を入力したら終了
        {
            break;
        }
        print_rectangle(h, w);
    }

    return 0;
}


Measured memory_bytes: 2628
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const int MAX_N = 1e6;
long long prime[MAX_N];
bool is_prime[MAX_N+1];

ll sieve(ll n){
	ll p = 0;
	for(ll i = 0; i <= n; i++) is_prime[i] = true;
	is_prime[0] = is_prime[1] = false;
	for(ll i = 2; i <= n; i++){
		if(is_prime[i]){
			prime[p++] = i;
			for(ll j = 2*i; j <= n; j+= i)
				is_prime[j] = false;
		}
	}
	return p;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	sieve(1000000);
	int x;
	cin >> x;
	for(int i = x; i <= 1000000; ++i){
		if(is_prime[i]){
			cout << i << endl;
			return 0;
		}
	}
	return 0;
}


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

int main() {
  int N, K, Q;
  cin >> N >> K >> Q;
  vector<int> A(Q);
  for (int i = 0; i < Q; i++) {
    cin >> A.at(i);
  }
  // 不正解　Q-(正解数)
  // 残りポイント　K-Q+正解数
  
  vector<int> ansnum(N);
  for (int i : A) {
    ansnum.at(i - 1)++;
  }
  
  for (int i = 0; i < N; i++) {
    if (K - Q + ansnum.at(i) > 0) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }
}

Measured memory_bytes: 1408
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <array>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>

using namespace std;
using lli = long long int;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (lli i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (lli i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

lli a, b;
int main() {
  cin >> a >> b;
  lli ans = 0;
  for (lli i=a; i<=b; ++i) {
    if (i%10 == i/10000%10 && i/10%10 == i/1000%10) ++ans;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 384
fun main(args : Array<String>) {
    val s = readLine()!!

    var sCnt = 0
    var tCnt = 0
    var rm = 0

    s.forEach { c ->
        if (c == 'T') {
            if (sCnt > 0) {
                tCnt++
            }
        } else {
            if (tCnt > 0) {
                if (sCnt > tCnt) {
                    rm += 2 * tCnt
                    sCnt = sCnt - tCnt + 1
                    tCnt = 0
                } else {
                    rm += 2 * sCnt
                    sCnt = 1
                    tCnt = 0
                }
            } else {
                sCnt++
            }
        }
    }

    if (sCnt > 0 && tCnt > 0) {
        rm += 2 * Math.min(sCnt, tCnt)
    }

    println(s.length-rm)
}

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

int main(){
  string S;
  cin >> S;
  if(S.at(5) == '0'&&(S.at(6) == '1'||S.at(6) == '2'||S.at(6) == '3'||S.at(6) == '4')){
    cout << "Heisei" <<endl;
  }else{
    cout << "TBD" << endl;
  }
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define bug1(x) cout<<#x<<" = "<<x<<endl
#define bug2(x,y) cout<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<endl
#define bug3(x,y,z) cout<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<" "<<#z<<" = "<<z<<endl
#define bug4(x,y,z,m) cout<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<" "<<#z<<" = "<<z<<" "<<#m<<" = "<<m<<endl

using namespace std;

template<class T> 
ostream& operator<<(ostream &os, vector<T> input) {
    os << "[ ";
    for(auto elem : input) { 
		os << elem << " ";
	}
	return os << "]";
}

template<class T> 
ostream& operator<<(ostream &os, set<T> input) {
    os << "{ ";
    for(auto elem : input) { 
		os << elem << " ";
	}
	return os << "}";
}

template<class T> 
ostream& operator<<(ostream &os, unordered_set<T> input) {
    os << "{ ";
    for(auto elem : input) { 
		os << elem << " ";
	}
	return os << "}";
}

template<class T> 
ostream& operator<<(ostream &os, multiset<T> input) {
    os << "{ ";
    for(auto elem : input) { 
		os << elem << " ";
	}
	return os << "}";
}

template<class T> 
ostream& operator<<(ostream &os, unordered_multiset<T> input) {
    os << "{ ";
    for(auto elem : input) { 
		os << elem << " ";
	}
	return os << "}";
}

template<class L, class R> 
ostream& operator<<(ostream &os, map<L,R> input) {
    os << "{ ";
    for(auto elem : input) { 
		os << "(" << elem.first << "," << elem.second << ") ";
	}
	return os << "}";
}

template<class L, class R> 
ostream& operator<<(ostream &os, unordered_map<L,R> input) {
    os << "{ ";
    for(auto elem : input) { 
		os << "(" << elem.first << "," << elem.second << ") ";
	}
	return os << "}";
}

#define ll long long
const int MAXN = 1000005;
const ll INF = 1e18;
const int MOD = 1e9 + 7;

class TaskE {
private:

public:
	void solveOne(int it){
		ll n, x, mod;
		cin >> n >> x >> mod;
		vector<ll> sum(MAXN, 0);
		vector<int> where(mod, -1);
		ll ans = 0;
		for(int it = 1; it <= n; it++) {
			sum[it] = x;
			ans += x;
			if(where[x] == -1) {
				where[x] = it;
			} else {
				ll ans2 = 0;
				for(int j = 1; j < where[x]; j++) {
					ans2 += sum[j];
				}
				ll tot = 0;
				for(int j = where[x]; j < it; j++) {
					tot += sum[j];
				}
				ll sz = it - where[x];
				ll ini = where[x] - 1;
				//ini + k * sz <= n
				ll k = (n - ini) / sz;
				ans2 += k * tot;
				ll rem = n - (ini + k * sz);
				for(int j = where[x]; rem > 0 ; j++, rem--) {
					ans2 += sum[j];
				}
				cout << ans2 << endl;
				return;
			}
			x = (x*x)%mod;
		}
		cout << ans << endl;
	}

	void solve(){
		int tc = 1;
		for(int it = 1; it <= tc; it++){
			solveOne(it);
		}
	}
};


int main(){
	ios_base::sync_with_stdio(false);
	TaskE solver;
	solver.solve();
	return 0;
}


Measured memory_bytes: 11384
#include <bits/stdc++.h>//Carefully Crafted by hetp111
using namespace std;
#define int long long
#define double long double
#define all(v) (v).begin(),(v).end()
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vii vector<pii>
#define MOD (1000000007)
#define MOD2 (998244353)
#define MOD3 (1000000009)
#define PI acos(-1)
#define eps (1e-8)
#define INF (1e18)
#define FASTER ios_base::sync_with_stdio(0);cin.tie(0)
template<class A,class B>ostream&operator<<(ostream&out,const pair<A,B>&a){return out<<"("<<a.first<<","<<a.second<<")";}
template<class A>ostream&operator<<(ostream&out,const vector<A>&a){for(const A &it:a)out<<it<<" ";return out;}
template<class A,class B>istream&operator>>(istream&in,pair<A,B>&a){return in>>a.first>>a.second;}
template<class A>istream&operator>>(istream&in,vector<A>&a){for(A &i:a)in>>i;return in;}
ifstream cinn("in.txt");ofstream coutt("out.txt");
int poww(const int &a,int b,const int &m=MOD){if(b==0)return 1;int x=poww(a,b/2,m);x=x*x%m;if(b&1)x=x*a%m;return x;}
int ceil(const int &a,const int &b){return (a+b-1)/b;}
////Read:
//Use __builtin_popcountll for ll;
//Check corner cases, n==1;
//
////Some function:
//__builtin_popcountll(), 

signed main(){
    FASTER;
    int n=5;
    vi v(n+1);
    for(int i=1;i<=n;i++)cin>>v[i];
    for(int i=1;i<=n;i++){
        if(v[i]==0){
            cout<<i;
            return 0;
        }
    }
}



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

const int INF = 1e+8;
int w, h, f, m;
int c[10][10];

struct State{
	int x, y, l, r, oxy, cost;
	State(int x_, int y_, int l_, int r_, int oxy_, int cost_){
		x = x_; y = y_; l = l_; r = r_; oxy = oxy_; cost = cost_;
	}
	State(){}
};
bool operator<(const State& a, const State& b){
	return a.cost > b.cost;
}

// d[y][x][l][r][oxy] := テヲツ篠佚」ツ?」テ」ツ?淌・ツキツヲテァツォツッ l, テ・ツ渉ウテァツォツッ r, テゥツ?クテァツエツ?oxy テ」ツ?ァ (x,y) テ」ツ?ォテ」ツ?淌」ツ?ゥテ」ツつ甘ァツ敖?」ツ?湘ヲツ慊?・ツーツ湘」ツつウテ」ツつケテ」ツδ?
int d[10][10][10][10][51];

int solve(int o){
	if( o < 2 ) return INF;
	
	// テ・ツ按敕ヲツ慊淌・ツ個?
	for(int y=0 ; y < 10 ; y++ ){
		for(int x=0 ; x < 10 ; x++ ){
			for(int l=0 ; l < 10 ; l++ ){
				for(int r=0 ; r < 10 ; r++ ){
					for(int m=0 ; m < 51 ; m++ ){
						d[y][x][l][r][m] = INF;
					}
				}
			}
		}
	}
	priority_queue<State> q;
	for(int x=0 ; x < w ; x++ ){
		int cost = -1 * min( c[0][x] , 0 );
		int oxy = min( m , o - 1 + max( c[0][x] , 0 ) );
		d[0][x][x][x][oxy] = cost;
		q.push( State(x, 0, x, x, oxy, cost) );
	}
	int res = INF;
	while( !q.empty() ){
		int x = q.top().x, y = q.top().y, l = q.top().l, r = q.top().r;
		int oxy = q.top().oxy, cost = d[y][x][l][r][oxy];
		q.pop();
		
		// テゥツ?クテァツエツ?」ツ?古」ツ?ェテ」ツ??
		if( oxy == 0 ) continue;
		// テ」ツつウテ」ツつケテ」ツδ暗」ツ?古、ツクツ甘ゥツ卍?f テ」ツつ津ィツカツ?」ツ?暗」ツ?ヲテ」ツ??」ツつ?
		if( f < cost ) return INF;
		// テ」ツつエテ」ツδシテ」ツδォテ」ツ?ョテヲツ卍?
		if( y == h-1 ){
			res = cost;
			break;
		}
		// テゥツ?クテァツエツ?1 テ」ツ?ョテ」ツ?ィテ」ツ?催」ツ?ッテァツァツサテ・ツ仰陛」ツ?ァテ」ツ?催」ツ?ェテ」ツ??
		if( oxy == 1 ) continue;
		
		// テヲツィツェテ」ツ?ォテァツァツサテ・ツ仰?
		for(int dx = -1 ; dx <= 1 ; dx += 2){
			int mx = x + dx;
			if( mx < 0 || w <= mx ) continue;
			
			int l_ = min(l, mx), r_ = max(r, mx), next_cost = cost, next_oxy;
			if( l_ == l && r_ == r ){
				next_oxy = oxy - 1;
			}else{
				next_cost += -1 * min( c[y][mx] , 0 );
				next_oxy = min( m , oxy - 1 + max( c[y][mx] , 0 ) );
			}
			if( next_cost < d[y][mx][l_][r_][next_oxy] ){
				d[y][mx][l_][r_][next_oxy] = next_cost;
				q.push( State(mx, y, l_, r_, next_oxy, next_cost) );
			}
		}
		
		// テァツクツヲテ」ツ?ォテァツァツサテ・ツ仰?
		if( y < h-1 ){
			int next_cost = cost + -1 * min( c[y+1][x] , 0 );
			int next_oxy = min( m , oxy - 1 + max( c[y+1][x] , 0 ) );
			if( next_cost < d[y+1][x][x][x][next_oxy] ){
				d[y+1][x][x][x][next_oxy] = next_cost;
				q.push( State(x, y+1, x, x, next_oxy, next_cost) );
			}
		}
	}
	if( f < res ) return INF;
	return res;
}

int main(){
	while( cin >> w >> h , w || h ){
		int o;
		cin >> f >> m >> o;
		for(int y=0 ; y < h ; y++ ){
			for(int x=0 ; x < w ; x++ ){
				cin >> c[y][x];
			}
		}
		int ans = solve(o);
		if( ans == INF )
			cout << "NA" << endl;
		else
			cout << ans << endl;
	}
}

Measured memory_bytes: 3320
n, q = map(int, input().split())
s = input()
ls = [0] * n
cnt = 0
for i in range(1, n):
    if s[i] == 'C' and s[i-1] == 'A':
        cnt += 1
    ls[i] += cnt
for j in range(q):
    l, r = map(int, input().split())
    print(ls[r-1]-ls[l-1])


Measured memory_bytes: 77376
#include <cstdio>
#include <cstring>

int main()
{
    char ring[101], p[101], line[202];
    scanf("%s", ring);
    scanf("%s", p);
    int ring_len = strlen(ring);
    int p_len = strlen(p);

    for(int i = 0; i < 2; i++){
        strcpy(line + i*(ring_len), ring);
    }

    if(strstr(line, p) != NULL) printf("Yes\n");
    else printf("No\n");
    return 0;
}

Measured memory_bytes: 964