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

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int N = scanner.nextInt();
        int X = scanner.nextInt();

        int prev = 0;
        int cnt = 1;

        for(int i=0; i<N; i++){
            int diff = scanner.nextInt();

            if(X < prev + diff ){
               break;
            }
            cnt++;
            prev += diff;
        }

        System.out.println(cnt);
    }
}

Measured memory_bytes: 23764
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>    
typedef long long ll;
#define rep(i, a, b) for (int i = a; i <= b; ++ i)
const int N = 200005, mo = 1000000007;
using namespace std;
int n, m, a[N], b[N];
void upd(int &x, int y) { 
    x = (x + y) % mo;
}
int main() {
    scanf("%d%d", &n, &m);
    rep(i, 1, n) scanf("%d", &a[i]);
    rep(i, 1, m) scanf("%d", &b[i]);
    int ret = 0, ans = 0;
    rep(i, 2, m) upd(ret, (ll) (b[i] - b[i - 1]) * (i - 1) % mo * (m - i + 1) % mo);
    rep(i, 2, n) {
        int tmp = (ll) ret * (a[i] - a[i - 1]) % mo * (i - 1) % mo * (n - i + 1) % mo;
        upd(ans, tmp);
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>

int main(void){
  int i;
  char o[51],e[51],oe[101];

  scanf("%s",&o);
  scanf("%s",&e);
  for(i = 0;i < (sizeof o);i++){
    oe[2*i] = o[i];
    oe[2*i+1] = e[i];
  }
  printf("%s\n",oe);
  return 0;
}


Measured memory_bytes: 256
N=int(input())
A=[]
for i in range(N):
  a = list(input().split())
  A.append([a[0],int(a[1]),(i+1)])
A.sort(key=lambda x:x[1],reverse=True)  #二個目の要素で降順並び替え
A.sort(key=lambda x:x[0])  #二個目の要素で降順並び替え
for i in A:
  print(i[2])

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int arr[100005];
main()
{
	int t,p;
    scanf("%d",&t);
    for(int i = 0;i < t;i++)
    {
        scanf("%d",&p);
        arr[p]++;
    }
    int cal=0;
    for(int i = 0;i <= 100004;i++)
    {
        if(arr[i]!=0)
        cal+=arr[i]-1;
    }
    int cal2=cal/2;
    cal%=2;
    cal2+=cal;
    printf("%d",t-cal2*2);
}


Measured memory_bytes: 640
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Object o = run();
        if (o != null)
            System.out.println();
    }

    private static ArrayList<Integer> nScan(Scanner sc, int n) {
        ArrayList<Integer> al = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            al.add(sc.nextInt());
        }
        return al;
    }

    private static Object run() {
        try (Scanner sc = new Scanner(System.in);) {
            int a = sc.nextInt();
            //int a = sc.nextInt();
            //int y = sc.nextInt();
            //int t = sc.next();
            //ArrayList<Integer> x = nScan(sc, n);
            //ArrayList<Integer> y = nScan(sc, n);
            //ArrayList<String> s = nScan(sc, n);
            //for (int i = 0; i < ?; i++) {
            //
            //}
            System.out.println((int)Math.floor(a + Math.pow(a,2) + Math.pow(a,3)));
            return null;
        }
    }
}

Measured memory_bytes: 26924
#include <stdio.h>

int main(){
    int arr[4];
    for(int i = 0; i < 4; i++){
        scanf("%1d", &arr[i]);
    }
    
    for(int i = 0; i < 2; i++){
        int cnt = 0;
        for(int j = i; j < 4; j++){
            if(arr[i] == arr[j]) cnt++;
            else break;
        }
        if(cnt >= 3){
            printf("Yes\n");
            return 0;
        }
    }
    
    printf("No\n");
    return 0;
}

Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;
using ll     = long long;
using pii    = pair<int, int>;
using pll    = pair<ll, ll>;
using vi     = vector<int>;
using vl     = vector<ll>;
using vvi    = vector<vi>;
using vvl    = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

