akhauriyash/Code-Regression huggingface dataset:
import sys
from collections import deque
from collections import defaultdict
import math
sys.setrecursionlimit(20000000)
#input = sys.stdin.readline
 
s = input()

s = s.replace("BC","X")
n = len(s)
ten = []
ans = 0
for i in range(n):
        if s[i] == "A" or s[i] == "X":
                ten.append(s[i])
        else:
                acount = 0
                for j in range(len(ten)):
                        if ten[j] == "A":
                                acount+=1
                        else:
                                ans += acount
                ten= []
acount = 0
for j in range(len(ten)):
        if ten[j] == "A":
                acount+=1
        else:
                ans += acount
print(ans)

Measured memory_bytes: 53184
N,X,M = map(int,input().split())
cur = X
S = set([X])
while True:
    nA = cur**2 % M
    if nA in S:
        break
    S.add(nA)
    cur = nA
loop = [nA]
while True:
    ne = loop[-1]**2 % M
    if ne == nA:
        break
    loop.append(ne)
ll = len(loop)
sl = sum(loop)
ans = [X]
while True:
    ne = ans[-1]**2 % M
    if ne == nA:
        break
    ans.append(ne)
la = len(ans)
if N <= la:
    print(sum(ans[:N]))
else:
    loop_num = (N-la)//ll
    loop_head = (N-la) % ll
    print(sum(ans)+sl*loop_num+sum(loop[:loop_head]))

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

public class Main {

    /**
     * @param args
     */
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        String S = sc.next();
        String ans = solve(S);

        if (ans != null) {
            System.out.println(ans);
        } else {
            System.out.println(-1);
        }

    }

    private static String solve(String S) {
        char[] ans = new char[26];
        char[] slist = S.toCharArray();
        boolean[] hit = new boolean[26];

        for (int i=0; i<slist.length; i++) {
            hit[slist[i] - 'a'] = true;
        }

        if (slist.length != 26) {
            char c = 'a';
            for (int i=0; i<hit.length; i++) {
                if (!hit[i]) {
                    c = (char) ('a' + i);
                    break;
                }
            }

            return S.concat(String.valueOf(c));
        }

        hit = new boolean[26];
        for (int i=25; i>=0; i--) {
//            System.err.print(i + ":" + slist[i] + " ");
            for (int j=(slist[i] - 'a' + 1); j<26; j++) {
//                System.err.print(j + " ");
                if(hit[j]) {
                    slist[i] = (char)('a' + j);
                    return new String(slist).substring(0, i+1);
                }
            }

//            System.err.println("(" + i + ": add " + (slist[i]) + ")");
            hit[slist[i]-'a'] = true;
        }

        return null;
    }
}


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

int main(void){
	int data[100001];
	int ans=0;
	int a;
	int n,k;
	while(1){
		cin >> n >> k;
		if(n==0 && k==0)break;
		ans=0;
		memset(data,0,sizeof(data));
		for(a=0;a<k;a++){
			int b;
			cin >> b;
			data[b]=1;
		}
		if(data[0]==0){
			int res=0;
			for(a=1;a<=n;a++){
				if(data[a]==1){
					res++;
					ans=max(ans,res);
				}else{
					res=0;
				}
			}
		}else{
			int res=0,x1=0,x2=0;
			bool zero=false;
			for(a=1;a<=n;a++){
				if(data[a]==1){
					res++;
					x1++;
					ans=max(ans,res);
				}else{
					if(zero){
						res=res-x2;
						x2=x1;
						x1=0;
					}else{
						res++;
						x2=x1;
						x1=0;
						zero=true;
					}
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;cin>>n;
	int p=n%10;
	if(p==2||p==4||p==7||p==9||p==5)cout<<"hon";
	else if(p==0||p==1||p==6||p==8)cout<<"pon";
	else cout<<"bon";
}

Measured memory_bytes: 3640
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int w = sc.nextInt();
		int h = sc.nextInt();
		int n = sc.nextInt();
      	boolean ws[] = new boolean[w];
      	boolean hs[] = new boolean[h];
      	int x,y,a;
      	int ww = 0;
      	int hw = 0;
      
      	Arrays.fill(ws,true);
      	Arrays.fill(hs,true);
      
      	for(int i = 0;i < n;i++){
          x = sc.nextInt();	
          y = sc.nextInt();	
          a = sc.nextInt();
          switch(a){
            case 1:
              for(int j=0;j<x;j++) ws[j] = false;
              break;
            case 2:
              for(int j=x;j<w;j++) ws[j] = false;
              break;
            case 3:
              for(int j=0;j<y;j++) hs[j] = false;
              break;
            case 4:
              for(int j=y;j<h;j++) hs[j] = false;
              break;
          }
        }
      
      	for(int i = 0;i < w;i++){
       	  if(ws[i]) ww++;
        }
      	for(int i = 0;i < h;i++){
       	  if(hs[i]) hw++;
        }

		System.out.println(hw*ww);
	}
}

Measured memory_bytes: 36212
H, W = map(int, input().split())
B = [input() for _ in range(H)]
BB = [[1<<30]*W for _ in range(H)]
for y in range(H):
    p=1<<30
    for x in range(W):
        p+=1
        if B[y][x]=="#":
            p=0
        BB[y][x] = p

    p = 1 << 30
    for x in range(W-1,-1,-1):
        p += 1
        if B[y][x] == "#":
            p = 0
        p = min(p, BB[y][x])
        BB[y][x] = p
#print(BB)
ans = 0
for x in range(W):
    p = 1 << 30
    for y in range(H):
        p = min(p+1, BB[y][x])
        BB[y][x] = p

    p = 1 << 30
    for y in range(H - 1, -1, -1):
        p = min(p+1, BB[y][x])
        ans = max(ans, p)
        BB[y][x] = p
#print(BB)
print(ans)


Measured memory_bytes: 57308
#include <iostream>

using namespace std;

int main(){
  int n;
  
  cin >> n;
  if(n % 10 == 3){
    cout << "bon" << endl;
  } else if((n % 10 == 0) || (n % 10 == 1) || (n % 10 == 6) || (n % 10 == 8)){
    cout << "pon" << endl;
  } else {
    cout << "hon" << endl;
  }
  return 0;
}

Measured memory_bytes: 3632
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;

#define ABS(a) ((a)<0?(-(a)):(a))

int main(){
    while(1){
	double q;
	cin >> q;
	if(q == -1)return 0;
	double a = q / 2;
	while(true){
	    a = a - (a*a*a - q)/(3*a*a);
	    if(ABS(a * a * a - q) < q * 0.00001)break;
	}
	printf("%.9lf\n", a);
    }
}

Measured memory_bytes: 1236
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Practice
{
    class Program
    {
        static void Main(string[] args)
        {
            SolveA();
            //SolveB();
            //SolveC();
            //SolveD();
        }
        private const long MOD = 1000000007;
       
        static void SolveA()
        {
            string n = Console.ReadLine();
            bool good = false;
            if( n[0] == n[1] && n[1] == n[2]) { good = true; }
            if( n[1 ] == n[2] && n[2] == n[3]) { good = true; }
            string ans = good ? "Yes" : "No";
            Console.WriteLine(ans);
        }
        #region よく使う便利関数
        private static bool isPrime(long x)
        {
            if( x == 2) { return true; }
            if( x < 2 || x % 2 == 0) { return false; }
            long i = 3;
            while( i * i <= x)
            {
                if( x % i == 0) { return false; }
                i = i + 2;
            }
            return true;
        }
        private static long lcm(long x, long y)
        {
            return x / gcd(x, y) * y;
        }
        private static long gcd(long x, long y)
        {
            return y > 0 ? gcd(y, x % y) : x;
        }

        private static int ReadAndParseInt()
        {
            return int.Parse(Console.ReadLine());
        }
        private static int[] ReadAndParseIntArr()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
        }
        private static long ReadAndParseLong()
        {
            return long.Parse(Console.ReadLine());
        }
        private static long[] ReadAndParseLongArr()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
        }
        #endregion
    }
}

