akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
using namespace std;
long long v[2005][2005];
const int mod=1e9+7;
int main() {
    long long n,k;
    scanf("%lld%lld",&n,&k);
    v[0][0]=1;
    for(int i=1;i<=n;i++){
        v[i][0]=1;
        for(int j=1;j<=i;j++)
            v[i][j]=(v[i-1][j-1]+v[i-1][j])%mod;
    }
    for(int i=1;i<=k;i++)
        printf("%lld\n",v[n-k+1][i]*v[k-1][i-1]%mod);    
    return 0;
}

Measured memory_bytes: 30080
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	scanInit()

	n := nextInt()
	m := nextInt()
	c := nextInt()
	blist := make([]int, m)

	for i := 0; i < m; i++ {
		blist[i] = nextInt()
	}

	amat := nextIntMat(n, m)

	okcnt := 0
	for j := 0; j < n; j++ {
		sum := c
		for i := 0; i < m; i++ {
			sum += amat[j][i] * blist[i]
		}
		if sum > 0 {
			okcnt++
		}
	}

	fmt.Println(okcnt)

}
func nextIntMat(a int, b int) [][]int {
	mat := make([][]int, a)
	for i := 0; i < a; i++ {
		mat[i] = make([]int, b)
		for j := 0; j < b; j++ {
			mat[i][j] = nextInt()
		}
	}
	return mat
}