int main() {
    ll n, a, b;
    cin >> n >> a >> b;
    if (a + b - 1 > n) {
        cout << -1 << "\n";
        return 0;
    }
    if (a * b < n) {
        cout << -1 << "\n";
        return 0;
    }
    vl arr;
    arr.reserve(n);
    ll val    = 0;
    ll to_add = n - b + 1;
    for (int i = 0; i < a; ++i) {
        arr.push_back(val++);
    }
    ll lastb = val - 1;
    val -= 2 * a;

    for (int i = a; i < to_add; ++i) {
        arr.push_back(val++);
        if (i % a == a - 1) {
            lastb = val - 1;
            val -= 2 * a;
            to_add++;
            b--;
        }
    }
    
    for (int i = 0; i < b - 1; ++i) {
        lastb -= a;
        arr.push_back(lastb);
    }
    vl sorted = arr;
    sort(sorted.begin(), sorted.end());
    for (int i = 0; i < n; ++i) {
        cout << 1 + lower_bound(sorted.begin(), sorted.end(), arr[i]) - sorted.begin() << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 6912
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.TreeSet;

import org.omg.Messaging.SyncScopeHelper;

public class Main {
	Scanner sc = new Scanner(System.in);
	public static void main(String[] args){
		new Main();
	}
	public Main(){
		new Test_200().doIt();
	}
	class Test_200{
		void doIt() {
			int A = sc.nextInt();
			int B = sc.nextInt();
			int K = sc.nextInt();
			for(int i = 100;i >= 1;i--) {
				if(A % i == 0 && B % i == 0)K = K - 1;
				if(K == 0) {
					System.out.println(i);
					break;
				}
			}
		}
	}
}


Measured memory_bytes: 22740
#include <iostream>
#include <vector>
#include <set>

using namespace std;

void solve()
{
	vector<int> fib;
	fib.push_back(1);
	fib.push_back(2);
	for(int i = 2; i < 1100; ++i)
	{
		fib.push_back((fib[i - 2] + fib[i - 1]) % 1001);
	}

	int V, d;
	while(cin >> V >> d)
	{	
		set<int> numbers;
		for(int i = 1; i <= V; ++i)
		{
			numbers.insert(fib[i]);
		}
		set<int>::iterator it = numbers.begin();
		int before_num;
		int ans = 0;
		before_num = *it;
		++it;
		while(it != numbers.end())
		{
			if(*it - before_num >= d)
			{
				++ans;
			}
			before_num = *it;
			++it;
		}
		cout << ans + 1 << endl;
	}
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 1232
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
#include <cmath>
#include <stack>

using namespace std;
using ll = long long int;

template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}


void solve(std::string s, std::string t){
  vector<vector<ll>>v(26);
  for(ll i=0; i<26; i++) {
    vector<ll> vv;
    v.push_back(vv);
  }
  ll cnt = 0;
  for(ll i=0; i<s.size(); i++) {
    v[s[i]-'a'].push_back(i+1);
  }
  ll prev = -1;
  for(ll i=0; i<t.size(); i++) {
    bool f = true;
    if(v[t[i]-'a'].size() == 0) {
      std::cout << -1 << std::endl;
      return;
    }
    ll offset = cnt*s.size();    
    auto lb = lower_bound(v[t[i]-'a'].begin(), v[t[i]-'a'].end(), prev-offset+1);
    if(lb == v[t[i]-'a'].end()) {
      cnt++;
      offset = cnt*s.size();
      prev = *(v[t[i]-'a'].begin())+offset;
    } else {
      prev = *lb+offset;
    }
  }
  std::cout << prev << std::endl;
}

int main(){
  std::string s;
  std::cin >> s;
  std::string t;
  std::cin >> t;
  solve(s, t);
  return 0;
}



Measured memory_bytes: 1688
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int,int>;


const long long INFLL = 1LL << 60;
const int INFI = 1000000000;


int main() {
    int h,w; cin >> h >> w;
    vector<vector<char>> v(h, vector<char> (w));
    vector<int> disph(h, 0);
    vector<int> dispw(w, 0);

    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin >> v[i][j];
            if(v[i][j] == '#') {disph[i]=1; dispw[j] = 1;}
        }
    }

    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(disph[i] && dispw[j]) cout << v[i][j];
        }
        if(disph[i])cout << endl;
    }
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

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

	if(n == 1) {
		cout << 2 << endl;
		return 0;
	}else if(n%2 ==0) {
		cout << n << endl;
		return 0;
	}

	for(int line = 3;line < n*(1/2);line++) {
		if(n%line == 0) {
			cout << 2*line << endl;
			return 0;
		}
	}
	cout << 2*n << endl;
}


Measured memory_bytes: 256
#!/usr/local/gnu/bin/bash
read n
x=(`tr ' ' '\n' | sort -n`)
m=10000000
for p in `seq ${x[0]} ${x[n-1]}`
do
    d=0
    for i in ${x[@]}
    do
        d=$((d+(i-p)*(i-p)))
    done
    ((d<m)) && m=$d
done
echo $m


Measured memory_bytes: 740
#include<stdio.h>
int main(){
  char op;
  int a,b,c,d,e;
  while(1){
  scanf("%d %c %d",&a,&op,&b);
  if(op == '+')c=a+b;
  else if(op == '-')c=a-b;
  else if(op == '/')c=a/b;
  else if(op == '*')c=a*b;
  else if(op == '?')break;
  printf("%d\n",c );}

  return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <algorithm>
using namespace std;
#define MAX 100
#define LMAX 1000
int main(){
    int n;
    int L, sum = 0, Max = 0;
    cin >> n;
    for(int i = 0;i < n;i++){
        cin >> L;
        sum += L;
        Max = max(Max,L);
    }
    sum -= Max;

    if(sum > Max){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }


}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
int m,n,max=-1000000,min=1000000;
long long int sum=0;
scanf("%d",&n);
for(;n>0;n--){
scanf("%d",&m);
if(max<m) max = m;
if(min>m) min = m;
sum = sum + m;
}
printf("%d %d %lld\n",min,max,sum);
return 0;
}

Measured memory_bytes: 600
#include<iostream>
#include<queue>
#include<vector>
#include<cstdio>
#include<cstring>

using namespace std;

struct P{int c,r;};
struct State{int t,pos, remain;};

/*--------heap begin---------*/
#define SIZE 10000
#define ELEMENT State
ELEMENT heap[SIZE];
int heap_size = 0;

/*
  push(x)  (up_heap)
  O(logN)
  verified: yes
*/
void push(ELEMENT x){
  heap[heap_size] = x;
  int pos = heap_size++;
  while(1){
    int par = ((pos-1)>>1);
    if(heap[pos].t >= heap[par].t || pos == 0) break;
    swap(heap[pos], heap[par]);
    pos = par;
  }
}

/*
  pop() (down_heap)
  O(logN)
  verified: yes
*/
void pop(){
  swap(heap[0], heap[--heap_size]);
  int pos = 0;
  while(2*pos + 1 < heap_size){
    int nex = (2*pos+2>=heap_size?2*pos+1: (heap[2*pos+2].t<heap[2*pos+1].t?2*pos+2:2*pos+1) );
    if(heap[nex].t >= heap[pos].t) break; // for maximum heap
    swap(heap[pos], heap[nex]);
    pos = nex;
  }
}

/*
  return root (maximum value in the tree)
  verified: yes
*/
ELEMENT top(){return heap[0];}

/*-------heap end----------*/

const int MAX = 5001;
const int INF = (1<<25);
int T[MAX][MAX];
vector<int> Edge[MAX];
P price[MAX];
int N,K;

void input(){
  scanf("%d %d",&N,&K);
  for(int i = 0; i < N; i++) scanf("%d %d",&price[i].c, &price[i].r);
  for(int i = 0; i < K; i++){
    int a,b;
    scanf("%d %d",&a, &b);
    a--;b--;
    Edge[a].push_back(b);
    Edge[b].push_back(a);
  }
}