Measured memory_bytes: 11092
package main

import (
	"fmt"
	"strings"
)

func fnMax(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func main() {
	var str string
	fmt.Scan(&str)
	max := 0
	tmp := 0
	sList := strings.Split(str, "")
	for i := 0; i < len(sList); i++ {
		if sList[i] == "A" || sList[i] == "C" || sList[i] == "G" || sList[i] == "T" {
			tmp++
		} else {
			max = fnMax(max, tmp)
			tmp = 0
		}
	}
	fmt.Println(fnMax(max, tmp))
}


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


int main() {
  int n, d;
  cin >> n >> d;
  long long x[n], y[n];
  for(int i = 0; i < n; i++){
    cin >> x[i] >> y[i];
  }
   double ans;
  int cnt = 0;
  for(int i = 0; i < n; i++){
    ans = sqrt(x[i]*x[i]+y[i]*y[i]);
    if(ans<=d)cnt++;
  }
  cout << cnt << endl;
}


Measured memory_bytes: 6700
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		char[] s = in.nextLine().toCharArray();
		long k = Long.parseLong(in.nextLine());
		System.out.println(solve(s, k));
		in.close();
	}

	private static char solve(char[] s, long k) {
		int index = getIndex(s);
		if (index < 0) {
			// すべて1で構成されている
			return '1';
		} else if (index > k - 1) {
			// １の範囲
			return '1';
		} else {
			return s[index];
		}
	}

	private static int getIndex(char[] s) {
		int result = -1;
		for (int i = 0; i < s.length; ++i) {
			if (s[i] != '1') {
				result = i;
				break;
			}
		}
		return result;
	}
}

Measured memory_bytes: 22996
// https://atcoder.jp/contests/abc076/tasks/abc076_a
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a, b;
    cin >> a >> b;
    cout << 2 * b - a << endl;

    return 0;
}


Measured memory_bytes: 256
import math
import os
import random
import re
import sys
from collections import defaultdict

# sys.stdin = open('input.in', 'r')
# sys.stdout = open('output.out', 'w') 

def count(n, h):
	count = 0
	if len(h) < 1:
		return count
	max = h[0]
	for i in h:
		if i >= max:
			max = i 
			count += 1

	return count

if __name__ == '__main__':
	n = int(input())
	h = list(map(int, input().rstrip().split()))
	print(count(n, h))

Measured memory_bytes: 4460
#include <iostream>

using namespace std;

int main(void){
  for(int n, count = 0; cin >> n; cout << count << endl, count = 0)
    for(int a = 0; a <= 9; a ++)
      for(int b = 0; b <= 9; b ++)
        for(int c = 0; c <= 9; c ++)
          for(int d = 0; d <= 9; d ++)
            if(a + b + c + d == n) count ++;

  return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ld long double
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using P=pair<long long,long long>;
#define rep(i,n) for(long long i=0; i<(long long)n; i++)
#define req(i,n) for(long long i=n-1; i>=0; i--)
#define range(i,a,b) for(long long i=a; i<b; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((long long)(x).size())
#define COUT(x) cout << x << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define onBoard(y,x) (y>=0 && y<h && x>=0 && x<w)
#define vint vector<int>
#define pri_que priority_queue
#define vvint vector<vector<int>>
#define vstr vector<string>
#define vp vector<pair<int,int>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define SUM(x) accumulate(x.begin(),x.end(),0)
#define MAX(x) *max_element(x.begin(),x.end())
#define MIN(x) *min_element(x.begin(),x.end())
#define couty cout<<"Yes"<<endl
#define coutn cout<<"No"<<endl
#define coutY cout<<"YES"<<endl
#define coutN cout<<"NO"<<endl
#define yn(x) cout<<(x?"Yes":"No")<<endl
#define YN(x) cout<<(x?"YES":"NO")<<endl
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a, long long b){return a/gcd(a,b)*b;}
const long long dx[8]={1,0,-1,0,1,-1,-1,1};
const long long dy[8]={0,1,0,-1,1,1,-1,-1};
const long long INF = 1e12;
const long long MOD = 1e9+7;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(15);

    int n,k; cin >> n >> k;
    vint a(n);
    rep(i,n) cin >> a[i];
    // vint s(n,1);
    // for(int i=k-1; i<n; i++){
    //     for(int j=i-k+1; j<=i; j++){
    //         s[i]*=a[j];
    //     }
    // }
    // for(int i=k-1; i<n-1; i++){
    //     if(s[i]<s[i+1]) cout<<"Yes"<<endl;
    //     else cout<<"No"<<endl;
    // }
    for(int i=k; i<n; i++){
        yn(a[i-k]<a[i]);
    }
}

