akhauriyash/Code-Regression huggingface dataset:
import math
import copy
import sys

def rotation(s):
    rot = []
    for i in range(1, len(s)):
        rot.append(s[i])

    rot.append(s[0])

    return rot

inputa = input().split()
inputb = input().split()
# inputc = input().split()

a = int(inputa[0])
# b = int(inputa[1])
# c = int(inputa[2])

# x = int(inputb[0])
# y = int(inputb[1])

# inputaList = [int(n) for n in inputa]

# inputb = input().split()
# inputbList = [int(n) for n in inputb]
#
# inputList = []
# inputNumList = []
# for i in range(a):
#     inputNum = input()
#     inputNumList = list(inputNum)
#     inputList.append(inputNumList)

# inputList = [int(n) for n in inputList]

b = [int(n) for n in inputb]
# c = [int(n) for n in inputc]

# a = str(inputa[0])
# inputaList = list(a)

max = 0

for i in range(a):
    for j in range(i+1, a):
        tmp = abs(b[i]- b[j])

        if tmp > max:
            max = tmp

print(max)

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

int main() {
  char s[4];
  scanf("%s",s);
  sort(s,s+4);
  if(s[0]==s[1]&&s[1]!=s[2]&&s[2]==s[3])cout << "Yes" <<endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
from itertools import groupby
def main():
    n=int(input())
    aa=sorted(map(int,input().split()))
    d={}
    for k,g in groupby(aa):
        d[k] = len(list(g))
    q=int(input())
    bc=[]
    for _ in range(q):
        b,c=map(int,input().split())
        bc.append((b,c))
    s = sum(k*v for k,v in d.items())
    for b,c in bc:
        if b in d:
            s += (c-b)*d[b]
            d[c] = d.setdefault(c, 0) + d[b]
            del d[b]
        print(s)
main()

Measured memory_bytes: 31816
H, W = map(int, input().split())
N = int(input())

a = list(map(int, input().split()))

l_list = []

for i in range(N):
    l_list += [i+1] * a[i]

judge = 0
for i in range(H):
    p_list = l_list[i*W:(i+1)*W]
    if judge % 2 == 1:
        p_list = p_list[::-1]
    for j in p_list:
        print(j, end=' ')
    print()
    judge += 1

Measured memory_bytes: 3828
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

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

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

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

    for(int bit = 1; bit < (1 << n); ++bit){
        int cnt = 0;    // 左から何桁埋めたか
        vector<int> InversionNumber(n, 0);
        for(int i = 0; i < n; ++i){
            if((bit >> i) & 1){
                ++cnt;
                InversionNumber[i] = 1;
            }
        }
        // 転倒数の前計算
        for(int i = n - 1; i > 0; --i){
            InversionNumber[i - 1] += InversionNumber[i];
        }

        for(int i = 0; i < n; ++i){
            if(dp[bit][i] == INF)   continue;

            for(int j = 0; j < n; ++j){
                if((bit >> j) & 1)  continue;
                
                // 直前と現在の表になっている数を求める
                int pre = (cnt - 1 - i) % 2 == 0 ? a[i] : b[i];
                int cur = (cnt - j) % 2 == 0 ? a[j] : b[j];
                // 広義単調増加になっていなければ continue
                if(pre > cur)   continue;

                chmin(dp[bit | (1 << j)][j], dp[bit][i] + InversionNumber[j]);
            }
        }
    }

    int ans = INF;
    for(int i = 0; i < n; ++i)  chmin(ans, dp[(1 << n) - 1][i]);
    if(ans == INF)  ans = -1;
    cout << ans << endl;
}

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

