akhauriyash/Code-Regression huggingface dataset:
//#define _CRT_SECURE_NO_WARNINGS
#include<cstdio>
#include<cstdlib>
#include<cstring>

struct Node {
	int key;
	Node* prev, * next;
};

Node* nil;

Node* listSearch(int key) {
	Node* cur = nil->next;//从头节点后面的元素开始访问
	while (cur != nil && cur->key != key) {
		cur = cur->next;
	}
	return cur;
}

void init() {
	nil = (Node*)malloc(sizeof(Node));
	nil->prev = nil;
	nil->next = nil;
}

void printList() {
	Node* cur = nil->next;
	int isf = 0;
	while (1) {
		if (cur == nil) break;
		if (isf++ > 0)printf(" ");
		printf("%d", cur->key);
		cur = cur->next;
	}
	printf("\n");
}

void deleteNode(Node* t) {
	if (t == nil)return;
	t->prev->next = t->next;
	t->next->prev = t->prev;
	free(t);
}

void deleteFirst() {
	deleteNode(nil->next);
}

void deleteLast() {
	deleteNode(nil->prev);
}

void deleteKey(int key) {
	//删除搜索到的结点
	deleteNode(listSearch(key));
}

void insert(int key) {
	Node* x = (Node*)malloc(sizeof(Node));
	x->key = key;
	//在头结点后添加元素
	x->next = nil->next;
	nil->next->prev = x;
	nil->next = x;
	x->prev = nil;
}

int main() {
	int key, n, i;
	int size = 0;
	char com[20];
	int np = 0, nd = 0;
	scanf("%d", &n);
	init();
	for (i = 0; i < n; i++) {
		scanf("%s%d", com, &key);//使用效率更高的输入函数
		if (com[0] == 'i') { insert(key); np++; size++; }
		else if (com[0] == 'd') {
			if (strlen(com) > 6) {
				if (com[6] == 'F')deleteFirst();
				else if (com[6] == 'L') deleteLast();
			}
			else {
				deleteKey(key);
				nd++;
			}
			size--;
		}
	}

	printList();

	return 0;
}


Measured memory_bytes: 33832
#include <bits/stdc++.h>
#define f0(i, n) for(int i(0); i < (n); i++)
#define f1(i, n) for(int i(1); i <= n; i++)

using namespace std;
typedef long long ll;
const int N = 102;

int n, k;
int res = INT_MAX;

void solve(int i, int remain, int mi, int ma){
    if(ma - mi >= res) return ;
    if(remain < 0) return ;
    if(i > k){
        if(remain == 0) res = min(res, ma - mi);
        return ;
    }
    f1(j, remain){
        solve(i + 1, remain - j, min(j, mi), max(j, ma));
    }
}

int main(){
    ios_base::sync_with_stdio(0);

    cin >> n >> k;
    ///solve(1, n, INT_MAX, 0)
    if(n%k==0){
        cout << 0;
        return 0;
    }
    cout << 1;
}



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

using namespace std;

int main(){
	int d, n;
	cin >> d >> n;
	long long ans;
	if(d == 0){
		if(n != 100){
			cout << n << endl;
		}else if(n == 100){
			cout << "101" << endl;
		}
	}else if(d == 1){
		if( n == 100){
			cout << 100 * 101 << endl;			
		}else{
			cout << 100 * n << endl;
		}
	}else if(d == 2){
		if(n == 100){
			cout << 10000 * 101<< endl;
		}else{
			cout << 10000 * n << endl;
		}
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <climits>
#include <cmath>
#include <utility>
#include <string>
#include <cstring>
#include <functional>

using namespace std;

int main() {

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

    int k, n;
    cin >> k >> n;

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

    int res = k - a[n-1] + a[0];
    for (int i = 1; i < n; ++i) {
        res = max(res, a[i] - a[i-1]);
    }
	
    cout << k - res << endl;
	return 0;
}

Measured memory_bytes: 1152
a,b=map(int,input().split())
num_list=[i for i in range(10)]
num_list=[str(i) for i in num_list]
s=input()
if s[a]=="-":
    s=s[:a]+s[a+1:]
    for i in range(len(s)):
        if s[i] not in num_list:
            print("No")
            exit()
    print("Yes")
    exit()
print("No")

Measured memory_bytes: 9172
#include <iostream>

int main(void){
    int a,b;
    std::cin >> a >> b;
    for(int i=1;i<=3;i++){
        if((a*b*i) % 2 == 1){
            std::cout << "Yes" << std::endl;
            return 0;
        }
    }
    
    std::cout << "No" << std::endl;
    
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;

namespace AtCorder
{
	public class Program
	{
		static void Main(string[] args)
		{
			string s = Console.ReadLine();
			int n = s.Length;
			bool isN = false;
			bool isS = false;
			bool isE = false;
			bool isW = false;
			for (int i = 0; i < n; i++) {
				if (s[i] == 'N') {
					isN = true;
				} else if (s[i] == 'S') {
					isS = true;
				} else if (s[i] == 'E') {
					isE = true;
				} else {
					isW = true;
				}
			}

			if ((isN && isS && isE && isW)
				|| ((isN && isS) && (isE == false && isW == false))
				|| ((isE && isW) && (isN == false && isS == false))) {
				Console.WriteLine("Yes");
			} else {
				Console.WriteLine("No");
			}
		}
	}
}

Measured memory_bytes: 11092
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
	int a,b,minn,maxn;
	cin >> a >> b;
	maxn=max(a,b);
	minn=min(a,b);
	while(1){
	    a=maxn%minn;
	    if(a==0){
	        cout << minn<<endl;
	        return 0;
	    }
	    maxn=minn;
	    minn=a;
	}
	
}

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

int main(){
	int n;
	cin >> n;
	vector<int> a(n);
	for(int i=0; i<n; i++){
		cin >> a[i];
	}
	sort(a.begin(), a.end(), greater<int>());
	int alice = 0;
	int bob = 0;
	for(int i=0; i<n; i+=2){
		alice += a[i];
		bob += a[i+1];
	}
	cout << alice - bob << endl;
	return 0;
}

Measured memory_bytes: 256
/**********************************************************************
   File hoge.cpp
   Author  harunaya
   Date   2020-03-06(Fri)
   note
**********************************************************************/

#include <bits/stdc++.h>
using namespace std;

int main() {
  int r, D, x2000;
  cin >> r >> D >> x2000;

  int x2001 = r * x2000 - D;
  int x2002 = r * x2001 - D;
  int x2003 = r * x2002 - D;
  int x2004 = r * x2003 - D;
  int x2005 = r * x2004 - D;
  int x2006 = r * x2005 - D;
  int x2007 = r * x2006 - D;
  int x2008 = r * x2007 - D;
  int x2009 = r * x2008 - D;
  int x2010 = r * x2009 - D;

  cout << x2001 << endl;
  cout << x2002 << endl;
  cout << x2003 << endl;
  cout << x2004 << endl;
  cout << x2005 << endl;
  cout << x2006 << endl;
  cout << x2007 << endl;
  cout << x2008 << endl;
  cout << x2009 << endl;
  cout << x2010 << endl;

}


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

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define fo(i, a, b) for(int i = a; i < b; i++)
#define SQ(a) (a)*(a)

int summation(int A[], int n){
    int s = 0; 
    for(int i = 0; i < n; i++){
        s += A[i];
    }
    return s;
}
int main(){
    int n, m; cin>> n >> m;
    int a[m];
    for(int i = 0; i < m; i++) cin>> a[i];
    int sum = summation(a, m);
    if(sum > n) cout<< -1 << "\n";
    else cout << n-sum << "\n";
}



Measured memory_bytes: 3676
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author silviase
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ATheNumberOfEvenPairs solver = new ATheNumberOfEvenPairs();
        solver.solve(1, in, out);
        out.close();
    }

    static class ATheNumberOfEvenPairs {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int m = in.nextInt();
            out.println(n * (n - 1) / 2 + m * (m - 1) / 2);
        }

    }
}