Measured memory_bytes: 4772
k, x = map(int, input().split())			# "5 7" -> ["5", "7"] -> 5, 7 => N=5,K=7

x_min = -1000000
x_max =  1000000

l = x_min
r = x_max

l = max( l, x-k+1 )
r = min( r, x+k-1 )

for i in range(l, r+1):
	print(i, end=' ')

print("")



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

#define EPS 1e-6

int main() {
    int m;
    while (cin >> m, m) {
        double a1 = 0;
        int v_sum = 0;
        for (int i = 0; i < m-1; i++) {
            int v;
            cin >> v;
            a1 += sin(M_PI * v / 180.0);
            v_sum += v;
        }
        a1 += sin(M_PI * (360 - v_sum) / 180.0);
        int n;
        cin >> n;
        double a2 = 0;
        v_sum = 0;
        for (int i = 0; i < n-1; i++) {
            int v;
            cin >> v;
            a2 += sin(M_PI * v / 180.0);
            v_sum += v;
        }
        a2 += sin(M_PI * (360 - v_sum) / 180.0);
        int ans;
        if (fabs(a1 - a2) < EPS) {
            ans = 0;
        } else if (a1 > a2) {
            ans = 1;
        } else {
            ans = 2;
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 1196
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>

using namespace std;

typedef long long int lld;

const lld mod = 1e9+7;
const lld INF = 1e9;

int main()
{
	int n;
	string s;

	cin >> s;

	n = s.size();

	int P = 0;
	int score = 0;

	for(int i = 0; i < n; i++)
	{
		if (P > 0)
		{
			if (s[i] == 'g')
			{
				score++;
				P--;
			}else
			{
				P--;
			}
		}else
		{
			if (s[i] == 'p')
			{
				score--;
				P++;
			}else
			{
				P++;
			}
		}
	}

	cout << score << endl;

	return 0;
}

Measured memory_bytes: 512
S = list(input())

flag = 0
if 'N' in S:
    if 'S' not in S:
        flag = 1

if 'S' in S:
    if 'N' not in S:
        flag = 1

if 'W' in S:
    if 'E' not in S:
        flag = 1
        
if 'E' in S:
    if 'W' not in S:
        flag = 1

print(['Yes', 'No'][flag])


Measured memory_bytes: 3060
sorted_list = list(map(int, input().strip().split()))

count = 0
while True:
    sorted_list = sorted(sorted_list, reverse=True)
    if sorted_list[0] == sorted_list[1] and sorted_list[1] == sorted_list[2]:
        break

    count += 1
    if sorted_list[0] > sorted_list[1]:
        sorted_list[1] += 1
        sorted_list[2] += 1
    else:
        sorted_list[2] += 2


print(count)


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

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

    int ans = N / 2;
    if (N % 2 != 0) ++ans;

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


Measured memory_bytes: 256
n=int(input())
que=[3,5,7]
ans=0
def dfs(s):
  global ans
  if n<s:
    return
  
  s=str(s)
  if "3" in s and "5" in s and "7" in s:
    ans+=1
  
  s=int(s)
  for i in que:
   dfs(10*s+i)
  
  return ans
print(dfs(0))


Measured memory_bytes: 9172
#include <algorithm>
#include <iostream>
#include <numeric>
#include <type_traits>
#include <vector>
using namespace std;

template <class M, class N>
common_type_t<M, N> gcd(M a, N b) {
  if (b == 0) {
    return a;
  } else {
    return gcd(b, a % b);
  }
}

template <class M, class N>
common_type_t<M, N> lcm(M a, N b) {
  return a * b / gcd(a, b);
}

int main(int argc, const char *argv[]) {
  using ll = long long;
  int n, m;
  cin >> n >> m;
  m *= 2;

  vector<ll> va(n);
  for (auto &a : va) {
    cin >> a;
  }

  auto is_csm = [&](ll n) {
    return n <= m && all_of(va.begin(), va.end(), [&](auto a) {
             return n % a == 0 && n / a % 2 == 1;
           });
  };

  ll a_lcm = accumulate(va.begin(), va.end(), 1ll,
                        [](auto acc, auto cur) { return lcm(acc, cur); });
  ll ans = 0;
  ll min_csm = a_lcm;
  if (!is_csm(a_lcm)) {
    if (!is_csm(a_lcm * 2)) {
      cout << 0 << "\n";
      return 0;
    }

    min_csm *= 2;
  }

  for (ll i = min_csm; i <= m; i += a_lcm * 2) {
    ans++;
  }

  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 1024
I=lambda:list(map(int,input().split()))[::-1];m,n=I();l=[I()+[i]for i in range(m)];c=[0]*-~n;a=[0]*m
for y,p,i in sorted(l):c[p]+=1;a[i]='%06d'%p+'%06d'%c[p]
print('\n'.join(a))

Measured memory_bytes: 94168
n = int(input())
s = sorted(list(map(int,input().split())))
q = int(input())
t = list(map(int,input().split()))
c = 0
import bisect
for i in t:
    ind = bisect.bisect_left(s,i)
    if ind<n and s[ind]==i:
        c += 1
print(c) 


Measured memory_bytes: 16708
#include<stdio.h>

int main(){
	int i, j;
	
	for( i = 1 ; i <= 9 ; i++){
		for( j = 1 ; j <= 9 ; j++){
			printf("%dx%d=%d\n", i, j, i * j);
		}
	}
	
    return 0;
}


Measured memory_bytes: 2056
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		String s ;
		int ac=0;
		int wa = 0;
		int tle=0;
		int re = 0;

		for(int i=0 ; i<n ; i++) {
			s = sc.next();
			if(s.compareTo("AC")==0) {
				ac++;
			}else if(s.compareTo("WA")==0) {
				wa++;
			}else if(s.compareTo("TLE")==0) {
				tle++;
			}else {
				re++;
			}
		}

		System.out.println("AC x "+ac);
		System.out.println("WA x "+wa);
		System.out.println("TLE x "+tle);
		System.out.println("RE x "+re);


		sc.close();

	}

}


Measured memory_bytes: 58060
using System;
using System.Collections.Generic;
class Program
{
		static void Main(string[] args)
		{
			var s = Console.ReadLine().Split(' ');
			int a = int.Parse(s[0]);
			int b = int.Parse(s[1]);
			var l = Console.ReadLine().Split(' ');
			int w = 0;
			foreach (var c in l)
			{ w += (int.Parse(c)); }
			string r = (a <= w) ? "Yes" : "No";
			Console.WriteLine(r);
		}
}

Measured memory_bytes: 14432
/*Stay true to yourself, yet always be open to learn. Work hard, and never give up on your dreams, 
even when nobody else believes they can come true but you. These are not cliches but real tools you 
need no matter what you do in life to stay focused on your path.
*/
 
 /*Pppppppp    UU      UU     CCCCCCCC    CCCCCCCC     HH     HH     UU      UU
   pp    pp    UU      UU     CC          CC           HH     HH     UU      UU
   pp    pp    UU      UU     CC          CC           HHHHHHHHH     UU      UU
   pppppppp    UU      UU     CC          CC           HHHHHHHHH     UU      UU
   pp          UU      UU     CC          CC           HH     HH     UU      UU
   pp          UUUUUUUUUU     CCCCCCCC    CCCCCCCC     HH     HH     UUUUUUUUUU
   */
 
#include <bits/stdc++.h>
using namespace std;

#define int long long
typedef long long ll;
#define loop(i,n)  for(int i=0;i<n;i++)
#define ford(i,a,b) for(int i=b;i>=a;i--)
#define read(a) int a; cin >>a;
#define readarr(a,n) int a[n] ; for(int i=0;i<n;i++) cin >> a[i];
#define readmat(a,n,m) int a[n][m]; for(int i=0;i<n;i++) for(j=0;j<m;j++) cin >> a[i][j];
#define pb push_back
#define ff first
#define ss second
#define vi vector<int>
#define pi pair<int,int>
#define vii vector<vector<int>>
#define sti set<int>
#define vpi vector<pair<int,int>>
#define print(a,n) for(int i=0;i<n;i++) cout<<a[i]<<" "; cout<<endl;
#define printmat(a,n,m) for(int i=0;i<n;i++) {for(j=0;j<m;j++) cout<<a[i][j]<<" "; cout<<endl;}
#define fast ios_base::sync_with_stdio(false);  cin.tie(NULL);
#define endl "\n"
#define mp make_pair
const ll inf = 1e18;
const ll mod = 1e9 + 7;

signed main()
{

    fast;
    ll n,k;
    cin >> n >> k;
    int r;
     r = n%k;
     if(r>k-r)
     r = k-r;
    cout<<r<<endl;
    return 0;
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <string.h>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <queue>
#include <math.h>
#include <assert.h>
#define ff first
#define ss second
#define ll long long
#define mod 998244353
using namespace std;
int k, a, b;
int main () {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin>>k>>a>>b;
    for(int i=a;i<=b;i++) {
        if(i%k==0) {
            cout<<"OK";
            return 0;
        }
    }
    cout<<"NG";
}
/*
 2
 1 1
 1 0
 1 1
 1 1
 */


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


int main(){
  int n;
  cin >>n;
  int a[n];
  for(int i=0;i<n;i++){
    cin >>a[i];
  }
  int minimum=a[0];
  for(int i=0;i<n;i++){
    if(minimum>a[i])
      minimum=a[i];
  }
  int max=a[0];
  for(int i=0;i<n;i++){
    if(max<a[i])
      max=a[i];
  }
  long long int sum=0;
  for(int i=0;i<n;i++){
    sum+=a[i];
  }
  cout << minimum << " " << max << " " << sum << endl;
}

Measured memory_bytes: 1204
i = input()

i = int(i)

flg = False

while i != 0:
  check = i % 10
  if check == 7:
    flg = True
    break
  i = int(i / 10)

check = i % 10
if check == 7:
	flg = True

if flg == True:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 9180
#include<stdio.h>
#include<vector>
#include<string>
using namespace std;

int main(){
  int hh, ww;
  int h, w;
  scanf("%d", &hh); scanf("%d", &ww); scanf("%d", &h); scanf("%d", &w);
  int res = (hh*ww) - (h*ww + w*hh) + (h*w);
  printf("%d\n", res);
}

Measured memory_bytes: 128
/* ＵＴＦ－８ */
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <array>
#include <queue>
#include <stack>
#include <algorithm>
#include <tuple>
#include <numeric>
#include <type_traits>
#include <limits>

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>

#define USE_COLORED 1

#ifdef USE_COLORED
static const char stdout_pre[]  = "\033[1m"; // bold black
static const char stderr_pre[]  = "\033[31;1m"; // bold red
static const char stdxxx_post[] = "\033[m";

// 当然ながら GCC(g++)/libstdc++ 依存
#include <ext/stdio_filebuf.h>
using stdio_filebuf = __gnu_cxx::stdio_filebuf<char>;
class colored_stdio_filebuf : public stdio_filebuf {
private:
	const char* const pre_;
	const char* const post_;

public:
	colored_stdio_filebuf(FILE* fp, const char* pre, const char* post) : stdio_filebuf(fp, std::ios_base::out), pre_(pre), post_(post)
	{
	}

protected:
	std::streamsize xsputn(const char* s, std::streamsize count) override
	{
		stdio_filebuf::xsputn(pre_, strlen(pre_));
		auto ret = stdio_filebuf::xsputn(s, count);
		stdio_filebuf::xsputn(post_, strlen(post_));
		return ret;
	}
};
#endif

int main()
{
#ifdef USE_COLORED
	if (getenv("DEBUG")) {
		std::cout.rdbuf(new colored_stdio_filebuf(stdout, stdout_pre, stdxxx_post));
		std::cerr.rdbuf(new colored_stdio_filebuf(stderr, stderr_pre, stdxxx_post));
	} else
#endif
	{
		int fd = open("/dev/null", O_WRONLY);
		dup2(fd, 2);
		close(fd);
	}
	
	int A, B;
	std::string op;
	std::cin >> A >> op >> B;
	if (op == "+")
		std::cout << (A+B) << "\n";
	else
		std::cout << (A-B) << "\n";
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
void func(int,int,double,int);
int p,q,a,n,cnt;
double k;
 
int main(){
  while(1){
    cin>>p>>q>>a>>n;
    if(!p&&!q&&!a&&!n) break;
    k=1.0*p/q;
    cnt=0;
    func(0,1,0,1);
    cout<<cnt<<endl;
  }
  return 0;
}
 
void func(int x,int w,double y,int I){
  if(-0.00000001<=k-y&&k-y<=0.00000001) cnt++;
  if(x==n) return ;
  for(int i=I;w*i<=a;i++){
    if(y+1.0/i>k+0.0000001) continue;
    func(x+1,w*i,1.0/i+y,i);
  }
}

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

int main()
{
    int x;
    cin >> x;
    if (x == 3 || x == 5 || x == 7)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
m, a, r, c, h = 0, 0, 0, 0, 0
for i in range(N):
  s = str(input())
  if s[0] == 'M':
    m += 1
  elif s[0] == 'A':
    a += 1
  elif s[0] == 'R':
    r += 1
  elif s[0] == 'C':
    c += 1
  elif s[0] == 'H':
    h += 1
    
ans = m*a*r + m*a*c + m*a*h + m*r*c + m*r*h + m*c*h + a*r*c + a*r*h + a*c*h + r*c*h
print(ans)

Measured memory_bytes: 9060
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static long Mod = (long)1e9 + 7;
        static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            var N = Sarray()[0];
            var A = Sarray();
            var dct = new Dictionary<long, long>();
            dct[0] = 1;
            var sum = 0L;
            foreach(var a in A)
            {
                sum += a;
                if (!dct.ContainsKey(sum)) dct[sum] = 0;
                ++dct[sum];
            }
            var ans = 0L;
            foreach(var d in dct)
                ans += d.Value * (d.Value - 1) / 2;
            WriteLine(ans);
            //Out.Flush();
        }
    }
}

Measured memory_bytes: 40640
from sys import setrecursionlimit
setrecursionlimit(10 ** 9)

n, a, b = [int(i) for i in input().split()]

if bin(a ^ b).count('1') % 2 == 0:
    print('NO')
    exit()

def dfs(i, a, b):
    if i == 1:
        return [a, b]
    d = (a ^ b) & -(a ^ b)
    ad = ((a & (~d ^ d - 1)) >> 1) + (a & d - 1)
    bd = ((b & (~d ^ d - 1)) >> 1) + (b & d - 1)
    c = ad ^ 1

    res1 = dfs(i - 1, ad, c)
    res2 = dfs(i - 1, c, bd)
    ans1 = [((r & ~(d - 1)) << 1) + (r & d - 1) + (d & a) for r in res1]
    ans2 = [((r & ~(d - 1)) << 1) + (r & d - 1) + (d & b) for r in res2]
    return ans1 + ans2

print('YES')
print(*dfs(n, a, b))

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

using namespace std;

int main()
{
    int n;
    int f = 0;
    
    while (scanf("%d", &n) && n){
        if (f++ != 0) printf("\n");
        
        int a, b, c, d;
        
        scanf("%d %d %d %d", &a, &b, &c, &d);
        
        int mat[4] = {500, 100, 50, 10};
        int res[4] = {20, 20, 20, 20}, rsum = 80;
        int st[4] = {d, c, b, a};
        
        for (int i = n; i <= 20000; i += 10){
            int tmp[4] = {d, c, b, a};
            int x = i;
            for (int j = 0; j < 4; j++){
                while (tmp[j] && x >= mat[j]){
                    x -= mat[j];
                    tmp[j]--;
                }
            }
            if (!x){
                x = i - n;
                int tsum = 0;
                for (int j = 0; j < 4; j++){
                    while (x >= mat[j]){
                        x -= mat[j];
                        if (tmp[j] < st[j]) tmp[j]++;
                        else tsum++;
                    }
                    tsum += tmp[j];
                }
                if (tsum < rsum){
                    rsum = tsum;
                    memcpy(res, tmp, sizeof(tmp));
                }
            }
        }
        
        for (int i = 3; i >= 0; i--){
            if (st[i] - res[i] > 0) printf("%d %d\n", mat[i], st[i] - res[i]);
        }
    }
    
    return (0);
}

Measured memory_bytes: 1192
// インクルード
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <iomanip>

// 名前空間省略
using namespace std;

// メイン
int main()
{
	// 入出力の高速化
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	// 表示精度変更
	cout << fixed << setprecision(16);

    int n;
    cin >> n;
    int sum=0;
    for(int i=1;i<=n;i++) sum+=i;
    cout << sum << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os, const map<T,U>& mp){ os << "{"; for(auto& p : mp){ os << p << ","; } os << "}"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
using ll = long long;
using ull = unsigned long long;
using pii = std::pair<int,int>;
using vi = std::vector<int>;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

constexpr long long ten(int n){ return n == 0 ? 1 : 10*ten(n-1); }

int main(){
    ll n,m; cin >> n >> m;
    vector<ll> a(n); rep(i,n) cin >> a[i];
    sort(all(a));

    ll L,R;
    L = 0; // Ax+Ay>=Lとなるものの数はM以上
    R = ten(18); // Ax+Ay>=Rとなるものの数はM未満

    while(R-L>1){
        ll M = (L+R)/2;

        ll cnt = 0;
        rep(i,n){
            ll tmp = lower_bound(all(a), M - a[i]) - a.begin();
            cnt += n - tmp;
        }

        if(cnt >= m){ // OK
            L = M;
        }else{
            R = M;
        }
    }

    vector<ll> sum(n+1,0);
    rep(i,n){
        sum[i+1] = sum[i] + a[i];
    }

    ll ans = 0;
    // R以上
    ll cnt = 0;
    rep(i,n){
        ll idx = lower_bound(all(a), R-a[i]) - a.begin();
        ll num = n - idx;
        ans += num * a[i];
        ans += sum[n] - sum[idx];

        cnt += num;
    }

    ans += (m-cnt) * L;
    cout << ans << endl;
}


Measured memory_bytes: 1792
program tle
  implicit none
  integer :: n, t
  integer :: ci, ti
  integer :: i, min
  read(*,*) n, t
  min = 1001
  do i = 1, n
     read(*,*) ci, ti
     if (ti .le. t .and. ci .lt. min) min = ci
  end do
  if (min .ne. 1001) then
     write(*,'(i0)') min
  else
     write(*,'(a)') "TLE"
  end if
  stop
end program tle

Measured memory_bytes: 768
#include <bits/stdc++.h>
#define ll long long
#define re register int
#define For(i,a,b) for(ll i=(a); i<=(b); i++)
const int INF=1<<30;
const int mod=1e9+3;
using namespace std;

template <typename T>
inline void read(T &x) { 
    x = 0;
    ll f = 1;
    char ch = getchar();
    while (!isdigit(ch)) {
        if (ch == '-') f = -1;
        ch = getchar();
    }
    while (isdigit(ch)) {
        x = x * 10 + (ch ^ 48);
        ch = getchar();
    }
    x *= f;
    return;
}
template <typename T>
inline void write(T x){
    if(x < 0) {
        putchar('-');
        x = -x; 
    } 
    if(x > 9) 
        write(x/10); 
    putchar(x % 10 + '0'); 
    return; 
}
inline ll qpow(ll a,ll b){
    ll x=1,y=a;
    while(b>=1){
        if(b%2==1) x=x*y%mod;
        y=y*y%mod;
        b/=2;
    } 
    return x;
}

int main(){
    string a;
    cin>>a;
    int cnt=0;
    for(int i=0;i<a.size();i++){
        if(a[i]=='C'){
            cnt=1;
        }
        if(a[i]=='F'&&cnt==1){
            cout<<"Yes";
            return 0;
        }
    }
    cout<<"No";
    return 0;
}

Measured memory_bytes: 256
import itertools
n, m, q = map(int, input().split())
li = [list(map(int, input().split())) for _ in range(q)]
ml = list(range(1, m+1))
a_list = list(itertools.combinations_with_replacement(ml,n))
ans_l = []
for l in a_list:
    tmp = 0
    for a, b, c, d in li:
        if l[b-1] - l[a-1] == c:
            tmp += d
    ans_l.append(tmp)
print(max(ans_l))

Measured memory_bytes: 92196
#include <bits/stdc++.h>
using namespace std;
int main() {

	long long n,m, cnt = 0;
	cin >> n >> m;
	long long a[m],b[m],c[n]={},d[n]={};
	for (int i=0;i<m;i++){
		cin >> a[i] >> b[i];
		if(a[i]==1){
			c[b[i]-1]++;
			if(c[b[i]-1]>0&&d[b[i]-1]>0){
				cnt++;
			}
		}
		if(b[i]==n){
			d[a[i]-1]++;
			if(c[a[i]-1]>0&&d[a[i]-1]>0){
				cnt++;
			}
		}
	}
	if(cnt>0){
		cout << "POSSIBLE" << endl;
	}else{
		cout << "IMPOSSIBLE" << endl;
	}
	return 0;
}

Measured memory_bytes: 6528
#include <iostream>
#include<math.h>
#include <limits>
#include <iomanip>
#include <algorithm>
using namespace std;
#define rep(i, n) for (int i =2; i <= (int)(n); i++)


long long  A[211111];
long long dp[211111];
int main() {
    long long   N;
    cin >> N ;
    
    rep(i, N) {
        cin >> A[i];
     
        dp[A[i]] ++;
    }
    
    
    for (int i = 1; i <= N;++i)cout << dp[i] << endl;
    
    return 0;
}

Measured memory_bytes: 6756
/*
    Written by Nitrogens
    Desire for getting accepted!!
*/
#include <cstdio>
#include <ctime>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <queue>
#include <map>
#include <bitset>
#include <stack>
#include <set>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

const int maxn = 3e2+5;
const int Mod = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const double e = exp(1);
const db PI = acos(-1);
const db eps = 1e-9;

#define Se second
#define Fi first
#define pb push_back
#define dbg(x) cout<<#x<<" = "<< (x)<< endl
#define dbg2(x1,x2) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<endl
#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<" "<<#x3<<" = "<<x3<<endl

int cnt[4], n;
db dp[maxn][maxn][maxn];

db solve(int a, int b, int c)
{
    if(!a && !b && !c)                    return 0.0;
    if(fabs(dp[a][b][c] - 0.0) > eps)     return dp[a][b][c];
    int d = a + b + c;
    db cost = (1.0 * n) / (1.0 * d);
    db pa = (1.0 * a) / (1.0 * d);
    db pb = (1.0 * b) / (1.0 * d);
    db pc = (1.0 * c) / (1.0 * d);
    dp[a][b][c] = cost;
    if(a >= 1) dp[a][b][c] += pa * solve(a - 1, b, c);
    if(b >= 1) dp[a][b][c] += pb * solve(a + 1, b - 1, c);
    if(c >= 1) dp[a][b][c] += pc * solve(a, b + 1, c - 1);
    //dbg3(a, b, c);
    //dbg(dp[a][b][c]);
    return dp[a][b][c];
}

int main()
{
    //ios::sync_with_stdio(false);
    //freopen("a.txt","r",stdin);
    //freopen("b.txt","w",stdout);

    int input;
    scanf("%d", &n);

    for(int i = 1; i <= n; i++)
    {
        scanf("%d", &input);
        cnt[input]++;
    }
    dp[0][0][0] = 0.0;
    db answer = solve(cnt[1], cnt[2], cnt[3]);

    printf("%.10f\n", answer);

    //cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
    return 0;
}


Measured memory_bytes: 219392
#include <bits/stdc++.h>
using namespace std;
constexpr long long MOD = 1000000007;
constexpr long long INF = 1LL << 60;
const long double PI = acosl(-1.0);
using ll = long long;
// 多倍長テンプレ
/* ---------------------- ここから ---------------------- */
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
using Real = mp::number<mp::cpp_dec_float<1024>>;
/* ---------------------- ここまで ---------------------- */
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 main() {
    ll n;
    cin >> n;
    ll a[n];
    for (ll i = 0; i < n; i++) cin >> a[i];
    Bint sum = 1;
    sort(a, a + n);
    for (ll i = 0; i < n; i++) {
        sum*=a[i];
        if (sum>1000000000000000000) {
            cout << "-1" << endl;
            return 0;
        }
    }
    cout << sum << endl;

}


Measured memory_bytes: 4464
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
        char c = input.readLine().charAt(0);
        if (isVowel(c)) {
            System.out.println("vowel");
        } else {
            System.out.println("consonant");
        }
    }

    private static boolean isVowel(char c) {
        return c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u';
    }
}

Measured memory_bytes: 21460
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) FOR(i,0,b)
#define INF 1e9+10
#define dump(x) cerr<<#x<<"="<<x<<endl
#define all(a) (a).begin(),(a).end()
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<vii> viii;
typedef pair<int,int> P;
template <class T> void chmin(T & a, T const & b) { if (b < a) a = b; }
template <typename T>
string to_string(const T &n){ostringstream stm;stm << n;return stm.str();}
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
using ll = long long;
const ll mod = LLONG_MAX;