void solve(){
  memset(T, -1, sizeof(T));
  T[0][0] = 0;
  push((State){0,0,0});
  while(heap_size){
    const State now = top();
    pop();
    
    if(now.t > T[now.pos][now.remain]) continue;
    
    if(now.remain > 0){
      for(int i = 0; i < (int)Edge[now.pos].size(); i++){
        State nex = now;
        nex.pos = Edge[now.pos][i];
        nex.remain--;
        
        if(T[nex.pos][nex.remain] == -1 || T[nex.pos][nex.remain] > nex.t){
          T[nex.pos][nex.remain] = nex.t;
          push(nex);
        }
      }
    }
    
    if(T[now.pos][price[now.pos].r] == -1 || T[now.pos][price[now.pos].r] > now.t+price[now.pos].c){
      T[now.pos][price[now.pos].r] = now.t+price[now.pos].c;
      push((State){now.t+price[now.pos].c, now.pos, price[now.pos].r});
    }
  }
  
  int ans = INF;
  for(int i = 0; i < MAX; i++) 
    if(T[N-1][i] >= 0) ans = min(ans,T[N-1][i]);
  printf("%d\n",ans);
}

int main(){
  input();
  solve();
  return 0;
}

Measured memory_bytes: 99348
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int N,c=0,b=0;
    cin >> N;
    vector<int> a(N);
    for (int i=0;i<N;i++){
        cin >> a.at(i);
    }
    sort(a.begin(), a.end());
    reverse(a.begin(), a.end());
    for (int i=0;i<N/2;i++){
        b=b+a.at(2*i); c=c+a.at(2*i+1);
    }
    if (N%2==1) b=b+a.at(N-1);
    cout << b-c << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  vector<int>vec(4);
  for(int i=0;i<4;i++){
    cin >>vec.at(i); 
  }
  sort(vec.begin(), vec.end());
  if (vec.at(0) ==1 && vec.at(1) ==4 && vec.at(2) ==7 && vec.at(3) ==9)cout <<"YES";
  else cout <<"NO";
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int INF = 1000000000;
int main(){
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  for (int i = 0; i < N; i++){
    cin >> A[i];
  }
  int tv = INF;
  int fv = 0;
  while (tv - fv > 1){
    int mid = (tv + fv) / 2;
    long long sum = 0;
    for (int i = 0; i < N; i++){
      sum += (A[i] - 1) / mid;
    }
    if (sum <= K){
      tv = mid;
    } else {
      fv = mid;
    }
  }
  cout << tv << endl;
}

Measured memory_bytes: 3976
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<vector>
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)

using namespace std;

int ans,cnt1;

int main() {
	int n, d;	cin >> n >> d;
	int x[10][10];
	rep(i, n){
		rep(j, d){
			cin >> x[i][j];
		}
	}


	rep(i, n) {
		REP(j,i+1,n) {
			rep(k, d){
				cnt1 += pow(x[i][k] - x[j][k], 2);

			}
			rep(k,cnt1+1){
				if (k*k == cnt1){ ans++; }
				
			}
			cnt1 = 0;
		}
	}

	cout << ans << endl;
	
	return 0;

}

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