// ---- readfunc
func scanInit() {
	const cap = 64 * 1024
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 1788
n = gets.to_i
maxs = gets.chomp.split(" ").map(&:to_i)
q = gets.to_i
boxes = Array.new(n){0}

for i in 0..(q-1)
    input = gets.chomp.split(" ").map(&:to_i)
    t = input[0]
    x = input[1]
    d = input[2]
    if t == 1 then # 収穫
        boxes[x-1] += d
        if boxes[x-1] > maxs[x-1] then
            puts x
            break
        end
    else # 出荷
        boxes[x-1] -= d
        if boxes[x-1] < 0 then
            puts x
            break
        end
    end
    puts 0 if i == q - 1
end


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

int main() {
    int h, w;
    while (1){
        cin >> h >> w;
        if(h == 0 && w == 0) break;
        for (int i = 0;i < h;i++){
            for (int j = 0;j < w;j++){
                if(i == 0 || i == h-1 || j == 0 || j == w-1){
                    cout << "#";
                }else{
                    cout << ".";
                }
            }
            cout << "\n";
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 1152
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		int A[] = new int[N];
		for (int i=0;i<N;i++) {
			A[i] = sc.nextInt();
		}
		for (int i=K;i<N;i++) {
			if (A[i]>A[i-K]) {
				System.out.println("Yes");
			} else {
				System.out.println("No");
			}
		}
	}
}

Measured memory_bytes: 60476
#include <algorithm>
#include <climits>
#include <cmath>
#include <csignal>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

using Graph = std::vector<std::vector<int>>;
using WGraph = std::vector<std::vector<std::pair<int, long long>>>;
using ll = long long;
using namespace std;

vector<ll> dijkstra(WGraph G, int s, int t) {
    int n = (int)G.size();
    std::vector<long long> dis(n, 1e16);
    dis.at(s) = 0;
    using P = std::pair<long long, int>;
    std::priority_queue<P, std::vector<P>, std::greater<P>> que;
    que.push(std::make_pair(0, s));

    while (!que.empty()) {
        auto p = que.top();
        que.pop();
        int v = p.second;
        if (dis.at(v) < p.first) {
            continue;
        }
        for (auto e : G.at(v)) {
            if (dis.at(e.first) > dis.at(v) + e.second) {
                dis.at(e.first) = dis.at(v) + e.second;
                que.push(std::make_pair(dis.at(e.first), e.first));
            }
        }
    }
    return dis;
}

int main() {
    int n = 0;
    cin >> n;
    WGraph G(n);
    int a = 0, b = 0;
    ll c = 0;
    for (int i=0; i<n-1; i++) {
        cin >> a >> b >> c;
        G.at(a-1).push_back(make_pair(b-1, c));
        G.at(b-1).push_back(make_pair(a-1, c));
    }
    int q = 0, k = 0;
    cin >> q >> k;
    vector<ll> dis = dijkstra(G, k-1, 0);
    int x = 0, y = 0;
    vector<ll> ans(q);
    for (int i=0; i<q; i++) {
        cin >> x >> y;
        ans.at(i) = dis.at(x-1) + dis.at(y-1);
    }
    for (ll x : ans) {
        cout << x << endl;
    }
    return 0;
}
 

Measured memory_bytes: 18160
#include <bits/stdc++.h>
#define rep(i,a,n) for (int i=a; i<n; i++)
#define P pair<int,int>
#define INF 1000000000
using namespace std;;
 
int N,M;
vector<int> cost(200001);
vector<vector<int>> G(200001,vector<int>());

void calc() {
  priority_queue<P,vector<P>,greater<P>> Q;
  rep(i,1,N+2) cost[i] = INF;
  cost[1] =0;
  Q.push(P(1,0));
  
  while(!Q.empty()) {
    P p = Q.top(); Q.pop();
    int v = p.first;
    if (cost[v] < p.second) continue;
    int M = G[v].size();
    rep(j,0,M) {
      int q = G[v][j];
      if (cost[q] > cost[v] + 1) {
        cost[q] = cost[v] + 1;
        Q.push(P(q,cost[q]));
      }
    }
  }
}           

int main() {
  cin >> N >> M;
  rep(i,0,M) {
    int x,y; cin >> x >> y;
    G[x].push_back(y); G[y].push_back(x);
  }
  
  calc();
  
  if (cost[N] == 2) cout << "POSSIBLE" << endl;
  else cout << "IMPOSSIBLE" << endl; 
  return 0; 
}

Measured memory_bytes: 16708
import java.util.Scanner;
 
public class Main {
 
    static Scanner sc = new Scanner(System.in);
    static int a = sc.nextInt();
    static int b = sc.nextInt();
    static int c = sc.nextInt();
    static int d = sc.nextInt();
    static int e = sc.nextInt();
    public static void main(String[] args) {
        microwave();
    }
 
    private static void microwave() {
        int t = 0;
 
            if (a < 0) {
                t += c * Math.abs(a) + d + e * b;
            } else {
                t += e * Math.abs(a - b);
            }
        System.out.println(t);
    }
 
}


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

int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, K; 	cin >> N >> K;
	vector<int> h(N);
	for (int i = 0; i < N; i++) cin >> h[i];
	vector<long long> dp(N, 10000000001);
	dp[0] = 0;
	for (int i = 0; i < N; ++i) {
		for (int j = 1; j <= K; ++j) {
			if (i + j >= N) break;
			dp[i + j] = min(dp[i + j], dp[i] + abs(h[i] - h[i + j]));
		}
	}
	cout << dp[N - 1] << endl;
	return 0;
}

Measured memory_bytes: 1408
#include <iostream>
using namespace std;
int a, b, c, d, e, f, w[6005]={1}, s[3035]={1};
int main() {
	int i, j;
	cin>>a>>b>>c>>d>>e>>f;
	for(i=0; i<f; i++) {
		if(w[i]) w[i+a*100] = w[i+b*100] = 1;
		if(s[i]) s[i+c] = s[i+d] = 1;
	}
	a*=100, c=0;
	for(i=100; i<f; i+=100) if(w[i])
		for(j=0; i+j<=f && j<=i/100*e; j++) if(s[j])
			if(j*(a+c) > c*(i+j)) a=i, c=j;
	cout<<a+c<<' '<<c;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

  public static void main (String[] args) {

    Scanner sc = new Scanner(System.in);
    
    long N = sc.nextLong();

    sc.close();

    int digits = countDigits(N);

    for (long A = 1; A * A <= N; A++) {
      if (N % A != 0) {
        continue;
      }
      long B = N / A;
      int digits_ = Math.max(countDigits(B), countDigits(A));
      digits = Math.min(digits, digits_);
    }

    System.out.println(digits);
    
  }

  static int countDigits(long N){
    
    int digits = 0;

    while (0 < N) {
      N /= 10;
      digits++;
    }
    
    return digits;
  
  }

}

Measured memory_bytes: 23764
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
using namespace std;

const int MAX = 1000001;
int a[MAX] = {};

int main(){

    cin >> a[1];

    set<int> s;
    s.insert(a[1]);
    int temp;

    for(int i=2; i<MAX; i++){
        if(a[i-1] % 2 == 0){
            a[i] = a[i-1]/2;
        }
        else{
            a[i] = 3*a[i-1] + 1;
        }

        if(s.find(a[i]) != s.end()){
            temp = i;
            break;
        }
        else{
            // cout << i << ": " << a[i] << endl;
            s.insert(a[i]);
        }
    }

    cout << temp << endl;

    return 0;
}

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

int main() {
   int N;
   cin >> N;
   int A[N];
   for (int i=0; i<N; i++){
       cin >> A[i];
   }
   sort(A,A+N);
   map<int,int> a;
   for (int i=0; i<N; i++) {
       if (a.count(A[i])) {
           a[A[i]]=a.at(A[i])+1;
       }
       else a[A[i]]=1;
   }
   int Q;
   cin >> Q;
   int B[Q+1],C[Q+1];
   for (int i=1; i<Q+1; i++) {
       cin >> B[i] >> C[i];
   }
   long long S[Q+1];
   S[0]=0;
   for (int i=0; i<N; i++) {
       S[0]+=A[i];
   }
   for (int i=1; i<=Q; i++) {
       if (a.count(B[i])) {
               S[i]=S[i-1]+a.at(B[i])*(C[i]-B[i]);
               if (a.count(C[i])) {
                   a[C[i]]=a.at(C[i])+a.at(B[i]);
                   a.erase(B[i]);
               }
               else {
                   a[C[i]]=a.at(B[i]);
                   a.erase(B[i]);
               }
           }
        else S[i]=S[i-1];
       cout << S[i] << endl;
   }
}

Measured memory_bytes: 8524
n = int(input())
A = [int(s) for s in input().split()]
cen = n //2
ANS = [0]*(cen)
A_p = A[cen:n]
ANS = ANS + A_p

for i in range(cen):
    part_sum = sum(ANS[cen-i-1::cen-i])
    dot = part_sum % 2
    if dot == A[cen-i-1]:
        pass
    else:
        ANS[cen-i-1] = 1

sum_ans = sum(ANS)
print(sum_ans)
if sum_ans == 0:
    pass
else:
    B = []
    for i in range(n):
        if ANS[i] != 0:
            B.append(i+1)
        else:
            pass
    BB = [str(a) for a in B]
    BB =" ".join(BB)
    print(BB)


Measured memory_bytes: 21300
n,q = map(int,input().split())
s = input()
count = [0]*n
for i in range(1,n):
    count[i]+=count[i-1]
    if s[i-1:i+1] == 'AC':
        count[i]+=1
for j in range(q):
    l,r = map(int,input().split())
    print(count[r-1]-count[l-1])


Measured memory_bytes: 9620
from collections import defaultdict,Counter
import queue

N=int(input())
ab=defaultdict(list)
for i in range(N-1):
    a,b=map(int,input().split())
    ab[a].append(b)
    ab[b].append(a)

q1=queue.Queue()
qN=queue.Queue()

dist=[None for i in range(N)]
dist[0]=1
dist[N-1]=-1

phase=1
for i in ab[1]:
    q1.put((i,phase))
for g in ab[N]:
    qN.put((g,phase))

while not (q1.empty() and qN.empty()):
    while True:
        if q1.empty():
            break
        next1,p=q1.queue[0]
        if p==phase:
            if dist[next1-1]==None:
                dist[next1-1]=1
            next1,p=q1.get()
            for i in ab[next1]:
                if dist[i-1]==None:
                    q1.put((i,phase+1))
        else:
            break


    while True:
        if qN.empty():
            break
        nextN,p=qN.queue[0]
        if p==phase:
            if dist[nextN-1]==None:
                dist[nextN-1]=-1
            nextN,p=qN.get()
            for i in ab[nextN]:
                if dist[i-1]==None:
                    qN.put((i,phase+1))
        else:
            break
    phase+=1

c=Counter(dist)
if c[-1]<c[1]:
    print("Fennec")
else:
    print("Snuke")

Measured memory_bytes: 85460
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;

public class Program
{

    public void Proc()
    {
        string wd = Reader.ReadLine();
        int cnt = 0;
        while(true) {
            string inpt = Reader.ReadLine();
            if(inpt == null || inpt.Equals("END_OF_TEXT")) {
                break;
            }
            cnt += inpt.Split(' ').Count(a => a.Equals(wd, StringComparison.CurrentCultureIgnoreCase));
        }
        Console.WriteLine(cnt);
    }


    public class Reader
	{
		private static StringReader sr;
		public static bool IsDebug = false;
		public static string ReadLine()
		{
			if (IsDebug)
			{
				if (sr == null)
				{
					sr = new StringReader(InputText.Trim());
				}
				return sr.ReadLine();
			}
			else
			{
				return Console.ReadLine();
			}
		}
		private static string InputText = @"






computer
Nurtures computer scientists and highly-skilled computer engineers
who will create and exploit ""knowledge"" for the new era.
Provides an outstanding computer environment.
END_OF_TEXT









";
	}

	public static void Main(string[] args)
	{
#if DEBUG
		Reader.IsDebug = true;
#endif
		Program prg = new Program();
		prg.Proc();
	}
}

Measured memory_bytes: 10196
using System;
using System.Text;

namespace GCDandLCM
{
    class Program
    {
        static void Main(string[] args)
        {
            var sb = new StringBuilder();
            while (true)
            {
                string str = Console.ReadLine();
                if (str == null)
                {
                    break;
                }
                double[] inputs = Array.ConvertAll(str.Split(' '), double.Parse);
                double gcd;
                if (inputs[0] > inputs[1])
                {
                    gcd = Myfunc(inputs[0], inputs[1]);
                }
                else
                {
                    gcd = Myfunc(inputs[1], inputs[0]);

                }
                sb.AppendFormat("{0} {1}\n", gcd, inputs[0] * inputs[1] / gcd);
            }
            sb.Remove(sb.Length - 1, 1);
            Console.WriteLine(sb);
        }


        public static double Myfunc(double a, double b)
        {
            double r = a % b;
            if (r != 0)
            {
                b = Myfunc(b, r);
            }
            return b;
        }
    }
}



Measured memory_bytes: 9324
from sys import stdin


def fetch_one_line():
    return stdin.readline().rstrip()


def fetch_int_input():
    return [int(s) for s in fetch_one_line().split()]


def fetch_inputs(times):
    return [fetch_one_line() for _ in range(times)]

def fetch_int_inputs(times):
    return [[int(s) for s in fetch_one_line()] for _ in range(times)]

def fetch_ints_inputs(times):
    return [fetch_int_input() for _ in range(times)]


N, M = fetch_int_input()
nums = fetch_int_input()

sums = [0]
for idx, num in enumerate(nums):
    sums.append(num + sums[idx])
sums = sums[1:]

sums = [s % M for s in sums]

remains = {}

for s in sums:
    if s in remains:
        remains[s] += 1
    else:
        remains[s] = 1

answer = 0
for v in remains.values():
    answer += int(v * (v - 1) / 2)

if 0 in remains:
    answer += remains[0]


print(answer)


Measured memory_bytes: 62576
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <fstream>
#include<cstdio>
#include<iomanip>

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

using namespace std;

typedef long long ll;
typedef unsigned long ul;
typedef long double ld;


ll n;
vector<ll> d;

int main() {



//    cin.rdbuf(in.rdbuf());

    cin >> n;
    REP(i, n) {
        ll x;
        cin >> x;
        d.push_back(x);
    }
    sort(d.begin(), d.end());
    ll prev = n / 2 - 1;
    ll next = n / 2;
    cout << d[next] - d[prev];

    return 0;
}


Measured memory_bytes: 1400
#include "bits/stdc++.h"

using namespace std;
typedef long long ll;
#define rep(i,j,n) for (int i = j; i < (n); i++)
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const ll INF = 1e9;

int main(){

  int n;cin>>n;
  int a[n+10];
  map<int,int>mp;

  rep(i,0,n){
    int a;cin>>a;
    mp[a]++;
  }

  ll count=0;
  for(map<int,int>::iterator itr=mp.begin();itr!=mp.end();itr++){
    if(itr->second%2)count++;
  }

  out(count);


  return 0;
}


Measured memory_bytes: 4992
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = Integer.parseInt(sc.next());
		Integer[] array = new Integer[n];
		
		for(int i = 0; i < n; ++i){
		    int tmp = sc.nextInt();
		    array[i] = tmp;
		}
		
		int sum = 0;
		
		Arrays.sort(array);
		
		int mini = 2147483647;
		boolean flag = true;
		
		for(int i = 0; i < n-1; ++i){
		    if(array[i] != array[i+1]) {
		        flag = false;
		        break;
		    }
		    else continue;
		}
		
		if(flag) System.out.println(0);
		else {
		for(int i = array[0] + 1; i < array[n-1]; ++i) {
		    for(int j = 0; j < n; ++j) {
		        int tmp = Math.abs((i-array[j]) * (i - array[j]));
		        sum += tmp;
		        
		    }
		    if(mini > sum) {
		        mini = sum;
		        sum = 0;
		    }
		    else sum = 0;
		}
		
		//System.out.println(array[0]);
		//System.out.println(array[1]);
		
		System.out.println(mini);
		}
	}
}