Measured memory_bytes: 24276
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>

#pragma GCC optimize("Ofast")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printin(a) printf(a ? "possible\n" : "inposible\n")
#define printdb(a) printf("%.50lf\n", a)//少数出力
#define printdbd(a) printf("%.16lf\n", a)//少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str())//string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2)//等差数列の和、初項,末項,項数
#define pb push_back
#define priq priority_queue
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg)/360.0)*2.0*PI)
#define rad_to_deg(rad) (((rad)/2.0/PI)*360.0)
#define Please return
#define AC 0

using ll = long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1000000007;
const double PI = acos(-1);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);//最初の改行対策
	while (c != '\n' && c != -1) {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

/*-----------------------------------------ここからコード-----------------------------------------*/


int main() {
	
	int n;
	cin >> n;
	bool b = false;
	rep1(i, 100000) {
		if (n == (int)floor((double)i * ((double)108 / (double)100))) {
			printf("%d\n", i);
			return 0;
		}
	}
		printf(":(\n");

	Please AC;
}


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

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define fst first
#define snd second
#define pf push_front
#define pb push_back
#define eb emplace_back
#define all(obj) (obj).begin(), (obj).end()
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
//#define int long long int
const int MOD = 1000000007;
const ll LINF = (ll)1e18 - 1;
const int INF = 1e9 - 1;
const double EPS = 0.000000001;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

VVI dp(100003, VI(13));

signed main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  int n = s.size();
  if(s[0] == '?') rep(i, 10) dp[0][i] = 1;
  else dp[0][s[0] - '0'] = 1;
  rep(i, n-1){
    if(s[i+1] != '?'){
      int c = s[i+1] - '0';
      rep(j, 13){
        int idx = (j * 10 + c) % 13;
        dp[i+1][idx] = (dp[i+1][idx] + dp[i][j]) % MOD;
      }
    }
    else{
      rep(j, 13){
        rep(k, 10){
          int idx = (j * 10 + k) % 13;
          dp[i+1][idx] = (dp[i+1][idx] + dp[i][j]) % MOD;
        }
      }
    }
  }
  out(dp[n-1][5]);
  return 0;
}


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

#define FOR(i,n,j) for(int i=(j);i<(n);++i)
#define ssort(n) sort((n).begin(),(n).end())
#define rsort(n) sort((n).begin(),(n).end(),greater<ll>())
using ll=long long;
using ld=long double;
typedef pair<int,int> P;
typedef pair<P,int> COST;
#define repl(i,n) for(ll i=0;i<(n);++i)
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
using Graf=vector<vector<int>>;

int main()
{
    int n,m;
    cin >> n >> m;
    vector<int> x(m),y(m);
    vector<int> ball(n,1);
    vector<bool> red_ball(n,false);
    int a,b;
    rep(i,m){
        cin >> a >> b;
        a--;b--;
        x[i]=a;y[i]=b;
    }

    red_ball[0]=true;
    rep(i,m){
        ball[y[i]]++;
        ball[x[i]]--;
        if(red_ball[x[i]]==true){
            if(red_ball[y[i]]==false){
                red_ball[y[i]]=true;
            }
            if(ball[x[i]]==0)
                red_ball[x[i]]=false;
        }

    }
    int count=0;
    rep(i,n){
        if(red_ball[i]==true){
            count++;
        }
    }
    cout << count << endl;
}

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

using namespace std;

int main()
{
    int n;
    cin >> n;
    int ans = 0;
    for (int i = 1; i <= n; i++)
    {
        int x;
        cin >> x;
        if (i % 2 == 1 && x % 2 == 1) ans++;
    }
    cout << ans << endl;
}

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