int main() {
  int n;
  cin >> n;
  
  vector<int> k(n);
  for(int i=0; i<n; i++) cin >> k[i];
  
  int count = 0;
  int ans = 0;
  
  if(n == 1) cout << 0 << endl;
  
  else{
  for(int i=0; i<=max(n-2,0); i++){
    if(k[i] >= k[i+1]) count++;
    else{
      if(count >= ans) ans = count;
      count = 0;
    }
  }
  
  if(count != 0) ans = max(count,ans);
  
  cout << ans << endl;
  }
	return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main()
{
   long long int a,b,k,p,s;
   cin>>a>>b>>k;
   if(k>=a)
    {
        k=k-a;
        a=0;
        b=b-k;
        if(b<0){
                b=0;
        }
        cout<<a<<" "<<b<<endl;
    }
   else{ a=a-k;cout<<a<<" "<<b<<endl;}

}


Measured memory_bytes: 256
#include<iostream>
#include <cstring>
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <stdlib.h>


using namespace std;
int main()
{
    int a,b,c;
    int count=0;
    int s[3];
    for (int i = 0; i < 3; i++)cin >> s[i];
    
    for (int i = 0; i < 3; i++) 
    {
        if (s[i] == 5)count++;
    }


    if (count == 2)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <bitset>
#include <tuple>
#include <set>
#include <map>
#define range(i, r) for(int i=0;i<r;i++)
#define ranges(i, l, r) for(int i=l;i<r;i++)
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
#define MODs 1000000007;
#define MODn 1000000009;
typedef long long int ll;
using namespace std;

int main(int argc, char const *argv[]) {
  int N;
  std::cin >> N;
  std::vector<int> A(N);
  for(int i=0;i<N;i++) std::cin >> A[i];
  std::vector<int> right(N+1,0),left(N+1,0);
  for(int i=0;i<N;i++){
    left[i+1]=max(left[i], A[i]);
  }
  for(int i=N-1;i>=0;i--){
    right[i]=max(right[i+1],A[i]);
  }
  for(int i=0;i<N;i++){
    std::cout << max(left[i],right[i+1]) << '\n';
  }
  return 0;
}


Measured memory_bytes: 3968
def kukan(n, a):
    dp = [[0] * n for _ in range(n)]
    for i in range(n):
        dp[i][i] = a[i]
    for i in range(n - 2, -1, -1):
        g0 = dp[i]
        g1 = dp[i + 1]
        for j in range(i + 1, n):
            L = a[i] - g1[j]
            R = a[j] - g0[j - 1]
            dp[i][j] = L if L > R else R
    return dp[0][n - 1]
 
 
n = int(input())
a = list(map(int, input().split()))
print(kukan(n, a))

Measured memory_bytes: 112988
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a=0,b=0,c;
    cin>>c;
    char s[c];
    for(int i=0;i<c;i++){
        cin>>s[i];
        if(s[i]=='I') a++;
        else a--;
        if(b<a) b=a;
    }
    cout<<b<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const ll MOD = 1000000007;
int main() {
  int x;
  cin >> x;
  printf(x == 1 ? "0\n" : "1\n");
}

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

namespace ConsoleApp15
{
    class Class128
    {
        static void Main()
        {
            int N = int.Parse(Console.ReadLine());
            var A = Console.ReadLine().Split().Select(long.Parse).ToArray();
            Array.Sort(A);
            long ans = 0;
            for(int i = 0; i < N; i++)
            {
                ans += A[3 * N - 2 * (i+1)];
            }
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 46228
#include <bits/stdc++.h>
#include <cctype>
#include <cmath>
#include <string>
using namespace std;
int main(){
    int N;
    unsigned long long sum = 0;
    bool judge = true;
    cin >> N;
    vector<int> A(N*N);
    for(int i = 0;i < N;i ++){
        for(int j = 0;j < N;j ++){
            cin >> A.at(N*i+j);
        }
    }
    for(int u = 0;u < N;u ++){
        for(int v = 0;v < N;v ++){
          	if(u >= v) continue;
          	int countx = 0;
            for(int x = 0;x < N;x ++){
              	if(x == u || x == v) continue;
                if(A.at(u*N+v)<A.at(u*N+x)+A.at(x*N+v)){
                  	countx ++;
                }
                if(A.at(u*N+v)>A.at(u*N+x)+A.at(x*N+v)){
                    judge = false;
                }
            }
          	if(countx == N-2) sum += A.at(u*N+v);
        }
    }
  	int ans = -1;
    if(judge){
 		cout << sum << endl;
    }else{
      	cout << ans << endl;
    }
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define fr(i1,m) for(int i1=0;i1<m;i1++)
using namespace std;

int main()
{
  long a,b,c;
  while(cin>>a>>b>>c)
  {
      long l,t=0,r,x,i;
      for(i=1;i<=100000;i++)
      {
          x=a+i*a;
          if(x%b==c)
          {
              cout<<"YES\n";
              t=1;
              break;
          }
      }
      if(t==0)
      {
          cout<<"NO\n";
      }
  }
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();

		if (n < 1000) {
			System.out.print("ABC");

		} else {
			System.out.print("ABD");
		}
	}
}

Measured memory_bytes: 23508
#include<bits/stdc++.h>
using namespace std;
int main()
{
long long a, b, c=0, d, e, f, g, h, i, j, k, l, m, n, o, p, x=0, y, z;
string str;
    cin>>str;
    d=str.size()-1;
    if(str[d]=='s')


cout<<str+"es" <<endl;
    else cout<<str+"s"<<endl;


} 

Measured memory_bytes: 3620
#include <iostream>
#include <algorithm>

using namespace std;
int main(){
	int i,n;
	cin >> n;
	int a[n];
	for(i=0;i<n;i++){
		cin >> a[i];
	}
	
	long long m=0,l=0,sum=0;
	for(i=0;i<n;i++){
		sum += a[i];
		if(i%2==0){
			if(sum <= 0){
				m += 1 - sum;
				sum = 1;
			}
		}else{
			if(sum >= 0){
				m += sum + 1;
				sum = -1;
			}
		}
	}
	sum = 0;
	for(i=0;i<n;i++){
		sum += a[i];
		if(i%2!=0){
			if(sum <= 0){
				l += 1 - sum ;
				sum = 1;
			}
		}else{
			if(sum >= 0){
				l += sum + 1;
				sum = -1;
			}
		}
	}
	cout << min(m,l) << endl;
}
	
				
				

Measured memory_bytes: 640
import java.util.*;
import java.util.Map.*;

public class Main {

	public static void main(String[] args) {
		Main main = new Main();
		main.run();
	}


	public void run() {
		Scanner sc = new Scanner(System.in);
		long x = sc.nextLong();
		long y = sc.nextLong();

		int cnt = 0;
		long z = x;
		while(z<=y) {
			z = z*2;
			cnt++;
		}
		System.out.println(cnt);
		sc.close();
	}
}


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

public class Main {

	public static void main(String[] args) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		try {
			String str = br.readLine();
			String[] arr = str.split(" ");
			
			int a = Integer.parseInt(arr[0]);
			int b = Integer.parseInt(arr[1]);
			
			if (a < b) System.out.println("a < b");
			else if(a > b) System.out.println("a > b");
			else System.out.println("a == b");
		} catch (IOException e) {
			// TODO 自動生成された catch ブロック
			e.printStackTrace();
		}

	}
}

Measured memory_bytes: 17032
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<=(n);i++)
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
 
int main(){
  string S;
  cin>>S;
  sort(all(S));
  string T="abcdefghijklmnopqrstuvwxyz";
  for(int i=0;i<26;i++) {
    bool a=true;
    for(char x:S) {
     if(x==T[i]) {
       a=false;
     }
    }
    if(a) {
      cout<<T[i]<<endl;
      return 0;
    }
  }
  cout<<"None"<<endl;
}

Measured memory_bytes: 3760
//g++ -std=c++17 -Wshadow -Wall -fsanitize=address -fsanitize=undefined -D_GLIBCXX_DEBUG -g PROGRAM -o OUTPUT -DLOCAL -lasan -lubsan
#include <bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>

#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define alli(a, n, k) (a + k), (a + n + k)
#define FP(i, a, b, k) for (__typeof(a) i = a; i < b; i += k)
#define FS(i, a, b, k) for (__typeof(a) i = a; i > b; i -= k)
#define IT(it, a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); ++it)
#define eps 1e-6
#define pi 3.141592653589793
using namespace std;
using namespace __gnu_pbds;

template <class T>
inline T gcd(T x, T y)
{
    if (!y)
        return x;
    return gcd(y, x % y);
}
typedef vector<int> VII;
typedef vector<ll> VLL;
typedef pair<int, int> PII;
typedef vector<pair<int, int>> VPII;
typedef vector<pair<int, PII>> VPPI;
const int MOD = 1e9 + 7;
const int INF = 1e9;


inline ll modulo(ll a, ll m)
{
    return (a % m + m) % m;
}

inline ll modInverse(ll a, ll m)
{
    assert(__gcd(a, m) == 1);
    ll m0 = m;
    ll y = 0, x = 1;

    if (m == 1)
        return 0;

    while (a > 1)
    {
        ll q = a / m;
        ll t = m;

        m = a % m, a = t;
        t = y;

        y = x - q * y;
        x = t;
    }

    if (x < 0)
        x += m0;

    return x;
}

inline ll modPow(ll x, ll y, ll m)
{ //x^y % m
    if (y == 0)
        return 1LL;
    else if (y == 1)
        return x;
    else
    {
        ll ans = modPow(x, y / 2, m) % m;
        if (y & 1)
        {
            return (((ans * ans) % m) * x) % m;
        }
        else
        {
            return (ans * ans) % m;
        }
    }
}

vector<string> split(char d,string s)
{
    stringstream ss(s);
    string t;
    vector<string> words;
    while(getline(ss,t,d))
    {
        words.pb(t);
    }

    return words;
}

int main(int argc, char *argv[])
{
#ifdef LOCAL
    auto start = chrono::high_resolution_clock::now();
#endif
    
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    char c;
    cin >> c;
    if(isupper(c))
        cout << "A";
    else
        cout << "a";

#ifdef LOCAL
    auto end = chrono::high_resolution_clock::now();
    double time_taken =
        chrono::duration_cast<chrono::nanoseconds>(end - start).count();

    time_taken *= 1e-9;

    cerr << "\nTime taken by program is : " << fixed
         << time_taken << setprecision(9);
    cerr << " sec" << endl;
#endif
    return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i < (int)(n); i++)
#define REP(i, m, n) for(int i = (m); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e9)
#define PI (acos(-1))
#define mp make_pair
#define pb push_back
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl

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> inline auto __lcm(T& a, T& b) 
{ return a * b / __gcd(a, b); }

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

    int cnt = 0;
    rep1(i, n-1) {
        if (p[i] != min(p[i+1], min(p[i], p[i-1])) \
         && p[i] != max(p[i+1], max(p[i], p[i-1]))) {
            cnt++;
        }
    }
    print(cnt);
}


Measured memory_bytes: 256
#include <iostream>
#include<cmath>
#include <vector>
#include <map>
#include <iomanip>
#include <algorithm>
#include <sstream>
#include <string>
#include <math.h>
#include <set>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
 
int main() {
    ios::sync_with_stdio(false);
	int n, a;
	cin >> n >> a;
	cout << n * n - a;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
    using namespace std;
    int main(){
    	int n;
    	scanf("%d",&n);
    	int a[n];
    	for(int i=0;i<n;++i){
    		scanf("%d",a+i);
    	}
    	sort(a,a+n);
    	map<int,int> mp,mp2;
    	for(int i=0;i<n;++i){
    		mp[a[i]]++;
    	}
    	int res=0;
    	for(int i=n-1;i>=0;--i){
    		if(mp2[a[i]]>0)continue;
    		if(mp[a[i]] > a[i]){
    			res += mp[a[i]]-a[i];
    			mp2[a[i]]++;
    		}
    		else if(mp[a[i]]<a[i]){
    			res += mp[a[i]];
    			mp2[a[i]]++;
    		}
    	}
    	printf("%d\n", res);
    }

Measured memory_bytes: 9600
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define PI 3.141592
#define all(a) (a).begin(), (a).end()


int main(){
    int H, N;
    cin >> H >> N;
    vector<int>A(N);
    for(int i = 0; i < N; i++) cin >> A[i];
    ll total = 0;
    for(int a : A) total+=a;
    if(total >= H) puts("Yes");
    else puts("No");
}


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

int main(){
  int W, H, x, y;
  double res;
  int multi = 0;
  cin >> W >> H >> x >> y;
  res =  (double)(((double)W * (double)H)/2.0);
  if((x * 2) == W && (y * 2) == H){
    multi = 1;
  }
  cout << setprecision(9) << res << ' ' << multi << endl;
  return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#define ll long long
#define INF 0x3f3f3f3f 
#define MEM(x,y) memset(x,y,sizeof(x))
#define int long long
#define rep(i , a , b) for(int i = a ; i <= b ; i ++)
#define P pair<int,int>
#define  sc(a) scanf("%lld",&a)
#define pf(a) printf("%lld ",a)
using namespace std;
signed main()
{
	int a[50] = { 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 };
	int q;
	cin >> q;
	cout << a[q - 1];
}











Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fastio() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define here(x) cout << " #x = " << x << endl;
#define show(x) {for( auto ii : x) cout << ii << setw(4); cout << endl;}
#define shop(n,x) {for(int i = 0; i < n; i++) cout << x << setw(4); cout << endl;}
#define ff first
#define ss second
#define sq(x) (x*x)
#define endl '\n'
#define en " "
#define pb push_back
#define mpair make_pair
ll mod=1000000007;
double pi=3.1415926536;
int main()
{
	fastio();
	int tt = 1;
	//cin >> tt;
	while(tt--)
	{
		// go fast 		check		//		CHECK -> if()   else if()
		
		ll n, x=0, m=0, y=0, d=1, k=mod;
		cin >> n >> k;
		ll a[n + 1] = {};
		ll dp[n + 1][k + 1] = {};	
		dp[0][0] = 1;	
		for(ll i = 1; i <= n; i++)
		{
			cin >> a[i];
			dp[i][0] = 1;
		}
		for(ll i = 1; i <= n; i++)
		{
			x = 1;
			for(ll j = 1; j <= k; j++)
			{
				if(j - a[i] >= 1)
					x += ( dp[i - 1][j] - dp[i - 1][j - a[i] - 1] + mod) % mod;
				else
					x += (dp[i - 1][j] % mod);
				x = x % mod;
				dp[i][j] = x;
			}
		}
		// shop(k + 1, i);
		// for(ll i = 0; i <= n; i++)
		// 	show(dp[i])
		cout << dp[n][k] << endl;
	}
}

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

int main(){
    using namespace std;
    unsigned long N;
    cin >> N;
    vector<vector<unsigned long>> t(9, vector<unsigned long>(9));
    const auto& top = [](unsigned long i) -> unsigned long {
        while(i > 9)i /= 10;
        return i;
    };
    const auto& bottom = [](unsigned long i) -> unsigned long {
        return i % 10;
    };
    for(unsigned long i{1}; i <= N; ++i)if(i % 10)++t[top(i) - 1][bottom(i) - 1];
    unsigned long ans{0};
    for(unsigned long i{0}; i < 9; ++i)for(unsigned long j{0}; j < 9; ++j)ans += t[i][j] * t[j][i];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import sys 
import numpy as np
from numba import jit
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
@jit(cache=True)
def solve(n):
  a = np.zeros(N+1,np.int64)
  for i in range(1,N+1):
      for j in range(i,N+1,i):
        a[j] += j
  ans = a.sum()
  return ans
 
N = int(readline())
print(solve(N))

Measured memory_bytes: 190848
#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define mod 998244353

using namespace std;
typedef pair<llint, llint> P;

struct edge{
	llint to, cost;
	edge(){}
	edge(llint a, llint b){
		to = a, cost = b;
	}
};

llint n;
vector<edge> G[100005];
llint dist[100005];

void bfs01(vector<edge> G[], int S, llint dist[])
{
	deque<int> deq;
	deq.push_back(S);
	
	for(int i = 0; i <= n; i++) dist[i] = inf;
	dist[S] = 0;
	
	while(deq.size()){
		int v = deq.front();
		deq.pop_front();
		for(int i = 0; i < G[v].size(); i++){
			int u = G[v][i].to, c = G[v][i].cost;
			if(dist[u] > dist[v] + c){
				dist[u] = dist[v] + c;
				if(c == 0) deq.push_front(u);
				else deq.push_back(u);
			}
		}
	}
}

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	for(int i = 0; i < n; i++){
		G[i].push_back(edge((i+1)%n, 1));
		G[i].push_back(edge(10*i%n, 0));
	}
	bfs01(G, 1, dist);
	
	cout << dist[0]+1 << endl;
	
	return 0;
}

Measured memory_bytes: 8320
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0,i##_len=(int)(n);i<i##_len;i++)
#define rep1(i,n)for(int i=1,i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=(int)(n)-1;0<=i;i--)
#define rrep1(i,n) for(int i=(int)(n);1<=i;i--)

#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define all(obj) (obj).begin(),(obj).end() 

#define pcount __builtin_popcount
#define SZ(x) ((int)(x).size())
#define LEN(x) ((int)(x).length())

#define dump(x)  cerr << #x << " = " << (x) << endl;

#define endl "\n"

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 lint;

using namespace std;
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin>>n;
	int t[n+1];
	t[0]=0;
	map<string,int>s;
	rep(i,n){
		string tmp1;
		int tmp2;
		cin>>tmp1>>tmp2;
		s.emplace(tmp1,i);
		t[i+1]=t[i]+tmp2;
	}
	string x;
	cin>>x;
	int pos=s[x];
	cout<<t[n]-t[pos+1]<<endl;
}

Measured memory_bytes: 3660
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String str;
        String[] alfa = {"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"};
        int[] count = new int[26];
        while(sc.hasNext()){
            str = sc.nextLine();
            String[] s = new String[str.length()];
            for(int i=0;i<str.length();i++){
                s[i] = String.valueOf(str.charAt(i));
            }
            for(int i=0;i<str.length();i++){
                for(int j=0;j<26;j++){
                    if(s[i].equalsIgnoreCase(alfa[j])) count[j]++;
                }
            }
        }
        for(int i=0;i<26;i++){
            System.out.println(alfa[i] + " : " +count[i]);
        }
    }
}


Measured memory_bytes: 27848
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<ll> vl;
typedef vector<vector<int, int> > vvi;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define in insert
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e9 + 5;
int main(){
    int n, l;
    cin >> n >> l;
    vs v;
    for(int i = 0; i < n; i++){
        string s;
        cin>>s;
        v.pb(s);
    }
    sort(all(v));
    for(int i  =0; i < v.size(); i++){
        cout << v[i];
    }
}

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

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

    auto f=[&](int p)->long {
        long res=0;
        long x=(k&~(1<<p))|((1<<p)-1);
        if (x>k) return 0;
        if (p==0) x=k;

        for(int i=0; i<n; ++i) {
            if ((a[i]|x)==x)
                res+=b[i];
        }
        return res;
    };

    long res=0;
    for(int i=0; i<31; ++i) {
        res=max(res, f(i));
    }
    cout<<res<<endl;
}