Measured memory_bytes: 21716
//writer: Sakura
//name: Programming Education

#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
using namespace std;

int n;
int a,b;

int main(){
	scanf("%d",&n);
	if(n==1){
		puts("Hello World");
		exit(0);
	}
	if(n==2){
		scanf("%d %d",&a,&b);
		int ans=a+b;
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    
    int n;
    int a[100009]={};
    int ans=0;
    long long t=0;
    int m=0;
    
    cin >> n;
    cin >> a[1];
    
    a[0] = 0;
    
    t += abs(a[1]);
    
    for(int i=2; i<=n; i++){
        
        cin >> a[i];
        t += abs(a[i]-a[i-1]);
        
    }
    
    a[n+1] = 0;
    
    t += abs(a[n]);
    
    for(int i=1; i<=n; i++){
        
        m = abs(a[i+1]-a[i]) + abs(a[i]-a[i-1]) - abs(a[i+1]-a[i-1]);
        ans = t - m;
        
        cout << ans << endl;
        
    }
    
    return 0;
    
}

Measured memory_bytes: 1664
main = do
  [n, y] <- map read . words <$> getLine
  let ns = [[a, b, n - (a + b)] | a <- [0..n], b <- [0..(n - a)]]
  let nsy = filter (\[a, b, c] -> 10000 * a + 5000 * b + 1000 * c == y) ns
  putStrLn $ if null nsy then "-1 -1 -1" else unwords (map show (head nsy))

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

int main() {

  int A, B;
  cin >> A >> B;
  
  int count = 0;
  for (int i = A; i <= B; i++) {
    int s = i % 10, t = i / 10000;
    int u = i / 10 % 10, v = i / 1000 % 10;
    if (s == t && u == v) count++;
  }
  cout << count << endl;
    
}


Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
l=r=now=0
ans=[0]*n 
while l<n:
    if r<n and now^a[r]==now+a[r]:
        now+=a[r]
        #ans[l]=r 
        r+=1
    else:
        now-=a[l]
        l+=1
        ans[l-1]=r-l+1
print(sum([ans[i] for i in range(n)]))

Measured memory_bytes: 24424
def main():
    tmp = input().split(" ")
    k = int(tmp[0])

    a = input().split(" ")
    a = [int(i) for i in a]

    ans = []
    for i in range(len(a)):
        if i == 0:
            ans.append(k - a[-1] + a[i])
        else:
            ans.append(a[i] - a[i - 1])
        
    print(sum(ans) - max(ans))


if __name__ == '__main__':
    main()

Measured memory_bytes: 26444
def main():
  s = input()
  if s != s[::-1]:
    print('No')
    return
  a = s[:(len(s)-1)//2]
  if a != a[::-1]:
    print('No')
    return
  b = s[(len(s)+1)//2:]
  if b != b[::-1]:
    print('No')
    return
  print('Yes')
  return

main()


Measured memory_bytes: 3060
import java.util.Scanner;

/**
 * 
 */

/**
 * @author kawakami
 *
 */
class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner as = new Scanner(System.in);
		
		String T = "";
		String W;
		String str = "";
		int count = 0;
		
		
		W = as.nextLine();
		W = W.toLowerCase();
	    
	    
	    
	    while(as.hasNext()){                  //EOF?????§??±????????????????????£?????????
	    	
	    	T = as.next();
	    	T = T.toLowerCase();
       
	    	/*if(T == "END_OF_TEXT"){
		    
	    		break;
	    		
	    	}*/
	    	
	    	if(T.indexOf(W) == 0 && T.lastIndexOf(W) == 0){
	    		
	    		count++;
	    		
	    	}
	    
             
        }
	    
	    str = String.valueOf(count);
	    System.out.println(str);

	}

}

Measured memory_bytes: 26296
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <cmath>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF=1001001001;
vector<pair<int64_t,int64_t>>func(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p;
}

int main(){
  int64_t N,M,K;
  cin>>N>>M>>K;
  vector<int>A(N);
  vector<int>B(M);
  for(int i=0;i<N;i++){
    cin>>A[i];
  }
  int64_t sumb=0;
  for(int i=0;i<M;i++){
    cin>>B[i];
    sumb+=B[i];
  }
  int ans=0,j=M;
  for(int i=0;i<=N;i++){
    while(j>0&&sumb>K){
      j--;
      sumb-=B[j];  
    }
    if(sumb>K){break;}
    ans=max(ans,i+j);
    if(i==N){break;}
    sumb+=A[i];
  }
  cout<<ans<<endl;
  return 0;
}

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

struct cst{int h; int w; int c;};
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll h, w;
  cin >> h >> w;
  vector<string> s(h);
  for(int i=0;i<h;i++)
    cin >> s[i];
  ll cnt=  0;
  for(int i=0;i<h;i++) {
    for(int j=0;j<w;j++) {
      if(s[i][j] == '#')
        cnt++;
    }
  }
  vector< vector<ll> > cost(h, vector<ll>(w, 1000000));
  vector< vector<ll> > used(h, vector<ll>(w, false));
  cost[0][0] = 1;
  int mi = 1;

  queue<cst> que;
  cst temp = {0, 0, 1};
  que.push(temp);
  while(!que.empty()) {
    cst t = que.front();
    que.pop();
    cost[t.h][t.w] = t.c;
    mi = max(mi, t.c);
    if(t.h > 0 && !used[t.h-1][t.w] && s[t.h-1][t.w] != '#') {
      que.push((cst){t.h-1, t.w, mi+1});
      used[t.h-1][t.w] = true;
    }
    if(t.h < h-1 && !used[t.h+1][t.w] && s[t.h+1][t.w] != '#') {
      que.push((cst){t.h+1, t.w, mi+1});
      used[t.h+1][t.w] = true;
    }
    if(t.w > 0 && !used[t.h][t.w-1] && s[t.h][t.w-1] != '#') {
      que.push((cst){t.h, t.w-1, mi+1});
      used[t.h][t.w-1] = true;
    }
    if(t.w < w-1 && !used[t.h][t.w+1] && s[t.h][t.w+1] != '#') {
      que.push((cst){t.h, t.w+1, mi+1});
      used[t.h][t.w+1] = true;
    }
  }

  if(!used[h-1][w-1]) {
    cout << -1 << endl;
  } else {
    cout << h * w - cost[h-1][w-1] - cnt << endl;
  }

}


