akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
import java.util.*;

class Main {
    static final long MOD = 1000000007;

    // Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
    public static void main(String[] args) throws Exception {
        final Scanner sc = new Scanner(System.in);
        long H;
        H = sc.nextLong();
        long W;
        W = sc.nextLong();
        char[][] a = new char[(int)(H)][(int)(W)];
        for(int i = 0 ; i < H ; i++){                
            a[i] = sc.next().toCharArray();               
        }
        solve(H, W, a);
    }

    static void solve(long H, long W, char[][] a){
        
        long[][] dp = new long[(int)(H+1)][(int)(W+1)];

        for (int i = 1; i <= (int)(H); i++){
            if (a[i-1][0] == '.'){
                dp[i][1] = 1;
            }else{
                break;
            }
        }

        for (int i = 1; i <= (int)(W); i++){
            if (a[0][i-1] == '.'){
                dp[1][i] = 1;
            }else{
                break;
            }
        }

        for (int i = 2; i <= (int)H; i++){
            for (int j = 2; j <= (int)W; j++){
                long up = a[i-2][j-1] == '.' ? dp[i-1][j] : 0;
                long left = a[i-1][j-2] == '.' ? dp[i][j-1] : 0;
                dp[i][j] = a[i-1][j-1] == '.' ? (up + left) % MOD : 0;
            }
        } 

        System.out.print(dp[(int)H][(int)W]);
    }
}


Measured memory_bytes: 50524
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <algorithm>
#include <numeric>
#include <utility>
#include <random>
#include <chrono>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>

using namespace std;

using LL = long long;
using ULL = unsigned long long;
using PII = pair<int, int>;
using PIL = pair<int, LL>;
using PLL = pair<LL, LL>;
// const int mod = 1e9 + 7;
// const int mod = 998244353;

inline void quickread() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
}

int n;
int x, y, z;

inline void work() {
    cin >> n;
    int a = 0, b = 0, c = 0;
    for (int i = 0; i < n; ++i) {
        cin >> x >> y >> z;
        tie(a, b, c) = forward_as_tuple(max(b, c) + x, max(a, c) + y, max(a, b) + z);
    }
    cout << max(a, max(b, c)) << "\n";
}

int main() {
    // freopen("input.txt", "r", stdin);
    quickread();
    work();
    return 0;
}

Measured memory_bytes: 256
s = input()
chars = len(s)
if chars % 2 != 0:
    s += 'X'
chars = len(s)
ans1, ans2 = 0, 0
for i in range(1, chars, 2):
    if s[i-1] != '0':
        ans1 += 1
    if s[i] != '1' and s[i] != 'X':
        ans1 += 1
for i in range(1, chars, 2):
    if s[i-1] != '1':
        ans2 += 1
    if s[i] != '0' and s[i] != 'X':
        ans2 += 1
print(min(ans1, ans2))

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

#define f first
#define s second
#define lc (rt<<1)
#define rc (rt<<1|1)
#define mp make_pair
#define pb push_back
#define lowbit(a) (a&(-a))
#define sz(x) (int)(x).size()
#define all(x) x.begin(),x.end()
#define mst(a,v) memset(a,v,sizeof(a))
#define IOS {ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);}
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<ld> vd;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

const int N=100010;
const int mod=1e9+7;
const ld PI=acos(-1.0);
const int inf=0x3f3f3f3f;
const ll INF=1e18;