Measured memory_bytes: 1152
import bisect

N = int(input())
l = sorted(list(map(int, input().split())))

result = 0

for i in range(N):
  for j in range(i + 1, N):
    cur = bisect.bisect_left(l, l[i] + l[j]) - j - 1
    result += cur if cur > 0 else 0   

print(result)

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define per(i,j,n) for(int i=(int)(j);(int)(n)<=i;i--)
#define int long long
#define ll long long
#define ALL(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define endl "\n"
const int MOD=1e9+7;
//const int MOD=998244353;
const int INF=(1ll<<62)-1;
signed main(){
  ll X; cin>>X;
  REP(i,0,1000){
    REP(j,0,1000){
      ll A=pow(i,5),B=pow(j,5);
      if(A-B==X){
        cout<<i<<" "<<j<<endl;
        return 0;
      }
      if(A+B==X){
        cout<<i<<" "<<-j<<endl;
        return 0;
      }
    }
  }
}

Measured memory_bytes: 4008
s=input()
n=len(s)
part=[]
start=0
ans=[0]*n
for end in range(n-1):
    if s[end]=='L' and s[end+1]=='R':
        part.append(list(s[start:end+1]))
        start=end+1
if start<n-1:
    part.append(list(s[start:]))
m=len(part)
cnt=[]
st=0
for i in range(m):
    cnt.append([0]*len(part[i]))
    for j in range(len(part[i])-1):
        if part[i][j]=='R' and part[i][j+1]=='L':
            cnt[i][j]=1
    R=cnt[i].index(1)
    if part[i].count('R')%2==0 and part[i].count('L')%2==1:
        ans[st+R]=part[i].count('R')//2+part[i].count('L')//2
        ans[st+R+1]=part[i].count('R')//2+part[i].count('L')//2+1
    elif part[i].count('R')%2==1 and part[i].count('L')%2==0:
        ans[st+R]=part[i].count('R')//2+part[i].count('L')//2+1
        ans[st+R+1]=part[i].count('R')//2+part[i].count('L')//2
    else:
        ans[st+R]=(part[i].count('R')+part[i].count('L'))//2
        ans[st+R+1]=ans[st+R]
    st+=len(part[i])