Measured memory_bytes: 256
#include"iostream"
#include"cmath"
#include"vector"
#include"algorithm"
#include"list"
#include"set"
#include"unordered_set"
#include"map"
#include"unordered_map"
#include"string"
#include"cstring"
#include"iomanip"
using namespace std;
typedef long long ll;
const int maxn=1e5+5;
int a[maxn];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;cin>>n;
    for(int i=0;i<n;++i)
        cin>>a[i];
    int curr=a[0];
    int x=0,ans=0;
    for(int i=1;i<n;++i)
    {
        if(x==0)
        {
            if(a[i]==a[i-1])
                continue;
            else if(a[i]>a[i-1])
            {
                x=1;continue;
            }
            else 
            {
                x=2;continue;
            }
        }
        else if(x==1)
        {
            if(a[i]>=a[i-1])
            {
                continue;
            }
            else 
            {
                ++ans;
                x=0;
            }
        }
        else
        {
            if(a[i]<=a[i-1])
            {
                continue;
            }
            else
            {
                ++ans;
                x=0;
            }
        }
    }
    cout<<1+ans<<'\n';
}









Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <vector>
#include <set>

using namespace std;

int main()
{
    string s,t;
    cin>>s>>t;
    bool ok=false;
    for (int i=0; i<200; i++)
    {
        s=s[s.size()-1]+s;
        s=s.substr(0, s.size()-1);
        if (s==t) ok=true;
    }
    if (ok) cout<<"Yes\n";
    else cout<<"No\n";
    return 0;
}