int main(){
    int i,x,r,d;

    scanf("%d %d %d",&r,&d,&x);

    for(i=0;i<10;i++){
        x=r*x-d;
        printf("%d\n",x);
    }

    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
int main()
{
 int N,m,x=0,t=0,u=0;
  scanf("%d",&N);
 
  char s[N];

   scanf("%s",&s);
   
   for(m=0;m<N;m++){
     if(s[m]=='.')
       t++;
   }
      x=t;
  for(m=0;m<N;m++){
     if(s[m]=='.')
       t--;
     else u++;
     if(x>(t+u))
       x=(t+u);
   }
 printf("%d\n",x);
  
  return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define v vector<long long>
#define f first
#define s second
#define pb push_back

using namespace std;
typedef long long ll;
int main() {
    ll a,b,c;
    cin>>a>>b>>c;
    ll m=max(a,max(b,c));
    cout<<m*10+(a+b+c-m)<<endl;
	return 0;
}

Measured memory_bytes: 256
#pragma region
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define repc(i, m, n) for (int i = m; i < n; i++)
#define reprc(i, m, n) for (int i = m; i > n; i--)
#define all(v) v.begin(), v.end()
#define INF 1e9
#define EPS 1e-10
using namespace std;
typedef long long ll;
#pragma endregion

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

    string s;
    s = to_string(N);

    rep(i, 3){
        if(s.at(i) == '7'){
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;
}

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

using namespace std;

#define int long long

const int mod = 1e9 + 7;

void solve() {
    int n;
    cin >> n;
    int ans = 1, bed1 = 1, bed2 = 1;
    for (int i = 0; i < n; ++i) ans = (ans * 10) % mod;
    for (int i = 0; i < n; ++i) bed1 = (bed1 * 8) % mod;
    for (int i = 0; i < n; ++i) bed2 = (bed2 * 9) % mod;
    cout << ((ans + bed1 - 2 * bed2) % mod + mod) % mod;
}

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	solve();
	return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define x first
#define y second
#define pb push_back
#define pf push_front

using ll = long long;
namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using namespace std;

ll M = 1000000007;
typedef pair<int, int> P;
ll GCD(ll x, ll y)
{
    return x ? GCD(y % x, x) : y;
}

ll LCM(ll m, ll n)
{
    if ((0 == m) || (0 == n))
        return 0;

    return ((m / GCD(m, n)) * n); // lcm = m * n / GCD(m,n)
}
int main()
{
    int n;
    ll m;
    cin >> n >> m;
    vector<ll> a(n);
    ll mlcm = 1;
    vector<int>eve(n);
    rep(i, n)
    {
        cin >> a[i];
        int tp=a[i];
        while(tp%2==0){
            tp/=2;
            eve[i]++;
        }
    }
    int isok=eve[0];
    bool ok=true;
    rep(i,n){
        if(eve[i]!=isok){
            ok=false;
        }
    }
    rep(i,n){
        
            mlcm = LCM(a[i]/2 , mlcm);
        
    }
    //cout<<mlcm<<endl;
    int cnt = 0;
    if (mlcm >m or !ok)
    {
    }
    else
    {
        rep(i, 1e9)
        {
            ll mul = 2 * i + 1;
            ll tmp=mlcm*mul;
            if (tmp<= m&&1<=tmp)
            {
                cnt++;
            }
            else
            {
                break;
            }
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
int main(){
	int t,n,a=1,arr[200000],j=0;
	queue <int> q;
	cin>>t;
	for(int i=1;i<=t;i++){
		cin>>n;
		q.push(n);
	}
	for(int i=1;i<=t;i++){
		if(q.front()==a){
			arr[a-1]=q.front();
			q.pop();
			a++;
		}
		else {
			q.pop();
			j++;
		}
	}
	if(a==1) cout<<"-1"<<endl;
	else cout<<j<<endl;
}


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

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

  int N, M;
  cin >> N >> M;
  int A[N];
  rep(i,N){
    cin >> A[i];
  }
  int dp[N+1][3000][N+1];
    for(int i=0;i<=N;i++){
    for(int j=0;j<2600;j++){
      for(int k=0;k<=N;k++){
        dp[i][j][k] = 0;
      }
    }
  }
  dp[0][0][0] = 1;

  for(int i=1;i<=N;i++){
    for(int j=0;j<2600;j++){
      for(int k=0;k<=i-1;k++){
        dp[i][j+(A[i-1])][k+1] += dp[i-1][j][k];
        dp[i][j][k] += dp[i-1][j][k];
      }
    }
  }
  int ans = 0;
  for(int k=1;k<=N;k++){
    ans += dp[N][M*k][k];
  }
  cout << ans << endl;
}

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

int main(){
  string s; int n; cin >> s >> n;
  vector<char> ans;
  for(int i = 0; i < s.length(); i++){
    ans.push_back(s[i]);
  }
  int r = 0;
  for(int i = 0; i < n; i++){
    int t; cin >> t;
    if(t == 1) r++;
    else{
      int f; char c; cin >> f >> c;
      if(f == 1){
        if(r % 2 == 0) ans.insert(ans.begin(), c);
        else ans.push_back(c);
      }
      else{
        if(r % 2 == 0) ans.push_back(c);
        else ans.insert(ans.begin(), c);
      }
    }
  }
  if(r % 2 == 0) for(int i = 0; i < ans.size(); i++) cout << ans[i];
  else for(int i = ans.size() - 1; i >= 0; i--) cout << ans[i];
  cout << endl;
  return 0;
}


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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  bool f = false;
  if(abs(b - a) <= d && abs(c - b) <= d) f = true;
  else if(abs(c-a) <= d) f = true;
  if(f) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
// 問題の URL を書いておく
// 

#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>

using namespace std;

//#define ENABLE_PRINT

#if defined(ENABLE_PRINT)

#define Print(v) \
do {\
    cout << #v << ": " << v << endl; \
}while(0)

#define PrintVec(v) \
do {\
    for(int __i = 0; __i < v.size(); ++__i) \
    { \
        cout << #v << "[" << __i << "]: " << v[__i] << endl; \
    }\
}while(0)

#else

#define Print(v) ((void)0)
#define PrintVec(v) ((void)0)

#endif

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

using ll = int64_t;

const ll M = 1000000000 + 7;

ll dp[2010] = {0};
ll sum[2010] = {0};

int main(int, const char**)
{
    int s;
    cin >> s;
    for(int i = 0; i <= s - 3; ++i)
    {
        dp[i + 3] = (sum[i] + 1) % M;
        sum[i + 3] = (sum[i + 2] + dp[i + 3]) % M;
    }
    cout << dp[s] << endl;
    return 0;
}


Measured memory_bytes: 3552
#include<bits/stdc++.h>
using namespace std;
#define MAX 100000
#define NIL -1
vector<int>G[MAX];
int color[MAX];
int n;
void dfs(int r,int c){
	color[r]=c;
	stack<int>s;
	s.push(r);
	while(!s.empty()){
		int u=s.top();
		s.pop();
		for(int i=0;i<G[u].size();i++){
			int v=G[u][i];
			if(color[v]==NIL){
				color[v]=c;
				s.push(v);
			}
		}
	}
}


void assignColor(){
	memset(color,-1,sizeof(color));
	int id=1;
	for(int u=0;u<n;u++){
		if(color[u]==NIL)dfs(u,id++);
	}
	 
}


int main(){
	int m;
	cin>>n>>m;
	for(int i=0;i<m;i++){
		int s,t;
		cin>>s>>t;
		G[s].push_back(t);
		G[t].push_back(s);
	}
	assignColor();
	int q;
	cin>>q;
	for(int i=0;i<q;i++){
		int x,y;
		cin>>x>>y;
		if(color[x]==color[y])cout<<"yes"<<endl;
		else cout<<"no"<<endl;
	}
} 


Measured memory_bytes: 8936
#![allow(dead_code)]
#![allow(unused_imports)]
#![allow(non_camel_case_types)]
#![allow(non_snake_case)]
use ascii::{AsciiChar, AsciiStr, AsciiString};
use indexmap::IndexMap;
use itertools::*;
use libm::*;
use num::*;
use ordered_float::OrderedFloat;
use permutohedron::LexicalPermutation;
use proconio::marker::{Bytes, Chars};
use proconio::{fastout, input};
use std::cmp::{max, min, Ordering};
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
use std::mem::swap;

fn count(p:(isize,isize,isize)) -> isize {
    let (x,y,z) = p;
    let mut s = HashSet::new();
    s.insert(x);s.insert(y);s.insert(z);
    match s.len() {
        1 => 1,
        2 => 3,
        _ => 6
    }
}

fn solve(n:isize) -> isize {
    let mut ret = 0;
    let e = (n as f64).sqrt() as isize;
        
    for x in 1..e {
        for y in 1..e {
            let a = (x+y) as f64;
            if x*x+y*y+x*y > n {continue}
            let b: isize = x*x+y*y+x*y-n;
            let c = (a * a - 4. * b as f64).sqrt();
            if c == c.floor() {
                let d = (c-a) as isize;
                if d<=0 {continue}
                if d % 2 == 0 {
                    ret += 1
                }
            }
        }
    }
    ret
}

fn main() {
    input!(n:isize);
    for i in 1..=n {
        println!("{}", solve(i));
    }
}


Measured memory_bytes: 2592
#include<iostream>
#include<string>
#include<algorithm>

typedef long long ll;
using namespace std;
int main()
{
	int a[114514];
	int b, c;
	c = 0;
	cin >> b;
	for (int i = 0; i < b * 2; i++)
	{
		cin >> a[i];
	}
	for (int l = 0; l < b * 2; l+=2)
	{
		c += a[1 + l] - a[l] + 1;
	}
	cout << c << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SIZE 1000500
#define NIL -1
#define L 14
using namespace std;
static string order[SIZE];
void init()
{
    for (int i = 0; i < SIZE; ++i)
    {
        order[i] = "NULL";
    }
}
long long getkey(string str)
{
    for (int i = 0; i < str.size(); ++i)
    {
        if (str[i] == 'A')
            str[i] = '1';
        else if (str[i] == 'C')
            str[i] = '2';
        else if (str[i] == 'G')
            str[i] = '3';
        else if (str[i] == 'T')
            str[i] = '4';
    }
    long long key = atoll(str.c_str());
    return key;
}
int h1(long long key)
{
    return key % SIZE;
}
int h2(long long key)
{
    return 1 + (key % (SIZE - 1));
}
bool find(string str)
{
    long long key = getkey(str), h;
    bool ans = false;
    for (int i = 0;; ++i)
    {
        h = (h1(key) + i * h2(key)) % SIZE;
        if (order[h] == "NULL")
            break;
        else if (order[h] == str)
        {
            ans = true;
            break;
        }
    }
    return ans;
}
void insert(string str)
{
    long long key = getkey(str), h;
    for (int i = 0;; ++i)
    {
        h = (h1(key) + i * h2(key)) % SIZE;
        if (order[h] == str)
            break;
        else if (order[h] == "NULL")
        {
            order[h] = str;
            break;
        }
    }
}
int main()
{
    int n;
    cin >> n;
    init();
    int count(0);
    bool ans[n] = {};
    for (int i = 0; i < n; ++i)
    {
        string tmp1, tmp2;
        cin >> tmp1 >> tmp2;
        if (tmp1 == "insert")
            insert(tmp2);
        else if (tmp1 == "find")
        {
            ans[count++] = find(tmp2);
        }
        else
        {
            exit(0);
        }
    }
    for (int i = 0; i < count; ++i)
    {
        if (ans[i])
            cout << "yes" << endl;
        else
            cout << "no" << endl;
    }
}


Measured memory_bytes: 68632
#include <iostream>
#include <map>
#include <vector>
using namespace std;

int main(){
  map<string,int,less<>> mp;
  map<string,int>::iterator p;
  vector<string> keys;
  string str;
  int i,N,M,X=0;
  
  cin >> N;
  for(i=0;i<N;i++){
    cin >> str;
    p=mp.find(str);
    if(p == mp.end()){
      mp.insert(make_pair(str,1));
      keys.push_back(str);
    }
    else mp[str]++ ;
  }
  
  cin >> M;
    for(i=0;i<M;i++){
    cin >> str;
    p=mp.find(str);
    if(p == mp.end()){
      mp.insert(make_pair(str,-1));
      keys.push_back(str);
    }
    else mp[str]-- ;
  }
  
  for(str : keys){
    X=max(X,mp[str]);
  }
  
  cout << X << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <cstdlib>
#include <iostream>
#include <string>
#include <time.h>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <vector>
#include <functional>
//#include "bits/stdc++.h"
using namespace std;
//using namespace std::vector;
#define rep(i,a,b) for(int i=(a);i<(b);++i)

#define huge 1000000007
typedef long long ll;
ll gcd(ll a, ll b);

int main(void) {

	ll N = 0;
	ll A = 0;
	ll B = 0;
	ll C = 0;
	ll D = 0;
	ll M = 0;
	//ll M = 0;
	ll a[200] = {};
	ll b[200] = {};
	ll v[3] = {};
	//ll *a, *b, *x;
	string S,T,U;
	ll count = 0;
	ll sum = 0;
	ll min = 100000;
	ll max = 0;
	int flag = 0;
	char temp,head;
	//int is = 0;
	

	//char p;
	cin >> A >> B >> N;
	//cin >> S;
	
	//a = (ll *)malloc(M * sizeof(ll));
	//b = (ll *)malloc(M * sizeof(ll));
	//vector<pair<int,int>> ch(N+1);
	//vector<bool> flag(N);
	
	//count--;
	//	cout << X << endl;
	//x = (ll *)malloc((N+1) * sizeof(ll));
	//c = (ll *)malloc((N) * sizeof(ll));
	//cin >> D >> G;
	//vector<pair<int,int>> tr(M);
	//vector<pair<int,int>> qes(Q);
	//sort(v.begin(), v.end());
	
	/*A = N / 1000;
	N %= 1000;
	B = N / 100;
	N %= 100;
	C = N / 10;
	N %= 10;
	D = N;*/

	
	
	if (B - A + 1 <= 2 * N) {
		rep(i, A, B + 1)
			cout << i << endl;
	}
	else {
		rep(i, A, A + N)
		cout << i << endl;

		rep(i, B-N+1, B+1)
			cout << i << endl;
	}


	return 0;

}

ll gcd(ll a, ll b) {
	ll c;
	c = a % b;
	while (c != 0) {
		a = b;
		b = c;
		c = a % b;
	}

	return b;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pq priority_queue
using namespace std;
const ll INF=(ll)1e9;
const ll MOD=(ll)1e9+7;
const ll MAX=510000;
vector<int> dx={1,0,-1,0},dy={0,1,0,-1};
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; }

int main(){
    ll N,K,ans=0;
    cin>>N>>K;
    if(K==1){
        cout<<"0"<<endl;
        return 0;
    }
    ll A[N+1];
    A[0]=0;
    map<ll,ll> m;
    for(ll i=1;i<=N;i++){
        cin>>A[i];
        A[i]--;
        A[i]+=A[i-1];
    }
    for(ll i=0;i<=N;i++){
        ans+=m[A[i]%K];
        m[A[i]%K]++;
        if(i-K+1>=0) m[A[i-K+1]%K]--;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 14336
#include <iostream>
#define MAX_N 100
using namespace std;
int main(void){
  int n, m;
  int a, b;
  int road[MAX_N][MAX_N];
  cin >> n >> m;
  for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j++){
      road[i][j] = 0;
    }
  }
  for(int i = 0; i < m; i++){
    cin >> a >> b;
    a--;
    b--;
    road[a][b]++;
    road[b][a]++;
  }
  for(int i = 0; i < n; i++){
    int road_num = 0;
    for(int j = 0; j < n; j++){
      road_num += road[i][j];
    }
    cout << road_num << endl;
  }
  return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.*;

public class Main {
    // static int INF = (1 << 30) - 1;
    // static long L_INF = (1L << 62) - 1;
    static long MOD = (long) 1e9 + 7;

    static class Solver {
        int N;
        char[][] S;

        // write your code
        void solve(InputReader in, PrintWriter out) {
            N = in.nextInt();
            S = new char[2][N];
            String S1 = in.next();
            for (int i = 0; i < N; i++) {
                S[0][i] = S1.charAt(i);
            }
            String S2 = in.next();
            for (int i = 0; i < N; i++) {
                S[1][i] = S2.charAt(i);
            }

            boolean[] used = new boolean[N];
            long ans = 0;
            if (S[0][0] == S[1][0]) {
                ans = 3;
                used[0] = true;
            } else {
                ans = 6;
                used[0] = true;
                used[1] = true;
            }
            for (int i = 1; i < N; i++) {
                if (used[i]) {
                    continue;
                }
                if (S[0][i] == S[1][i]) {
                    ans *= ((S[0][i - 1] == S[1][i - 1]) ? 2 : 1);
                    used[i] = true;
                } else {
                    ans *= ((S[0][i - 1] == S[1][i - 1]) ? 2 : 3);
                    used[i] = true;
                    used[i + 1] = true;
                }
                ans %= MOD;
            }

            out.println(ans);
        }

        void debug(Object... os) {
            System.err.println(Arrays.deepToString(os));
        }
    }

    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Solver solver = new Solver();
        solver.solve(in, out);
        out.close();
    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

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


Measured memory_bytes: 22612
#include<bits/stdc++.h>
#define INF 2147483647
#define lli long long int
#define MOD 1000000007
#define pb push_back

using namespace std;
typedef vector<int> vi;
typedef vector< vector<int> > vvi;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;

int main() {
	
	int n,w; cin >> n >> w;
	vvi table(n+10,vi(w+10,0));

	vi val(n,0);
	vi wei(n,0);
	for (int i = 0; i < n; i++) {
		cin >> val[i] >> wei[i];
	}

	for (int i = 0; i < n; i++) {
		for (int j = 0; j <= w; j++) {
			if(j < wei[i]) {
				table[i+1][j] = table[i][j];
			}else{
				table[i+1][j] = max(table[i][j],table[i][j-wei[i]] + val[i]);
			}
		}
	}
	
	cout << table[n][w] << endl;

	return 0;
}

Measured memory_bytes: 7068
#include <cstdio>
#include <map>
#include <string>
using namespace std;

map<string, int> m;

int main(){
	char buf[33];
	while (scanf("%s", buf, 33) != EOF) {
		if (m.find(buf) != m.end()) {
			m[buf] += 1;
		}
		else {
			m[buf] = 0;
		}
	}
	map<string, int>::iterator itr = m.begin();
	string sl, sc;
	int l, c;
	sl = sc = (*itr).first;
	c = (*itr).second;
	l = (*itr).first.size();
	while (++itr != m.end()) {
		if ((*itr).first.size() > l) {
			sl = (*itr).first;
			l = (*itr).first.size();
		}
		if ((*itr).second > c) {
			sc = (*itr).first;
			c = (*itr).second;
		}	
	}
	printf("%s %s\n", sc.c_str(), sl.c_str());

	return 0;
}

Measured memory_bytes: 2852
#include<bits/stdc++.h>
using namespace std;
main()
{
    int c[9];
    while(cin>>c[1])
    {
        for(int i=2;i<=9;i++)
            cin>>c[i];
        int t1,t2,t3,t4,t5,t6,t7,t8=0;
        for(int i=1;i<=9;i++)
            t8+=c[i];
        t1=c[1]+c[5]+c[9];
        t2=t8-c[3]-c[5]-c[7];
        t3=t8-c[3]-c[4]-c[8];
        t4=t8-c[1]-c[6]-c[8];
        t5=t8-c[1]-c[5]-c[9];
        t6=t8-c[2]-c[4]-c[9];
        t7=t8-c[2]-c[6]-c[7];
        //cout<<t1<<t2<<t3<<t4<<t5<<t6<<t7<<t8<<endl;
        if(2*t1==t2&&2*t1==t3&&2*t1==t4&&2*t1==t5&&2*t1==t6&&2*t1==t7&&3*t1==t8)
            cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

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

template < typename T >
void vprint(T &v){
	REP(i, v.size()){
		cout << v[i] << " ";
	}
	cout << endl;
}

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

	vector<ll> C(N);
	REP(i, N) C[i] = A[i] + B[i];
	sort(C.rbegin(), C.rend());
	ll res = 0;
	REP(i, N) res -= B[i];
	REP(i, N) if(i%2==0) res += C[i];
	cout << res << endl;
    return 0;
}

Measured memory_bytes: 2560
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
   double a,arr[1000],sum=0,ab=0,ab1=0,dd,dd1;
   cin>>a;
   for(int i=0;i<a;i++)
   {
       cin>>arr[i];
       sum+=arr[i];
   }
   dd=ceil(sum/a);
   dd1=floor(sum/a);
   for(int i=0;i<a;i++)
   {
     ab+=(dd-arr[i])*  (dd-arr[i]);
     ab1+=(dd1-arr[i])*  (dd1-arr[i]);
   }
   if(ab<ab1)
{cout<<ab<<endl;}
else{cout<<ab1<<endl;}
//   cout<<c<<endl;
   return 0;
}


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

n,T=map(int,input().split())
t=list(map(int,input().split()))
res=0
for i in range(n-1):
    if t[i]+T>t[i+1]:
        res+=(t[i+1]-t[i])
    else:
        res+=T
res+=T
print(res)

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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

typedef pair<int,int> pi;

int main()
{
    int m,n;
    cin >>m >>n;
    vector<string> c(m);
    rep(i,m) cin >>c[i];

    vector<pi> t[26];
    rep(i,m)rep(j,n)
    {
        if(c[i][j]!='.') t[c[i][j]-'A'].pb(pi(i,j));
    }

    int exist[26]={0};
    rep(i,26) if(t[i].size()>0) exist[i]=1;

    int ans=0;

    while(1)
    {
        bool erased=false;
        rep(i,26)
        {
            if(!exist[i]) continue;

            pi p=t[i][0], q=t[i][1];

            // ???????????????????£? (1or2??????)
            vector<pi> quake;
            if(p.fi==q.fi)
            {
                int l=min(p.se,q.se)+1, r=max(p.se,q.se)-1;
                for(int j=l; j<=r; ++j)
                {
                    if(c[p.fi][j]=='.')
                    {
                        quake.pb(pi(p.fi,j));
                        break;
                    }
                }
            }
            else if(p.se==q.se)
            {
                int l=min(p.fi,q.fi)+1, r=max(p.fi,q.fi)-1;
                for(int j=l; j<=r; ++j)
                {
                    if(c[j][p.se]=='.')
                    {
                        quake.pb(pi(j,p.se));
                        break;
                    }
                }
            }
            else
            {
                if(c[p.fi][q.se]=='.') quake.pb(pi(p.fi,q.se));
                if(c[q.fi][p.se]=='.') quake.pb(pi(q.fi,p.se));
            }

            // ???????????????
            int dx[4]={1,-1,0,0}, dy[4]={0,0,1,-1};
            #define IN(x,y) (0<=x && x<n && 0<=y && y<m)
            for(const auto &P:quake)
            {
                string touch="....";
                rep(j,4)
                {
                    for(int k=1; k<=max(n,m); ++k)
                    {
                        int nx=P.se+k*dx[j], ny=P.fi+k*dy[j];
                        if(!IN(nx,ny)) break;

                        if(c[ny][nx]!='.')
                        {
                            touch[j]=c[ny][nx];
                            break;
                        }
                    }
                }
                int ct=0;
                rep(j,4) if(touch[j]=='A'+i) ++ct;
                if(ct==2)
                {
                    exist[i]=0;
                    c[p.fi][p.se]='.';
                    c[q.fi][q.se]='.';
                    erased=true;
                    break;
                }
            }

            if(erased) break;
        }

        if(!erased) break;
        ans+=2;
    }

    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 3324
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>

using namespace std;

#define rep(i, a, b) for(auto (i)=a;i<b;i++)
#define list(i, N) for(auto (i)=0;i<N;i++)

typedef long long ll;
typedef vector <ll> vi;
typedef pair <ll, ll> pi;
#define mp make_pair
#define pb push_back
#define eb emplace_back

#define int ll
#define INF 1e18+5
#define mod 1000000007

template<class T>
T max(T a, T b, T c) {
    return max(a, max(b, c));
}

string intoBase(int base, int num){
    string ans = "";
    while(num){
        ans += num/base;
        num /= base;
    }
    reverse(ans.begin(),ans.end());
    return ans;
}

int32_t main() {

    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int n, k; cin >> n >> k;
    string ans = intoBase(k,n);
    cout << ans.length() << "\n";

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
template<typename T>
void read(T &x)
{
	char ch=getchar();
	int f=1;
	for (x=0;ch!='-'&&(ch<'0'||ch>'9');ch=getchar());
	if (ch=='-') f=-1,ch=getchar();
	for (;ch>='0'&&ch<='9';x=x*10+ch-'0',ch=getchar());
	x*=f;
}
int n,ans;
int v[110],f[110][410];
ll m,w[110],base;
int main()
{
	read(n),read(m);
	for (int i=1;i<=n;i++)
		read(w[i]),read(v[i]);
	base=w[1]-1;
	for (int i=1;i<=n;i++)
		w[i]-=base;		
	for (int i=1;i<=n;i++)
		for (int j=i;j>=1;j--)
			for (ll k=min(4LL*n,m-base*j);k>=w[i];k--)
					f[j][k]=max(f[j][k],f[j-1][k-w[i]]+v[i]);
	for (int i=0;i<=n;i++)
		for (int j=0;j<=4*n;j++)
			ans=max(ans,f[i][j]);
	printf("%d",ans);
	return 0;
}

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

#define rep(i, n) for (int i=0; i<(n); ++i)
using ll = long long;
using P = pair<int, int>;

int main() {
  int r;
  cin >> r;
  cout << 3*r*r << endl;
  return 0;
}


Measured memory_bytes: 256
from math import gcd

N = int(input())
A = list(map(int, input().split()))

v = 0
for a in A: v = gcd(a, v)
if v > 1:
	print('not coprime')
	raise SystemExit


V = set()
for v in A:
	for i in range(2, v+1):
		if i * i > v: break
		if v % i == 0:
			if v in V:
				print('setwise coprime')
				raise SystemExit

			V.add(v)
			while v % i == 0: v //= i
	if v != 1:
		if v in V:
			print('setwise coprime')
			raise SystemExit

		V.add(v)

print('pairwise coprime')


Measured memory_bytes: 181244
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
long long int mod = (long long int)1000000007;
using namespace std;

void solve()
{
    ll i,j,k,n;
    std::cout.precision(10);
    int yes=0;
    cin>>n;
    string s;
    cin>>s;
    int r=0,g=0,b=0;
    ll dpr[n],dpg[n],dpb[n];
    for(i=0;i<n;i++)
    {
        if(s[i]=='R')
        {
            r++;
        }
        else if(s[i]=='G'){
            g++;
        }
        else
        {
            b++;
        }
        dpr[i]=r;
        dpb[i]=b;
        dpg[i]=g;
    }
    // for(i=0;i<n;i++)
    // {
    //     cout<<dpr[i]<<" ";
    // }
    ll ans=0;
    for(j=1;j<n-1;j++)
    {
        if(s[j]=='R')
        {
            ans+=dpb[j-1]*(dpg[n-1]-dpg[j]);
            ans+=dpg[j-1]*(dpb[n-1]-dpb[j]);
        }
        else if(s[j]=='G')
        {
            ans+=dpr[j-1]*(dpb[n-1]-dpb[j]);
            ans+=dpb[j-1]*(dpr[n-1]-dpr[j]);
        }
        else if(s[j]=='B')
        {
            ans+=dpr[j-1]*(dpg[n-1]-dpg[j]);
            ans+=dpg[j-1]*(dpr[n-1]-dpr[j]);
        }
        int i=j-1,k=j+1;

        while(i>=0 && k<n)
        {
            if(s[i]!=s[j] && s[i]!=s[k] && s[k]!=s[j])
            {
                ans--;
            }
            
            i--;
            k++;
        }
    }
    cout<<ans;
}
int main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
    int i,j,k;
    int t;
    std::cout.precision(10);
    t=1;
    while(t--)
    {
        solve();
        cout<<"\n";
    }
}

Measured memory_bytes: 3708
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace みんプロ
{
    class A
    {
        static void Main(string[] args)
        {
            int[] nk = Console.ReadLine().Split().Select(int.Parse).ToArray();
            string ans = "NO";
            if ((nk[0] + 1) / nk[1] >= 2) { ans = "YES"; }
            Console.WriteLine(ans);
        }
    }
}


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

int main() {

  int N;
  cin>>N;
  string a[N];
  for(int i = 0; i < N; i++) cin>>a[i];

  int ans = 0;
  for(int i = 0; i < N; i++) {
    if(a[i] == "E869120") ans++;
  }

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



Measured memory_bytes: 3324
#include <atcoder/lazysegtree>
#include <atcoder/modint>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
using mint = modint998244353;
const mint dv = mint(1) / 9;
struct S { mint a, b; };
using F = int;
S op(S l, S r) { return S{l.a * r.b + r.a, l.b * r.b}; }
S e() { return S{0, 1}; }
F id() { return -1; }
S mapping(F f, S x) { return f == id() ? x : S{(x.b - 1) * dv * f, x.b}; }
F composition(F f, F g) { return f == id() ? g : f; }
int inline read() {
    int b, c = 0;
    while ((b = getchar() - 48) >= 0) c = c * 10 + b;
    return c;
}
main() {
    int n = read(), q = read();
    lazy_segtree<S, op, e, F, mapping, composition, id> seg(vector(n, S{1, 10}));
    while (q--) {
        int l = read(), r = read(), d = read();
        seg.apply(l - 1, r, d);
        printf("%d\n", seg.all_prod().a.val());
    }
}

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

int main() {
    int_fast64_t N(0);
    int c;
    c = fgetc(stdin);
    N += c - 48;
    c = fgetc(stdin);
    N *= 10;
    N += c - 48;
    c = fgetc(stdin);
    N *= 10;
    N += c - 48;
    int_fast64_t ans(numeric_limits<int_fast64_t>::max());
    while(c = fgetc(stdin), c != EOF){
        ans = min(ans, abs(N - 753));
        N *= 10;
        N += c - 48;
        N %= 1000;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import std.stdio, std.algorithm, std.string, std.conv, std.array, std.range, std.math;
int read() { return readln.chomp.to!int; }
int[] reads() { return readln.split.to!(int[]); }

void solve(int n, int m, int d) {
    double ans = (){
        if (d == 0)
            return 1.0 / n;
        else
            return 2.0 * (n - d) / n / n;
    }();
    ans *= m - 1;
    writefln("%.10f", ans);
}

void main() {
    int n, m, d; readf("%d %d %d\n", &n,&m,&d);
    solve(n, m, d);
}

unittest {
    solve(2, 3, 1);
    solve(1000000000,180707,0);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int n,m,pos[N],cnt[N];
char s[N],t[N];
int main()
{
	scanf("%s",s+1);
	n=strlen(s+1);
	for (int i=1;i<=n;i++)
		if (s[i]!='x') t[++m]=s[i],pos[m]=i;
	for (int i=1;i<=m;i++)
		if (t[i]!=t[m-i+1]) return puts("-1"),0;
	for (int i=1;i<=n+1;i++) cnt[i]=cnt[i-1]+(s[i]=='x');
	pos[m+1]=n+1;
	int ans=0;
	for (int i=1;i<=(m+1)/2;i++){
		int n1=cnt[pos[i]]-cnt[pos[i-1]];
		int n2=cnt[pos[m-i+2]]-cnt[pos[m-i+1]];
		ans+=abs(n1-n2);
	}
	printf("%d\n",ans);
	return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int>a(n);
  rep(i,n) cin >> a.at(i);
  int ans = 0;
  int i=1;
  rep(j,n){
    if(i==a.at(j)) i++;
    else ans++;
  }
  if(i==1) cout << -1 << endl;
  else cout << ans << endl;
    
  return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    int n,m;
    cin>>n>>m;
    int a,ans=1;
    a=m/n;
    if (m%n==0) {
      cout<<m/n<<endl;
      return 0;
    }
    for (size_t i = 1; i < a+1; i++) {
      if (m%i==0) {
        if (ans<i) {
          ans=i;
        }
      }
    }
    cout<<ans<<endl;






}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,s,n) for (int i = (s); i < (n); ++i)
#define rrep(i,n,g) for (int i = (n)-1; i >= (g); --i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define len(x) (int)(x).size()
#define dup(x,y) (((x)+(y)-1)/(y))
#define pb push_back
#define Field(T) vector<vector<T>>
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  set<string> ws;
  ws.emplace(s);
  bool flag = true;
  rep(i,0,n-1) {
    string w;
    cin >> w;
    if (ws.count(w)) flag = false;
    if (s[len(s)-1] != w[0]) flag = false;
    ws.emplace(w);
    s = w;
  }
  if (flag) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 3596
import sys
import heapq


def solve(N: int, M: int, A: "List[int]", B: "List[int]"):
    tasks = list(map(tuple, zip(A, B)))
    tasks.sort()
    tasks.reverse()

    earnables = []

    ans = 0
    for i in range(M + 1):
        while len(tasks) > 0 and tasks[-1][0] <= i:
            _, pay = tasks.pop()
            heapq.heappush(earnables, -pay)
        if len(earnables) > 0:
            ans += -heapq.heappop(earnables)

    return ans


# -----------------------------------------------------------------------------
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()

    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    A = [int()] * (N)  # type: "List[int]"
    B = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        A[i] = int(next(tokens))
        B[i] = int(next(tokens))

    ans = solve(N, M, A, B)
    if ans is not None:
        print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 21328
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1000000000
#define LINF 1000000000000000000
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;

typedef pair<int, int> P;
typedef pair<long long, long long> LLP;

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

    int sum = A[0];

    long long count = 0;

    int l = 0, r = 0;

    while (l < N) {
        if (r < N - 1 && (sum & A[r + 1]) == 0) {
            r++;
            sum += A[r];
        } else {
            count += r - l + 1;
            sum -= A[l];
            l++;
            if (l > r) {
                r = l;
                if (r < N) sum += A[r];
            }
        }
    }

    cout << count << endl;

    return 0;
}

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

int main() {
  int N;
  int i=0;
  int p=0;
  int w=0;
  int g=0;
  int y=0;
  string hinaColor="";
  
  cin >> N;
  while(i<N){
    cin >> hinaColor;
      if(hinaColor=="P"){
        p++;
      }else if(hinaColor=="W"){
        w++;
      }else if(hinaColor=="G"){
        g++;
      }else if(hinaColor=="Y"){
        y++;
      }
    i++;
  }
  
  if(p>0 && w>0 && g>0 && y>0){
    cout << "Four" <<endl;
  }else if(p>0 && w>0 && g>0){
    cout << "Three" <<endl;
  }
}


Measured memory_bytes: 3608
#include "bits/stdc++.h"
#define ALL(x) x.begin(), x.end()
#define LEN(x) (int)x.size()
#define iostreamBooster() do{ cin.tie(nullptr); ios_base::sync_with_stdio(false); }while(0)
using namespace std;
typedef int64_t i64;
typedef pair<int,int> pii;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF = 0x3f3f3f3f;

signed main()
{
  int N;
  int a[100010];
  int l[100010] {};
  int r[100010] {};

  cin >> N;
  for (int i = 1; i <= N; ++i) cin >> a[i];

  for (int i = 1; i <= N; ++i) l[i] = __gcd(l[i-1], a[i]);
  for (int i = N; i >= 1; --i) r[i] = __gcd(r[i+1], a[i]);

  int maxv = 0;
  for (int i = 1; i <= N; ++i) {
    chmax(maxv, __gcd(l[i-1], r[i+1]));
  }

  cout << maxv << endl;

  return 0;
}



Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include <functional>
#include <algorithm>
#include <string>
#include <cmath>

using namespace std;

long long a[100005];
long long pac[100005];
long long ac[100005];

int main()
{
    int N, K;

    cin >> N >> K;

    for (int i = 0; i < N;i++)
    {
        cin >> a[i];
        
        pac[i + 1] = pac[i] + max(a[i], 0LL);
        ac[i + 1] = ac[i] + a[i];
    }

    long long ans = -1e16L;

    long long base = pac[N];

    if(N == 1)
    {
        if(a[0] >= 0)
        {
            cout << a[0] << endl;
        }
        else
        {
            cout << 0 << endl;
        }
        return 0;
    }

    for (int i = 0; i <= N - K;i++)
    {
        long long t = base - (pac[i + K] - pac[i]);
        ans = max(max(t + ac[i + K] - ac[i], t), ans);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 2560
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class TaskD {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int q = in.nextInt();

            int[] a = in.nextIntArray(n);

            long[] sum = new long[n + 1];
            long[] sum2 = new long[n + 2];
            for (int i = 0; i < n; i++) {
                sum[i + 1] = sum[i] + a[i];
                sum2[i + 2] = sum2[i] + a[i];
            }

            // 最大は必ずとれる

            for (int i = 0; i < q; i++) {
                int x = in.nextInt();

                int cannot = n - 1;
                int can = 0;
                while (cannot - can > 1) {
                    int mid = (cannot + can) / 2;

                    if (n - 1 - 2 * mid >= 0 && Math.abs(x - a[n - 1 - mid]) >= Math.abs(x - a[n - 1 - 2 * mid])) {
                        can = mid;
                    } else {
                        cannot = mid;
                    }
                }

                long ans = a[n - 1];
                ans += sum[n - 1] - sum[n - can - 1];
                ans += sum2[n - 2 * can - 1];

                out.println(ans);
            }
        }

    }

    static class InputReader {
        private BufferedReader br;
        private StringTokenizer st;

        public InputReader(InputStream inputStream) {
            br = new BufferedReader(new InputStreamReader(inputStream));
            st = new StringTokenizer("");
        }

        public String nextString() {
            while (!st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine(), " ");
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(nextString());
        }

        public int[] nextIntArray(int n) {
            int[] res = new int[n];
            for (int i = 0; i < n; i++) {
                res[i] = nextInt();
            }
            return res;
        }

    }
}



Measured memory_bytes: 51660
import java.util.*;
import java.util.Scanner;

public class Main {
	
	public static void funct(int[][] arr) {
		int[] t=new int[arr.length];
		for(int i=0;i<arr.length;i++) {
			t[i]=arr[i][1]-arr[i][0];
		}
		int c=0;
		for(int i=1;i<arr.length-1;i++) {
			if(t[i]==0 && t[i-1]==0 && t[i+1]==0) {
				c++;
			}
		}
		if(c>=1) {
			System.out.println("Yes");
		}
		else {
			System.out.println("No");
		}
	}
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int[][] arr=new int[n][2];
		for(int i=0;i<n;i++) {
			int[] temp=new int[2];
			temp[0]=sc.nextInt();
			temp[1]=sc.nextInt();
			arr[i]=temp;
		}
		funct(arr);
	}

}


Measured memory_bytes: 36028
shuru = input().split()
n = 0
while str(shuru[1]) !='?':
    if str(shuru[1]) == '+':
        result = int(shuru[0]) +int(shuru[2]) 
        print('%d'%result)
    if str(shuru[1]) == '-':
        result = int(shuru[0]) - int(shuru[2])
        print('%d'%result)
    if str(shuru[1]) == '*':
        result = int(shuru[0]) *int(shuru[2])
        print('%d'%result)
    if str(shuru[1])  == '/' and str(shuru[2]) != '0':
        result = int(shuru[0]) / int(shuru[2])
        print('%d'%result)
    n = n + 1
    shuru = input()
    shuru = shuru.split()



Measured memory_bytes: 5592
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder.Contest.A
{
	class Program
	{
		public static void Main(string[] args)
		{
			var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
			Console.SetOut(sw);

			Scanner cin = new Scanner();

			string s = cin.next();
			string t = cin.next();
			int ans = 0;
			for (int i = 0; i < s.Length; i++)
			{
				if (s[i] == t[i]) ans++;
			}
			Console.WriteLine(ans);
			Console.Out.Flush();
		}
	}

	class Scanner
	{
		string[] s;
		int i;

		char[] cs = new char[] { ' ' };

		public Scanner()
		{
			s = new string[0];
			i = 0;
		}

		public string next()
		{
			if (i < s.Length) return s[i++];
			string st = Console.ReadLine();
			while (st == "") st = Console.ReadLine();
			s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
			if (s.Length == 0) return next();
			i = 0;
			return s[i++];
		}

		public int nextInt()
		{
			return int.Parse(next());
		}

		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = nextInt() + add;
			}
			return Array;
		}

		public long nextLong()
		{
			return long.Parse(next());
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = nextLong() + add;
			}
			return Array;
		}

		public double nextDouble()
		{
			return double.Parse(next());
		}

		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = nextDouble() + add;
			}
			return Array;
		}
	}
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
 
#define mod 1000000007
#define inf 1000000000
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define popcount(x) __builtin_popcountll(x)
 
const long double PI = acos(-1);
 
ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a / gcd(a,b) * b;}
 
int main(){
  ll n;
  string s;
  cin >> n >> s;

  ll ans = 0;
  for(ll i = 0; i < 1000; i++){
      string t = "";
      t += i/100 + '0', t += (i/10)%10 + '0', t += i%10 + '0';
      //cout << t << endl;
      ll cnt = 0;
      for(ll j = 0; j < n; j++){
          if(s[j] == t[cnt]) cnt++;
          if(cnt == 3){
              ans++;
              break;
          }
      }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256