#define pb push_back
#define all(x) (x).begin(), (x).end()
#define for1(i, a, b) for (int i = (int)a; i < (int)(b); ++i)
#define rfor1(i, a, b) for (int i=(int)b-1;i>=(int)a;i--)
#define for2(i, a, b) for (int i = (int)a; i <= (int)(b); ++i)
#define for3(i, a, b) for (int i = (int)a; i < (int)(b); i=i+2)
#define for4(i, a, b) for (int i = (int)a; i <= (int)(b); i=i+2)
#define tc(t) int t; cin>>t; while(t--)
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;cin>>n;
    cout <<"ABC"<<n<<endl;

}









Measured memory_bytes: 3612
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define MOD 1000000007

// x^n
ll mod_pow(ll x, ll n) {
  if (n == 0) return 1;
  ll res = mod_pow(x * x % MOD, n / 2);
  if (n & 1) res = res * x % MOD;
  return res;
}

// x^{-1}
ll mod_inv(ll x) { return mod_pow(x, MOD - 2); }

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  map<int, int> mp;
  for (int i = 0; i < n; ++i) {
    int m = a[i];
    map<int, int> mp2;
    for (int j = 2; j * j <= m; ++j) {
      while (m % j == 0) {
        mp2[j]++;
        m /= j;
      }
    }
    if (m != 1) {
      mp2[m]++;
    }
    for (auto a : mp2) {
      mp[a.first] = max(mp[a.first], mp2[a.first]);
    }
  }
  ll l = 1;
  for (auto a : mp) {
    l = (l * mod_pow(a.first, a.second)) % MOD;
  }
  ll sum = 0;
  for (int i = 0; i < n; ++i) {
    sum = (sum + mod_inv(a[i])) % MOD;
  }
  cout << (l * sum) % MOD << endl;
  return 0;
}

Measured memory_bytes: 768
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include<algorithm>
#include <iomanip>

using namespace std;
typedef long long ll;
///定義場所///
int i, j, k, l, m, n;
int N, M, K;
ll MOD = 1000000007;
ll ans = 0;