Measured memory_bytes: 256
A, B, K = map(int, input().split())

N = set()
for i in range(A, min(A + K, B + 1)):
    N.add(i)
for i in range(B, max(B - K, A - 1), -1):
    N.add(i)

N = list(N)
N.sort()
print(*N, sep='\n')


Measured memory_bytes: 38256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <math.h>
using namespace std;
int main(){
    int m, d;
    cin >> m >> d;
    int sum = 0;
    for(int i = 2;i <= m; i++){
        for(int j = 22; j <= d;j++){
            int d1 = j%10;
            if(d1 == 1)continue;
            int d2 = j/10;
            if(i == d1*d2){
                sum++;
            }
        }
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define fast_io()                \
    ios::sync_with_stdio(false); \
    std::cin.tie(0);
#define mod 998244353
typedef long long ll;
typedef long double ld;
using namespace std;

int main()
{
    fast_io();
    int n;
    ll ans = 0;
    cin >> n;
    ll l[n];
    for (int i = 0; i < n; i++)
        cin >> l[i];
    sort(l, l + n);
    for (int i = 0; i < n - 2; i++)
        for (int j = i + 1; j < n - 1; j++)
            for (int k = j + 1; k < n; k++)
            {
                if (l[i] == l[j] || l[i] == l[k] || l[j] == l[k])
                    continue;
                if ((l[i] + l[j] > l[k]))
                    if ((l[j] + l[k] > l[i]))
                        if ((l[k] + l[i] > l[j]))
                            ans++;
            }
    cout << ans;
    return 0;
}


Measured memory_bytes: 3184
#include <bits/stdc++.h>
#ifdef __DEBUG__
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
#else
    #define DBG(X)
    #define SAY(X)
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int dx[]={1, 0, -1, 0, 1,-1, 1,-1};
int dy[]={0, 1, 0, -1, 1, 1,-1,-1};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S> p) { for (auto el : p) cout << "[" << el.first << ";" << el.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const deque<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const set<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

int N;
vector<ll> A;
void input(){
    fast_io();
    cin >> N;
    A = fetch_vec<ll>(N);
}

int solve(){
    ll ans = 0;
    for (int i = 0; i < N; i++)
    {
        if(A[i]%2){
            ans+=(A[i]-1)/2;
            if(i+1<N){
                if(A[i+1]){
                    A[i+1]--;
                    ans++;
                }
            }
        }
        else{
            ans += A[i]/2;
        }
    }
    cout << ans << endl;
    
    return 0;
}   

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

Measured memory_bytes: 1024
from math import ceil

N, H = map(int, input().split())
a, b = [0]*N, [0]*N
for i in range(N):
  a[i], b[i] = map(int, input().split())

a = max(a)
b.sort(reverse=True)

ans = 0
atk = 0
for i in range(N):
  if a >= b[i] or atk >= H:
    break
  ans += 1
  atk += b[i]

if atk < H:
  ans += ceil((H - atk) / a)

print(ans)


Measured memory_bytes: 10868
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int N, C;
int d[33][33];
int c[510][510];

int solve() {
    vector<int> cost[3] = {vector<int>(C), vector<int>(C), vector<int>(C)};
    for (int color = 0; color < C; color++) {
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                cost[(i+j)%3][color] += d[c[i][j]][color];
            }
        }
    }
    int res = inf;
    for (int c0 = 0; c0 < C; c0++) {
        for (int c1 = 0; c1 < C; c1++) {
            if (c0 == c1) continue;
            for (int c2 = 0; c2 < C; c2++) {
                if (c0 == c2 || c1 == c2) continue;
                res = min(res, cost[0][c0]+cost[1][c1]+cost[2][c2]);
            }
        }
    }
    return res;
}

void input() {
    cin >> N >> C;
    for (int i = 0; i < C; i++)
        for (int j = 0; j < C; j++)
            cin >> d[i][j];
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            cin >> c[i][j];
            c[i][j]--;
        }
    }
}

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

    input();
    cout << solve() << endl;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define inc(i, l, r) for (int i = l; i <= r; i++)
#define dec(i, l, r) for (int i = l; i >= r; i--)
#define pii pair<int, int>
#define fi first
#define se second
#define pb push_back
const int maxn = 1e6 + 5;

int dis[505][505];
int vis[505][505];
int n, res, x;
int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};

int main() {
    cin >> n;
    inc(i, 1, n) inc(j, 1, n) dis[i][j] =
        min(min(i - 1, n - i), min(j - 1, n - j));
    inc(i, 1, n * n) {
        cin >> x;
        int q = (x - 1) % n + 1, r = (x + n - 1) / n;
     //   if (dis[r][q]) printf("%d %d %d\n", q, r, dis[r][q]);
        res += dis[r][q];
        vis[r][q] = 1;
        queue<pii> que;
        que.push(pii(r, q));
        while (que.size()) {
            pii p = que.front();
            que.pop();
            int xx = p.fi, yy = p.se;
            inc(j, 0, 3) {
                int nx = xx + dx[j], ny = yy + dy[j];
                if (nx < 1 || nx > n || ny < 1 || ny > n) continue;
                if (dis[nx][ny] > dis[xx][yy] + 1 - vis[xx][yy]) {
                    dis[nx][ny] = dis[xx][yy] + 1 - vis[xx][yy];
                    que.push(pii(nx, ny));
                }
            }
        }
    }
    cout << res << "\n";
}

Measured memory_bytes: 5580
A, B = map(int, input().split())

def calcXorSum(a):
    if a % 2 == 1:
        n_ones = int((a + 1) / 2)
        return n_ones % 2
    else:
        n_ones = int(a / 2)
        return n_ones % 2 ^ a

print(calcXorSum(B) ^ calcXorSum(A - 1))