print(' '.join(map(str,ans)))

Measured memory_bytes: 21668
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = ll(1e12);
const ll mod = ll(1e9) + 7;
const double pi = acos(-1);
#define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(ll (i) = 1; (i) <= (n); ++(i))
#define rrep1(i,n) for(ll (i) = (n); (i) >= 1; --(i))
#define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i))
#define pf(x) cout << (x) << endl
#define all(x) (x).begin(),(x).end()
#define yes pf("Yes")
#define no pf("No")

ll gcd(ll a,ll b){
    if(a < b)swap(a, b);
    if(b == 0) return a;
    return gcd(b,a%b);
}

ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b;
}

ll factorial(ll n){
    ll t = 1;
    rep1(i, n){
        t *= i;
        t %= mod;
    }
    return t;
}

ll power(ll a, ll b){
    a %= mod;
    if(b == 0){
        return 1;
    }
    ll ans = power(a, b / 2);
    ans = ans * ans % mod;
    if(b % 2 == 1){
        ans = ans * a % mod;
    }
    return ans;
}

ll combination(ll a, ll b){
    if((a == b) || (b == 0)){
        return 1;
    }
    if(a < b) return 0;
    ll ans = 1;
    for(ll i = 0; i < b; i++) {
        ans *= (a - i);
        ans /= (i + 1);
        ans %= mod;
    }
    return ans;
}