int N,k;
ll h[112345];
ll dp[112345];
signed main(){  
    cin>>N>>k;

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

    rep(i,N)dp[i]=INF;

    dp[1]=abs(h[1]-h[0]);
    dp[0]=0;


    for(int i=0;i<N;i++){
        for(int step=0;step<=k;step++){
            dp[i+step]=min(dp[i]+abs(h[i+step]-h[i]),dp[i+step]);
        }
    }
    






    cout<<dp[N-1]<<endl;

    

 
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);(i)++)
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);(i)--)
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);(i)--)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
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; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& input, vector<T>& v) { for (auto& elemnt : v)input >> elemnt; return input; }

class segtree {
    int n = 1; VI mindat, maxdat;
public:
    segtree(VI a) {
        int _n = a.size();
        while (n < _n)n *= 2;
        mindat.resize(2 * n - 1, INF);
        maxdat.resize(2 * n - 1, 0);
        FOR(i, 0, _n)mindat[i + n - 1] = maxdat[i + n - 1] = a[i];
        rFOR(i, 0, n - 1) {
            mindat[i] = min(mindat[2 * i + 1], mindat[2 * i + 2]);
            maxdat[i] = max(maxdat[2 * i + 1], maxdat[2 * i + 2]);
        }
    }
    int Min(int a, int b, int k, int l, int r) {
        if (b <= l || r <= a)return INF;
        if (a <= l && r <= b)return mindat[k];
        else {
            int s = Min(a, b, 2 * k + 1, l, (l + r) / 2);
            int t = Min(a, b, 2 * k + 2, (l + r) / 2, r);
            return min(s, t);
        }
    }
    int Min(int a, int b) { return Min(a, b, 0, 0, n); }
    int Max(int a, int b, int k, int l, int r) {
        if (b <= l || r <= a)return 0;
        if (a <= l && r <= b)return maxdat[k];
        else {
            int s = Max(a, b, 2 * k + 1, l, (l + r) / 2);
            int t = Max(a, b, 2 * k + 2, (l + r) / 2, r);
            return max(s, t);
        }
    }
    int Max(int a, int b) { return Max(a, b, 0, 0, n); }
};