int main()
{
    IOS
    int a,b,k;
    cin>>a>>b>>k;
    for(int i=0; i<k; i++)
    {
        if(i&1)
        {
            a+=b/2,b=b/2;
        }
        else
        {
            b+=a/2,a=a/2;
        }
    }
    cout<<a<<' '<<b;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <map>
#include <unordered_map>
#include <utility>

using namespace std;

int N;
string S;

struct pair_hash {
	template <class T1, class T2>
	std::size_t operator () (const std::pair<T1, T2> &p) const {
		auto h1 = std::hash<T1>{}(p.first);
		auto h2 = std::hash<T2>{}(p.second);

		// Mainly for demonstration purposes, i.e. works but is overly simple
		// In the real world, use sth. like boost.hash_combine
		return h1 ^ h2;
	}
};

using P = pair<string, string>;

void solve() {
	long long ans;
	cin >> N >> S;
	string S1, S2;
	S1 = S.substr(0, N);
	S2 = S.substr(N, N);
	reverse(S2.begin(), S2.end());

	//unordered_map<P, int, pair_hash> um;
	map<P, int> um;
	for (int Nbits_i = 0; Nbits_i < 1 << N; Nbits_i++)
	{
		string A1 = "", B1 = "";
		for (int S1_i = 0; S1_i < N; S1_i++)
		{
			if (Nbits_i >> S1_i & 1) {
				A1 += S1[S1_i];
			}
			else {
				B1 += S1[S1_i];
			}
		}
		um[P(A1, B1)]++;
	}
	long long sum = 0;
	for (int Nbits_i = 0; Nbits_i < 1 << N; Nbits_i++)
	{
		string A2 = "", B2 = "";
		for (int S2_i = 0; S2_i < N; S2_i++)
		{
			if (Nbits_i >> S2_i & 1) {
				A2 += S2[S2_i];
			}
			else {
				B2 += S2[S2_i];
			}
		}
		sum += um[P(A2, B2)];
	}

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

int main() {
	solve();

	return 0;
}


Measured memory_bytes: 91904
import copy

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

for k in range(min(K, 41)):
    B = [0 for _ in range(N)]
    for i in range(N):
        left = max(i-A[i], 0)
        right = min(i+A[i], N-1)
        B[left] += 1
        if (right+1<N):
            B[right+1] -= 1
    for i in range(1, N):
        B[i] += B[i-1]
    A = copy.deepcopy(B)
print(" ".join(list(map(str, A))))


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

const ll LINF = 1e18;
const int INF = 1e9;
const ll MOD = 1000000007;

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

ll is_digit(ll N){
    ll ret = 0;
    while(N){
        ret++;
        N /= 10;
    }
    return ret;
}
ll func(ll N){
    ll ans = INF;
    for(ll a = 1; a*a <= N; a++){
        if(N % a == 0){
            ll b = N / a;
            ll tmp = max(is_digit(a), is_digit(b));
            ans = min(ans, tmp);
        }
    }
    return ans;
}
int main(){

    ll n;
    cin >> n;
    cout << func(n) << endl;
    return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <algorithm> // sort
#include <math.h> // sort

#define REP(i, n) for (long long i = 0; i < (n); i++) 
typedef long long ll;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;
using namespace std;

//F
//遠くにいく
//X,Yのabsの最大
int main(){
    //std::ifstream in("input.txt");
    //std::cin.rdbuf(in.rdbuf());
    string s;
    cin >> s;

    s[3] = '8';

    cout << s << endl;


    return 0;    

}



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

int main(){
  int H,W;
  cin >> H >> W;
  vector<string> S(H);
  for(int i=0;i<H;i++)  cin >> S.at(i);

  vector<int> same(5,0);
  vector<vector<int>> x(H,vector<int>(W,0));
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      int cnt=0;
      if(x.at(i).at(j)==0){
        x.at(i).at(j)=1;
        cnt++;
      }
      if(x.at(i).at(W-1-j)==0){
        x.at(i).at(W-1-j)=1;
        cnt++;
      }
      if(x.at(H-1-i).at(j)==0){
        x.at(H-1-i).at(j)=1;
        cnt++;
      }
      if(x.at(H-1-i).at(W-1-j)==0){
        x.at(H-1-i).at(W-1-j)=1;
        cnt++;
      }
      same.at(cnt)++;
    }
  }

  vector<int> al(26,0);
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      al.at(S.at(i).at(j)-'a')++;
    }
  }
  for(int i=0;i<26;i++){
    while(al.at(i)!=0){
      bool flag=false;
      for(int j=4;j>=1;j--){
        if(same.at(j)==0) continue;
        if(al.at(i)<j)  continue;
        flag=true;
        same.at(j)--;
        al.at(i)-=j;
        break;
      }
      if(!flag){
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;

  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <deque>
using namespace std;
const int N = 3000;
string s, t;
int dp[3001][3001];
main() {
  cin >> s >> t;
  for(int i = 1; i <= (int)s.size(); i++) {
    for(int j = 1; j <= (int)t.size(); j++) {
      dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
      if(s[i - 1] == t[j - 1]) {
        dp[i][j] = dp[i - 1][j - 1] + 1;
      }
    }
  }

  deque < char > ans;
  int n = s.size(), m = t.size();
  while(n && m) {
    if(dp[n][m] == dp[n - 1][m]) n--;
    else if(dp[n][m] == dp[n][m - 1]) m--;
    else if(dp[n][m] == dp[n - 1][m - 1] + 1) {
      ans.push_front(s[n - 1]); n--; m--;
    }

  }

  for(int i = 0; i < ans.size(); i++) {
    printf("%c", ans[i]);
  }
}

Measured memory_bytes: 35456
h, w = map(int, input().split())

# 一発目を横に切る
tmp = h // 3
a = tmp * w
b = (h-tmp) // 2 * w
c = h*w - a - b
ans = max([a, b, c]) - min([a, b, c])

tmp = (h+2) // 3
a = tmp * w
b = (h-tmp) // 2 * w
c = h*w - a - b
ans = min(ans, max([a, b, c]) - min([a, b, c]))

tmp = h // 3
a = tmp * w
b = (h-tmp) * (w//2)
c = h*w - a - b
ans = min(ans, max([a, b, c]) - min([a, b, c]))

tmp = (h+2) // 3
a = tmp * w
b = (h-tmp) * (w//2)
c = h*w - a - b
ans = min(ans, max([a, b, c]) - min([a, b, c]))

# 一発目を縦に切る
tmp = w // 3
a = tmp * h
b = (w-tmp) // 2 * h
c = w*h - a - b
ans = min(ans, max([a, b, c]) - min([a, b, c]))

tmp = (w+2) // 3
a = tmp * h
b = (w-tmp) // 2 * h
c = w*h - a - b
ans = min(ans, max([a, b, c]) - min([a, b, c]))

tmp = w // 3
a = tmp * h
b = (w-tmp) * (h//2)
c = w*h - a - b
ans = min(ans, max([a, b, c]) - min([a, b, c]))

tmp = (w+2) // 3
a = tmp * h
b = (w-tmp) * (h//2)
c = w*h - a - b
ans = min(ans, max([a, b, c]) - min([a, b, c]))

print(ans)

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

using namespace std;



main(){
    double ans = 0.0;
    int n;
    scanf("%d" , &n);

    while( n -- ){
        double x;
        scanf("%lf" , &x);

        ans += 1.0/x;
    }

    printf("%.10f\n" , 1.0/ans);

    return 0;
}


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

#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

int64_t grundy(const vector<vector<int64_t>>& adjs, int64_t v, int64_t p) {
    int64_t g = 0;

    for (auto u : adjs[v]) {
        if (u == p) {
            continue;
        }

        auto t = grundy(adjs, u, v);

        g ^= t + 1;
    }

    return g;
}

int main() {
    int64_t n;
    cin >> n;

    vector<vector<int64_t>> adjs(n);
    for (auto _ : irange(0L, n - 1)) {
        int64_t x, y;
        cin >> x >> y;
        --x;
        --y;
        adjs[x].push_back(y);
        adjs[y].push_back(x);
    }

    auto g = grundy(adjs, 0, -1);

    if (g != 0) {
        cout << "Alice" << endl;
    } else {
        cout << "Bob" << endl;
    }
}

Measured memory_bytes: 11904
#include <bits/stdc++.h>
 
#define ALL(l)  (l).begin(),(l).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
ll mod =  1000000007;
ll maxn = 1000000000;
 
//---------------------------------------------------------------------------------------------------
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vll = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける
using vs = vector<string>; // stringの1次元の型に vs という別名をつける
using pll = pair<ll, ll>; // これ以降 pii という型名はpair<ll, ll> と同じ意味で使える
//---------------------------------------------------------------------------------------------------
 
int main(){
   int n,p;
   cin>>n>>p;
   p+=n*3;
   cout<<p/2<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;
int main(){
    int n;
    cin >> n;
    vector<double> a(n);
    double ans=0;
    for(int i=0;i<n;i++){
        cin >> a[i];
        ans+=1/a[i];
    }
    cout << 1/ans << endl;
}

Measured memory_bytes: 256
# /usr/bin/python
# -*- coding: utf-8 -*-
#
import sys
 

def isfour(s):
  for i in s:
    if i == 'Y':
      return True
  return False


input()
s = list(map(str, sys.stdin.readline().rstrip().split()))
if isfour(s):
  print("Four")
else:
  print("Three")




Measured memory_bytes: 38384
n,k=map(int,input().split())
a=[int(i) for i in input().split()]
dp=[10**9]*n
dp[0]=0
dp[1]=abs(a[1]-a[0])
for i in range(2,n):
    for j in range(max(0,i-k),i):
        dp[i]=min(dp[j]+abs(a[i]-a[j]),dp[i])
print(dp[-1])


Measured memory_bytes: 52320
// "static void main" must be defined in a public class.
import java.util.*;
public class Main {
    public static void main(String[] args) {
       Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int y = sc.nextInt();
        int[] a = new int[x];
        int c=0;
        for(int i=0;i<x;i++){
            a[i] = sc.nextInt();
            c=c+a[i];
        }
        int count=0;
        for(int j=0;j<a.length;j++){
            if((a[j]*4*y)>=c){count++;}
            if(count==y){System.out.println("Yes");return;}
        }
        
        
        System.out.println("No");
    }
}


Measured memory_bytes: 23764
N = int(input())
H = list(map(int, input().split()))
INF = 10**9
dp = [INF] * N
dp[0] = 0
dp[1] = abs(H[1]-H[0])
for i in range(2, N):
    dp[i] = min(dp[i], dp[i-1] + abs(H[i]-H[i-1]))
    dp[i] = min(dp[i], dp[i-2] + abs(H[i]-H[i-2]))
print(dp[N-1])

Measured memory_bytes: 52208
#include<bits/stdc++.h>
using namespace std;
int n,t[2],a[5][100010],to[100010];
char buffer[10000010],*hed;
inline char Getchar(){
    return *hed++;
}
inline int rd(){
    register int x=0;
    char c;
    do c=Getchar();
    while(!isdigit(c));
    do{
        x=(x<<1)+(x<<3)+(c^48);
        c=Getchar();
    }while(isdigit(c));
    return x;
}
inline int abs(int x){
    return x>=0?x:-x;
}
int main(){
    int len=fread(buffer,1,10000000,stdin);
    hed=buffer;
    n=rd();
    for(int i=1;i<=3;i++)
        for(int j=1;j<=n;j++)
            a[i][j]=rd();
    for(register int i=1;i<=n;i++){
        to[i]=a[2][i]/3+1;
        if(!((a[1][i]-a[2][i]==-1&&a[2][i]-a[3][i]==-1&&a[1][i]%3==1)||(a[1][i]-a[2][i]==1&&a[2][i]-a[3][i]==1&&!(a[1][i]%3)))||(abs(i-to[i])&1)){
            puts("No");
            return 0;
        }
        t[i&1]^=(a[1][i]>a[2][i]);
    }
    for(register int i=1;i<=n;i++){
        while(to[i]!=i){
            t[i&1^1]^=1;
            swap(to[i],to[to[i]]);
        }
    }
    puts(t[0]||t[1]?"No":"Yes");
    return 0;
}

Measured memory_bytes: 5504
#include<cstdio>
int main(void){
  int n;
  int a[5555];
  int k=0;
  bool v;
  for(int i=1;i<5556;i++){
    v=true;
    for(int j=3;j<(10*i+1);j+=2){
if((10*i+1)%j==0)v=false;
    }
   if(v){
     a[k]=(10*i)+1;
    k++;
  }
}
  k=0;
  scanf("%d",&n);
  while(n>0){
printf("%d",a[k]);
    if(n>1)printf(" ");
    else printf("\n");
    n--;
    k++;
  }
  return 0;
}

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



int main() {
#ifdef HOME
    assert(freopen("in", "r", stdin));
#endif


    ll n, a, b;
    while (cin >> n >> a >> b) {
        ll ans;
        if (n == 1 && a != b) {
            ans = 0;
        } else if (a > b) {
            ans = 0;
        } else {
            ll mn = (n - 1) * a + b;
            ll mx = (n - 1) * b + a;
            ans = mx - mn + 1;
        }
        printf("%lld\n", ans);
    }


#ifdef HOME
    cerr << "time: " << clock() * 1.0 / CLOCKS_PER_SEC << endl;
#endif
    return 0;
}



Measured memory_bytes: 256
from operator import itemgetter
n,m= map(int,input().split())
a = list(map(int,input().split()))
s = [list(map(int,input().split())) for i in range(m)]

a.sort()
t = sorted(s,key = itemgetter(1),reverse = True)

p = 0

for i in range(m):
    if p + t[i][0] >= len(a):
        for j in range(p,len(a)):
            if a[p] < t[i][1]:
                p +=1
            else:
                break
    elif a[p + t[i][0]-1] > t[i][1]:
        for j in range(p,len(a)):
            if a[p] < t[i][1]:
                p +=1
            else:
                break
    else:
        p += t[i][0]

p1 = 0
q = 0
for i in range(m):
    if p1 + t[i][0] < p:
        q += t[i][0] * t[i][1]
        p1 += t[i][0]
    else:
        q += t[i][1] * (p-p1)
        break

print(q + sum(a[p:]))


Measured memory_bytes: 33740
#include <bits/stdc++.h>
using namespace std;
int main(){
    string S;
    cin>>S;
    vector<int> a(S.size(),0);
    int length=0;
    for(int i =0;i<S.size();i++){
        char s =S.at(i);
        if(s=='A'||s=='T'||s=='G'||s=='C'){
            length ++;
            a.at(i)=length;
        }         
        else{
            length=0;
        }
    }
    int ans = 0;
    sort(a.begin(),a.end());
    ans=a.at(S.size()-1);
    cout<<ans<<endl;
}

Measured memory_bytes: 256
def Fibonacci(n):
  if n==1 or n==2:
    return 1
  a,b=1,1
  for i in range (3,1+n):
    a,b=a+b,a
  return a

n,m=map(int,input().split())
bk=-1
ans=1
for i in range(m):
  a=int(input())
  if bk==-1 and a==2:
    ans*=2
  elif bk+1==a:
    print(0)
    exit()
  ans*=Fibonacci(a-bk-1)
  bk=a
if bk!=m:
  ans*=Fibonacci(n-bk)
print(ans%(10**9+7))

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

class Program
{
	static void Main(string[] args)
	{
		//読み込む
		StringBuilder S = new StringBuilder(Console.ReadLine());
		int Q = int.Parse(Console.ReadLine());

		//反転回数が奇数かを確かめる変数
		bool isOdd = true;

		//最初or末尾に追加する文字列を格納
		StringBuilder first = new StringBuilder("");
		StringBuilder last = new StringBuilder("");

		//文字列の長さが2以上かを判定する変数
		bool longer = false;
		if(S.Length > 1){
				longer = true;
		}

		//ループ処理で読み込む
		for(int i=0; i<Q; i++){
				string[] line = Console.ReadLine().Split(' ');
				string Ti = line[0];

				//Ti = 1のとき
				if(Ti == "1"){
						//フラグが立っている場合のみ、反転
						if(longer){
								if(isOdd){
										isOdd = false;
								}else{
										isOdd = true;
								}
						}
				}

				//Ti = 2のとき
				else{
						//追加をフラグに反映
						longer = true;

						//命令を変数に格納
						int Fi = int.Parse(line[1]);
						string Ci = line[2];

						//反転回数が偶数の場合
						if(isOdd){
								if(Fi == 1){
										//先頭に追加
										first.Append(Ci);
								}else{
										//末尾に追加
										last.Append(Ci);
								}
						}
						//奇数の場合
						else{
								if(Fi == 2){
										//先頭に追加
										first.Append(Ci);
								}else{
										//末尾に追加
										last.Append(Ci);
								}
						}
				}
		}

		//firstを反転
		string newFirst = new string(first.ToString().Reverse().ToArray());
		//再びStringBuilderを作成
		StringBuilder answer = new StringBuilder(newFirst);

		answer.Append(S);
		answer.Append(last);

		string Str = answer.ToString();

		//反転回数が偶数の場合、そのまま出力
		if(isOdd){
				Console.WriteLine(Str);
		}
		//反転回数が奇数の場合、文字列を反転して出力
		else{
        string newS = new string(Str.Reverse().ToArray()); 
				Console.WriteLine(newS);
        }
	}
}

Measured memory_bytes: 24244
#include<bits/stdc++.h>
using namespace std;
const int N=305;
int f[N][N][N],n,K;char s[N];
int main(){
  //freopen("pp.in","r",stdin);
  //freopen("pp.out","w",stdout);
  scanf("%s%d",s+1,&K);n=strlen(s+1);
  for(int i=1;i<=n;i++)
      for(int k=0;k<=K;k++)f[i][i][k]=1;
  for(int len=2;len<=n;len++){
      for(int i=1;i+len-1<=n;i++){
          int j=i+len-1;
          for(int k=0;k<=K;k++){
              f[i][j][k]=max(f[i+1][j][k],f[i][j-1][k]);
              if(s[i]==s[j])f[i][j][k]=max(f[i][j][k],f[i+1][j-1][k]+2);
              if(k)f[i][j][k]=max(f[i][j][k],f[i+1][j-1][k-1]+2);
          }
      }
  }
  cout<<f[1][n][K]<<endl;
  return 0;
}

Measured memory_bytes: 110464
#include<stdio.h>

int main(){
  int n,x;
  int i;
  scanf("%d%d",&n,&x);
  int l[120];
  int y=0;
  int count=0;
  for(i=0;i<n;i++){
    scanf("%d",&l[i]);
  }
  i=0;
  while(y<=x){
    count++;
    y+=l[i];
    i++;
  }

  printf("%d",count);

  return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-9;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
struct segT {
private:
	int n;
	vector<ll> node;
public:
	segT(int n_) {
		n = 1;
		while (n < n_)n *= 2;
		node.resize(2 * n - 1, 0);
	}
	void update(int k, ll a) {
		k += n - 1;
		node[k] = a;
		while (k > 0) {
			k = (k - 1) / 2;
			node[k] = node[k * 2 + 1] + node[k * 2 + 2];
			node[k] %= mod;
		}
	}
	ll query(int a, int b, int k = 0, int l = 0, int r = -1) {
		if (r < 0)r = n;
		if (r <= a || b <= l)return 0;
		if (a <= l && r <= b)return node[k];
		else {
			ll vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
			ll vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
			return (vl + vr) % mod;
		}
	}
};
int n;
ll a, b;
ll s[1 << 17];
int main() {
	cin >> n >> a >> b; if (a > b)swap(a, b);
	s[0] = -INF;
	rep1(i, n) {
		cin >> s[i];
	}
	bool f = true;
	rep1(i, n - 2) {
		if (s[i + 2] - s[i] < a) {
			f = false;
		}
	}
	if (!f) {
		cout << 0 << endl;
		return 0;
	}
	n++;
	int le = 0;
	segT sg(n);
	sg.update(0, 1);
	rep1(i, n - 1) {
		ll d = s[i] - s[i - 1];
		int ri = upper_bound(s, s + n, s[i] - b)-s;
		ll sum = sg.query(le, ri);
		sg.update(i, sum);
		if (d < a) {
			le = i - 1;
		}
	}
	cout << sg.query(le, n) << endl;
	//stop
	return 0;
}

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


#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = (int)1e9 + 7; typedef vector<ll> VL;
void dbg(){ cerr << "\n"; }  template <class T, class ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T> void amax(T& a,T b){ a=max(a,b);}

vector<int64_t> fct, inv;
void finit(int cmx, ll mod =MD){
	fct.resize(cmx+20); inv.resize(cmx+20);
	auto bin_pows =[](ll x, ll n, ll mod){
		ll res = 1LL;
		for(; n > 0; n >>=1, x = x*x %mod) if(n & 1) res = res * x %mod;
		return res;
	};
	fct[0] = fct[1] = inv[1] = 1;
	for(int i=2;i<cmx+3;i++) fct[i] = fct[i-1] * i % mod;
	inv[cmx] = bin_pows(fct[cmx], mod-2, mod);
	for(int i=cmx;i>=1;i--) inv[i-1] = inv[i] * i % mod;
}
ll nCk(ll n, ll k, ll mod =MD) {
	if(k > n || n <0 || k <0) return 0;
	ll ret =fct[n] * inv[k] % mod * inv[n-k] % mod;
	return ret;
}

int main() {
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n, k;
	cin >>n >>k;
	VL a(n);
	rep(i, n) cin >>a[i];
	sort(all(a));
	finit(100050);
	ll ans =0;
	rep(i, n){
		(ans += a[i] * nCk(i, k-1)) %=MD;
		(ans += MD - (a[i] * nCk(n-1-i, k-1)) % MD ) %=MD;
	}
	cout << ans <<"\n";
	return 0;

}



Measured memory_bytes: 2560
n, a, b=map(int,input().split())
s = input()
A = 0
B = 0
for S in s:
  #print(S, A, B, a, b, a+b)
  if S == 'a' and A < a + b:
    A += 1
    print('Yes')
  elif S == 'b' and A < a + b and B < b:
    A += 1
    B += 1
    print('Yes')
  else:
    print('No')

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

namespace ABC125A
{
    class Program
    {
        static void Main(string[] args)
        {


            Double[] x = Console.ReadLine().Split().Select(s => Double.Parse(s)).ToArray();

            Double a = 0;
            
            for(Double i = x[0]; i < x[2] + 0.5; i += x[0])
            {
                a += x[1];
            }

   
            Console.WriteLine((double)a);


        }
    }
}


Measured memory_bytes: 11348
n = int(input())
s = []

def comb2(x):
	if x==0:
		return 0
	ans = x*(x-1)/2
	return ans

for i in range(n):
	s.append(sorted(list(input())))

s = sorted(s)
count = [0 for _ in range(len(s))]

x = 0

for i in range(n-1):
	if s[i] == s[i+1]:
		count[x] += 1
	else:
		count[x] += 1
		x = x + 1
	if i == n-2:
		count[x] += 1

ans = 0
#print (count)
for i in count:
	ans += comb2(i)


print(int(ans))

Measured memory_bytes: 25420
#define _CRT_SECURE_NO_WARNINGS

#include<stdio.h>
#include<iostream>
#include<cmath>
#include<vector>
#include<string>
#include<string.h>
#include<algorithm>
#include<numeric>
#include<random>
#include <functional>
using namespace std;

int main() {
	string O;
	string E;
	string ans;
	int gu = 0;
	int ki = 0;
//	int i = 1;
	cin >> O >> E;
	for (int i = 1;i<=(O.size()+E.size());i++) {
		if (i%2==0) {
			ans += E[gu];
			gu++;
		}
		else {
			ans += O[ki];
			ki++;
		}
	}

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

Measured memory_bytes: 256
S = [i for i in input()]
f = 0
for i in range(len(S)//2):
  #print(S[i], S[-1-i])
  if not S[i] == S[-1-i]:
    f = 1
    print('No')
    break
#print(f)
if f == 0:
  s = S[:int((len(S)-1)/2)]
  for i in range(int(len(s)//2)):
    if not s[i] == s[-1-i]:
      f = 1
      print('No')
      break
#print(f)
if f == 0:
  s = S[int((len(S)+3)/2-1):]
  for i in range(int(len(s)//2)):
    #print(s[i], s[-1-i])
    if not s[i] == s[-1-i]:
      f = 1
      print('No')
      break
if f ==0:
  print('Yes')

Measured memory_bytes: 3192
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <cstring>
#include <map>
#include <set>
#include <algorithm>

using namespace std;

int main()
{
  int N, M;
  cin >> N >> M;
  vector<pair<long, int>> shop(N);
  for (int i=0;i<N;i++) {
    int a,b;
    cin >> a >> b;
    shop[i] = make_pair(a, b);
  }
  sort(shop.begin(), shop.end());
  int sum = 0;
  long ans = 0;
  for (int i = 0; i < N; i++) {
    int count = M-sum < shop[i].second ? M-sum : shop[i].second;
    sum += shop[i].second;
    ans += count * shop[i].first;
    if (sum >= M) break;
  }
  cout << ans << endl;
}


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

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

class Mint{
    public:
    int v;
    const long long MOD = 1000000007;
    Mint():v(0){}
    Mint(signed v):v(v){}
    Mint(long long t){v=t%MOD; if(v<0)v+=MOD;}

    Mint pow(long long k){
        Mint res(1), tmp(v);
        while(k){
            if(k&1)res*=tmp;
            tmp*=tmp;
            k>>=1;
        }
        return res;
    }
    Mint inv(){return pow(MOD-2);}

    Mint& operator+=(Mint a){v+=a.v; if(v>=MOD)v-=MOD; return *this;}
    Mint& operator-=(Mint a){v+=MOD-a.v; if(v>=MOD)v-=MOD; return *this;}
    Mint& operator*=(Mint a){v=1LL*v*a.v%MOD; return *this;}
    Mint& operator/=(Mint a){return (*this)*=a.inv();}

    Mint operator+(Mint a) const{return Mint(v)+=a;};
    Mint operator-(Mint a) const{return Mint(v)-=a;};
    Mint operator*(Mint a) const{return Mint(v)*=a;};
    Mint operator/(Mint a) const{return Mint(v)/=a;};

    Mint operator-(){return v ? MOD-v : v;}
    bool operator==(Mint a)const{return v==a.v;}
    bool operator!=(Mint a)const{return v!=a.v;}

    Mint operator=(Mint a) {v=a.v;return a;}

    friend ostream& operator<<(ostream& os, const Mint& mint){
        os << mint.v;
        return os;
    }
};

class cmbs{
    public:
    vector<Mint> fact, finv, inv;
    cmbs(){
        fact.clear(); finv.clear(); inv.clear();
    }
    void init(int n){
        if(n+1 <= (signed)fact.size())return;
        fact.assign(n+1,1);
        finv.assign(n+1,1);
        inv.assign(n+1,1);

        for(int i=1; i<=n; i++) fact[i] = fact[i-1]*Mint(i);
        finv[n] = Mint(1)/fact[n];
        for(int i=n; i>=1;i--) finv[i-1] = finv[i]*Mint(i);
        for(int i=1; i<=n; i++) inv[i] = finv[i]*fact[i-1];
    }
    Mint comb(long long n, int k){
        if(n<k||k<0)return Mint(0);
        Mint res(1);
        for(int i=0; i<k; i++){
            res *= Mint(n-i);
            res /= Mint(i+1);
        }
        return res;
    }
    Mint C(int n,int k){
        if(n<k||k<0)return Mint(0);
        init(n);
        return fact[n]*finv[n-k]*finv[k];
    }
    Mint P(int n, int k){
        if(n<k || k<0)return Mint(0);
        init(n);
        return fact[n]*finv[n-k];
    }
    Mint H(int n, int k){
        if(n<0||k<0)return Mint(0);
        if(!n&&!k)return Mint(1);
        init(n+k-1);
        return C(n+k-1,k);
    }
    Mint S(int n, int k){
        Mint res;
        init(k);
        for(int i=0; i<=k; i++){
            Mint v = (C(k,i) * Mint(k-i).pow(n));
            if(i%2==0) res+=v;
            else res-=v;
        }
        return res;
    }
};

int main(){
    ll n,k;
    cin>>n>>k;
    cmbs cmb; cmb.init(k);
    cout<< (cmb.S(n,k) * cmb.finv[k]) <<endl;
    return 0;
}


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

int main() {
    int N, R;
    cin >> N >> R;
    if (N >= 10) {
        cout << R << endl;
    }
    else {
        int ans = 100 * (10-N) + R;
        cout << ans << endl;
    }
}

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

using namespace std;

#define fRead(x)  freopen(x,"r",stdin)
#define fWrite(x) freopen (x,"w",stdout)

#define LL long long
#define ULL unsigned long long
#define ff first
#define ss second
#define pb push_back
#define INF 2e16
#define PI acos(-1.0)
#define mk make_pair

#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define min4(a,b,c,d) min(a,min(b,min(c,d)))
#define max4(a,b,c,d) max(a,max(b,max(c,d)))
#define SQR(a) ((a)*(a))
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define ROF(i,a,b) for(int i=a;i>=b;i--)
#define REP(i,b) for(int i=0;i<b;i++)
#define MEM(a,x) memset(a,x,sizeof(a))
#define ABS(x) ((x)<0?-(x):(x))

#define scanI(a) scanf("%d",&a)
#define scanI2(a,b) scanI(a) , scanI(b)
#define scanI3(a,b,c) scanI(a), scanI(b), scanI(c)
#define scanI4(a,b,c,d) scanI(a), scanI(b), scanI(c), scanI(d)

#define scanL(a) scanf("%I64d",&a)
#define scanL2(a,b) scanL(a) , scanL(b)
#define scanL3(a,b,c) scanL(a), scanL(b), scanL(c)
#define scanL4(a,b,c,d) scanL(a), scanL(b), scanL(c), scanL(d)

#define SORT(v) sort(v.begin(),v.end())
#define REV(v) reverse(v.begin(),v.end())

#define FastRead ios_base::sync_with_stdio(0);cin.tie(nullptr);

int main()
{
    int a , b;
    cin >> a >> b;
    string s1,s2;
    for(int i = 0;i < b;i++){
        char d = a + '0';
        s1 += d;
    }
    for(int i = 0;i < a;i++){
        char d = b + '0';
        s2 += d;
    }
    cout << min(s1,s2) << endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
using namespace std;
typedef long long int ll;
#define mod                          1000000007  // 1e9 + 7 >>>  ans%mod
#define greator_sort(arr,n)          sort(arr, arr+n, greater<int>())  //descending order sorting of array
#define mk(arr,n,type)               type*arr = new type[n];    //to make array dynamically // n = size_of_array  |  type = int or long long etc;                      
#define w(x)                         int x;cin>>x; while(x--)   //x = test cases




int main()
{
	int check;
	string s;cin>>s;
	string t;cin>>t;
	for(int i=0;i<s.size();i++)
	{
		if(t[i]==s[i])
			check=1;

		else if(t[i] !=s[i])\
		{
			check=0;
			cout<<"No"<<endl;
			break;
		}
	}
	if(check==1)
		cout<<"Yes"<<endl;
}


Measured memory_bytes: 3568
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#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=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define uni(e) e.erase(unique(e.begin(),e.end()),e.end())
#define double long double
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 INF=1e10;
int MOD=1e9+7;
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
int keta(int a){
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
}
int kurai(int a,int b){
  int m=pow(10,b),n=pow(10,b-1);
  return (a%m)/n;
}
int ketawa(int a){
  int k=0;
  rep(i,keta(a)){
  k+=kurai(a,i+1);
  }
  return k;
}
int gcd(int a,int b){
  if(a%b==0)
    return b;
  return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
int mid(int a,int b,int c){
  vector<int> k(3);
  k[0]=a;k[1]=b;k[2]=c;
  sort(all(k));
  return k[1];
}
bool sosuu(int a){
  bool b=1;
  if(a<=1)
    return 0;
  else{
  rep1(i,sqrt(a)-1){
  if(a%(i+1)==0)
  b=0;
  }
  return b;
  }
}
int modpow(int a,int b,int m=MOD){
 if(!b)return 1; if(b&1)return modpow(a,b-1,m)*a%m;
 int memo = modpow(a,b>>1,m);
 return memo*memo%m;
}
int fact_mod(int n) {
    int f=1; 
for(int i=2;i<n+1;i++) f=f*(i%MOD)% MOD;
    return f;
}
int mod_pow(int x,int n) {
    int res=1;
    while(n>0){
        if(n&1) res=(res*x)%MOD; 
        x=(x*x)%MOD;        
n>>=1; 
    }
    return res;
}
int c_mod(int n, int r) {
    if(r>n-r) r=n-r;
    if(r==0) return 1;
    int a=1;
    rep(i,r) 
a=a*((n-i)%MOD)%MOD;
    int b=mod_pow(fact_mod(r), MOD-2);
    return (a%MOD)*(b%MOD)%MOD;
}
signed main(){
  int a;
  cin>>a;
  vector<int> b(a);
  rep(i,a)
    cin>>b[i];
  int c;
  rep(i,100){
  rep(j,a){
  if(b[j]%2==1){
  c=i;
    goto A;
  }
    else
      b[j]/=2;
  }
  }
  A:
  out(c);
 }

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

using namespace std;


string s;
string t;
int dp[3010][3010];

int solve(int i, int j){
	if(i == 0 || j == 0)	return dp[i][j] = 0;
	
	if(dp[i][j] != -1)      return dp[i][j];
	
	return dp[i][j] = max(solve(i-1,j),max(solve(i,j-1),(s[i-1] == t[j-1]) + solve(i-1,j-1)));	
}	

string recover(int i, int j){
	if(i == 0 || j == 0){
		return "";
	}
	int val = (s[i-1] == t[j-1]);
	if(dp[i][j] == dp[i-1][j]){
		return recover(i-1,j);
	}else if(dp[i][j] == dp[i][j-1]){
		return recover(i,j-1);
	}else if(dp[i][j] == dp[i-1][j-1] + val){
		return recover(i-1,j-1) + s[i-1]  ;
	}
}

int main(){
	cin.tie();
	ios_base::sync_with_stdio(0);
	cin >> s >> t;
	for(int i = 1; i <= s.size();i++){
		for(int j = 1; j <= t.size();j++){
			dp[i][j] = max(dp[i-1][j],max(dp[i][j-1],(s[i-1] == t[j-1]) + dp[i-1][j-1]));	
		}
	}
	int i = s.size(), j = t.size();
	string ans;
	while(i != 0 && j != 0){
		int val = (s[i-1] == t[j-1]);
		if(dp[i][j] == dp[i-1][j]){
			i = i-1;
			j = j;
		}else if(dp[i][j] == dp[i][j-1]){
			i = i;
			j = j - 1;
		}else if(dp[i][j] == dp[i-1][j-1] + val){
			ans += s[i-1];
			i = i-1;
			j = j-1;
		}
	}
	reverse(ans.begin(),ans.end());
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 35584
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
#define fore(i,a,b) for(ll i=(a);i<=(b);++i)
#define rep(i,n) fore(i,0,(n)-1)
#define rfore(i,a,b) for(ll i=(b);i>=(a);--i)
#define rrep(i,n) rfore(i,0,(n)-1)
#define all(x) (x).begin(),(x).end()
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
template<class T>
bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>
bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
template<class T>
ll sum(const T& a){return accumulate(all(a),0LL);}

void solve(string n){
    ll m=n.size();
    vvl cnt(m+1,vl(2));
    cnt[0][1]=1;
    rep(i,m){
        ll x=n[i]-'0';
        cnt[i+1][0]=min(cnt[i][0]+x,cnt[i][1]+10-x);
        cnt[i+1][1]=min(cnt[i][0]+x+1,cnt[i][1]+10-(x+1));
    }
    cout<<cnt[m][0]<<endl;
}

int main(){
    string n;
    cin >> n;
    solve(n);
}


Measured memory_bytes: 56836
#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <utility>
#include <complex>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <tuple>
#include <bitset>
#include <limits>
#include <algorithm>
#include <array>
#include <random>
#include <complex>
#include <regex>
#include <iomanip>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define fcout cout << fixed << setprecision(10)
#define rep(i,n)    for(int i=0; i<(int)n; i++)
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define all(x) x.begin(), x.end()
const ll inf = 1e18;
const ll mod = 1e9 + 7;

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

// mod. m での a の逆元 a^(-1) を計算する。
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

int main(){
    string s;
    cin >> s;
    if(s == "ABC") cout << "ARC" << endl;
    else cout << "ABC" << endl;
}



Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
#include <stack>
#include <math.h>
#include <set>
#include <cstdio>
#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define P pair<int, int>

#define MOD 1000000007
#define INF 1012345678
#define NINF (-2147483647-1)
#define LLINF 9223372036854775807
using ll = long long;
using namespace std;

//gcd(int)
int gcd(int a, int b) {
    return b ? gcd(b, a%b) : a;
}

int main() {
    int N, cnt = 0, M = NINF, L = INF;
    ll ans = 0;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
        if (A[i] < 0) {
            cnt++;
            ans -= A[i];
            M = max(M, A[i]);
        }
        else {
            ans += A[i];
            L = min(L, A[i]);
        }
    }
    if (cnt % 2 == 0) {
        cout << ans << endl;
    }
    else {
        if (L + M > 0) {
            cout << ans + M + M << endl;
        }
        else {
            cout << ans - L - L << endl;
        }
    }
    /*else {
        sort(RALL(A));
        int left = -1, right = N;
        while (right - left > 1) {
            int mid = (left + right) / 2;
            if (A[mid] < 0) {

            }
        }
    }*/
    getchar(); getchar();
    return 0;
}

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

const int N = 1e6 + 5;

#define st first
#define nd second

typedef pair<int,int> pun;
typedef long long ll;

int main() {
	int m, n, k;
	scanf("%d%d%d", &n, &m, &k);
	bool ans = false;
	for (int i = 0; i <= n; i ++) {
		for (int j = 0; j <= m; j ++) {
			if (i * (m - j) + j * (n - i) == k) ans = true;
		}
	}
	printf("%s\n", ans? "Yes" : "No");
}


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

int main()
{
    int a[3];
    int ans = 0;

    for ( int i = 0; i < 3; ++i ) {
        scanf("%d", &a[i] );
    }

    sort( a, a + 3, greater<int>() );

    ans += a[0];
    ans *= 10;
    ans += a[1] + a[2];

    printf("%d\n", ans );

    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <set>
#include <queue>
#include <deque>
#include <map>
#include <stack>
#include <cmath>
using namespace std;

#define mod 1000000007
#define ten5 100005
#define ten52 200005
#define ten53 300005
#define ten6 1000005
#define PI 3.1415926
#define pb(x) push_back(x)
#define all(x) x.begin(),x.end()
#define mkpr(x1,x2) make_pair(x1,x2)
typedef long long int ll;

//stack<char> stk;
//set<ll> sll;
//set<pair<ll,ll>> spll;
map<string,ll> mp;
map<string,ll>::iterator mpit;
//map<ll,ll> mp;
//deque<ll> deq;
vector<ll> vll;
ll num[ten52];
//priority_queue<pair<ll,ll>> pq;          //decreasing


int main(void)
{
    ll m=0,n,i=0,j,k=0;
    string s;
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>s;
        sort(all(s));
        mp[s]++;
    }
    for(mpit=mp.begin();mpit!=mp.end();mpit++)
    {
        j=mpit->second;
        m+=(j)*(j-1)/2;
    }
    cout<<m;
    return 0;
}


Measured memory_bytes: 11412
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); i++)
typedef long long ll;
const int mod = 1e9 + 7;

int main() {

    double w, h, x, y;
    cin >> w >> h >> x >> y;

    double ans = (w*h) / 2;

    cout << fixed << setprecision(7) << ans << " ";
    if(x == w/2 && y == h/2){
        cout << 1 << endl;
    }
    else{
        cout << 0 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <functional>
#include <limits>
#include <cassert>
#include <bitset>

using namespace std;

/* template */

using ll = long long;

void debug_out() { std::cout << std::endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cout << "debug: "; debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif

#define rep(i, a, n) for (int i = (int)(a); i < (int)(n); i++)
#define rrep(i, a, n) for (int i = ((int)(n-1)); i >= (int)(a); i--)
#define Rep(i, a, n) for (long long i = (long long)(a); i< (long long)(n); i++)
#define RRep(i, a, n) for (long long i = ((long long)(n-1ll)); i>=(long long)(a); i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}

struct Edge{
    int to;
    ll weight;
    Edge(int t, ll w) : to(t), weight(w){ }
};

struct edge{
    int from;
    int to;
    ll weight;
    edge(int f,int t,ll w) : from(f), to(t), weight(w){ }
};


using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;
using edges = vector<edge>;

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

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

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

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

constexpr ll LNF = 1LL<<50;

constexpr int INF = 1e9+7;

const long double PI=3.14159265358979323846;


vector<int> dx = {1,0,-1,1,-1,0};
vector<int> dy = {1,1,1,0,0,-1};

/* template */

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<int> a(n);
    map<int,int> m;
    rep(i,0,n){
        cin >> a[i];
        m[a[i]]++;
    }
    int ans = 0;
    rep(i,0,n){
        int flag = 0;
        m[a[i]]--;
        for(int j = 1; j*j<=a[i]; j++){
            if(a[i]%j==0){
                if(m[j]>0){
                    flag = 1;
                    break;
                }
                if(m[a[i]/j]>0){
                    flag = 1;
                    break;
                }
            }
        }
        if(flag==0){
            ans++;
        }
        m[a[i]]++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 33028
import java.io.*;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {

    static class Task {

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            String str = in.next();
            System.out.println(str.equals("ABC") ? "ARC" : "ABC");
        }
    }

    private static void sort(double[] arr) {
        Double[] objArr = Arrays.stream(arr).boxed().toArray(Double[]::new);
        Arrays.sort(objArr);
        for (int i = 0; i < arr.length; i++) {
            arr[i] = objArr[i];
        }
    }

    private static void sort(int[] arr) {
        Integer[] objArr = Arrays.stream(arr).boxed().toArray(Integer[]::new);
        Arrays.sort(objArr);
        for (int i = 0; i < arr.length; i++) {
            arr[i] = objArr[i];
        }
    }

    private static void sort(long[] arr) {
        Long[] objArr = Arrays.stream(arr).boxed().toArray(Long[]::new);
        Arrays.sort(objArr);
        for (int i = 0; i < arr.length; i++) {
            arr[i] = objArr[i];
        }
    }

    private static void solve() {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task task = new Task();
        task.solve(1, in, out);
        out.close();
    }

    public static void main(String[] args) {
        new Thread(null, () -> solve(), "1", 1 << 26).start();
    }

    static class InputReader {

        public BufferedReader reader;
        public StringTokenizer tokenizer;

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

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

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

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

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

    }

}

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

long GCD(long a, long b);

int main(void){
    int N;

    cin >> N;
    vector<long> A(N);

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

    for(int i = 0; i < N - 1; i++)
        A[i + 1] = GCD(A[i], A[i + 1]);

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

    return 0;
}

long GCD(long a, long b){
    long tmp;

    if(a < b){
        tmp = a;
        a = b;
        b = tmp;
    }

    long re = a % b;

    while(re != 0){
        a = b;
        b = re;
        re = a % b;
    }

    return b;
}


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



int main() {
  int k;
  cin >> k;
  int x = 7%k;
  set<int> s;
  int i = 1;
  while(s.count(x) == 0){
    if(x == 0){
      cout << i << endl;
      return 0;
    }
    s.insert(x);
    x = (x*10+7)%k;
    i++;
  }
  cout << -1 << endl;
  return 0;
}

Measured memory_bytes: 50420
s = [input() for _ in range(2)]
N = int(s[0])
P = s[1].split()
for i in range(N):
    P[i] = int(P[i])
P = [N+1] + P

count = 0
min_p = N+1

for i in range(N+1):
    if min_p > P[i]:
        count += 1
        min_p = P[i]
            
print(count)


Measured memory_bytes: 19444