int main(){
    ll h,n,dp[20001];
    rep0(i, 20001)dp[i] = INF;
    dp[0] = 0;
    cin >> h >> n;
    vector<pair<ll, ll>> a(n);
    rep0(i, n){
        ll b,c;
        cin >> b >> c;
        a[i] = make_pair(b, c);
    }
    sort(all(a));
    rep1(i, 20000){
        rep0(j, n){
            if(a[j].first >= i)dp[i] = min(dp[i],a[j].second);
            else dp[i] = min(dp[i],dp[i - a[j].first] + a[j].second);
        }
    }
    ll ans = INF;
    nfor(i, h, 20001)ans = min(ans,dp[i]);
    pf(ans);
    return 0;
}



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

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i,n) cin >> a[i];
  vector<ll> x(n);
  rep(i,n){
    if(i%2==0) x[0] += a[i];
    else x[0] -= a[i];
  }
  x.push_back(x[0]);
  for(int i = n-1; i > 0; --i){
    x[i] = 2 * a[i] - x[i+1];
  }
  rep(i,n){
    if(i==0) cout << x[i];
    else cout << " " << x[i];
  }
  return 0;
}

Measured memory_bytes: 2928
main :: IO ()
main = do
    num <- read <$> getLine
    putStrLn $ show $ resolveBank num


banking :: [Integer]
banking = 100 : 101 : (map truncate $ (zipWith (*) (cycle [(1.01 :: Double)]) (map fromIntegral $ tail banking)))

resolveBank :: Integer -> Integer
resolveBank num =
    let status = take 1 $ filter ((>= num) . fst) $ zip banking [0..]
    in  snd $ head status


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