Measured memory_bytes: 2940
str = input()
a,b = [int(x) for x in str.split()]
r = [0] * a
c = [0] * b
s = []
for i in range(0,a):
	str = input()
	s.append(str)
	for j in range(0,b):
		if str[j] == '#':
			r[i] += 1
			c[j] += 1
for i in range(0,a):
	if r[i] != 0:
		str = s[i]
		for j in range(0,b):
			if c[j] != 0:
				print(str[j],end="")
		print()


Measured memory_bytes: 4468
import java.util.Scanner;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int w = sc.nextInt();
    int n = sc.nextInt();
    int[] num = new int[w];
    for(int i=0;i<num.length;i++){
      num[i] = i+1;
    }
    for(int j=0;j<n;j++){
      String str = sc.next();
      String[] ab = str.split(",");
      int a = Integer.parseInt(ab[0])-1;
      int b = Integer.parseInt(ab[1])-1;
      int temp = num[a];
      num[a] = num[b];
      num[b] = temp;
    }
    for(int k=0;k<w;k++){
      System.out.println(num[k]);
    }
  }
}

Measured memory_bytes: 26104
MOD = 10**9 + 7

class ModInt:
    def __init__(self, x):
        if isinstance(x, ModInt):
            self.x = x.x
        else:
            self.x = x % MOD
    
    # str関数を使用したとき
    def __str__(self):
        return str(self.x)
    
    def __int__(self):
        return self.x
    
    __index__ = __int__
    
    # print関数を使用したとき
    __repr__ = __str__

    ## 四則演算
    def __add__(self, other):
        return ModInt(self.x + ModInt(other).x)
    
    def __sub__(self, other):
        return ModInt(self.x - ModInt(other).x)

    def __mul__(self, other):
        return ModInt(self.x * ModInt(other).x)
    
    # /
    def __truediv__(self, other):
        # a * a^(p - 2) ≡ 1 (mod p) 逆元から求める
        return ModInt(self.x * pow(ModInt(other).x, MOD - 2, MOD))

    # //
    def __floordiv__(self, other):
        return self.x // ModInt(other).x

    # 累乗
    def __pow__(self, other):
        return ModInt(pow(self.x, ModInt(other).x, MOD))

    ## 四則演算の順序
    __radd__ = __add__

    def __rsub__(self, other):
        return ModInt(other - self.x)
    
    __rmul__ = __mul__

    def __rtruediv__(self, other):
        return ModInt(other * pow(self.x, MOD - 2, MOD))

    def __rfloordiv__(self, other):
        return ModInt(other // self.x)
    
    # 累乗の順序
    def __rpow__(self, other):
        return ModInt(pow(other, self.x, MOD))
    
    ## 不等号
    def __lt__(self, other):
        return self.x < ModInt(other).x
    
    def __gt__(self, other):
        return self.x > ModInt(other).x

    def __le__(self, other):
        return self.x <= ModInt(other).x
    
    def __ge__(self, other):
        return self.x >= ModInt(other).x
    
    def __eq__(self, other):
        return self.x == ModInt(other).x
    
    def __ne__(self, other):
        return self.x != ModInt(other).x

def comb(n, r):
    res = ModInt(1)
    for i in range(n-r+1, n+1):
        res = res * i
    for i in range(2, r+1):
        res = res / i
    return res

n, a, b = map(ModInt, map(int, input().split()))

ans = 2 ** n

ans = ans - comb(n, a)
ans = ans - comb(n, b)
ans = ans - 1

print(ans)


Measured memory_bytes: 42352
#include <bits/stdc++.h>
using namespace std;
const int mx=100010;
int arr[mx][3],n;
int dp[mx][3];
int f(int pos,int ty){
	if(pos==n)return 0;
	int &ans=dp[pos][ty];
	if(ans^-1)return ans;
	for(int i=0;i<3;i++){
		if(ty^i){
			ans=max(ans,f(pos+1,i)+arr[pos][i]);
		}
	}
	return ans;
}

int main(int argc, char const *argv[])
{
	memset(dp,-1,sizeof dp);
	cin>>n;
	for(int i=0;i<n;i++){
		for(int j=0;j<3;j++){
			cin>>arr[i][j];
		}
	}
	cout<<max({f(0,0),f(0,1),f(0,2)})<<endl;

	return 0;
}

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

int a,b,now;

int main()
{
    scanf("%d%d",&a,&b);
    now=b-a;    //算出b等差数列的最后一项
    printf("%d",(now+1)*now/2-b);     //(now+1)*now/2为b塔的原始高度(等差数列求和公式)
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define MN 100000
pair<long long,int> p[MN+5];
int s[MN+5];long long S[MN+5];
vector< pair<int,int> > ans;
int main()
{
	int n,i;
	scanf("%d",&n);
	for(i=1;i<=n;++i)scanf("%lld",&p[i].first),p[i].second=i,s[i]=1;
	sort(p+1,p+n+1);
	for(i=n;i>1;--i)
	{
		if(n-2*s[i]<0)return 0*puts("-1");
		int x=lower_bound(p+1,p+n+1,make_pair(p[i].first-n+2*s[i],0))-p;
		if(p[x].first!=p[i].first-n+2*s[i])return 0*puts("-1");
		s[x]+=s[i];S[x]+=S[i]+s[i];ans.push_back(make_pair(p[x].second,p[i].second));
	}
	if(S[1]!=p[1].first)return 0*puts("-1");
	for(i=0;i<ans.size();++i)printf("%d %d\n",ans[i].first,ans[i].second);
}

Measured memory_bytes: 4980
#include <iostream> // プログラムの耳と口
#include <vector> // 超有能配列秘書
#include <algorithm> // みんな大好きソートと二分探索
#include <queue> // きゅーちゃん、だいすき
#include <string> // to_string
#include <functional> // 関数を変数に入れる子
#include <set> // 値の取得・挿入・削除を高速に
#include <map> // setの妹 これまた優秀
#include <random> // 乱択さん
// なぞなぞ： メモリの海上で未使用部分を奪い合う人々は誰？　答え：ハイレーツ
#define DB cerr<<"D"<<endl // これはデバッグ用
using namespace std; using ll=long long; using ld=long double; const int INF=1e9; const ll LINF=1e18; const double dINF = 1e18; const ld ldINF = 1e18; const double EPS = 1e-6;
template<typename T, typename U, typename O> void caut(T a, U b, O c){cout<<"("<<a<<","<<b<<","<<c<<") ";} template<typename T, typename U> void caut(T a, U b){cout<<"("<<a<<","<<b<<") ";} template<typename T> void caut(T a){cout<<"("<<a<<") ";};
using P=pair<int,int>;
//const ll M = 1e9+7;
ll M;
ll mod_pow(ll x, ll a) { ll an = 1; while(a > 0) { if (a&1) an = an * x % M; x = x * x % M; a >>= 1;} return an;}
ll adad(ll x) {return x*(x+1)/2;} // 1～xの総和
void add(ll& x, ll y) {x+=y; x%=M;}; void mul(ll& x, ll y) {x*=y; x%=M;}; template<typename T, typename U> void chmax(T& x, U y) {if (x<y) x=y;}; template<typename T, typename U> void chmin(T& x, U y) {if (x>y) x=y;}
bool vaild(int x, int y, int hh, int ww){return 0<=x&&x<hh&&0<=y&&y<ww;}

int main() {
  int h,w,k; cin>>h>>w>>k;
  int an=0;
  string s[h]; for(int i=0;i<h;i++) cin>>s[i];
  for(int i=0;i<1<<h;i++) {
    string s2[h];
    for(int j=0;j<h;j++) {
      s2[j]=s[j];
    }
    for(int j=0;j<h;j++) {
      if (i & (1<<j)) {
        for(int l=0;l<w;l++) {
          s2[j][l]='R';
        }
      }
    }
    for(int j=0;j<1<<w;j++) {
      string s3[h];
      for(int j=0;j<h;j++) {
        s3[j]=s2[j];
      }
      for(int l=0;l<w;l++) {
        if (j & (1<<l)) {
          for(int p=0;p<h;p++) {
            s3[p][l]='R';
          }
        }
      }
      int sm = 0;
      for(int l=0;l<h;l++) {
        for(int p=0;p<w;p++) {
          //cout<<s3[l];
          sm += s3[l][p]=='#';
        } //cout<<endl;
      }
      an += sm == k;
    }
  }
  cout<<an<<endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define pb push_back
#define cmin(a,b) (a>b?a=b:a)
#define cmax(a,b) (a<b?a=b:a)
#define lop(i,s,t) for(int i=s;i<(t);++i)
#define rep(i,s,t) for(int i=s;i<=(t);++i)
#define dec(i,s,t) for(int i=s;i>=(t);--i)
#define fore(i,v) for(int i=g[v],d=es[i].d;i;i=es[i].nxt,d=es[i].d)
using namespace std;

#define Pr(f,...) //printf(f,##__VA_ARGS__),fflush(stdout)

typedef long long ll;

const int N=405,M=1e5+5; 

int n,m,x[M],y[M],fail[N],ans;
bitset<N> alive[N]; 

int main(int argc,char *argv[]){
#ifdef CURIOUSCAT
	//freopen("dat.in","r",stdin);
	//freopen("my.out","w",stdout);
#endif
	scanf("%d%d",&n,&m); 
	rep(i,1,m){
		scanf("%d%d",x+i,y+i); 
	}
	rep(i,1,n){
		bitset<N> &z=alive[i]; 
		z[i]=1;
		dec(j,m,1){
			if(z[x[j]]&&z[y[j]])fail[i]=1; 
			else if(z[x[j]]) z[y[j]]=1;
			else if(z[y[j]]) z[x[j]]=1;
		}
	}
	rep(i,1,n)if(!fail[i]){
		rep(j,i+1,n)if(!fail[j]){
			if(!(alive[i]&alive[j]).count())++ans;
		}
	}
	printf("%d\n", ans);
	return 0; 
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef vector <int> vi;
typedef set <int> se;
#define endl "\n"
#define for(i,a,b) for(int i = a;i<b;i++)
#define all(v) v.begin(),v.end()
#define ff first
#define ss second
#define ll long long
#define mod 1000000007
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);


void solve(){
    int x;
    cin>>x;
    if(x==1) cout<<0<<endl;
    else if(x==0) cout<<1<<endl;


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

Measured memory_bytes: 3680
#include <bits/stdc++.h>
#pragma GCC optimize(3,"Ofast","inline")
using namespace std;
int n,tot,x;
bitset<4000001>bs;
int main(){
	scanf("%d",&n),bs[0]=1;
	for(int i=1;i<=n;i++)scanf("%d",&x),tot+=x,bs|=(bs<<x);
	for(int i=(tot+1)/2;i<=4000000;i++)if(bs[i]){cout<<i<<"\n";return 0;}
}

Measured memory_bytes: 5200
n, k = map(int, input().split())
aa = list(map(int, input().split()))

mod = 10**9+7

ans = 0

s = 0
count = [0 for _ in range(2000)]
for a in aa :
    s += sum(count[a:])
    count[a-1] += 1
ans = s*k%mod

s = 0
for i in range(2000) :
    s += count[i]*sum(count[i+1:])
ans = (ans+s*k*(k-1)//2)%mod

print(ans)

Measured memory_bytes: 3188
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <queue>
#include <cmath>

#define	MOD 1000000007;
#define PI 3.14159265358979323846;
#define rep(i,n) for(ll i = 0;i<(ll)n;i++)
using namespace std;
typedef long long ll;
static const int MAX = 200002;
static const long long INFTYL = 9223372036854775807;
ll mod = 1000000007;
ll tt[MAX];
ll sm[MAX];
ll s[MAX];
ll t[MAX];
ll c[MAX];

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

	ll maxValue = 0;
	rep(i, N) {
		cin >> s[i] >> t[i] >> c[i];
	}

	rep(i, C + 1) {
		if (i != 0) {
			rep(j, MAX) tt[j] = 0;
			//現在のChannelに対してだけ 累積和を行う
			rep(j, N) {
				if (c[j] == i) {
					tt[2 * s[j] - 1]++;
					tt[2 * t[j]]--;
				}
			}
			rep(j, MAX) {
				if (0 != j) {
					tt[j] += tt[j - 1];
				}
			}

			//現在のChannelで使用する録画機をカウントする
			//一つのチャンネルでは最大１台しか使わない。
			//そのため以下のようにttが２台以上あったとしても1台のみカウントする
			rep(j, MAX) {
				if (tt[j] > 0) {
					sm[j]++;
				}
			}
		}
	}
	int mx = 0;
	rep(i, MAX) {
		if (mx < sm[i]) {
			mx = sm[i];
		}
	}

	cout << mx << endl;
	return 0;
}

//A[2 * s - 1]++;
//A[2 * t]--;

Measured memory_bytes: 7296
//C++ template-------------------------------------------------
#include <bits/stdc++.h>
using namespace std;
//define-------------------------------------------------------
#define rep(i, n) for (int i = 0; i < (int)(n); i++) //指定回数ループマクロ
#define reps(i, n) for (int i = 1; i < (int)(n); i++) //1-origin
#define rrep(i, n) for (int i = ((int)(n)-1); i>=0; i--) //逆順
#define rreps(i, n) for (int i= ((int)(n)); i>0; i--) //逆順1-origin
//typedef------------------------------------------------------
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<string> vs;
//const--------------------------------------------------------
const ll MOD = 1000000007;
const int INF = 1e9;
const double PI = acos(-1.0); //3.141592....
int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};
//main---------------------------------------------------------
int main() {
    int d, t, s; 
    cin >> d >> t >> s; 
    if (s * t >= d) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3632
sd = input()
t = input()
for i in range(len(sd) - len(t), -1, -1):
    t_kamo = sd[i:i + len(t)]
    for j in range(len(t) + 1):
        if j == len(t):
            s = sd[:i].replace("?", "a") + t + sd[i + len(t):].replace("?", "a")
            print(s)
            exit()
        if t_kamo[j] == "?":
            continue
        elif t_kamo[j] != t[j]:
            break
print("UNRESTORABLE")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
//#include <boost/array.hpp>
//#include <boost/range/numeric.hpp>
//#include <boost/range/algorithm.hpp>
//#include <boost/multiprecision/cpp_int.hpp>

#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;
//using namespace boost::multiprecision;

const long long INF = LLONG_MAX;
const long long MOD = 1000000007;
const long double PI = M_PI;

#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); ++i)
#define RFOR(i,n,r) for(ll i = (ll)(n-1); i >= r; --i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,n,0)
#define ALL(x) x.begin(),x.end()
#define CALL(x) x.cbegin(),x.cend()
#define RALL(x) x.rbegin(),x.rend()
#define CRALL(x) x.crbegin(),x.crend()

#define cout cout << fixed << setprecision(12)
#define dbglf cerr << '\n'

#define ACCM(arr) accumulate(ALL(arr),0LL)
#define Yes(ex) cout << ((ex) ? "Yes" : "No") << endl
#define YES(ex) cout << ((ex) ? "YES" : "NO") << endl

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using vi = vector<ll>;
using vvi = vector<vi>;
using vp = vector<pair<ll, ll>>;
using vs = vector<string>;
using vc = vector<char>;
using lst = list<ll>;
using pq = priority_queue<ll>;

template < typename T >
inline void veccin(vector<T>& v) {
    for (auto && e : v) { cin >> e; }
}

template < typename T >
inline void dbg(T a) { cerr << a << ' '; }

ll n, m, k;
ll ans = 0, sum = 0, cnt = 0;
//long double d;
string s;
char c/*1, c2, c3*/;

/*--------------------template--------------------*/

int main() {
	cin >> s;
	n = s.length();
	string s1(s.begin(),s.begin()+(n-1)/2);
	string s2(s.begin()+(n+3)/2-1,s.end());
	dbg(s1);dbg(s2);dbglf;
	string ss = (reverse(ALL(s)), s),
	ss1 = (reverse(ALL(s1)), s1),
	ss2 = (reverse(ALL(s2)), s2);
	dbg(ss1);dbg(ss2);dbglf;
	reverse(ALL(s));
	reverse(ALL(s1));
	reverse(ALL(s2));
	Yes(s==ss&&s1==ss1&&s2==ss2);
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		char[] ch, ch_;
		Scanner scan = new Scanner(System.in);
		String str = scan.nextLine();
		int q = scan.nextInt();
		for(int i = 0; i < q; i++){
			String order = scan.next();
			int beg = scan.nextInt();
			int end = scan.nextInt();
			switch(order){
			case "print":
				System.out.println(str.substring(beg, end + 1));
				break;
			case "reverse":
				ch = str.toCharArray();
				ch_ = ch.clone();
				for(int j = beg; j <= end; j++){
					ch[end - (j - beg)] = ch_[j];
				}
				str = new String(ch); //char[]???String?????????
				break;
			case "replace":
				String p = scan.next();
				ch = str.toCharArray();
				ch_ = p.toCharArray();
				for(int j = beg; j <= end; j++){
					ch[j] = ch_[j - beg];
				}
				str = new String(ch); //char[]???String?????????
				break;
			}
		}
		scan.close();
	}
}

Measured memory_bytes: 28960
# coding: utf-8
# Your code here!
S=int(input())

if S==10**18:
    print(0,0,10**9,0,0,10**9)
elif S>10**9:
    y=S//10**9
    x=S-y*10**9
    y+=1
    x=10**9-x
    print(0,0,10**9,1,x,y)
else:
    print(0,0,S,0,0,1)


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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    import bisect
    
    N,K=MI()
    A=LI()
    

    rev0=0
    for i in range(N):
        for j in range(N):
            if A[i]>A[j]:
                if j>=i:
                    rev0+=(K*(K+1))//2
                else:
                    rev0+=(K*(K-1))//2
            rev0%=mod
                

        
    print(rev0)
        
               
    

main()


Measured memory_bytes: 39920
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
using namespace std;

int main() {
    int n;
    cin >> n;
    int sum = 0;
    int ans = 1000000000;
    vector<int> a(n);
    vector<int> b(n);
    for (int i = 0; i < n; i++) {
        cin >> a.at(i);
        sum += a.at(i);
    }
    for (int i = 0; i < n; i++) {
        cin >> b.at(i);
        sum += b.at(i);
    }
    for (int i = 0; i < n; i++) {
        int mini = 0;
        for (int j = i + 1; j < n; j++) {
            mini += a.at(j);
        }
        for (int j = 0; j < i; j++) {
            mini += b.at(j);
        }
        ans = min(ans, mini);
    }
    cout << sum - ans << endl;
}

Measured memory_bytes: 256