int main() {
    init();

    int n, k;
    cin >> n >> k;
    VI p(n);
    FOR(i, 0, n)cin >> p[i];

    segtree seg(p);

    vector<bool> isSorted(n - k + 1);
    int cnt = 0, itr = 1;
    FOR(i, 0, n - k + 1) {
        while (itr < i + k) {
            if (p[itr - 1] > p[itr])cnt++;
            itr++;
        }
        isSorted[i] = (cnt == 0);
        if (p[i] > p[i + 1])cnt--;
    }

    vector<bool> New(n - k + 1, false);
    New[0] = true;
    FOR(i, 0, n - k) {
        int MAX = seg.Max(i, i + k);
        int MIN = seg.Min(i, i + k);
        New[i + 1] = !(p[i] == MIN && MAX < p[i + k]);
    }

    int ans = 0;
    bool plus = false;
    FOR(i, 0, n - k + 1) {
        if (isSorted[i])plus = true;
        else if(New[i])ans++;
    }
    if (plus)ans++;

    cout << ans << "\n";
}


Measured memory_bytes: 5888
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define N_MAX 200002

using namespace std;
typedef long long ll;
int N, M, K;
const ll MOD = 998244353;

ll inv[N_MAX],fac[N_MAX],finv[N_MAX];

void init(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<N_MAX;i++){
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        fac[i]=fac[i-1]*(ll) i%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}