int main() {
	int T[101][101], r, c;

	cin >> r >> c;
	for (int i = 0; i < r; i++) {
		for (int j = 0; j < c; j++) {
			cin >> T[i][j];
		}
	}
	for(int i = 0; i <= r; i++) {
		T[i][c] = 0;
	}
	for (int i = 0; i < c; i++) {
		T[r][i] = 0;
	}

	for (int i = 0; i < r; i++) {
		for (int j = 0; j < c; j++) {
			T[i][c] += T[i][j];
			T[r][j] += T[i][j];
			T[r][c] += T[i][j];
		}
	}

	for (int i = 0; i<= r; i++) {
		for (int j = 0; j <= c; j++) {
			if (j)cout << " ";
			cout << T[i][j];
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 3096
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		final int a = sc.nextInt();
		final int b = sc.nextInt();
		sc.close();
		String abStr = ""+a+b;
		int ab = Integer.parseInt(abStr);

		if(Math.pow((int)Math.sqrt(ab), 2) == ab) System.out.println("Yes");
		else 								 	  System.out.println("No");
	}

}

Measured memory_bytes: 20820
#include <iostream>
#include <sstream>
#include <string>
#include <set>
#include <map>
#include <algorithm>
using namespace std;

typedef set <string> SS;
typedef map <string, bool> MSB;
typedef map <string, SS> MSS;
typedef pair <string, SS> PSS;

int n;
MSS L;
SS G;
SS T;
string start;

SS D;
SS V;
int solve( string group )
{
  if ( V.find( group ) != V.end() ) return 0;
  V.insert( group );
  SS members = L[group];
  for ( SS ::iterator it = members.begin(); it != members.end(); ++it ) {
    string member = *it;
    if ( G.find( member ) == G.end() ) {
      D.insert( member );
    } else {
      solve( member );
    }
  }
  return D.size();
}

int main( void )
{
  string line;
  while ( cin >> n && n ) {
    L.clear();
    G.clear();
    T.clear();
    bool first = true;
    for ( int i = 0; i < n; i++ ) {
      cin >> line;
      replace( line.begin(), line.end(), ',', ' ' );
      replace( line.begin(), line.end(), '.', ' ' );
      replace( line.begin(), line.end(), ':', ' ' );
      string group, member;
      istringstream is( line );
      is >> group;
      if ( first ) start = group;
      first = false;
      G.insert( group );
      while ( is >> member ) {
	L[group].insert( member );
      }
    }

    for ( MSS ::iterator it_i = L.begin(); it_i != L.end(); ++it_i ) {
      SS list = (*it_i).second;
      for ( SS ::iterator it_j = list.begin(); it_j != list.end(); ++it_j ) {
	string member = *it_j;
	if ( G.find( member ) != G.end() ) T.insert( (*it_i).first );
      }
    }

    D.clear();
    V.clear();
    int answer = solve( start );
    cout << answer << endl;
  }
  return 0;
}

Measured memory_bytes: 1048
from collections import deque

S = list(input())
Q = int(input())
answer = deque(S)
reverse = False
for _ in range(Q):
  query = input()
  if query == '1':
    reverse ^= True
  else:
    ope, types, alphabet = query.split()
    if types == '1':
      if reverse:
        answer.append(alphabet)
      else:
        answer.appendleft(alphabet)
    else:
      if reverse:
        answer.appendleft(alphabet)
      else:
        answer.append(alphabet)
if reverse:
  result = ''
  for i in range(len(answer)):
    result += answer.pop()
  print(result)
else:
  result = ''
  for i in range(len(answer)):
    result += answer.popleft()
  print(result)


Measured memory_bytes: 12724
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
ll GCD(ll a,ll b) {return b ? GCD(b,a%b):a;}
ll LCM(ll c,ll d){return c/GCD(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
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 (a>b) { a=b; return 1; } return 0; }
int main(){
 ll n;
 cin>>n;
 ll ans=n*(n+1);
 ll cnt=0;
 for(ll i=2;i*i<=n;i++){
   for(ll j=2;i*j<=n;j++){
      ans+=i*j;
      if(j!=i&&j*j>n)ans+=i*j;
   }
 }
 cout<<ans-1<<"\n";
}



Measured memory_bytes: 3648
import java.util.Scanner;

class Main
{
   public static void main(String[] args)
   {
      Scanner stdIn = new Scanner(System.in);
      int a = stdIn.nextInt();
      int b = stdIn.nextInt();
      int c = a*b;
      int d = 2*(a+b);
      System.out.println( c + " " + d );
   }
}

Measured memory_bytes: 26016
#include<cstdio>
#include<cstring>

const int maxn = int(4e4) + 7, mod = int(1e9) + 7;
typedef long long ll;
ll fac[maxn], inv[maxn];

ll power_mod(ll p, ll q) {
	ll ret = 1;
	while (q) {
		if (q & 1) ret = ret * p % mod;
		p = p * p % mod;
		q >>= 1;
	}
	return ret;
}

void init() {
	fac[0] = 1;
	for (int i = 1; i <= maxn - 10; ++i) fac[i] = fac[i - 1] * i % mod;
	inv[maxn - 10] = power_mod(fac[maxn - 10], mod - 2);
	for (int i = maxn - 11; i >= 0; --i) inv[i] = inv[i + 1] * (i + 1) % mod;
}

ll C(int x, int y) {
	return fac[x] * inv[y] % mod * inv[x - y] % mod;
}

int n, a[2000007], b[2000007], dp[4007][4007];

int main() {
	init();
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		scanf("%d%d", a + i, b + i);
		dp[2001 - a[i]][2001 - b[i]]++;
	}
	for (int i = 1; i <= 4001; i++)
		for (int j = 1; j <= 4001; j++) {
			dp[i][j] = (dp[i][j] + dp[i - 1][j]) % mod;
			dp[i][j] = (dp[i][j] + dp[i][j - 1]) % mod;
		}
	ll ans = 0;
	for (int i = 1; i <= n; i++) ans = (ans + dp[2001 + a[i]][2001 + b[i]]) % mod;
	for (int i = 1; i <= n; i++) ans = (ans - C(a[i] + a[i] + b[i] + b[i], a[i] + a[i]) + mod) % mod;
	printf("%lld\n", ans * power_mod(2, mod - 2) % mod);
	return 0;
}

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

#define _p(...) (void)printf(__VA_ARGS__)
#define forr(x,arr) for(auto&& x:arr)
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) _rep3(i,0,n)
#define _rep3(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2,)(__VA_ARGS__)
#define _rrep2(i,n) _rrep3(i,0,n)
#define _rrep3(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2,)(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
#define bit(n) (1LL<<(n))
#define sz(x) ((int)(x).size())
#define fst first
#define snd second
using ll=long long;using pii=pair<int,int>;using vb=vector<bool>;
using vi=vector<int>;using vvi=vector<vi>;using vvvi=vector<vvi>;
using vl=vector<ll>;using vvl=vector<vl>;using vvvl=vector<vvl>;
using vd=vector<double>;using vvd=vector<vd>;using vvvd=vector<vvd>;
using vpii=vector<pii>;using vvpii=vector<vpii>;using vvvpii=vector<vvpii>;

void panic() {
  cout << "No" << endl;
  exit(0);
}

vi solve() {
  int n, x;
  cin >> n >> x;

  if (x == 1 || x == 2*n-1) {
    panic();
  }

  if (x == n) {
    vi ans;
    rep(i, 2*n-1) {
      ans.push_back(i+1);
    }
    return ans;
  }
  if (n == 3) {
    if (x == 2) {
      return {4,5,1,2,3};
    }
    if (x == 4) {
      return {2,1,5,4,3};
    }
  }

  vi ans(2*n-1, -1);
  vb used(2*n);

  if (x != 2) {
    ans[n] = x+1;
    ans[n-1] = x;
    ans[n-2] = x-1;
    ans[n+1] = x-2;

    used[x+1] = 1;
    used[x] = 1;
    used[x-1] = 1;
    used[x-2] = 1;
  }
  else {
    ans[n] = x-1;
    ans[n-1] = x;
    ans[n-2] = x+1;
    ans[n+1] = x+2;

    used[x-1] = 1;
    used[x] = 1;
    used[x+1] = 1;
    used[x+2] = 1;
  }

  //cout << "ans:"; rep(ii,sz(ans)) cout << ' ' << ans[ii]; cout << endl;
  //cout << "used:"; rep(ii,sz(used)) cout << ' ' << used[ii]; cout << endl;

  int p = 1;
  rep(i, 2*n) {
    if (ans[i] != -1) continue;
    while (used[p]) p++;
    ans[i] = p;
    used[p] = 1;
  }
  return ans;
}

void Main() {
  vi ans = solve();
  cout << "Yes" << endl;
  forr(a, ans) {
    cout << a << endl;
  }
}
int main() { cin.tie(nullptr); ios::sync_with_stdio(false); Main(); return 0; }


Measured memory_bytes: 2420
#include<bits/stdc++.h>
using namespace std;
int main(){
    int L,R;
    cin >> L >> R;

    int D = R - L;

    int l = L%2019;
    int r = R%2019;


    if(D < 2019){
        vector<int> amari(D+1);
        for(int i=0;i<D+1;i++){
            int tmp = l + i;
            if(tmp == 2019){
                l = 0;
                amari[i] = 0;
            }else{
                amari[i] = tmp;
            }
        }

        int min = 3000;

        for(int i=0;i<D;i++){
            for(int j=i+1;j<D+1;j++){
                if(amari[i]*amari[j]%2019 < min) min = amari[i]*amari[j]%2019;
            }
        }

        cout << min << endl;
    }else{
        cout << 0 << endl;
    }
    return 0;
}

Measured memory_bytes: 256