//関数リスト//
int ctoi(char c) {
	switch (c) {
	case '0': return 0;
	case '1': return 1;
	case '2': return 2;
	case '3': return 3;
	case '4': return 4;
	case '5': return 5;
	case '6': return 6;
	case '7': return 7;
	case '8': return 8;
	case '9': return 9;
	default: return 0;
	}
}
//(注)pairの型・比較する場所(first/second)は毎回変えて使用する
bool pairCompare(const pair<ll, ll> firstElof, pair<ll, ll> secondElof)
{
	return firstElof.second > secondElof.second;
}
//////////////
int main()
{
	cin >> N >> M;
	ll X[1000], Y[1000], Z[1000];
	for (i = 0; i < N; i++) {
		cin >> X[i] >> Y[i] >> Z[i];
	}
	vector<ll>sum(N, 0);
	for (i = 0; i < 8; i++) {
		switch (i) {
		case(0):
			for (j = 0; j < N; j++) {
				sum[j] = X[j] + Y[j] + Z[j];
			}
			break;
		case(1):
			for (j = 0; j < N; j++) {
				sum[j] = -X[j] + Y[j] + Z[j];
			}
			break;
		case(2):
			for (j = 0; j < N; j++) {
				sum[j] = X[j] - Y[j] + Z[j];
			}
			break;
		case(3):
			for (j = 0; j < N; j++) {
				sum[j] = X[j] + Y[j] - Z[j];
			}
			break;
		case(4):
			for (j = 0; j < N; j++) {
				sum[j] = -X[j] - Y[j] + Z[j];
			}
			break;
		case(5):
			for (j = 0; j < N; j++) {
				sum[j] = -X[j] + Y[j] - Z[j];
			}
			break;
		case(6):
			for (j = 0; j < N; j++) {
				sum[j] = X[j] - Y[j] - Z[j];
			}
			break;
		case(7):
			for (j = 0; j < N; j++) {
				sum[j] = -X[j] - Y[j] - Z[j];
			}
			break;
		}
		sort(sum.begin(), sum.end());
		reverse(sum.begin(), sum.end());
		ll pre = 0;
		for (j = 0; j < M; j++) {
			pre += sum[j];
		}
		ans = max(ans, pre);
	}
	cout << ans;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
a, b, c, d = [], [], [], []
for i in range(n) :
  ai, bi = map(int, input().split())
  a.append(ai), b.append(bi)
for i in range(m) :
  ci, di = map(int, input().split())
  c.append(ci), d.append(di)

for i in range(n) :
  cost, ans = 10**18, 0
  for j in range(m) :
    if cost > abs(a[i] - c[j]) + abs(b[i] - d[j]) :
      cost = abs(a[i] - c[j]) + abs(b[i] - d[j])
      ans = j+1
  print(ans)


Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#define REP(i,n) for(int i = 0;i < (n);i++)
#define pb push_back
using namespace std;
const int INF = 1e9;
typedef long long ll;

int main(){
  int n;
  cin >> n;
  string s;
  cin >> s;
  int res = 0;
  REP(i,s.size()){
    if(s[i] == '(')
      res++;
    else
      res--;
    if(res < 0){
      s.insert(s.begin(),'(');
      i++;
      res++;
    }
    //cout << i << endl;
    //cout << s << endl;
    //cout << res << endl;
  }
  if(res > 0){
    REP(i,res){
      s.insert(s.end(),')');
    }
  }
  cout << s << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int swap(int *a, int *b)
{
	int tmp = *a;
	*a = *b;
	*b = tmp;
	return (0);
}

int main(void)
{
	int lot[64];
	int w, n;
	int f, t;
	int i;

	scanf("%d %d", &w, &n);
	for (i = 1; i <= w; i++) lot[i] = i;
	for (i = 0; i < n; i++){
		scanf("%d,%d", &f, &t);
		swap(lot + f, lot + t);
	}
	for (i = 1; i <= w; i++) printf("%d\n", lot[i]);

	return 0;
}

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

using namespace std;

//#define int long long

using ll = long long;
using pii =  pair<int, int>;

const int IINF =  0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const int INF = sizeof(int) == sizeof(long long) ? LINF : IINF;
const ll MOD = 1e9+7;

#define for_(i,a,b) for(int i = (a);i < (b);i++)
#define rfor_(i,a,b) for(int i = (b)-1;i >= (a);i--)

#define rep(i,n) for_(i,0,n)
#define rrep(i,n) rfor_(i,0,n)

#define pb push_back
//#define eb emplace_back
#define mp make_pair
#define ft first
#define sd second

#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define rev(a) reverse(all(a))

#define endl '\n'

int main(int argc, char const* argv[])
{
    int a, b, c;
    cin >> a >> b >> c;

    if (a == b) {
        cout << c << endl;
    } else if (b == c) {
        cout << a << endl;
    } else if (a == c) {
        cout << b << endl;
    }
    return 0;
}


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

int main(){
  int n;
  cin >> n;
  vector<string> a(n);
  for(int i=0;i<n;i++)
    cin >> a.at(i);
  
  sort(a.begin(),a.end());
  
  int k=1;
  for(int i=1;i<n;i++){
    if(a.at(i)!=a.at(i-1))
      k++;
  }
  cout << k << endl;
}

Measured memory_bytes: 9512
#include <bits/stdc++.h>
using namespace std;
#define all(v) (v).begin(), (v).end()
#define lp(i, n) for (int i = 0; i < (n) ; ++i)
#define sz(v) (int)(v).size()
#define ll long long
#define mod 1000000007

int main(){
ios::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL);
        int n; cin >> n;
        int an = 0, cur = -1, mx = -1;
        lp(i, n) { int a; cin >> a; if (a > cur) { mx = max(mx, an); an = 0; } else an++; cur = a; }
        mx = max(mx, an);
        cout << mx;
return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
#define TRUE 1
#define MAX (2001 * 2001)
int sum,a[MAX],flag[MAX],datanum;
void allsearch(int num,int sum){
  if(num == datanum){
    flag[sum] = TRUE;
    return;
  }
  allsearch(num+1,sum);
  allsearch(num+1,sum + a[num]);
}

int main(){
  int temp,checknum,i,j;
  scanf("%d",&datanum);
  for(i=0;i<datanum;i++)scanf("%d",&a[i]);
  allsearch(0,0);
  scanf("%d",&checknum);
  for(i=0;i<checknum;i++){
    scanf("%d",&temp);
    if(flag[temp] == TRUE)printf("yes\n");
    else printf("no\n");
  }
  return 0;
}



Measured memory_bytes: 2108
#include "bits/stdc++.h"
using namespace std;

#define all(x)  x.begin(), x.end()
#define mp      make_pair
#define pii     pair<int, int>
#define pll     pair<long long, long long>
#define ll      long long

static const int MOD = 998244353;

#define N 4040

int Len(const bitset<N> &a) {
        for (int res = N - 1; res >= 0; res --) {
                if (a[res]) return res + 1;
        }
        return 0;
}

bitset<N> gcd(bitset<N> s, bitset<N> t) {
        int n = Len(s), m = Len(t);
        if (n < m) return gcd(t, s);
        if (t.none()) return s;
        int d = n - m;
        bitset<N> u = t;
        u <<= d;
        s ^= u;
        return gcd(t, s);
}

long long ModPow(long long x, long long n, long long m) {
        long long res = 1;
        while (n > 0) {
                if (n & 1) res = res * x % m;
                x = x * x % m;
                n >>= 1;
        }
        return res;
}

int main() {
        int q;
        scanf("%d", &q);
        bitset<N> x;
        cin >> x;
        bitset<N> g;
        for (int i = 0; i < q; i ++) {
                bitset<N> s;
                cin >> s;
                g = gcd(g, s);
        }
        int n = Len(x);
        bitset<N> d(0);
        int m = Len(g);
        int ans = 0;
        for (int i = n - 1; i >= m - 1; i --) {
                if (x[i]) ans = (ans + ModPow(2, i - m + 1, MOD)) % MOD;
                if (x[i] == d[i]) continue;
                d ^= (g << i - m + 1);
        }
        bool ok = true;
        for (int i = n - 1; i >= 0; i --) {
                if (d[i] < x[i]) break;
                if (d[i] > x[i]) ok = false;
        }
        printf("%d\n", ans + ok);
        return 0;
}


Measured memory_bytes: 12416
// ABC 118 B
#include<bits/stdc++.h>

using namespace std;
//container util
//------------------------------------------
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define PB(a) push_back(a)
#define ALL(x) (x).begin(),(x).end()

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;


int main(){
// magic spell------------------------------
  cin.tie(0);
  ios::sync_with_stdio(false);
//------------------------------------------

  int n,m,k,c;
  int ret=0;
  cin  >>  n >> m;
  VI a(m,0);
  REP(i,n){
    cin >> k; 
    REP(j,k){
     cin >> c; 
     a[c-1]++;
    }
  }
  REP(i,m){
    if(a[i]==n){
      ret++;
    }
  }
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 256
H, W = map(int, input().split())
field = [input() for _ in range(H)]
ans = [["."] * W for _ in range(H)]
for i in range(H):
    for j in range(W):
        if field[i][j] == "#":
            ans[i][j] = "#"
            continue
        cnt = 0
        for di, dj in ((1, 0), (1, -1), (0, -1), (-1, -1), (-1, 0), (-1, 1), (0, 1), (1, 1),):
            ni = i + di
            nj = j + dj
            if 0 <= ni < H and 0 <= nj < W and field[ni][nj] == "#":
                cnt += 1
        ans[i][j] = str(cnt)
[print("".join(row)) for row in ans]


Measured memory_bytes: 3188
import sys
read = sys.stdin.buffer.read
input = sys.stdin.readline
input = sys.stdin.buffer.readline


#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode('utf-8')

#
#import numpy as np

from itertools import combinations

def main():
	k,n=MI()
	A=LI()
	ans=A[-1]-A[0]

	for i in range(n-1):
		ans=min(ans,A[i]+k-A[i+1])

	print(ans)





if __name__ == "__main__":
	main()

Measured memory_bytes: 20460
#include<bits/stdc++.h>
using namespace std;
vector<pair<int, int> > v;
int main()
{
	int n;
	scanf("%d",&n);
	while(n--)
	{
		int x, y;
		scanf("%d%d",&x,&y);
		v.push_back(make_pair(x, y)); 
	}
	sort(v.begin(), v.end());
	int i;
	for(i=0; i<v.size(); i++) printf("%d %d\n",v[i].first, v[i].second);
	return 0;
}


Measured memory_bytes: 3888
package main

import (
	"bufio"
	"bytes"
	"fmt"
	"io"
	"io/ioutil"
	"math"
	"os"
	"path/filepath"
	"runtime"
	"strings"
)

func main() {
	b, _ := ioutil.ReadAll(os.Stdin)
	if len(b) == 0 {
		test()
	} else {
		solve(bytes.NewReader(b), os.Stdout)
	}
}

func solve(r io.Reader, w io.Writer) {
	var n, a int
	fmt.Fscanln(r, &n, &a)
	time := n
	// k-1: count of eating cookies.
	// k <= log2(n) because
	//   - shortest eating interval is 2
	for k := 1; k <= int(math.Ceil(math.Log2(float64(n)))); k++ {
		s := int(math.Ceil(math.Pow(float64(n), 1/float64(k))))
		c := 0
		for ; c <= k; c++ { // TODO: binary search should be better
			if n <= pow((s-1), (k-c))*pow(s, c) {
				break
			}
		}
		t := (k-1)*a + s*c + (s-1)*(k-c)
		if t < time {
			time = t
		}
	}
	fmt.Fprintln(w, time)
}

func test() {
	tests := []struct {
		in   string
		want string
	}{
		{in: `8 1`, want: `7`},
		{in: `1000000000000 1000000000000`, want: `1000000000000`},
		// {in: `10 10`, want: `10`},
		// {in: `100 0`, want: `13`},
		// {in: `100 1`, want: `16`},
		// {in: `100 2`, want: `19`},
		// {in: `100 3`, want: `22`},
		// {in: `100 4`, want: `25`},
		// {in: `100 5`, want: `28`},
		// {in: `100 6`, want: `30`},
	}
	for i, tt := range tests {
		fmt.Printf("=== TEST %d\n", i)
		buf := new(bytes.Buffer)
		solve(strings.NewReader(chomp(tt.in)), buf)
		if got, want := chomp(buf.String()), chomp(tt.want); got != want {
			fmt.Printf("%d: got %v, want %v\n", i, got, want)
		}
	}
}

func chomp(s string) string {
	return strings.Trim(s, "\n")
}

func assert(b bool) {
	if !b {
		_, file, line, ok := runtime.Caller(1)
		if ok {
			f, _ := os.Open(file)
			defer f.Close()
			s := bufio.NewScanner(f)
			lnum := 0
			for s.Scan() {
				lnum++
				if lnum == line {
					wd, _ := os.Getwd()
					fname, _ := filepath.Rel(wd, file)
					fmt.Printf("assertion fails: %s:%d: %v\n", fname, line, s.Text())
					break
				}
			}
		}
	}
}

func pow(a, b int) int {
	r := 1
	for i := 0; i < b; i++ {
		r *= a
	}
	return r
}


Measured memory_bytes: 640
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations,groupby
import sys
import bisect
import string
import math
import time
import random
def S_():
    return input()
def LS():
    return [i for i in input().split()]
def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def NI(n):
    return [int(input()) for i in range(n)]
def NI_(n):
    return [int(input())-1 for i in range(n)]
def StoI():
    return [ord(i)-97 for i in input()]
def ItoS(nn):
    return chr(nn+97)
def LtoS(ls):
    return ''.join([chr(i+97) for i in ls])
def GI(V,E,Directed=False,index=0):
    org_inp=[]
    g=[[] for i in range(n)]
    for i in range(E):
        inp=LI()
        org_inp.append(inp)
        if index==0:
            inp[0]-=1
            inp[1]-=1
        if len(inp)==2:
            a,b=inp
            g[a].append(b)
            if not Directed:
                g[b].append(a)
        elif len(inp)==3:
            a,b,c=inp
            aa=(inp[0],inp[2])
            bb=(inp[1],inp[2])
            g[a].append(bb)
            if not Directed:
                g[b].append(aa)
    return g,org_inp
def GGI(h,w,search=None,replacement_of_found='.',mp_def={'#':1,'.':0}):
#h,w,g,sg=GGI(h,w,search=['S','G'],replacement_of_found='.',mp_def={'#':1,'.':0}) # sample usage
    mp=[1]*(w+2)
    found={}
    for i in range(h):
        s=input()
        for char in search:
            if char in s:
                found[char]=((i+1)*(w+2)+s.index(char)+1)
                mp_def[char]=mp_def[replacement_of_found]
        mp+=[1]+[mp_def[j] for j in s]+[1]
    mp+=[1]*(w+2)
    return h+2,w+2,mp,found
def bit_combination(k,n=2):
    rt=[]
    for tb in range(n**k):
        s=[tb//(n**bt)%n for bt in range(k)]
        rt+=[s]
    return rt
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['Yes','No']
mo=10**9+7
inf=float('inf')
l_alp=string.ascii_lowercase
u_alp=string.ascii_uppercase
ts=time.time()
sys.setrecursionlimit(10**7)
input=lambda: sys.stdin.readline().rstrip()

def ran_input():
    import random
    n=random.randint(4,16)
    rmin,rmax=1,10
    a=[random.randint(rmin,rmax) for _ in range(n)]
    return n,a

show_flg=False
show_flg=True

ans=0
k,s=LI()
for x in range(k+1):
    for y in range(k+1):
        if 0<=s-x-y<=k:
            ans+=1

print(ans)

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

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;

using namespace std;


int main(int argc, const char * argv[]) {
    // source code
    int n , m;
    cin >> n >> m;
    vector<int> a(m);
    vector<int> c(m, 0);
    rep(i, m) {
        int b;
        cin >> a[i] >> b;
        rep (j, b) {
            int tmp_c;
            cin >> tmp_c;
            c[i] += (1 << --tmp_c);
        }
    }

    vector<int> dp(1 << n, 1e7);
    dp[0] = 0;
    rep (j, m) rep (i, 1 << n) {
        int t = i | c[j];
        dp[t] = min(dp[t], dp[i] + a[j]);
    }
    if (dp[(1 << n) - 1] == 1e7) cout << -1;
    else cout << dp[(1 << n) - 1];
    return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int a[200001], n,f[200001],ans;
bool b[200001];
int jShu;

int main(){
	cin>>n;
	for(int i=1; i<=n; i++) cin>>a[i],f[i]=1;
	for(int i=1;i<=n;i++)
	{
		b[a[i]]=true;
		if(b[a[i]-1]) f[a[i]]=max(f[a[i]],f[a[i]-1]+1);
		ans=max(f[a[i]],ans);
	}

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


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

#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define spa << " " <<
ll MOD = 1e9+7;
ll INF = 1e18;
void chmin(ll &a, ll b) { if (a > b) a = b; }
void chmax(ll &a, ll b) { if (a < b) a = b; }

int main(){
  ll i, j;
  ll n, m;
  cin >> n >> m;
  //vector<ll> x(n), y(n), z(n);
  vector<ll> buf(n);
  ll s[8][n];
  ll x, y, z;
  ll xbuf, ybuf, zbuf;
  for(i = 0; i < n; i++){
    cin >> x >> y >> z;
    for(j = 0; j < 8; j++){
      xbuf = x; ybuf = y; zbuf = z;
      if(j % 2 == 1)
        xbuf *= -1;
      if((j >> 1) % 2 == 1)
        ybuf *= -1;
      if((j >> 2) % 2 == 1)
        zbuf *= -1;
      s[j][i] = xbuf + ybuf + zbuf;
      //cout << j spa xbuf spa ybuf spa zbuf << endl;
      //cout << s[j][i] << endl;
    }
  }
  ll result = 0;
  ll sumbuf = 0;
  for(i = 0; i < 8; i++){
    for(j = 0; j < n; j++)
      buf[j] = s[i][j];
    sort(ALL(buf));
    reverse(ALL(buf));
    for(j = 0, sumbuf = 0; j < m; j++)
      sumbuf += buf[j];
    //cout << sumbuf << endl;
    chmax(result, sumbuf);
  }
    
  
  
  
  cout << result << endl;

  return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());

        // 主処理
        boolean judge = a <= 8 && b <= 8;
        String result = judge ? "Yay!" : ":(";

        // 出力
        System.out.println(result);
        sc.close();
    }
}


Measured memory_bytes: 21972
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rrep(i,n) for(int i=1; i<=(int)(n); i++)
#define pb push_back
#define all(v) v.begin(),v.end()
#define fi first
#define se second
#define bigger (char)toupper
#define smaller (char)tolower
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef vector<char> vc;
typedef long long ll;
typedef unsigned long long ull;

//const ll mod=1000000007;

int main() {
    int N;
    cin>>N;
    vi v(26,0);
    string s;
    cin>>s;
    rep(i,s.size()) {
        v[s[i]-'a']++;
    }
    rep(i,N-1) {
        string S;
        cin>>S;
        vi c(26,0);
        rep(j,S.size()) c[S[j]-'a']++;
        rep(j,26) {
            v[j]=min(v[j],c[j]);
        }
        rep(j,26) c[j]=0;
    }
    rep(i,26) {
        if(v[i]==0) continue;
        else {
            rep(j,v[i]) cout<<char(i+'a');
        }
    }
    cout<<endl;
}

Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        s: usize,
        w: usize
    }
    println!("{}", if s > w {"safe"} else {"unsafe"});
}


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

using namespace std;


void solve() {
    int n, X,Y;
    cin >> n >> X >> Y;
    vector<int> a(n+1);
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }

    const int INF = 0x3f3f3f3f;
    int sufA = 0;
    int sufB = INF;
    int res = abs(a[n] - Y);
    for (int i = n-1; i >= 1; i--) {
        int ta = abs(a[i] - a[n]);
        ta = min(ta, sufB);
        int tb = abs(a[i] - a[n]);
        tb = max(tb, sufA);
        sufA = max(sufA, ta);
        sufB = min(sufB, tb);
    }
    res = max(res, sufA);
    cout << res;
}

void solve2(){
    int n, X,Y;
    cin >> n >> X >> Y;
    vector<int> a(n+1);
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    int res = abs(a[n] - Y);
    if (n>=2) res = max(res, abs(a[n-1]-a[n]));
    cout << res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve2();
    cout << endl;
}


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

int main()
{
    int n, h;
    cin >> h >> n;
    vector<int> a(n), b(n);
    rep(i,n) cin >> a[i] >> b[i];

    //dp[i][j] i番目までの魔法、モンスターのHPjまでの最小魔法消費量
    vector<vector<int>> dp(n+1, vector<int>(h+1));
    rep(i,n+1)rep(j,h+1) dp[i][j] = INF;
    rep(i,n)dp[i][0] = 0;
    rep(i,n)
    {
        rep(j,h+1)
        {
            if(j - a[i] >= 0)
            {
                dp[i+1][j] = min(dp[i][j], dp[i+1][j-a[i]]+b[i]);
            }
            else dp[i+1][j] = min(dp[i][j], dp[i+1][0] + b[i]);
            //cout << dp[i+1][j] << " ";
        }
       // cout << endl;
    }
    cout << dp[n][h] << endl;
    
}

Measured memory_bytes: 39424
#include <bits/stdc++.h>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i,a,b) for (ll i=(a);i<(ll)b; i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define INF 100000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll,ll> p;
const int MOD = 1000000007;

// vector<p> cut(M);
// cut[i].second
// cut[i].first;
// REP(i,M){
//     int a,b;cin>>a>>b;
//     cut[i] = make_pair(b,a);//last first の順番
// }
// for(int i=0; i<N;i++){
// }
// sort(cut.begin(),cut.end()); //sort
// char '' str ""
int town[9];
int d[201][201];
void warshall_floyd(int V){
  for(int k=1; k<=V;k++)
    for(int i=1; i<=V;i++)
      for(int j=1; j<=V;j++) d[i][j] = min(d[i][j], d[i][k] + d[k][j]);

}

int main(void)
{
    int N,M, R;cin>>N>>M>>R;
    for(int i=0; i<R;i++) cin>>town[i];
    for(int i=0; i<201; i++) {
         for(int j=0; j<201; j++) {
             if(i==j) d[i][j]=0;
             else     d[i][j]=INF;
         }
     }
    for(int i=0; i<M;i++){
      int a,b,c;
      cin>>a>>b>>c;
      d[a][b] = c; d[b][a] = c;
    }
    warshall_floyd(N);

    int ans=1000000000;
    sort(town, town+R);
    while(next_permutation(town, town+R)){
      int sum=0;
      for(int i=1; i<R; i++){
        sum += d[town[i]][town[i-1]];
      }
      ans = min(ans, sum);
    }

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


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

int main()
{
  int n;
  string s;
  cin>>n>>s;
  int ans=0;
  for(int i=0;i<1000;i++){
    string t;
    int x=i;
    for(int j=0;j<3;j++){
      t+='0'+x%10;
      x/=10;
    }
    int ti=0;
    for(int j=0;j<n;j++){
      if(s[j]==t[ti]){
        ++ti;
        if(ti==3){
          break;
        }
      }
    }
    if(ti==3){
      ans++;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

    const int COST = 800, REFUND = 200, PACKAGE = 15;

    int no_of_refunds = no_of_meals/PACKAGE;
    int total_cost = no_of_meals*COST - no_of_refunds*REFUND;
    cout << total_cost;

    return 0;
}


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

int main(void){
    // 定義
    int n,x,y,ans[10000],dist;
    // 入力
    scanf("%d%d%d",&n,&x,&y);
    // 解
    for (int i=1;i<=n;i++){
        for (int j=1;j<=n;j++){
            if (i <= j){
                dist = j - i;
                if (dist > abs(x - i) + 1 + abs(y - j)){
                    dist = abs(x - i) + 1 + abs(y - j);
                }else if (dist > abs(y - i) + 1 + abs(x - j)){
                    dist = abs(y - i) + 1 + abs(x - j);
                }
                ans[dist]++;
            }
        }
    }
    for (int k=1;k<=n-1;k++){
        printf("%d\n",ans[k]);
    }
}


Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_map>
#include<climits>
#include<cstdlib>
#include<cmath>
#include<string>
#include<iomanip>
#include<bitset>

using namespace std;

#define ll long long int

ll const MOD = 1000000007;
ll const INF = (long long int)1 << 61;

ll mypow(ll x,ll n){
    ll ret = 1;
    while(n > 0){
        if(n&1){
            ret = (ret*x)%MOD;
        }
        x = (x*x)%MOD;
        n >>= 1;
    }
    return ret;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
 
    ll n,k;
    cin >> n >> k;

    string str;
    cin >> str;

    str += 'E';

    vector<ll> za;

    for(int i = 0; i < str.size() - 1; i++){
        ll count = 1;
        while(i < str.size() - 1 && str[i] == str[i+1]){
            count++;
            i++;
        }
        za.push_back(count);
    }

    bool zero;
    if(str[0] == '0'){
        zero = true;
    }else{
        zero = false;
    }

    vector<ll> sum(za.size() + 1,0);

    for(int i = 1; i <= za.size(); i++){
        sum[i] = sum[i-1] + za[i-1];
    }

    ll ans = 0;

    if(zero){

        for(int i = 0; i < za.size(); i++){
            if(i%2 == 0){
                
                    ans = max(ans,sum[min((ll)sum.size() - 1,i + 2*(k - 1) + 2)] - sum[i]);
                
            }else{
                ans = max(ans,sum[min((ll)sum.size() - 1,i + 2*k + 1)] - sum[i]);
            }
        }
    }else{

        for(int i = 0; i < za.size(); i++){
            if(i%2 == 1){
                
                    ans = max(ans,sum[min((ll)sum.size() - 1,i + 2*(k - 1) + 2)] - sum[i]);
                
            }else{
                ans = max(ans,sum[min((ll)sum.size() - 1,i + 2*k + 1)] - sum[i]);
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 2116
n,m=map(int,input().split())
l_n=[list(map(int,input().split())) for _ in range(n)]
l_m=[list(map(int,input().split())) for _ in range(m)]
# print(l_n,l_m)


for i,j in l_n:
    distance=0
    cnt = 0
    ans = float ( "inf" )
    for k,l in enumerate(l_m):
        a,b=l
        distance=abs(i-a)+abs(j-b)
        if ans>distance:
            ans=min(ans,distance)
            cnt=k+1
    print(cnt)


Measured memory_bytes: 9108
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int T = sc.nextInt();

		int sumB = 0;
		int i = 1;
		while(true) {
			if(i*A < T + 0.5) {
				i++;
				sumB += B;
			}else {
				break;
			}
		}

		System.out.println(sumB);
		sc.close();
	}
}

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

# B - Multiplication 2
n = int(input())
a = list(map(int, input().split()))

ans = 1
upper = 10 ** 18

if 0 in set(a):
	print(0)
else:
	for i in range(n):
		ans *= a[i]
	
		if ans > upper:
			print(-1)
			exit()

	print(ans)

Measured memory_bytes: 21796
import sys
import re
import math
import collections
import bisect
import itertools
import fractions
import functools
import copy
import heapq
import decimal
import statistics
import queue

# import numpy as np

sys.setrecursionlimit(10 ** 9)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))
na1 = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().split()))


# ===CODE===
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


def main():
    n = ni()

    ans = []
    odd = int(n % 2)
    for i in range(n):
        for j in range(i + 1, n):
            if i + j + 2 != n + 1 - odd:
                ans.append([i + 1, j + 1])

    print(len(ans))
    for a, b in ans:
        print(a, b)


if __name__ == '__main__':
    main()


Measured memory_bytes: 11752
#include <bits/stdc++.h>
using namespace std;
template<typename T = int> vector<T> create(size_t n){ return vector<T>(n); }
template<typename T, typename... Args> auto create(size_t n, Args... args){ return vector<decltype(create<T>(args...))>(n, create<T>(args...)); }
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n; cin >> n;
	function<void(string)> dfs = [&](string c){
		if(c.size() == n){
			for(auto & e : c) e += 'a';
			cout << c << endl;
			return;
		}
		int mx = -1;
		if(c.empty()) mx = -1;
		else mx = *max_element(c.begin(), c.end());
		for(int i = 0; i <= mx + 1; i++){
			c.push_back(i);
			dfs(c);
			c.pop_back();
		}
	};
	dfs("");
	return 0;
}


Measured memory_bytes: 1536
# -*- coding: utf-8 -*-
import sys 
sys.setrecursionlimit(10**6)
MOD = 10**9+7 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = int(readline())
if N >= 30:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 61744
import java.io.*;
import java.util.*;
import java.lang.*;
import java.text.*;
import java.math.*;
public class Main {
	public static void main(String[] args) throws IOException{
		BufferedReader re=new BufferedReader(new InputStreamReader(System.in));
		//StringTokenizer t=new StringTokenizer(re.readLine());
		//int a=Integer.parseInt(t.nextToken()),b=Integer.parseInt(t.nextToken()),k=Integer.parseInt(t.nextToken());
		String str=re.readLine();
		int a=0;
		for(int i=0;i<str.length();++i) {
			if(str.charAt(i)=='1')++a;
		}
		System.out.println(2*Math.min(a,str.length()-a));
	}
}


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

#define rep(i, n) REP(i, 0, n)
#define REP(i, k, n) for(int i = (int)k; i < (int)n; i++)
#define rrep(i, n) RREP(i, 0, n)
#define RREP(i, k, n) for(int i = (int)n-1; i > (int)k-1; i--)
#define mmax(start, end) *max_element(start, end)
#define mmin(start, end) *min_element(start, end)
#define ALL(x) (x).begin(), (x).end()
#define debug(x) cerr << #x << " " << x << endl;

typedef long long ll;

int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
int dx8[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
int dy8[8] = {-1, 0, 1, -1, 1, -1, 0, 1};

int N, A;
int x[51];
long long dp[51][51][2600];

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

    cin >> N >> A;
    REP(i,1,N+1) cin >> x[i];

    // int X = max(*max_element(x+1,x+N+1), A);

    dp[0][0][0] = 1;
    // REP(xi,1,N+1) {
    //     rep(ch_n,xi+1) {
    //         rep(sum,2501) {
    //             if(sum<x[xi])
    //                 dp[xi][ch_n][sum] = dp[xi-1][ch_n][sum];
    //             else if(ch_n>=1)
    //                 dp[xi][ch_n][sum] = dp[xi-1][ch_n][sum] + dp[xi-1][ch_n-1][sum-x[xi]];
    //         }
    //     }
    // }
    rep(xi,N) {
        rep(ch_n,N) {
            rep(sum,2500) {
                if(dp[xi][ch_n][sum]) {
                    dp[xi+1][ch_n][sum] += dp[xi][ch_n][sum];
                    dp[xi+1][ch_n+1][sum+x[xi+1]] += dp[xi][ch_n][sum];
                }
            }
        }
    }

    // rep(i,N+1) {
    //     cout << i << ":" << endl;
    //     rep(j,N+1) {
    //         rep(k,25) {
    //             cout << dp[i][j][k] << " ";
    //         } cout << endl;
    //     } cout << endl << endl;
    // }

    // ll ans = 0;
    // REP(ch_n,1,N+1)
    //     ans += dp[N][ch_n][A*ch_n];
    //
    // cout << ans << endl;

    ll ret = 0;
	for (ll a = 1; a <= N; ++a) ret += dp[N][a][A*a];
	cout << ret << endl;
    return 0;
}


Measured memory_bytes: 50176