ll inv_(ll n){
    if(n == 1) return 1;
    else return MOD-inv_(MOD%n)*(MOD/n)%MOD;
}

ll comb(ll n, ll r){
  ll ans;
  if(n < r){
      ans = 0;
  }else{
      ans = (fac[n]*finv[r])%MOD;
      ans = (ans*finv[n-r])%MOD;
      ans = (ans+MOD)%MOD;
  }
  return ans;
}

ll calc[200005];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    cin >> N >> M >> K;
    calc[0] = 1;
    calc[1] = M;
    init();
    for(int i = 2; i <= 200000; i++){
        calc[i] = (calc[i-1]*(M-1))%MOD;
    }
    ll ans = 0;
    for(int i = N-K; i <= N; i++){
        ll cb = comb(N-1, i-1);
        ans += (cb*calc[i])%MOD;
        ans %= MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 9904
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
#define mp make_pair
#define fast ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
#define ff first
#define ss second
#define INF (ll) (1e9)
#define mod (ll) (1e9 + 7)
#define endl "\n"
#define tt ll testcase; cin>>testcase; while(testcase--)
 
const int mxn = 1*(1e5) + 5;
ll n, m;
 
void solve(){
    ll x, k, d;
    cin >> x >> k >> d;
    ll r = abs(x)/d;
    ll ans = 0;
    if(r > k) {
        ans = abs(x) - abs(k*d);
    } else {
        ans = abs(x) - abs(r*d);
        if((k-r)%2) {
            ans = abs(ans-d);
        }
    }
    cout << ans;
}
 
int main(){
    fast;
    #ifndef ONLINE_JUDGE 
    freopen("input.txt", "r", stdin); 
    freopen("output.txt", "w", stdout); 
    #endif 
     // tt
        solve();
    return 0;
}

Measured memory_bytes: 3584
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <map>
#include <math.h>
using namespace std;
int a[1000000];
int main()
{  int k=1;
    for(int i=1;i<=100000;i++)
    {
        a[k]=i*i;
        k++;
    }
    long long n;
while(~scanf("%lld",&n))
{
    for(int i=1;i<k;i++)
    {
        if(n>=a[i]&&n<a[i+1])
        {
            printf("%d\n",a[i]);
            break;
        }
    }
}
    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define cs const
#define re register
#define pb push_back
#define pii pair<int,int>
#define ll long long
#define fi first
#define se second
#define bg begin
cs int RLEN=1<<20|1;
inline char gc(){
    static char ibuf[RLEN],*ib,*ob;
    (ib==ob)&&(ob=(ib=ibuf)+fread(ibuf,1,RLEN,stdin));
    return (ib==ob)?EOF:*ib++;
}
inline int read(){
    char ch=gc();
    int res=0;bool f=1;
    while(!isdigit(ch))f^=ch=='-',ch=gc();
    while(isdigit(ch))res=(res+(res<<2)<<1)+(ch^48),ch=gc();
    return f?res:-res;
}
inline ll readll(){
    char ch=gc();
    ll res=0;bool f=1;
    while(!isdigit(ch))f^=ch=='-',ch=gc();
    while(isdigit(ch))res=(res+(res<<2)<<1)+(ch^48),ch=gc();
    return f?res:-res;
}
inline int readstring(char *s){
	int top=0;char ch=gc();
	while(isspace(ch))ch=gc();
	while(!isspace(ch)&&ch!=EOF)s[++top]=ch,ch=gc();
	return top;
}
template<typename tp>inline void chemx(tp &a,tp b){a<b?a=b:0;}
template<typename tp>inline void chemn(tp &a,tp b){a>b?a=b:0;}
cs int mod=1e9+7;
inline int add(int a,int b){return (a+=b)>=mod?(a-mod):a;}
inline int dec(int a,int b){a-=b;return a+(a>>31&mod);}
inline int mul(int a,int b){static ll r;r=1ll*a*b;return (r>=mod)?(r%mod):r;}
inline void Add(int &a,int b){(a+=b)>=mod?(a-=mod):0;}
inline void Dec(int &a,int b){a-=b,a+=a>>31&mod;}
inline void Mul(int &a,int b){static ll r;r=1ll*a*b;a=(r>=mod)?(r%mod):r;}
inline int ksm(int a,int b,int res=1){for(;b;b>>=1,Mul(a,a))(b&1)&&(Mul(res,a),1);return res;}
inline int Inv(int x){return ksm(x,mod-2);}
inline int fix(int x){return (x<0)?x+mod:x;}
cs int N=1000005;
int n,a[N],p[N],pw[N];
char s[N];
int main(){
	#ifdef Stargazer
	freopen("lx.in","r",stdin);
	#endif
	n=read();
	readstring(s);
	int fg=1;
	for(int i=1;i<=n;i++){
		a[i]=s[i]-'1';
		if(a[i]==1)fg=0;
	}
	if(fg){
		for(int i=1;i<=n;i++)a[i]/=2;
	}
	for(int i=1;i<=n;i++)
	pw[i]=(i&1?0:pw[i>>1]+1),p[i]=(p[i-1]+pw[i]); 
	int res=0;
	for(int i=1;i<=n;i++)
	if(p[n-1]==p[i-1]+p[n-i])
	(res+=a[i])&=1;
	cout<<res*(fg+1)<<'\n';
}

Measured memory_bytes: 13952
#include<stdio.h>

#define N 2000

void solve(int,int);

int A[N];
int M[N];
int n,flag=0;

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

  for(i=0; i < q; i++){
    flag = 0;
    solve(0,M[i]);
    if(flag == 1){
      printf("yes\n");
    }else{
      printf("no\n");
    }
  }

  return 0;
}

void solve(int i,int m){
  if(m == 0){
    flag = 1;
  }else if(i < n){
    solve(i+1,m-A[i]);
    solve(i+1,m);
  }
}

Measured memory_bytes: 584