akhauriyash/Code-Regression huggingface dataset:
import java.util.Arrays;
import java.util.Scanner;	
public class Main
{

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc =new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		
		int[]ar = new int[M];
		for(int i =0; i<M; i++) {
			ar[i]= sc.nextInt();
			
		}
		Arrays.sort(ar);
	
	int[]dis = new int[M-1];
	for(int i =0; i<dis.length; i++) {
		dis[i] = Math.abs(ar[i]-ar[i-i+i+1]);
	}
	Arrays.sort(dis);
	
	int count = 0;
	for(int i =0; i<dis.length-N+1; i++) {
		count += dis[i+0];
	}
	System.out.println(count);

}
}

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

int main() {
	long long ans=0,k;
	vector<int> a,b;
	long long n;
	cin >> n;
	for(auto i=1;i<=n+1;i++) {
		cin >> k;
		a.push_back(k);
	}
	for(auto i=1;i<=n;i++) {
		cin >> k;
		b.push_back(k);
	}
	for(auto i=0;i<n;i++) {
		int x =min(a[i],b[i]);
		b[i]-=x;
		ans+= x;
		x = min(a[i+1],b[i]);
		a[i+1] -= x, b[i] -= x;
		ans+=x;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1400
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>

#define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using namespace std;
int main(){
	short x;
	cin>>x;
	cout<<!x<<endl;
	return 0;
}

Measured memory_bytes: 3624
#include <cstdio>
using namespace std;

int main() {
	int N, M, h, w;
	scanf("%d%d%d%d", &N, &M, &h, &w);
	if (N % h) {
		puts("Yes");
		for (int i = 0; i < N; i++, puts(""))
			for (int j = 0; j < M; j++)
				if (!(i % h))
					printf("500 ");
				else if (!((i + 1) % h))
					printf("-501 ");
				else	
					printf("0 "); 
		return 0;
	}
	if (M % w) {
		puts("Yes");
		for (int i = 0; i < N; i++, puts(""))
			for (int j = 0; j < M; j++)
				if (!(j % w))
					printf("500 ");
				else if (!((j + 1) % w))
					printf("-501 ");
				else	
					printf("0 ");
		return 0;
	}
	puts("No");
	return 0;
}

Measured memory_bytes: 1280
#include<stdio.h>
#include<cstring>
#include<cstdlib>
using namespace std;
struct  node{
int key;
node *p,*r,*l;
};
node *NIL , *root;
void inserts(int k){
 node *y = NIL;
 node *x = root;
 node *z;
 z = (node*)malloc(sizeof(node));
 z->key = k;
 z->l = NIL;
 z->r = NIL;
 while( x != NIL ){
    y = x;
    if( z->key < x->key ){
        x = x->l;
    }else x = x->r;
 }z->p = y;
 if(y == NIL)root = z;
 else {
    if( z->key < y->key ){
        y->l = z;
    }else y->r = z;
 }
}
node* finds(node *x , int k){
while( x != NIL && x->key != k ){
    if(k < x->key)x = x->l;
    else x = x->r;
}return x;
}
node* getmin(node *x){
while ( x->l != NIL) x = x->l;
return x;
}

node* getree(node *u){
if(u -> r != NIL)return getmin( u ->r );
node *y = u->p ;
while( y != NIL && u == y->r){
    u = y;
    y = y->p;
}
return y;
}

void deletes(node *u){
node *y , *x;
if(u -> l == NIL|| u ->r == NIL)
   y = u;
else y = getree(u);

if(y->l != NIL)x = y->l;
else x = y->r;

if(x != NIL){
    x->p = y->p;
}
if(y -> p == NIL){
root = x;
} else {
    if( y == y->p->l)
    y->p->l = x;
    else y->p->r = x;
}

if( y != u )u->key = y->key;

free(y);
}

void iuorde(node *u){
if( u == NIL )return;
iuorde( u->l );
printf(" %d",u->key);
iuorde( u->r );
}
void iuorder(node *u){
if( u == NIL )return ;
printf(" %d",u->key);
iuorder( u->l );
iuorder( u->r );
}

int main(){
int n , i , x;
char ss[100];
scanf("%d",&n);
while(n--){
    scanf("%s",ss);
    if(!strcmp(ss,"insert")){
        scanf("%d",&x);inserts(x);
    }
else if(!(strcmp(ss,"find"))){
    scanf("%d",&x);if(finds(root,x)==NIL)printf("no\n");
    else printf("yes\n");
}
else if(!strcmp(ss,"delete")){
     scanf("%d",&x);
     deletes(finds(root,x));
}
    else {
    iuorde(root);
    printf("\n");
    iuorder(root);
    printf("\n");
    }

}
return 0;
}

Measured memory_bytes: 21484
#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <string>
#include <utility>

int testcase_ends() {
  size_t n;
  scanf("%zu", &n);
  if (n == 0) return 1;

  char buf[131072];
  scanf("%s", buf);
  std::string s = buf;

  std::vector<size_t> p(n);
  size_t ba = 0;
  for (size_t i = 0; i < 100; ++i) {
    char c = s[i];
    size_t j = i % n;
    if (c == 'M') {
      ++p[j];
    } else if (c == 'S') {
      ba += p[j] + 1;
      p[j] = 0;
    } else if (c == 'L') {
      p[j] += ba + 1;
      ba = 0;
    }
  }

  std::sort(p.begin(), p.end());
  for (auto pi: p) printf("%zu ", pi);
  printf("%zu\n", ba);
  return 0;
}

int main() {
  while (!testcase_ends()) {}
}



Measured memory_bytes: 2860
#include <iostream>

int main() {
    int x, a, b;
    std::cin >> x >> a >> b;

    if(b - a <= 0) {
        std::cout << "delicious" << std::endl;
    } else if(b - a <= x) {
        std::cout << "safe" << std::endl;
    } else {
        std::cout << "dangerous" << std::endl;
    }
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main{

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n =scan.nextInt();
		int b[]=new int[n];
		for(int i=0;i<n-1;i++) {
			b[i]=scan.nextInt();
		}
		scan.close();
		int sum=b[0]+b[n-2];
		for(int i=1;i<n-1;i++) {
			sum+=Math.min(b[i-1],b[i]);
		}

		System.out.println(sum);
	}

}

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

int main(){
  int a,b,k;
  cin>>a>>b>>k;
  if(b-a<2*k){
    for(int i=a;i<=b;i++)cout<<i<<endl;
    return 0;
  }
  for(int i=a;i<a+k;i++)cout<<i<<endl;
  for(int i=b-k+1;i<=b;i++)cout<<i<<endl;
}


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

using namespace std;
using ll = long long;
using ii = pair<ll, ll>;

const int MAX { 200010 };
const ll MOD { 1000000007 }, oo { 1LL << 62 };

struct Point { ll x, y; };
struct Circle { long double x, y, r; };

Circle from_3_points(const Point& P, const Point& Q, const Point& R)
{
    auto a = 2*(Q.x - P.x);
    auto b = 2*(Q.y - P.y);
    auto c = 2*(R.x - P.x);
    auto d = 2*(R.y - P.y);

    auto det = a*d - b*c;

    // Pontos colineares
    if (det == 0)
        return { 0, 0, -1 };

    auto k1 = (Q.x*Q.x + Q.y*Q.y) - (P.x*P.x + P.y*P.y);
    auto k2 = (R.x*R.x + R.y*R.y) - (P.x*P.x + P.y*P.y);

    // Solução do sistema por Regra de Cramer
    long double cx = (long double) (k1*d - k2*b)/det;
    long double cy = (long double) (a*k2 - c*k1)/det;

    auto r = hypotl(cx - P.x, cy - P.y);

    return { cx, cy, r };
}

double solve(int N, const vector<Point>& xs)
{
    if (N == 2)
        return hypotl(xs.front().x - xs.back().x, xs.front().y - xs.back().y)/2.0;

    vector<int> ns(3, 1);
    ns.resize(N);

    long double ans = 1e9;

    do {
        vector<int> ps;

        for (int i = 0; i < N; ++i)
            if (ns[i])
                ps.push_back(i);

        auto c = from_3_points(xs[ps[0]], xs[ps[1]], xs[ps[2]]);
        bool ok = c.r > 0;

        for (auto p : xs)
        {
            if (hypotl(p.x - c.x, p.y - c.y) > c.r)
            {
                ok = false;
                break;
            }
        }

        if (ok)
            ans = min(c.r, ans);
    } while (prev_permutation(ns.begin(), ns.end()));

    for (int i = 0; i < N; ++i)
    {
        for (int j = i + 1; j < N; ++j)
        {
            auto r = hypotl(xs[i].x - xs[j].x, xs[i].y - xs[j].y)/2;
            auto cx = (xs[i].x + xs[j].x)/2.0;
            auto cy = (xs[i].y + xs[j].y)/2.0;

            bool ok = true;

            for (auto p : xs)
            {
                if (hypotl(p.x - cx, p.y - cy) > r)
                {
                    ok = false;
                    break;
                }
            }

            if (ok)
                ans = min(r, ans);
        }
    }

    return ans;
}

int main()
{
    ios::sync_with_stdio(false);

    int N;
    cin >> N;

    vector<Point> xs(N);

    for (int i = 0; i < N; ++i)
        cin >> xs[i].x >> xs[i].y;

    auto ans = solve(N, xs);

    cout.precision(15);
    cout << fixed << ans << '\n';

    return 0;
}



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

int main(){

    // omajinai
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    // omajinai

    int w,h,n;
    cin >> w >> h >> n;
    int a1 = 0,a2 = w,a3 = 0,a4 = h;
    int x,y,a;

    for(int i = 0;i < n;i ++){
        cin >> x >> y >> a;
        if(a == 1){
            a1 = max(a1,x);
        }else if(a == 2){
            a2 = min(a2,x);
        }else if(a == 3){
            a3 = max(a3,y);
        }else{
            a4 = min(a4,y);
        }
    }

    if(a1 > a2 || a3 > a4){
        cout << 0 << endl;
    }else{
        cout << (a2-a1) * (a4-a3) << endl;
    }
}


Measured memory_bytes: 256
from collections import Counter

N = int(input())
a = Counter(list(map(int, input().split())))#.most_common()
max_total = 0

for i in range(min(a), max(a)+1):
    total = 0
    if i in a:
        total += a[i]
    if i-1 in a:
        total += a[i-1]
    if i+1 in a:
        total += a[i+1]
    max_total = max(max_total, total)
    
print(max_total)

Measured memory_bytes: 14564
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
typedef long long ll;
using namespace std;

int main() {
    int a,b;
    cin >> a >> b;
    cout << max(a+b,max(a-b,a*b)) << endl;

    return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
l = [-1, -1, -1]
for i in range(N+1):
  for j in range(N-i+1):
    if 1000 * i + 5000 * j + 10000 * (N-i-j) == M:
      l = [i, j, N-i-j]
print(l[2], l[1], l[0])


Measured memory_bytes: 2940
#include<iostream>
using namespace std;
int main()
{
    int a[500],n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
     
    }
    int s=0;
    for(int i=1;i<=n;i+=2)
    {
        if(a[i]%2!=0)
        s++;
    }
    cout<<s<<endl;
    return 0;
}

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

#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define dbg(a)  cerr << __LINE__ << ": " << #a << " = " << a << '\n'
typedef long long ll;

const double PI = acos(-1.0);
const int MOD = 1e9 + 7;
const int MXN = 1e5 + 5;


int main(){FIO
   #ifndef  ONLINE_JUDGE
   freopen("in", "r", stdin);
   freopen("out", "w", stdout);
   #endif
   int h, w, k;
   cin>>h>>w>>k;
   string ss[h];
   for (int i = 0; i < h; ++i)
   {
   	cin>>ss[i];
   }
   int res = 0;
   for (int i = 0; i < (1<<h); ++i)
   {
   	for (int j = 0; j < (1<<w); ++j)
   	{
         int cnt = 0;
   		for (int row = 0; row < h; ++row)
   		{
   			for (int col = 0; col < w; ++col)
   			{
   				if(!(i>>row & 1) and !(j>>col & 1) and ss[row][col] == '#') cnt++;
   			}
   		}
   		// cout<<cnt<<" ";
   		if(cnt == k) res++;
   	}
   }

   cout<<res<<endl;
   return 0;
}

Measured memory_bytes: 3628
//ABC 132 B Ordinary Number

#include <iostream>

using namespace std;

int main() {
    int n;
    cin >> n;
    int p[n];
    int cnt=0;
    for(int i=0; i<n; i++) cin >> p[i];

    for(int i=1; i<n-1; i++)
        if(p[i-1] > p[i] && p[i] > p[i+1] ||
           p[i-1] < p[i] && p[i] < p[i+1]) cnt++;

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>

int main(){
    int alice,bob;
    scanf("%d %d",&alice,&bob);
    if(alice==1){
        alice=14;
    }
    if(bob==1){
        bob=14;
    }
    if(alice>bob){
        printf("Alice");
    }
    else if(alice==bob){
        printf("Draw");
    }
    else{
        printf("Bob");
    }

}


Measured memory_bytes: 1704
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;

int main() {
  string s, t;
  cin >> s >> t;

  string s_new = "";
  string t_new = "";
  sort(s.begin(), s.end());
  sort(t.begin(), t.end());
  reverse(t.begin(), t.end());

  if (s < t) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

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

#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807;
const int INF = pow(2,29);
const int MOD = 1000000007;

int main() {
  int A, B; cin >> A >> B;
  int result = max(0, A-B*2);
  cout << result << endl;
  return 0;
}

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

int main()
{
    int n;
    cin >> n;
    
    ll ans = 1;
    for(int i = 1; i <= n; ++i)
    {
        ans *= i;
        ans %= 1000000007;
    }
    
    cout << ans << endl;
    return 0;
}

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

 
int main() {
  int a,b,c,d,e,f;
  cin >> a >> b >> c >> d >> e >> f;
  vector<int> cd = {0};
  vector<bool> dp(3005);
  dp[0] = 1;
  for(int i=1;i<3005;i++){
    if(i-c >= 0){
      if(dp[i-c]) dp[i] = 1;
    }
    if(i-d >= 0){
      if(dp[i-d]) dp[i] = 1;
    }
    if(dp[i]) cd.push_back(i);
  }
  
  double mx = 0.0;
  int ans1 = 0,ans2 = 0,n = cd.size();
  rep(A,105)rep(B,105){
    int water = 100*(a*A+b*B);
    if(water > f) continue;
    int bound = min(e*water/100,f-water);
    int left = -1,right = n;
    while(right - left > 1){
      int mid = (right + left)/2;
      if(cd[mid] <= bound) left = mid ;
      else right = mid;
    }
    int sugar = cd[left];
    //cout << water << " " << sugar << endl;
    if(mx <= (double)(100*sugar)/(sugar+water)){
      mx = (double)(100*sugar)/(sugar+water);
      ans1 = water + sugar;
      ans2 = sugar;
    }
  }
      
  cout << ans1 << " " << ans2 << endl; 
    
    
  return 0;
}



Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
    int a;
    int ever=0;
    int odd=0;
    cin>>a;
    for (int i=1; i<=a; i++) {
        if(i%2==0){
            ever += 1;
        }else if(i%2==1){
            odd += 1;
        }
    }
    cout<<ever*odd<<endl;
    return 0;
}

Measured memory_bytes: 256
N = gets.to_i
xs = gets.split.map(&:to_f)
M, k = gets.split.map(&:to_i)
as = gets.split.map{|c| c.to_i - 1}

base = (N-1).times.to_a
as.each do |a|
    base[a-1], base[a] = base[a], base[a-1]
end

def combine(arr1, arr2)
    ret = []
    arr1.length.times do |i|
        ret[i] = arr1[arr2[i]]
    end
    ret
end

arr = (N-1).times.to_a
while k > 0
    if k % 2 == 1
        arr = combine(arr, base)
    end
    base = combine(base, base)
    k /= 2
end

diff = (N-1).times.map{|i| xs[i+1] - xs[i]}
diff = combine(diff, arr)
ans = [xs[0]]
(N-1).times do |i|
    ans[i+1] = ans[i] + diff[i]
end
puts ans

Measured memory_bytes: 70724
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repR(i, n) for(int i = n; i >= 0; ++i)
#define FDS(i, n) for(ll i = 0; i < n; ++i)
#define FDSR(i, n) for(int i = n; i >= 0; ++i)
#define FOR(i, m, n) for(int i = m; i < n; ++i)
#define FORR(i, m, n) for(int i = m;i >= n;--i)
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
#define itn int
#define ednl endl
using namespace std;
typedef long long ll;
int main(){
	int A,B,C;
	cin>>A>>B>>C;
	if(A<C&&C<B){
		cout<<"Yes"<<endl;
	}
	else if(A>C&&C>B){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<cstdio>
#include<set>
#include<map>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repn(i, n) for(int i = 1; i <= n; i++) 
#define lint long long
#define all(x) (x).begin(), (x).end()


// ログを出すやつ。簡単なデバッグに
inline void logger(){ cout << endl; }
template<typename A, typename... B>
void logger(const A& a, const B&... b){
    cout << a << " , ";
    logger(b...);
}


int main(){
    int N; long K; cin>>N>>K;
    int c[41]={}; // c[i]=上からi桁目の1の個数
    rep(i, N){
        long a; cin >> a;
        repn(j, 40) if(a & ((long)(long)1<<(40-j))) c[j]++;
    }

    long dp[41][2]; dp[0][0] = 0; dp[0][1] = 0;
    repn(i, 40){
        if(!(K & ((long)1<<(40-i)))){
            dp[i][0] = dp[i-1][0] + ((long)1<<(40-i))*c[i];
            if(dp[i-1][1] != 0) dp[i][1] = dp[i-1][1] + ((long)(long)1<<(40-i)) * max(c[i], N-c[i]);
            else dp[i][1] = 0;
        }
        else{
            dp[i][0] = dp[i-1][0] + ((long)1<<(40-i))*(N-c[i]);
            if(dp[i-1][1] != 0)
                dp[i][1] = max(dp[i-1][1] + ((long)1<<(40-i)) * max(c[i], N-c[i]), dp[i-1][0] + ((long)1<<(40-i)) * c[i]);
            else
                dp[i][1] = dp[i-1][0] + ((long)1<<(40-i))*(c[i]);
        }
    }


    cout << max(dp[40][0], dp[40][1]) << endl;
}

Measured memory_bytes: 888
import bisect

N = int(input())
L = list(map(int, input().split()))
L.sort()
ans = 0
for i in range(N-1, 1, -1):
    for j in range(i-1, 0, -1):
        a, b = L[i], L[j]
        c = a - b + 1
        if c > b: continue
        ans += (j - bisect.bisect_left(L, c))
print(ans)

Measured memory_bytes: 74360
// Codeforces 1.12.6
// AtCoder 1.6
// Paiza 1.7.3

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

type (
	in struct {
		Scanner *bufio.Scanner
	}
	str string
	lm  struct{}
	su  struct{}
)

func (in *in) s() string {
	in.Scanner.Scan()
	return in.Scanner.Text()
}

func (in *in) i() int64 {
	return in.ibase(10)
}

func (in *in) ibase(base int) int64 {
	i, _ := strconv.ParseInt(in.s(), base, 64)
	return i
}

func (in *in) ss(n int64) []string {
	a := make([]string, n)
	for i := range a {
		a[i] = in.s()
	}
	return a
}

func (in *in) is(n int64) []int64 {
	a := make([]int64, n)
	for i := range a {
		a[i] = in.i()
	}
	return a
}

func (in *in) imat(h int64, w int64) [][]int64 {
	a := make([][]int64, h)
	for y := range a {
		a[y] = make([]int64, w)
		for x := range a[y] {
			a[y][x] = in.i()
		}
	}
	return a
}

func stdin() in {
	scn := bufio.NewScanner(os.Stdin)
	scn.Split(bufio.ScanWords)
	max := 200000
	buf := make([]byte, max)
	scn.Buffer(buf, max)
	return in{Scanner: scn}
}

func (*lm) max(a int64, b int64) int64 {
	if a > b {
		return a
	}
	return b
}

func (*lm) min(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func (*lm) abs(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

func (lm *lm) gcd(a, b int64) int64 {
	if a < b {
		a, b = b, a
	}
	if b == 0 {
		return a
	}
	return lm.gcd(b, a%b)
}

func (*su) arr(arr []int64) string {
	ret := make([]string, len(arr))
	for i, x := range arr {
		ret[i] = strconv.FormatInt(x, 10)
	}
	return strings.Join(ret, " ")
}

func (su *su) mat(matrix [][]int64) string {
	ret := make([]string, len(matrix))
	for i := range matrix {
		ret[i] = su.arr(matrix[i])
	}
	return strings.Join(ret, "\n")
}

func (*su) bool(b bool) str {
	if b {
		return "Yes"
	}
	return "No"
}

func (s str) upper() string {
	return strings.ToUpper(string(s))
}

func (s str) lower() string {
	return strings.ToLower(string(s))
}

func main() {
	// utilities.
	const zz int64 = int64(0)
	const mod int64 = int64(1000000007)
	in, lm, su := stdin(), lm{}, su{}
	_, _, _ = in, lm, su

	// read here.
	a, s := in.i(), in.s()

	// solve here.
	ans := ""
	if a < 3200 {
		ans = "red"
	} else {
		ans = s
	}

	printable := ans
	// print here.
	fmt.Println(printable)
}


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

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

  vector<ll> a(n+1);
  for(int i = 1;i <= n; i++) {
    if(i%15 == 0){
      a[i] = 0;
    } else if(i%3 == 0) {
      a[i] = 0;
    } else if(i%5 == 0) {
      a[i] = 0;
    } else {
      a[i] = i;
    }
  }

  long long ans = 0;
  for (int i  = 1; i <= n; i++) {
    ans += a[i];
  }

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


Measured memory_bytes: 11000
using System;
using System.Linq;

namespace AtCoder.DP
{
    class EDPC_M_FPS
    {
        public static void Main()
        {
            var nk = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
            var a = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
            var n = nk[0];
            var k = nk[1];

            const long mod = 1000000007;
            /* Fi = (1+x+x^2+x^3+x^4+...+x^(ai)) = (1-x^(ai+1))/(1-x)
             * P/(1-x)=Q ⇒ P=Q(1-x) ⇒ p[n]=q[n]-q[n-1] ⇒ q[n]=Σp[i]
             */
             
            var q = new long[k + 1];
            q[0] = 1;

            for (int i = 0; i < n; i++)
            {
                for (int j = 1; j <= k; j++)
                    q[j] = (q[j] + q[j - 1]) % mod;
                for (int j = k; j >= a[i] + 1; j--)
                    q[j] = (q[j] - q[j - a[i] - 1]) % mod;
            }
            Console.WriteLine(q[k] < 0 ? q[k] + mod : q[k]);
        }
    }
}

Measured memory_bytes: 29028
#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define printV(v) for(auto&& x : v){cout << x << " ";} cout << endl
#define printVV(vv) for(auto&& v : vv){for(auto&& x : v){cout << x << " ";}cout << endl;}
#define printP(p) cout << p.first << " " << p.second << endl
#define printVP(vp) for(auto&& p : vp) printP(p);

typedef long long ll;
typedef pair<int, int> Pii;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<Pii> vp;
const int inf = 1e9;
const int mod = 1e9 + 7;

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

    int W, H;
    cin >> W >> H;
    vi p(W);
    rep(i, W) cin >> p[i];
    vi q(H);
    rep(i, H) cin >> q[i];

    vp v;
    rep(i, W) {
        v.emplace_back(Pii(p[i], 1));
    }
    rep(i, H) {
        v.emplace_back(Pii(q[i], 0));
    }
    sort(all(v));

    int ans = 0;
    vi cnt(2);
    rep(i, H + W) {
        int x, c;
        tie(x, c) = v[i];
        if (c) {
            ans += x * ((H + 1) - cnt[c^1]);
            cnt[c]++;
        } else {
            ans += x * ((W + 1) - cnt[c^1]);
            cnt[c]++;
        }
    }
    cout << ans << endl;

}


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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

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

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "(" << p.first << "," << p.second << ")";
    return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "{";
    rep(i, (int)v.size()) {
        if (i)
            os << ",";
        os << v[i];
    }
    os << "}";
    return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
    for (auto val : array)
        std::cout << val << ", ";
    std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << std::setprecision(10);

    int n; std::cin >> n;
    vi a(n); rep(i, n) std::cin >> a[i];
    ll mp = 0, pm = 0, tot = 0;
    bool plus = true;
    rep(i, n) {
        tot += a[i];
        if (plus && tot < 1) pm += (-1*tot)+1, tot = 1; 
        else if (!plus && tot > -1) pm += tot+1, tot = -1;
        plus ^= 1;
    }
    plus = false, tot = 0;
    rep(i, n) {
        tot += a[i];
        if (plus && tot < 1) mp += (-1*tot)+1, tot = 1; 
        else if (!plus && tot > -1) mp += tot+1, tot = -1;
        plus ^= 1;
    }
    std::cout << min(pm, mp) << "\n";
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define REP2(i,x,n) for (int i = x; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);

//-----DPでもとける

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

  int INF = 100005;

  bool dp[INF];
  REP(i,INF) dp[i] = false;
  REP2(i,100, 106) dp[i] = true;

  REP2(i,106,x+1){
    if(dp[i-100] || dp[i-101] || dp[i-102] || dp[i-103] || dp[i-104] || dp[i-105]){
      dp[i] = true;
    }
  }

  if(dp[x]) cout << 1 << endl;
  else cout << 0 << endl;
  return 0;
}

Measured memory_bytes: 3636
inf = 10 ** 13

n, m, l = map(int, input().split())

d = [[inf] * n for _ in range(n)]
for _ in range(m):
    a, b, c = map(int, input().split())
    d[a - 1][b - 1] = d[b - 1][a - 1] = c
for k in range(n):
    for i in range(n):
        for j in range(n):
            d[i][j] = min(d[i][j], d[i][k] + d[k][j])

e = [[1 if d[i][j] <= l else inf for j in range(n)] for i in range(n)]
for k in range(n):
    for i in range(n):
        for j in range(n):
            e[i][j] = min(e[i][j], e[i][k] + e[k][j])

q = int(input())
for _ in range(q):
    s, t = map(int, input().split())
    a = e[s - 1][t - 1]
    print(a - 1 if a < inf else -1)


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

int main(){
  int n;
  cin >> n ;
  vector<int> a(n);
  vector<int> b(n);


  for (int i = 0; i < n; i++)
  {
    cin >> a[i];
    b[i] = a[i];
  }
  sort(a.begin(),a.end());
  int maxa=a[n-1];
  int maxb=a[n-2];


  for (int i = 0; i < n; i++)
  {
    if(b[i]==maxa) cout << maxb << endl;
    else cout << maxa << endl;
  }
  
  
  
}

Measured memory_bytes: 3200
#include<bits/stdc++.h>
#define ll long long 
#define ld long double
#define X first
#define Y second
#define pb push_back
#define max_el(x) max_element(x.begin(),x.end())-x.begin()
#define min_el(x) min_element(x.begin(),x.end())-x.begin()
#define mp make_pair
#define endl '\n'
#define fastread ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
// DONT USE MEMSET, USE VECTORS

void solve(){
	ll a,b,k;
	cin>>a>>b>>k;
	if(k >= a+b){
		cout<<0<<" "<<0<<endl;
	}
	else{
		if(k <= a){
			cout<<a-k<<" "<<b<<endl;
		}
		else{
			cout<<0<<" "<<a+b-k<<endl;
		}
	}
}

int main(){
	fastread;
	int t = 1;
	// cin>>t;
	for(int i=1;i<=t;i++){
		// cout<<"Case #"<<i<<": ";
		solve();
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cassert>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#include <random>
#include <complex>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<long double,long double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<61;
const double pi=acos(-1);
const double eps=1e-10;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

string s;

int main(){
	cin>>s;
	int res=0;
	for(int i=0;i<3;i++) res+=s[i]-'0';
	cout<<res<<endl;
}

Measured memory_bytes: 256
tax = ->(x, t){
     (x + x * t * 0.01).to_i
}
loop {
    a, b, c = gets.split.map(&:to_i)
    break if a == 0 && b == 0 && c == 0
    ans = -1
    (1..c).each{|x|
        (1..c).each{ |y|
            if tax[x,a] + tax[y,a] == c
                ans = [ans, tax[x,b] + tax[y,b]].max
            end
        }
    }
    puts ans
}


Measured memory_bytes: 6860
x = int(input())
a = x % 100
a5 = a // 5
x5 = a - 5*a5
a4 = x5 // 4
x4 = x5 - 4*a4
a3 = x4 // 3
x3 = x4 - 3*a3
a2 = x3 // 2
x2 = x3 - 2*a2
a1 = x2 // 1
x1 = x2 - 4*a1
aaa = a1 + a2 + a3 + a4 + a5
xxx = (x - a) // 100
if xxx < aaa:
  print(0)
else:
  print(1)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 10000000000000009
//#define INF 9223372036854775807
typedef long long ll;
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define ORREP(i,n) for(int i=(n);i>=1;--i)
#define ZREP(i,n) for(int i=1;i<(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define rollcall cout<<"I'm Sucu."<<endl;
#define YES(s) s?cout << "YES" << endl:cout << "NO" << endl
#define Yes(s) s?cout << "Yes" << endl:cout << "No" << endl
#define Taka(s) s?cout << "Takahashi" << endl:cout << "Aoki" << endl
#define out(s,t,u) s?cout << t << endl:cout << u << endl
#define int ll
#define Endl endl

int UF[214514];
void UFinit(int n){
    for(int i=0;i<=n;i++){
        UF[i]=i;
    }
}
int UFroot(int k){
    if(UF[k]==k){
        return k;
    }else{
        UF[k]=UFroot(UF[k]);
        return UF[k];
    }
}
int UFsame(int P,int Q){
    if(UFroot(P)==UFroot(Q)){
        return true;
    }else{
        return false;
    }
}
void UFunite(int P,int Q){
    int p=UFroot(P);
    int q=UFroot(Q);
    if(p==q)return;
    if(p>q)swap(p,q);
    UF[q]=p;
}


signed main(){
    int N,M,l;
    int K[114514];
    vector<int> L[114514];
    cin >> N >> M;
    REP(i,N){
        cin >> K[i];
        REP(j,K[i]){
            cin >> l;l--;
            L[i].push_back(l);
        }
    }
    UFinit(N+M);
    REP(i,N){
        REP(j,K[i]){
            UFunite(i,N+L[i][j]);
        }
    }
    REP(i,N){
        if(!UFsame(0,i)){
            cout << "NO" << Endl;return 0;
        }
    }
    cout << "YES" << Endl;
    return 0;
}   

Measured memory_bytes: 8448
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1000000007;
const ld PI = acos(-1);  
const ld EPS = 0.0000000001;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define rep(i, n) for(ll i=0; i<(ll)(n); i++)
#define repd(i, n) for(ll i=n-1; 0<=i; i--)
#define FOR(i, a, b) for(ll i=a; i<(ll)(b); i++)
#define FORD(i, a, b) for(ll i=b-1; (ll)(a)<=i; i--)
#define ALL(x) x.begin(), x.end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};


int main(){
    ll n;   cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    map<ll, ll> key;
    ll res=1;
    rep(k, n){
        ll tmp = a[k];
        for(int i=2; i*i<=tmp; i++){
            
            if(tmp%i==0 && 0<key[i]) res = 0;
            while(tmp%i==0){
                tmp /= i;   key[i] = 1;
            }
        }
        if(1<tmp){
            if(0<key[tmp]) res = 0;
            key[tmp] = 1;
        }
        if(res==0) break;
    }
    if(res==1) cout << "pairwise coprime";
    else{
        res=a[0];
        rep(i, n-1){
            res = gcd(res, a[i+1]);
            //cout << res << ' ';
        }
        if(res==1) cout << "setwise coprime";
        else cout << "not coprime";
    }
    cout << endl;
}


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

int main() {
#ifdef Hwang_Baek_I
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int a, b, c, n; cin >> a >> b >> c >> n;
	int ans = 0;
	for (int i = 0; i <= n; i++) {
		for (int j = 0; i * a + b * j <= n; j++) {
			int rest = n - i * a - b * j;
			if (rest % c == 0) ans++;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <iomanip>
#include <algorithm>
#include <queue>

using namespace std;

int main(){
    int N, Q;
    cin >> N >> Q;
    vector<int> a(N-1), b(N-1), p(Q), x(Q);
    vector<vector<int>> Graph(N);
    vector<long long> counter(N, 0);

    for (int i = 0; i < N-1; i++){
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
        Graph[a[i]].emplace_back(b[i]);
        Graph[b[i]].emplace_back(a[i]);
    }
    for (int i = 0; i < Q; i++){
        cin >> p[i] >> x[i];
        p[i]--;
        counter[p[i]] += x[i];  // 各クエリの頂点のみに加算
    }

    // BFS
    vector<int> dist(N, -1);
    queue<int> q;
    q.push(0);
    dist[0] = 0;
    while(!q.empty()){
        int now = q.front();
        q.pop();
        for (int next : Graph[now]){
            if (dist[next] == -1) {
                dist[next] = dist[now] + 1;
                counter[next] += counter[now];
                q.push(next);
            }
        }
    }

    for (int i = 0; i < N-1; i++){
        cout << counter[i] << " ";
    }
    cout << counter[N-1] << endl;

    return 0;
}


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

const int MX = 4322;
int n , k , x , y ;
int bit[2][MX][MX] , all[2];
char c[2];

void add(int t,int x,int y){
            bit[t][x][y]++;
}

int get(int t,int x,int y)
{
if( x<1000 || y < 1000 )return 0;
return bit[t][x][y];
}

int get0(int x,int y,int t){
int tt = 1-t;
int tmp = get(t ,x,y)     -get(t ,x-k,y)    -get(t ,x,y-k)    +get(t ,x-k,y-k);
    tmp-= get(tt,x,y)     -get(tt,x-k,y)    -get(tt,x,y-k)    +get(tt,x-k,y-k);
return tmp;
}

int main()
{

    scanf("%d %d",&n,&k);
    for(int i=0; i<n; i++){
        scanf("%d %d %s",&x,&y,c);
        x%=(2*k);  y%=(2*k);
        x+=1001;   y+=1001;
        add(c[0]=='W',x,y);
        all[c[0]=='W']++;
    }

for(int t=0;t<2;t++){
    for(int i=0;i<MX;i++)
    for(int j=0;j<MX;j++){
        if( i )bit[t][i][j]+=bit[t][i-1][j];
        if( j )bit[t][i][j]+=bit[t][i][j-1];
        if(i*j)bit[t][i][j]-=bit[t][i-1][j-1];
    }
}

    int ans=0,tmp=0;
    for(int x=1001; x<1001+k; x++)
        for(int y=1001; y<1001+k; y++)
            for(int t=0; t< 2  ; t++)
            {
                tmp = 0;
                tmp+= get0(x    ,y    ,t);
                tmp+= get0(x+k  ,y+k  ,t);
                tmp+= get0(x+k  ,y-k  ,t);
                tmp+= get0(x+k+k,y    ,t);
                tmp+= get0(x    ,y+k+k,t);
                tmp+= get0(x+k+k,y+k+k,t);
                tmp+= all[1-t];
                ans=max(ans,tmp);
                if( ans == n )
                {
                    printf("%d\n",ans);
                    return 0;
                }

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


Measured memory_bytes: 146304
#何とか法, AOJのgrl1c
#初め満杯
import sys
input = sys.stdin.readline
#print = sys.stdout.write

n,m,l =map(int, input().split( ))
Edge = [[] for _ in range(n)]

for i in range(m):
    a,b,c = map(int, input().split( ))
    Edge[a-1].append([b-1,c])
    Edge[b-1].append([a-1,c])

dp = [[10**10 for _ in range(n)] for __ in range(n)]

for i in range(n):
    for ed in Edge[i]:
        dp[i][ed[0]] = ed[1]

for i in range(n):
    dp[i][i] = 0

for k in range(n):
    for j in range(n):
        for i in range(n):
            dp[i][j] = min(dp[i][j],dp[i][k] + dp[k][j])

"""
以下が要点
"""
dp2 = [[10**8 for _ in range(n)] for __ in range(n)]
for j in range(n):
    for i in range(j):
        if dp[i][j] <=l:
            dp2[i][j] = 1
            dp2[j][i] = 1
for i in range(n):
    dp2[i][i] = 1
    
for k in range(n):
    for j in range(n):
        for i in range(n):
            dp2[i][j] = min(dp2[i][j],dp2[i][k] + dp2[k][j])
"""
以上
"""
q = int(input())
ans = []
for i in range(q):
    s,t = map(int, input().split( ))
    if dp2[s-1][t-1] >10**6:###
        print(-1)
    else:
        print(dp2[s-1][t-1]-1)
#print(dp)
#print(*ans)


Measured memory_bytes: 66652
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <utility>
#include <algorithm>
#include <bitset>
#include <numeric>
#include <math.h>
#include <tuple>
#include <queue>
#include <set>

using namespace std;

long long N;
long long ans = 0;

void calc_357(long long x, int a, int b, int c){

    if(x > N) return;
    if(a&&b&&c) ans++;

    calc_357(x*10+3, 1, b, c);
    calc_357(x*10+5, a, 1, c);
    calc_357(x*10+7, a, b, 1);
}


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

    cin >> N;

    calc_357(0, 0, 0, 0);
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<ll> ql;
typedef deque<ll> dql;
typedef priority_queue<ll/*, vl, greater<ll>*/> pql; //降順(/*昇順*/)
typedef set<ll> sl;
typedef pair<ll, ll> pl;
typedef vector<vl> vvl;
typedef vector<pl> vpl;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rep2(i, n) for(ll i = 1; i <= ll(n); i++)
//#define rep(i, k, n) for(ll i = k-1; i < ll(n); i++)
//#define rep2(i, k, n) for(ll i = k; i <= ll(n); i++)
#define all(v) (v).begin(), (v).end()
ll mod(ll a, ll b) {if(b == 0) return 0; return (a % b + b) % b;}
bool chmin(ll &a, ll b) {if(b < a) {a = b; return 1;} return 0;}
bool chmax(ll &a, ll b) {if(b > a) {a = b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const ll MAX = 1e9;
const char newl = '\n';

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

  ll k, num=7;
  cin >> k;
  
  ll ans = 0;
  vl cnt(k);
  while(++ans) {
    if(num%k==0) {cout << ans << newl; return 0;}
    num *= 10;
    num += 7;
    num %= k;
    if(++cnt[num]==2) {cout << -1 << newl; return 0;}
  }
}

Measured memory_bytes: 11112
#include<bits/stdc++.h>
using namespace std;
vector<int>v[5];
int check[5];
void DFS(int u,int& dem){
	dem++;
	check[u]=1;
	//cout<<u<<endl;
	for(int i=0;i<v[u].size();i++){
		if(check[v[u][i]]==0){
			DFS(v[u][i],dem);
			break;
		}
	}
}
int main(){
	for(int i=1;i<=3;i++){
		int x,y;
		cin>>x>>y;
		v[x].push_back(y);
		v[y].push_back(x);
	}
	int dem=0;
	DFS(1,dem);
	if(dem==4)
		cout<<"YES";
	else
		cout<<"NO";
}

Measured memory_bytes: 256
N, M, Q = map(int, input().split())
abcd = [list(map(int, input().split())) for i in range(Q)]
m = M-1

def DFS(s):
    if len(s) == N:
        return [s]
    ans = []
    if s == '':
        r = 0
    else:
        r = int(s[-1])
    for i in range(r, M):
        ans.extend(DFS(s+str(i)))
    return ans


V = DFS('')
final_ans = 0
for v in V:
    answer = 0
    A = [int(c)+1 for c in v]
    for a, b, c, d in abcd:
        if int(v[b-1]) - int(v[a-1]) == c:
            answer += d
    final_ans = max(final_ans , answer)
print(final_ans)

Measured memory_bytes: 82496
#include<bits/stdc++.h>
using namespace std;
int x, y;
vector<int> mx;
vector<int> my;
bool can[4010][16010];

int main(void){
    string s;
    cin >> s >> x >> y;
    int cnt=0, swi=0;
    for(int i=0;i<s.size();++i){
        if(s[i]=='F'){
            ++cnt;
        }else{
            if(swi==0){
                mx.push_back(cnt);
                swi = 1;
            }else{
                my.push_back(cnt);
                swi = 0;
            }
            cnt = 0;
        }
    }
    if(cnt!=0){
        if(swi==0){
            mx.push_back(cnt);
        }else{
            my.push_back(cnt);
        }
    }
    if(my.size()==0 && y!= 0){
        cout << "No" << endl;
        return 0;
    }
    for(int i=0;i<4010;++i){
        for(int j=0;j<16010;++j){
            can[i][j] = false;
        }
    }
    can[0][mx[0]+8000] = true;
    for(int i=1;i<mx.size();++i){
        for(int j=0;j<16010;++j){
            if((j-mx[i])>=0){
                if(can[i-1][j-mx[i]]) can[i][j] = true;
            }
            if((j+mx[i])<16010){
                if(can[i-1][j+mx[i]]) can[i][j] = true;
            }
        }
    }
    if(!can[mx.size()-1][x+8000]){
        cout << "No" << endl;
        return 0;
    }
    if(my.size()!=0){
        for(int i=0;i<4010;++i){
            for(int j=0;j<16010;++j){
                can[i][j] = false;
            }
        }
        can[0][my[0]+8000] = true;
        can[0][-my[0]+8000] = true;
        for(int i=1;i<my.size();++i){
            for(int j=0;j<16010;++j){
                if((j-my[i])>=0){
                    if(can[i-1][j-my[i]]) can[i][j] = true;
                }
                if((j+my[i])<16010){
                    if(can[i-1][j+my[i]]) can[i][j] = true;
                }
            }
        }
        if(!can[my.size()-1][y+8000]){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 62976
/*########  IN THE NAME OF ALLAH   ##########*/

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define MAX 999999999999999999
#define nl printf("\n")
#define  r0 return 0
#define  r1 return 1
#define sf1(x)  scanf("%lld",&x)
#define sf2(x,y)  scanf("%lld %lld",&x,&y)
#define sf3(x,y,z)  scanf("%lld %lld %lld",&x,&y,&z)
#define pf1(x)  printf("%lld\n",x)
#define pf2(x,y)  printf("%lld %lld\n",x,y)
#define pf3(x,y,z)  printf("%lld %lld %lld\n",x,y,z)
#define yes  printf("YES\n")
#define no  printf("NO\n")
#define pc(x)  printf("Case %lld :",x)
#define pb push_back
#define mp make_pair
#define pa pair<ll,ll>
#define mem(a,b) memset(a,b,sizeof(a))
#define MIN  -99999999999999999
#define READ(f) freopen(f,"r",stdin)
#define WRITE(f) freopen(f,"w",stdout)
#define pi 2.0*acos(0.0)
#define sp printf(" ")
#define vs(v) (v.begin(),v.end())
ll max(ll a,ll b) {if(a>b) return a; else return b;} ll min(ll a,ll b) {if(a<b) return a; else return b;}
ll power(ll B,ll P){ if(P==0) return 1; ll X=power(B,P/2); if(P%2==0) return X*X; else return B*X*X;}
ll fx[]={1,-1,0,0}; ll fy[]={0,0,1,-1};

ll A[3000005],B[3000005],C[3000005],visited[3000005],level[3000005];
char CH[1000][1000];
vector<ll>V,G;

int main()
{
   ll T,N,E,u,Q,v,i,j,k,sum=0,ck=0,x,y,cs=0;

   string S,S1;

   double d1,d2,d3;
   cin>>N>>E;

   if(N==1 || E==1){cout<<"1"<<endl;r0;}
   ll d=N*E;
   ll ans=d/2;
   if(d%2) ans++;
   cout<<ans<<endl;



 /************ALEYA YOUSUF ************/


 /************ALLAH IS ALMIGHTY ************/
return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define INF 0x3f3f3f3f3f3f3f3f
#define PI acos(-1.0)
#define MOD 1000000007
//#define eps 1e-10
#define R freopen("555input.txt","r",stdin);
#define W freopen("555output.txt","w",stdout);
//
#define N 11005
#define M 1000000005
int n,num4 ,num2,i,t,h,w,j,k,a[N];
int main ()
{
    
    scanf("%d%d",&h,&w);
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        scanf("%d",&t);
        for(j=0;j<t;j++)
            a[k++]=i;
    }
    for(i=0;i<h;i++){
        for(j=0;j<w;j++)
    {
        printf("%d ",a[i*w+j]);
    }
    printf("\n");
    i++;if(i==h)break;
    for(j=w-1;j>=0;j--)
    {
        printf("%d ",a[i*w+j]);
    }
    printf("\n");
    }
    return 0;

}


Measured memory_bytes: 384
// Tue Jun 30 14:06:52 IST 2020  
#include <bits/stdc++.h>        
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define forn(ii,a,b)        for(int ii = (int)a ; ii < (int)b  ; ii++ )
#define debug(x)           cerr << #x << " " << x << " -- \n"
#define I__O               ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define int64              long long    
#define pb                 push_back
#define f1                 first 
#define s1                 second    
#define all(x)             (x).begin(),(x).end() 
#define precise(x)         cout << fixed << setprecision(12) << x << '\n'; 
#define tough_nut          numeric_limits<int64>::min()
const int MOD = 1e9+7;
const double pi = 3.141592653589793238;
using namespace  std ;       
using namespace __gnu_pbds;
 
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set ; 
const int N = 3e5+7; 
const int64 INF = INT64_MAX;  
int64 tests(){ 
    int n;
    cin >> n;
    vector <int> a(n+1);
    int ans = 0;
    for(int i = 1 ; i <= n ; i++ )
        cin >> a[i],ans += (i&1 and a[i]&1);
    cout << ans << '\n';
    return 0;
}
int32_t main(){
    I__O ;     
    int cases = 1 ;  
    // cin >> cases ;  
    while(cases--) 
        tests();      
    return 0 ; 
}


Measured memory_bytes: 3636
N = int(input())
A = [list(map(int,input().split())) for i in range(2)]

def turnpoint(list,n):
    sum1 = 0
    sum2 = 0
    for i in range(n):
        sum1 += list[0][i]
    for i in range(N-n+1):
        sum2 += list[1][N-i-1]
    return sum1 + sum2


maxvalue = 0
for i in range(N):
    maxvalue = max(maxvalue,turnpoint(A,i+1))

print(maxvalue)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
int a,b;
int calc(int x,int y){
    int xcnt = 0,ycnt = 0;
    while(x){
        x /= 10;
        xcnt++;
    }
    while(y){
        y /= 10;
        ycnt++;
    }
    return max(xcnt,ycnt);
}
signed main(){
    int n;cin >> n;
    int ans = 29;
    for(int i = 1;i*i <= n;i++){
        if(n%i == 0){
            a = i,b = n/i;
            ans = min(ans,calc(a,b));
            
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#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;
using Graph = vector<vector<int>>;

class UnionFind {
public:
    vector <int> par; // 各元の親を表す配列
    vector <int> siz; // 素集合のサイズを表す配列(1 で初期化)

    // Constructor
    UnionFind(int sz_): par(sz_), siz(sz_, (int)1) {
        for (int i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }
    void init(int sz_) {
        par.resize(sz_);
        siz.assign(sz_, (int)1);
        for (int i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }

    // Member Function
    // Find
    int root(int x) { // 根の検索
        while (par[x] != x) {
            x = par[x] = par[par[x]]; // x の親の親を x の親とする
        }
        return x;
    }

    // Union(Unite, Merge)
    bool merge(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        // merge technique（データ構造をマージするテク．小を大にくっつける）
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(int x, int y) { // 連結判定
        return root(x) == root(y);
    }

    int size(int x) { // 素集合のサイズ
        return siz[root(x)];
    }
};

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

  int N, M, K;
  cin >> N >> M >> K;
  int a, b;

  UnionFind uf1(N), uf2(N);
  int A[N]{}, B[N]{}, ans[N];
  rep(i, M){
    cin >> a >> b;
    --a; --b;
    uf1.merge(a, b);
    A[a]++; A[b]++;
  }
  rep(i, N){
    ans[i] = uf1.size(i) - A[i] - 1;
  }
  rep(i, K){
    cin >> a >> b;
    --a; --b;
    if(uf1.issame(a, b)){
      --ans[a]; --ans[b];
    }
  }
  rep(i,N){
    cout << ans[i] << ' ';
  }
}

Measured memory_bytes: 6272
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<list>
#include<set>
#include<map>
#include<utility>
#include<queue>

#define rep(i,x) for(ll i=0;i<(int)(x);i++)
#define reps(i,x) for(ll i=1;i<=(int)(x);i++)
#define rrep(i,x) for(ll i=((int)(x)-1);i>=0;i--)
#define rreps(i,x) for(ll i=((int)(x));i>0;i--)

#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define INF 2e9

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; }
typedef long long ll;
typedef std::pair<ll, ll> P;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

using namespace std;

int main()
{
    string s;
    cin >> s;
    string p, q;
    p = s[0] + s[1];
    q = s[2] + s[3];

    ll f0 = 1;
    ll f1 = 1;

    if(s[0] - '0' == 0){
        if(s[1] - '0' == 0) f0 = 0;
    }else{
        ll e = s[0] - '0';
        ll h = s[1] - '0';
        if(10*e + h > 12) f0 = 0;
    }

    if(s[2] - '0' == 0){
        if(s[3] - '0' == 0) f1 = 0;
    }else{
        ll e = s[2] - '0';
        ll h = s[3] - '0';
        if(10*e + h > 12) f1 = 0;
    }

    if(f0 == 0 && f1 == 0){
        cout << "NA";
    }else if(f0 == 1 && f1 == 0){
        cout << "MMYY";
    }else if(f0 == 0 && f1 == 1){
        cout << "YYMM";
    }else{
        cout << "AMBIGUOUS";
    }


}

Measured memory_bytes: 256