akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#pragma gcc optimize("ofast")
using namespace std;

#define ll long long //data types used often, but you don't want to type them time by time
#define ull unsigned long long
#define ui unsigned int
#define mod 1000000007
#define us unsigned short
#define IOS ios_base::sync_with_stdio(0); //to synchronize the input of cin and scanf
#define INF LONG_MAX
#define PI 3.1415926535897932384626
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define rep(x,j,n)for(int x=j;x<n;x++)
#define all(x) (x).begin(), (x).end()

typedef vector<pair<ll,ll>> vpi;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll,ll> pi;

bool prime(ll n)
{
    if(n<=1)return false;
    if(n<=3)return true;
    if(n%2==0||n%3==0)return false;
    for(ll i=5;i*i<=n;i+=6)
    {
        if(n%i==0||n%(i+2)==0)return false;
    }
    return true;
}

ll modexp(ll a,ll b,ll m)
{
    ll r=1;
    a=a%m;
    while(b>0)
    {
        if(b&1)r=(r*a)%m;
        b = b>>1;
        a=(a*a)%m;
    }
    return r%m;
}
bool comp(pair<ll,ll>a,pair<ll,ll>b)
{
    return a.fi>b.fi;
}


int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    long double r,ans; cin>>r;
    ans = PI*r*2;
    cout<<fixed<<setprecision(10)<<ans<<endl;
    return 0;

}
/*
1
4
4 2
10 3
3 4
9 2
*/


Measured memory_bytes: 3804
#include<iostream>
using namespace std;
int main()
{
	int a;
	int b;
	int c;
	long int k;
	int d;
	int e;
	int f;
	cin>>a>>b>>c>>k;
	int x=a-b;
	if(k%2==0)
	{
		d=x;
	}
	else{
		d=-x;
	}
	cout<<d<<endl;
}

Measured memory_bytes: 256
class UnionFind:
    def __init__(self):
        self.data = {}
        self.rank = {}

    def make_set(self,x):
        if not x in self.data:
            self.data[x] = x
            self.rank[x] = 0

    def find_set(self,x):
        path = []
        while self.data[x] != x:
            path.append(x)
            x = self.data[x]
        for y in path:
            self.data[y] = x
        return x

    def same(self,x,y):
        if self.find_set(x) == self.find_set(y):
            return True
        else:
            return False

    def unite(self,x,y):
        rx = self.find_set(x)
        ry = self.find_set(y)
        if not rx == ry:
            if self.rank[rx] > self.rank[ry]:
                self.data[ry] = rx
            elif self.rank[rx] < self.rank[ry]:
                self.data[rx] = ry
            else:
                self.data[rx] = ry
                self.rank[rx] += 1

n,q = map(int, raw_input().split(' '))
s = UnionFind()
for i in range(n):
    s.make_set(i)
for i in range(q):
    c,x,y = map(int,raw_input().split(' '))
    if c == 0:
        s.unite(x,y)
    else:
        if s.same(x,y):
            print 1
        else:
            print 0

Measured memory_bytes: 10140
#include<bits/stdc++.h>
#define  mes(a, b)  memset(a, b, sizeof a)
#define pb push_back
typedef unsigned long long int ull;
typedef long long int ll;
const int    maxn = 1e3 + 20;
const int    maxm = 1e5 + 10;
const ll     mod  = 1e9 + 7;
const ll     INF  = 1e18 + 100;
const int    inf  = 0x3f3f3f3f;
const double pi   = acos(-1.0);
const double eps  = 1e-8;
using namespace std;
int main(){
    string s;cin >> s;
    if(s[2] == s[3] && s[5] == s[4]) puts("Yes");
    else puts("No");
}

Measured memory_bytes: 256
N,W=map(int,input().split())
dp=[[0]*(W+1) for i in range(N+1)]
for i in range(1,N+1):
  w,v=map(int,input().split())
  for j in range(1,W+1):
    if j>=w:
      dp[i][j]=max(dp[i-1][j],dp[i-1][j-w]+v)
    else:
      dp[i][j]=dp[i-1][j]
print(dp[-1][-1])

Measured memory_bytes: 119916
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;

#define ALL(a)     (a).begin(),(a).end()
#define EACH(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c)    sort((c).begin(),(c).end())
#define RSORT(c)    sort((c).rbegin(),(c).rend())
#define MAXINDEX(c) distance((c).begin(),max_element((c).begin(),(c).end()))
#define MININDEX(c) distance((c).begin(),min_element((c).begin(),(c).end()))
#define DEBUG(x)   std::cerr <<#x<<" = "<<(x)<<" ("<<__FILE__<<"::"<<__LINE__<<")"<<std::endl;
#define ERROR(s)   std::cerr <<"Error::"<<__FILE__<<"::"<<__LINE__<<"::"<<__FUNCTION__<<"::"<<(s)<<std::endl;
#define FOR(i,a,b) for (auto i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)

constexpr bool __debugFlag = false;

// 色々さぼってるので汎用的には使えない恐れも!!!!!!!!

int main(int argc, char **argv){ 
    
    // get inputs 
    size_t numberOfCandle;
    size_t numberOfLight;

    cin >> numberOfCandle >> numberOfLight;
    
    vector <int> candleCordinates( numberOfCandle ); 
    for(size_t i=0; i<numberOfCandle; i++) {
        cin >> candleCordinates[i] ;
    }


    int64_t globalMinTime = 2 * ( abs(candleCordinates[0]) + abs(candleCordinates[numberOfCandle-1])  );
    for(size_t i=0; i<=numberOfCandle-numberOfLight; i++){
        int beginValue = candleCordinates[i];
        int endValue = candleCordinates[i + numberOfLight - 1];

        int64_t minusSideTime = beginValue < 0 ? abs(beginValue) : 0;
        int64_t plusSideTime = endValue > 0 ? abs(candleCordinates[i + numberOfLight - 1]) : 0;

        int64_t localMinTime = min ( 2 * minusSideTime + plusSideTime , minusSideTime + 2 * plusSideTime ) ;
        globalMinTime = min ( globalMinTime , localMinTime) ;       
    }   


    if(__debugFlag ){
        
        cout << "N," << numberOfCandle << ",K,"  << numberOfLight << endl;
        for(size_t i=0; i<numberOfCandle; i++) {
            cout << candleCordinates[i] << ",";
        }
        cout << endl;
    }


    cout << globalMinTime << endl;
    return 0;
}


Measured memory_bytes: 640
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

# 改行またはスペース区切りの入力をすべて読み込んでイテレータを返します。
def get_all_int():
    return map(int, open(0).read().split())

def log(*args):
    print("DEBUG:", *args, file=sys.stderr)

def inv(x):
    return pow(x, MOD-2, MOD)

def nPk(n,k):
    
    # x=1
    # for a in range(n-k+1, n+1):
    #     x = x * a % MOD
    # return x
    return kaijo[n] * inv(kaijo[n-k]) % MOD

def nCk(n,k):
    return nPk(n,k) * inv(kaijo[k])

MOD = 10**9+7

kaijo = [0] * 400020
kaijo[0] = 1
for i in range(1, len(kaijo)):
    kaijo[i] = kaijo[i-1] * i % MOD

n,k = get_nums_l()

if k >= n-1:
    print(nCk(n+n-1, n) % MOD)
    exit()

# 0人の部屋=zがk以下であるような人数の並べ方の個数

# z=0 1
# z=1 nC1 * (n-1)**1
# z=2 nC2 * (n-2)**2
# z=3 nC3 * (n-3)**3

ans = 1
for z in range(1,k+1):
    ans += nCk(n,z) * nCk(n-1, z)

print(ans%MOD)

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

using ll = long long;
using pii = pair<int, int>;
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < (n); i++)
#define per(i, b) per2(i, 0, b)
#define per2(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define ALL(c) (c).begin(), (c).end()
#define SZ(x) ((int)(x).size())

constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }

template <class T, class U>
void chmin(T& t, const U& u) {
    if (t > u) t = u;
}
template <class T, class U>
void chmax(T& t, const U& u) {
    if (t < u) t = u;
}

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

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

#ifdef LOCAL
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << H;
    debug_out(T...);
}
#define debug(...) \
    cerr << __LINE__ << " [" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif

constexpr ll INF = TEN(18);
const int MX = 3010;

ll dp[MX][MX][4];
ll v[MX][MX];

int main() {
    int R, C, K;
    cin >> R >> C >> K;
    rep(i, K) {
        int r, c, val;
        cin >> r >> c >> val;
        --r, --c;
        v[r][c] = val;
    }

    rep(i, MX) rep(j, MX) rep(k, 4) dp[i][j][k] = -INF;
    dp[0][0][0] = 0;

    rep(i, R) {
        rep(j, C) {
            for (int k = 2; k >= 0; --k) {
                if (dp[i][j][k] >= 0) {
                    chmax(dp[i][j][k + 1], dp[i][j][k] + v[i][j]);
                }
            }
            rep(k, 4) {
                if (dp[i][j][k] >= 0) {
                    if (i + 1 < R) {
                        chmax(dp[i + 1][j][0], dp[i][j][k]);
                    }
                    if (j + 1 < C) {
                        chmax(dp[i][j + 1][k], dp[i][j][k]);
                    }
                }
            }
        }
    }

    ll ans = -INF;
    rep(k, 4) chmax(ans, dp[R - 1][C - 1][k]);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 357012
#include <stdio.h>

int n,q;
int ac[100001] = {0};

int main(int argc, char *argv[])
{
    scanf("%d %d\n", &n, &q);
    char pre = '-', c;
    int sum = 0;
    for (int i = 0; i < n; i++) {
        scanf("%c", &c);
        if (pre == 'A' && c == 'C') ++sum;
        ac[i] = sum;
        pre = c;
    }
    for (int i=0; i<q;i++) {
        int l,r;
        scanf("%d %d\n", &l, &r);
        printf("%d\n", ac[r-1] - ac[l-1]);
    }
    return 0;
}


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

#define REP(i ,n) for(int i=0 ;i < n; i++)
#define REPB(i ,n) for(int i=n; i >= 0; i--)
#define FOR(i ,m ,n) for(int i=m; i < n; i++)
#define FORB(i, m, n) for(int i=m; i>= n; i--)
#define ll long long
#define pb push_back
#define popb pop_back
#define debug(i) cout<< #i<< "= "<< i << endl
using namespace std;

int main(){
    int n;
    ll ans = 0;
    vector<int>l;
    cin >> n;
    REP(i,n){
        int t;
        cin >> t;
        l.pb(t);
    }

    sort(l.begin(),l.end(),greater<int>());

    REP(i,(n-2)){
        FOR(j,(i+1),(n-1)){
            FOR(k,(j+1),n){
                if(l[i] < (l[j] + l[k])) ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

typedef long long ll;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int k, n;
    cin >> k >> n;
    vector<int> a(n);
    for(auto &x : a)
        cin >> x;
    sort(a.begin(), a.end());
    int mx = -1;
    for(int i=1; i<n; i++){
        mx = max(a[i%n]-a[(i-1)%n], mx);
    }
    cout << k-max(mx, (k-a[n-1])+a[0]);
    return 0;
}


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

int main() {

    std::string name, namePlus;

    std::cin >> name >> namePlus;

    namePlus.pop_back();

    if (name == namePlus)   std::cout << "Yes" << std::endl;
    else                    std::cout << "No"  << std::endl;
}

Measured memory_bytes: 3596
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
    int n,a,b,i;
    cin>>n;
    for(i=0;i<n;i++){
        cin>>a>>b;
        a=a%b;
        if(a==0)cout<<b<<endl;
        else cout<<a<<endl;
    }
    return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef long  l;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
const double PI=3.141592653589;
const ll INF=1000000007;
const ll LMAX=1000000000000001;
ll gcd(ll a,ll b){if(a<b)swap(a,b);ll c=a%b;while(c!=0){a=b;b=c;c=a%b;}return b;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};


int main(){
  int n; cin>>n;
  bool f=1;
  rep(i,n){
    int a; cin>>a;
    if(a%2==0){
      if(a%3!=0&&a%5!=0)
      f=0;
    }
  }
  if(f)
  puts("APPROVED");
  else
  puts("DENIED");

  return 0;
}


Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func a(l [][]int, B [][]rune, H, W int) [][]int {
	n := [][]int{}
	d := [][]int{{1, 0}, {-1, 0}, {0, 1}, {0, -1}}
	for _, xy := range l {
		y := xy[0]
		x := xy[1]
		for _, dxy := range d {
			ny := y + dxy[0]
			nx := x + dxy[1]
			if 0 <= ny && ny < H && 0 <= nx && nx < W && B[ny][nx] == '.' {
				B[ny][nx] = '#'
				n = append(n, []int{ny, nx})
			}
		}
	}
	return n
}

func main() {
	HW := strings.Split(nextLine(), " ")
	H, _ := strconv.Atoi(HW[0])
	W, _ := strconv.Atoi(HW[1])
	B := make([][]rune, H)
	for i := 0; i < H; i++ {
		B[i] = make([]rune, W)
		for j, v := range nextLine() {
			B[i][j] = v
		}
	}
	l := [][]int{}
	for i := 0; i < H; i++ {
		for j := 0; j < W; j++ {
			if B[i][j] == '#' {
				l = append(l, []int{i, j})
			}
		}
	}
	ans := 0
	for len(l) != 0 {
		l = a(l, B, H, W)
		ans++
	}
	fmt.Println(ans - 1)
}


Measured memory_bytes: 127488
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		@SuppressWarnings("resource")
		Scanner sc = new Scanner(System.in);

		while (sc.hasNext()) {
			long a = sc.nextLong();
			long b = sc.nextLong();

			System.out.print(greatestcommondivisor(a, b) + " ");
			System.out.println(leastcommonmultiple(a, b));
		}

	}

	public static long greatestcommondivisor(long a, long b) {
		if (a > b) {
			long tmp;
			tmp = a;
			a = b;
			b = tmp;
		}

		while (a != 0) {
			long tmp = a;
			a = b % a;
			b = tmp;
		}
		return b;
	}

	public static long leastcommonmultiple(long a, long b) {
		long c = greatestcommondivisor(a, b);

		long d = a * b / c;

		return d;
	}

}

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

int main()
{
	char rome[110];
  int	num, ara, nu;
	while(cin >> rome){
		num = ara = nu = 0;
		for(int i = 0; rome[i] != '\0'; i++){
			if (rome[i] == 'I') num = 1;
			else if (rome[i] == 'V') num = 5;
			else if (rome[i] == 'X') num = 10;
			else if (rome[i] == 'L') num = 50;
			else if (rome[i] == 'C') num = 100;
			else if (rome[i] == 'D') num = 500;
			else if (rome[i] == 'M') num = 1000;

			if (nu < num)	ara += num - nu - nu;
			else ara += num;
			nu = num;
		}
		cout << ara << endl;
	}
	return (0);
}

Measured memory_bytes: 1140
#include<bits/stdc++.h>
#define N 1005
using namespace std;
typedef long long ll;
ll dp[N][N];
ll d[N][N];
int h,w,n;

int main(){
  while(1){
    cin>>h>>w>>n;
    if(!h&&!w&&!n)break;
    memset(dp,0,sizeof(dp));
    dp[0][0]=n-1;
    for(int i=0;i<h;i++)
      for(int j=0;j<w;j++)
	cin>>d[i][j];
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	ll cnt=dp[i][j],a,b;
	a=b=cnt/2;
	if(cnt%2){
	  if(d[i][j])b++;
	  else a++;
	}
	dp[i+1][j]+=a;
	dp[i][j+1]+=b;
      }
    }
    for(int i=0;i<h;i++)
      for(int j=0;j<w;j++)
	d[i][j]=(d[i][j]+dp[i][j])%2;
    int y=0,x=0;
    while(y<h&&x<w){
      if(d[y][x])x++;
      else y++;
    }
    cout<<y+1<<' '<<x+1<<endl;
  }
  return 0;
}

Measured memory_bytes: 16956
#include<cstdio>
#include<vector>
using namespace std;
int main(){
    for(;;){
        int n,m;
        scanf("%d%d",&n,&m);
        if(n==0&&m==0) break;
        vector<int> ns(n+1),ms(m+1);
        for(int i=1;i<=n;i++){
            scanf("%d\n",&ns[i]);
        }
        for(int i=1;i<=m;i++){
            scanf("%d\n",&ms[i]);
        }
        int at=1;
        for(int i=1;i<=m;i++){
            at+=ms[i];
            if(at>=n){
                printf("%d\n",i);
                break;
            }
            at+=ns[at];
            if(at>=n){
                printf("%d\n",i);
                break;
            }
        }
    }
}

Measured memory_bytes: 0
N,K=map(int,input().split())
x=list(map(int,input().split()))
left=[0]*(N-K+1)
right=[0]*(N-K+1)
for i in range(len(left)):left[i]=abs(x[i])+abs(x[i+K-1]-x[i])
x=x[::-1]
for i in range(len(right)):right[i]=abs(x[i])+abs(x[i+K-1]-x[i])
print(min(min(left),min(right)))

Measured memory_bytes: 14224
import java.util.*;

public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner (System.in);
		
		int l = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();
		
		int jday, mday, result;
		
		if (a % c == 0) {
			jday = a / c;
		} else {
			jday = (a / c) + 1;
		}
		
		if (b % d == 0) {
			mday = b / d;
		} else {
			mday = (b / d) + 1;
		}
		
		if (jday > mday) {
			result = l - jday;
		} else {
			result = l - mday;
		}
		
		System.out.println(result);
		
	}

}

Measured memory_bytes: 17360
import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.math;

void main()
{
	string w = chomp(readln());
	int[26] alphabet_list;

	for(int i = 0;i < w.length;i ++)
	{
		alphabet_list[to!int(w[i])-97] ++;
	}

	int odd_num_count = 0;

	for(int i=0;i < 26;i ++)
	{
		if(alphabet_list[i]%2 != 0)
		{
			odd_num_count ++;
		}
	}

	if(odd_num_count == 0)
	{
		writeln("Yes");
	}
	else
	{
		writeln("No");
	}

}


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

int main(){

  int X, N;  cin >> X >> N;
  vector<int> a(N);
  bool ok;
  int minCount=101;
  int ans=101;
  
  for(int i=0; i<N; i++){
    cin>>a.at(i);
  }
  

  for(int i=0; i<=101; i++){
    ok=true;
    for(int j=0; j<N; j++){
      if(i==a.at(j)){
        ok=false;
      }
    }
    if(ok){
      int count = abs(X-i);
      if(count<minCount){
        minCount=count;
        ans = i;
        //cout<<ans<<endl;
      }else if(count==minCount){
        ans = min(ans,i);
        //cout<<count<<endl;
      }
    }
  }
  cout << ans;
}

Measured memory_bytes: 3588
package main

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

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	num, _ := strconv.Atoi(scanString())
	return num
}

func scanString() string {
	sc.Scan()
	return sc.Text()
}

func scanInts(n int) []int {
	sl := make([]int, n)
	for i := range sl {
		sl[i] = scanInt()
	}
	return sl
}

func scanStrings(n int) []string {
	sl := make([]string, n)
	for i := range sl {
		sl[i] = scanString()
	}
	return sl
}

func init() {
	sc.Split(bufio.ScanWords)
}

func main() {
	r, D, x := scanInt(), scanInt(), scanInt()
	for i := 1; i <= 10; i++ {
		x = r*x - D
		fmt.Println(x)
	}
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
const long long MOD = 1e9+7;
int main(){    
    map<string,long> mp;
    int n;
    cin >> n;
    string s;
    long t;
    long sumt = 0;
    rep(i,n){
        cin >> s >> t;
        sumt+=t;
        mp[s]=sumt;
    }
    string x;
    cin >> x;
    cout << sumt-mp[x] << endl;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
from itertools import accumulate #list(accumulate(A))

# BIT木

# Binary Indexed Tree (Fenwick Tree)
class BIT:
    def __init__(self, n):
        self.n = n
        self.data = [0]*(n+1)
        self.el = [0]*(n+1)
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.data[i]
            i -= i & -i
        return s
    def add(self, i, x):
        # assert i > 0
        self.el[i] += x
        while i <= self.n:
            self.data[i] += x
            i += i & -i
    def get(self, i, j=None):
        if j is None:
            return self.el[i]
        return self.sum(j) - self.sum(i)

N, M, Q = mi()
bit = BIT(N)
lrpq = dp2(0, 3, M+Q)

for i in range(M):
    l, r = mi()
    lrpq[i][1] = l-1
    lrpq[i][2] = r-1

for i in range(M, M+Q):
    p, q = mi()
    lrpq[i][0] = i
    lrpq[i][1] = p-1
    lrpq[i][2] = q-1

lrpq = sorted(lrpq, key=lambda x:(x[2], x[0]))

ans = [0]*(Q)

for i in range(M+Q):
    if lrpq[i][0] == 0:
        #L[lrpq[i][1]] += 1
        bit.add(lrpq[i][1]+1, 1)
        #BIT_update(lrpq[i][1]+1, 1)
    else:
        bit.sum(lrpq[i][2])
        if lrpq[i][1] > 0:
            ans[lrpq[i][0]-M] = bit.sum(lrpq[i][2]+1) - bit.sum(lrpq[i][1])
        else:
            ans[lrpq[i][0]-M] = bit.sum(lrpq[i][2]+1)

for num in ans:
    print(num)

Measured memory_bytes: 73160
N = int(input())
A = sorted(list(map(int,input().split())))
B = sorted(list(map(int,input().split())))
C = sorted(list(map(int,input().split())))
ans = 0
import bisect
b = []
for i in B:
    x = bisect.bisect_right(C,i)
    b.append(N-x)
y = sum(b)
c = [y]
for i in range(1,N):
    y -= b[i-1]
    c.append(y)
c.append(0)
for i in A:
    a = bisect.bisect_right(B,i)
    ans += c[a]
print(ans)

Measured memory_bytes: 29852
# DP(貰うDP)
def main():
    from builtins import abs
    N, K = map(int, input().split())
    h = list(map(int, input().split()))

    dp = [0] * N
    for i in range(1, N):
        dp[i] = min(dp[j] + abs(h[i] - h[j]) for j in range(max(0, i - K), i))
    print(dp[N - 1])


main()


Measured memory_bytes: 13980
N,K=(int(i) for i in input().split())
s=input()
S=list(s)

if(S[K-1]=='A'):
    S[K-1]='a'
elif(S[K-1]=='B'):
    S[K-1]='b'
elif(S[K-1]=='C'):
    S[K-1]='c'

A=''.join(S)
print(A)


Measured memory_bytes: 3060
N = int(input())
A = list(map(int, input().split()))
index = []
num = 1
tmp = 0
for i,a in enumerate(A):
    tmp += 1
    if a == num:
        index.append(i+1)
        num += 1
        tmp = 0
        continue
if num == 1:
    print(-1)
else:
    ans = index[0]-1
    for i in range(1, len(index)):
        ans += index[i] - index[i-1] - 1
    ans += tmp
    print(ans)

Measured memory_bytes: 24744
import java.io.PrintWriter
val pw = PrintWriter(System.out)

fun main(args : Array<String>) {
    func()
    pw.flush()
}

fun func() {
    var ss = next()

    while (true) {
        ss = ss.slice(0..ss.length-3)
        if (ss.slice(0 until ss.length/2) == ss.substring(ss.length/2)) {
            println(ss.length)
            break
        }
    }
}

fun next() = readLine()!!

fun println(value : Any) {
    pw.println(value)
}

Measured memory_bytes: 33716
a=[list(map(int,input().split())) for i in range(3)]
n=int(input())
x=[[0,0,0],[0,0,0],[0,0,0]]
for i in range(n):
  b=int(input())
  for j in range(3):
    for k in range(3):
      if a[j][k]==b:
        x[j][k]=1

ans='No'
for i in range(3):
  if x[0][i]+x[1][i]+x[2][i]==3:
    ans='Yes'

for i in range(3):
  if x[i][0]+x[i][1]+x[i][2]==3:
    ans='Yes'


if x[0][0]+x[1][1]+x[2][2]==3:
  ans='Yes'
elif x[2][0]+x[1][1]+x[0][2]==3:
  ans='Yes'

print(ans)


Measured memory_bytes: 3064
import java.util.*;
class Main{
	public static void main(String[] args){
		Scanner input = new Scanner(System.in);
		int N = input.nextInt();
		int W = input.nextInt();
		int[][] items = new int[N][2];
		for(int i = 0; i < N; i++){
			items[i][0] = input.nextInt();
			items[i][1] = input.nextInt();
		}
		/*for(int i = 0; i < N; i++){
			System.out.print(items[i][0] + " ");
			System.out.println(items[i][1]);
		} */

		long [][] dp = new long[N+1][W+1];
		for(int i = 0; i < dp.length; i++){
			Arrays.fill(dp[i], -1);
		}
		dp[0][0] = 0;
		for(int i = 1; i < dp.length; i++){
			for(int j = 0; j < dp[i].length; j++){
				if(j >= items[i-1][0]) dp[i][j] = Math.max(dp[i-1][j-items[i-1][0]] == -1 ? -1 : dp[i-1][j-items[i-1][0]] + items[i-1][1], dp[i-1][j]);
				else dp[i][j] = dp[i-1][j];
			}
		}
		long max = 0;
		for(int j = 0; j <= W; j++) max = (long) Math.max(dp[N][j], max);
		System.out.println(max);

	}
}


Measured memory_bytes: 126932
#include <bits/stdc++.h>
#define int long long int
#define endl "\n"
#define mod 1000000007
#define ps(x,noOfDecimal) fixed<<setprecision(noOfDecimal)<<x
  
using namespace std;
signed main()
{

  std::ios::sync_with_stdio(false);
  cin.tie(); cout.tie();
 
    int n;
    cin>>n;
    vector<pair<int,int>> arr;
    for(int i=0;i<n;i++){
    int x,y;
    cin>>x>>y;
    arr.push_back(make_pair(x,y));
    }
    sort(arr.begin(), arr.end());
    int mn = arr[0].first + arr[0].second;
    int mx = arr[0].first - arr[0].second;
    int ans = 0; 
    for(int i = 1 ; i < n ; i++){
      int temp = ans;
      ans = max(arr[i].first + arr[i].second - mn , arr[i].first - arr[i].second - mx);
      ans = max(ans,temp);
      int tmn = arr[i].first + arr[i].second;
      int tmx = arr[i].first - arr[i].second;
      mx = min(mx,tmx);
      mn = min(mn,tmn);

    }

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

Measured memory_bytes: 7492
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
using namespace std;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define in(x) cin >> x
#define out(str) cout << str << endl

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

int H,W,h,w;

int main(){
    cin>>H>>W>>h>>w;
    out((H-h)*(W-w));
}


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

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(solver());
        }
        static long solver()
        {
            var N = int.Parse(Console.ReadLine());
            var D = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            long MOD = 998244353;

            if (D[0] != 0) return 0;

            var distance = new long[D.Max() + 1];
            foreach (int d in D) distance[d] += 1;
            if (distance[0] != 1) return 0;
            long result = 1;
            for (int i = 1; i < distance.Length; i++)
            {
                for (int j = 0; j < distance[i]; j++)
                {
                    result *= distance[i - 1];
                    result %= MOD;
                }
            }
            return result;
        }
    }
}


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

int main() {
    int L;cin>>L;
    double a =L/3.0;
    double ans = a*a*(L-2*a);
     cout << fixed << setprecision(12);
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <string>
using namespace std;
int main(){
	int n;
	cin >> n;

	int G[100][100] = {};
	for(int i=0; i<n; i++){
		int u,k;
		cin >> u >> k;
		for(int l=0; l<k; l++){
			int v;
			cin >> v;
			G[u-1][v-1] = 1;
		}
	}

	for(int i=0; i<n; i++){
		for(int l=0; l<n; l++){
			cout << G[i][l];
			if(l==n-1){
				cout << endl;
			}
			else{
				cout << " ";
			}
		}
	}

	return 0;
}


Measured memory_bytes: 3108
n = int( input( ) )
s = [ int( val ) for val in raw_input( ).split( " " ) ]
q = int( input( ) )
t = [ int( val ) for val in raw_input( ).split( " " ) ]

cnt = 0
cnt = 0
for ti in t:
	low = 0
	high = n - 1
	while low <= high:
		m = ( low+high )/2
		if ti < s[m]:
			high = m - 1
		elif s[m] < ti:
			low = m + 1
		else:
			cnt += 1
			break

print( cnt )

Measured memory_bytes: 13160
#include<cstdio>
#include<iostream>
#include<algorithm>

using namespace std;

#define pii pair<int,int>
#define mp make_pair
#define f first
#define s second

pii NO=mp(-10000,-10000);
pii dp[33][33][33][33];
int ck[33][33][33][33];
int sum[33][33];
int a[33][33];
int T,cs,n,m,s,tot;

inline int get(int x1, int y1, int x2, int y2) {
	return sum[x2][y2]-sum[x2][y1-1]-sum[x1-1][y2]+sum[x1-1][y1-1];
}

pii go(int x1, int y1, int x2, int y2) {
	if(tot-get(x1,y1,x2,y2)>s) return NO;
	
	pii &ret=dp[x1][y1][x2][y2];
	if(ck[x1][y1][x2][y2]==cs) return ret;
	ck[x1][y1][x2][y2]=cs,ret=mp(1,get(x1,y1,x2,y2));

	if(x1<x2) {
		for(int nx=x1+1;nx<=x2;++nx) {
			pii t1=go(x1,y1,nx-1,y2);
			pii t2=go(nx,y1,x2,y2);
			if(ret.f < t1.f+t2.f) {
				ret.f = t1.f+t2.f;
				ret.s = min(t1.s,t2.s);
			}
			else if(ret.f == t1.f+t2.f && ret.s < min(t1.s,t2.s)) {
				ret.s = min(t1.s,t2.s);
			}
		}
	}
	if(y1<y2) {
		for(int ny=y1+1;ny<=y2;++ny) {
			pii t1=go(x1,y1,x2,ny-1);
			pii t2=go(x1,ny,x2,y2);
			if(ret.f < t1.f+t2.f) {
				ret.f = t1.f+t2.f;
				ret.s = min(t1.s,t2.s);
			}
			else if(ret.f == t1.f+t2.f && ret.s < min(t1.s,t2.s)) {
				ret.s = min(t1.s,t2.s);
			}
		}
	} return ret;
}

int main() {
	//freopen("input.txt","r",stdin);
	while(scanf("%d%d%d",&n,&m,&s),n) {
		cs++;
		for(int i=1;i<=n;++i) for(int j=1;j<=m;++j)
			scanf("%d",&a[i][j]);
		for(int i=1;i<=n;++i) for(int j=1;j<=m;++j)
			sum[i][j]=sum[i-1][j]+sum[i][j-1]+a[i][j]-sum[i-1][j-1];
		tot=sum[n][m];
		pii ans=go(1,1,n,m);
		printf("%d %d\n",ans.f,s-(tot-ans.s));
	}
}

Measured memory_bytes: 14936
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <fstream>
using namespace std;
int q;

int main()
{
    int x;
    cin >> x;
    int64_t rs = (x / 500) * 1000;
    x = x - (x / 500 * 500);
    rs += x / 5 * 5;
    cout << rs;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using ll  = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define erep(e,v) for(auto && e :v)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? (int)1e9:(int)1e18)
#define EPS 0.0000000001
using namespace std;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
template<class T> void join (T cont){for(auto itr = cont.begin();itr != cont.end();cont++){
    cout << (itr == cont.begin() ? "":" ") << *itr << endl;
}}
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
signed main(){
    int n;
    while(cin >> n,n){
        int ans = 1;
        int sub = n;
        for(int i = 2; i <= (int)1e5;i++){
            int sum = i * (i-1) / 2;
            int res = n - sum;
            if(res > 0 and res % i == 0){
                ans = i;
                sub = res/i;
            }
        }
        cout << sub  << " " << ans << endl;
    }
}






Measured memory_bytes: 3104
#include <stdio.h>
int dp[100010][15];
char st[100010];
const int mmod=1e9+7;

int main()
{
    for (int i=1;i<13;i++) dp[0][i]=0;
    dp[0][0]=1;
    scanf("%s",st+1);
    int i;
    for (i=1;st[i];i++)
    {
        for (int j=0;j<13;j++) dp[i][j]=0;
        if (st[i]!='?')
        {
            int now=st[i]-'0';
            for (int j=0;j<13;j++)
            {
                int go=j*10+now;go%=13;
                dp[i][go]+=dp[i-1][j];
                dp[i][go]%=mmod;
            }
        }
        else
        {
            for (int now=0;now<10;now++)
            for (int j=0;j<13;j++)
            {
                int go=j*10+now;go%=13;
                dp[i][go]+=dp[i-1][j];
                dp[i][go]%=mmod;
            }
        }
    }
    printf("%d\n",dp[i-1][5]);
}



Measured memory_bytes: 6144
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<set>
#include<vector>
#define MAXN 1000000
#define MAXM 2000000
#define INF 0x7FFFFFFF
using namespace std;
struct edge
{
	int u,v,val;
	edge(){};
	edge(int _u,int _v,int _val):u(_u),v(_v),val(_val){};
};
struct state
{
	int u,dn;
	state(){};
	state(int _u,int _dn):u(_u),dn(_dn){};
};
vector<edge> G[MAXN+5],edges;
bool operator < (state a,state b){return a.dn>b.dn;}
bool operator < (edge a,edge b){return a.val<b.val;}
int N,dist[MAXN+5],setfa[MAXN*2+5];
int im[MAXN+5],imcnt=0;
vector<int> need;
void Init()
{
	fill(dist,dist+1+MAXN,INF);
	for(int i=0;i<=MAXN+3;i++)
		setfa[i]=i,im[i]=-1;
}
int Findfa(int x)
{
	if(setfa[x]==x)
		return x;
	return setfa[x]=Findfa(setfa[x]);
}
void Union(int x,int y)
{
	int fx=Findfa(x),fy=Findfa(y);
	if(fx==fy)
		return;
	setfa[fx]=fy;
}
void Dijkstra()
{
	priority_queue<state> que;
	que.push(state(1,0));
	dist[1]=0;
	while(que.empty()==false)
	{
		int u=que.top().u;
		int dn=que.top().dn;
		que.pop();
		if(dn!=dist[u])
			continue;
		for(int i=0;i<G[u].size();i++)
		{
			int v=G[u][i].v;
			int val=G[u][i].val;
			if(dist[v]>dn+val)
			{
				dist[v]=dn+val;
				que.push(state(v,dist[v]));
			}
		}
	}
}
int main()
{
//	freopen("in.txt","r",stdin);
	Init();
	int M,a,b,c;
	scanf("%d %d",&N,&M);
	imcnt=N;
	for(int i=1;i<=M;i++)
	{
		scanf("%d %d %d",&a,&b,&c);
		edges.push_back(edge(a,b,c));
	}
	int newN=N;
	sort(edges.begin(),edges.end());
	int lastw=-1;
	for(int i=0;i<=edges.size();i++)
	{
		if(need.size()!=0&&(lastw!=edges[i].val||i==edges.size())&&i!=0)
		{
			for(int j=0;j<need.size();j++)
			{
				int u=need[j];
				if(im[Findfa(u)]==-1)
					im[Findfa(u)]=++imcnt;
				G[u].push_back(edge(u,im[Findfa(u)],1));
				G[im[Findfa(u)]].push_back(edge(im[Findfa(u)],u,1));
			}
			for(int j=0;j<need.size();j++)
				setfa[need[j]]=need[j],im[need[j]]=-1;
			need.clear();
		}
		if(i==edges.size())
			break;
		int u=edges[i].u,v=edges[i].v;
		need.push_back(u);
		need.push_back(v);
		Union(u,v);
		lastw=edges[i].val;
	}
	Dijkstra();
	if(dist[N]==INF)
		printf("-1\n");
	else
		printf("%d\n",dist[N]/2);
	return 0;
}

Measured memory_bytes: 56172
N, M, C = map(int, input().split())
B = list(map(int, input().split()))
count = 0
for i in range(N):
    A = list(map(int, input().split()))
    x = C
    for index, val in enumerate(B):
        x += A[index] * val
    if x > 0:
        count += 1
print(count)


Measured memory_bytes: 3060
NM = list(map(int,input().split()))
N,M = NM[0], NM[1]
li = list(map(int,input().split()))

if N>=M:
    ans = 0
else:
    li.sort()
    diff = []
    for i in range(M-1):
        diff.append(li[i+1]-li[i])
    diff.sort()
    if N == 1:
        ans = sum(diff)
    else:
        ans = sum(diff[:-(N-1)])
print(ans)

Measured memory_bytes: 13968
#include <queue>
#include <cstdlib>
#include <iomanip>
#include <utility>
#include <math.h>
#include <vector>
#include <algorithm>
#include <string>
#include <iostream>

using namespace std;

vector<pair<int,int> > v;

int vsearch(int id)
{
    for(int i = 0;i<v.size();i++)
    {
        if(v[i].first==id)
            return i;
    }
    return -1;
}

int main() {
    
    int const price = 1000000;
    int n;
    while(cin >> n && n!=0)
    {
        int e[n],p[n],q[n];
        for(int i = 0; i<n;i++)
        {
            cin >> e[i] >> p[i] >> q[i];
        }
        
        for(int i = 0; i< n; i++)
        {
            int id = vsearch(e[i]);
            if(id < 0)
                v.push_back({e[i],p[i]*q[i]});
            else
                v[id].second += p[i]*q[i];
        }
        bool ch = true;
        for(int i = 0;i<v.size();i++)
        {
            if(v[i].second >= price)
            {
                cout << v[i].first << endl;
                ch = false;
            }
        }
        if(ch) cout << "NA" << endl;
        vector<pair<int,int> >().swap(v);
    }
    
    return 0;
}

Measured memory_bytes: 3000
#include<bits/stdc++.h>
using namespace std;
const int maxn=100000+50;

struct node{
	int id,rank;
	//node(int x,int y):id(x),rank(y){}
	bool operator <(const node& rhs) const {
		return rank<rhs.rank;
	}
}a[maxn];


int n,x,y;

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&x);
		a[i-1].id=i;a[i-1].rank=x;
	}
	sort(a,a+n);
	for(int i=0;i<n;i++)printf("%d ",a[i].id);
}

Measured memory_bytes: 1536
#include <iostream>
#include <numeric>
#include <vector>
#include <algorithm>
#include <map>
#include<queue>
#include <sstream>
#include <set>
typedef  long long ll;
const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};
const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = { 0, 1, 0,-1};
const int INF = 1e9;
#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
int guki (int a){
    if(a%2==0) return 0;
    else return 1;
}
int gcd(int a, int b){
    if(a%b==0){
        return b;
    }else{
        return (gcd(b,a%b));
    }
}
int lcm(int a, int b){
    int x = gcd(a,b);
    return (a*b/x);
}
using namespace std;
int main(){
    string S;
    cin >> S;

    int ans = 0,cnt =0;
    vector<char> hant(4);
    hant[0] = 'A';
    hant[1] = 'C';
    hant[2] = 'T';
    hant[3] = 'G';

    REP(i,S.size()){
        bool fl = true;
        REP(j,4){
            if(S[i]==hant[j]){
                fl = false;
                S[i] = '1';
            }
        }
        if(fl) S[i] = '0';
    }

    

    REP(i,S.size()){
        bool fl2 = false;

        if(S[i]=='1')fl2=true;

        while(fl2){
            if(S[i]=='1'){
                i++;
                cnt ++;
            }else{
                fl2 = false;
            }
        }
        ans = max(ans,cnt);
        cnt = 0;
    }

    cout << ans <<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
using tpl = tuple<char, int>;
typedef pair<int,int> pii;
typedef long long ll;

void fastStream(){cin.tie(0);std::ios_base::sync_with_stdio(0);}

int N;
int A[100010];
int front[100010];
int back[100010];

int main(){

    fastStream();
    cin >> N;
    for(int i = 0; i < N; i++) cin >> A[i+1];
    A[0] = 0;
    A[N+1] = 0;
    N += 2;
    
    for(int i = 1; i < N; i++){
        front[i] = front[i-1] + abs(A[i] - A[i-1]);
    }
    for(int i = N - 2; i >= 0; i--){
        back[i] = back[i+1] + abs(A[i] - A[i+1]);
    }
    
    for(int i = 1; i < N - 1; i++){
        cout << front[i-1] + back[i+1] + abs(A[i-1] - A[i+1]) << endl;
    }


    return 0;
}



Measured memory_bytes: 2432
#include <iostream>

using namespace std;

int main(){
    int n, m;
    int a[100000];
    long score[10000] = {0};
    long cnt[100001] = {0};
    long deq[100001] = {0};
    long inc = 0;
    long ans;
    cin >> n >> m;
    cin >> a[0];
    for(int i = 1; i < n; i++){
        cin >> a[i];
        if(a[i] > a[i-1]){
            cnt[a[i]]--;
            cnt[a[i-1]+1]++;
            deq[a[i]+1] += (a[i]-a[i-1]+m)%m - 1;
        }
        if(a[i] < a[i-1]){
            cnt[a[i]]--;
            cnt[a[i-1]+1]++;
            inc++;
            deq[a[i]+1] += (a[i]-a[i-1]+m)%m - 1;
        }
    }
    for(int i = 1; i < n; i++){
        score[1] += min((a[i]-a[i-1]+m)%m, a[i]);
    }
    ans = score[1];
    inc += cnt[1];
    for(int i = 2; i <= m; i++){
        score[i] = score[i-1]-inc + deq[i];
        inc+= cnt[i];
        ans = min(ans, score[i]);
    }
    for(int i = 1; i <= m; i++){
        //cout << score[i] << endl;
    }
    cout << ans << endl;
}

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

typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=100005;

int main(){
    
    int N,L;cin>>N>>L;
    vector<int> S(N);
    int sum=0;
    for(int i=0;i<N;i++){
        S[i]=L+i;
        sum+=S[i];
    }
    if(S[0]<=0&&S[N-1]>=0) cout<<sum<<endl;
    else if(S[N-1]<0) cout<<sum-S[N-1]<<endl;
    else cout<<sum-S[0]<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int N, arr[51], i, j, cnt=0;
	scanf("%d", &N);
	for(i=0; i<N; i++){
		scanf("%d", &arr[i]);
	}
	for(i=1; i<=N; i++){
			if(arr[i-1]!=i)
				cnt++;
	}
	if(cnt>2)
		printf("NO");
	else
		printf("YES");
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define pb push_back
#define fi first
#define se second
#define pi pair<int, int>
#define rep(i, a, n) for(int i = a; i <= n; i++)
#define per(i, a, n) for(int i = a; i >= n; i--)
#define REP(i, a, n) for(int i = a; i < n; i++)
#define Y "YES"
#define N "NO"
using namespace std;

ll n, ans;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	//freopen("in.txt", "r", stdin);

	cin >> n;
	rep(i, 1, n-1)
		ans += (n-1)/i;
	cout << ans;
}

Measured memory_bytes: 3644
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<iomanip>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
#define LINF (long long)4e18

using ll = long long;


int main(){
   int N; cin >> N;
   string S; cin >> S;
   int ans = 0;
   rep(i,N-1){
      int sum = 0;
      for(char c = 'a'; c <= 'z'; c++){
         bool ok = false;
         rep(j,i+1){
            repr(k,i+1,N){
               if(S[j] == c && S[k] == c) ok = true;
            }
         }
         if(ok) sum++;
      }
      ans = max(ans,sum);
   }
   cout << ans << endl;
}



Measured memory_bytes: 256
//Date and time of submission: 
 
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll N=1e5+5;
string s;
int main() {
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL);
	map<char,ll> mp;
	cin>>s;
	for(char ch:s)
	++mp[ch];
	if(mp['a']==1&&mp['b']==1&&mp['c']==1)
	cout<<"Yes";
	else
	cout<<"No";
	return 0;
}


Measured memory_bytes: 256
using System;
 
class Program
{
        const String even = "Even";
        const String odd = "Odd";
 
        static void Main(String[] arg)
		{
            //出力用の文字列
            String ret;
 
            // 整数の取得
            String[] nums = Console.ReadLine().Split(' ');
            int a = int.Parse(nums[0]);
            int b = int.Parse(nums[1]);
            
            // 積の演算
            int product = a * b;
 
            // 
            if(product % 2 == 0)
            {
                ret = even;
            }
            else
            {
                ret = odd;
            }
 
            Console.WriteLine(ret);
		}
}

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

using namespace std ; 

const int N =1e6 + 7 ; 

int n , k ;  
long long C ; 

int dyn = 1 ;
int ri[N] , li[N] ;


struct line{
        long long x , b; 
        line(){
                x = 0LL , b = 4e18 ; 
        }
        line(long long _x , long long _b){
                x = _x ; 
                b = _b ; 
        }
        long long eval(long long X){ 
                return 1LL * X * x + b ; 
        }
} c[N<<2] ; 
        

        void update(line r , int node = 1 , long long L = 1 , long long R = N ){
                
                long long m = (L + R) >> 1 ; 


                bool le = (c[node].eval(L) > r.eval(L)) ; 
                bool mid = (c[node].eval(m) > r.eval(m)) ; 
                
                if(mid){
                        swap(c[node] , r) ; 
                }

                if(L == R -1 ){
                        return ; 
                }
                if(le == mid){
                        if(ri[node] == -1){
                                ri[node] = ++ dyn ;
                        }
                        update(r , ri[node] , m , R ) ; 
                }
                else{
                        if(li[node] == -1){
                                li[node] = ++dyn ;
                        }
                        update(r , li[node] , L , m ) ; 
                }

        }

        long long query( long long x , int node = 1, long long L = 1 , long long R = N ){

                long long m = (L + R) >> 1 ; 

                long long evalx = c[node].eval(x) ; 

                if(R - L == 1)
                        return evalx ;

                if(x < m){
                        if(li[node] == -1)
                                return evalx ;
                        return min(evalx , query(x , li[node] , L , m ) )  ;
                }
                else {
                        if(ri[node] == -1)
                                return evalx; 
                        return min(evalx , query(x , ri[node] , m , R) )  ; 
                }

        }

        vector<line> lns ; 

long long dp[N] ;

int main(){

        ios_base::sync_with_stdio(0) ; 
        cin.tie(0) ; 
        memset(li , -1 , sizeof li) ; 
        memset(ri , -1 , sizeof ri) ;
        //freopen("in.in" , "r" ,stdin) ; 

        cin >> n >> C ;

        for(int i = 0 ;i < n;i++){
                long long x ; 
                cin>> x ; 

                if(i){
                        dp[i] = 1LL * x * x + query(x)  + C ; 
                }

                update(line( -2LL * x, dp[i] + x * x )) ; 
        }

        cout<< dp[n-1] ; 
        return 0; 
}

Measured memory_bytes: 75504
#include <iostream>

using namespace std;

int main()
{
   int inputA, inputB, outArea, outPerimeter;
   cin >> inputA >> inputB;
   
   outArea = inputA * inputB;
   outPerimeter = inputA * 2 + inputB * 2;
   
   cout << outArea << " " << outPerimeter << endl; 
   
   return 0;
}


Measured memory_bytes: 3032
N = int(input())
S = [str(input()) for _ in range(N)]

A = 0
W = 0
T = 0
R = 0

for i in range(N):
    if S[i] == "AC":
        A += 1
    elif S[i] == "WA":
        W += 1
    elif S[i] == "TLE":
        T += 1
    elif S[i] == "RE":
        R += 1

print("AC x",A)
print("WA x",W)
print("TLE x",T)
print("RE x",R)


Measured memory_bytes: 79144
using System;
using System.Linq;
using System.Collections.Generic;

namespace Algorithm
{
    class Program
    {
        static long[,,,] dp = new long[101, 4, 4, 4];
        static void Main(string[] args)
        {
            var s = Console.ReadLine();
            Console.WriteLine(s.Replace("2017", "2018"));
        }
    }
}


Measured memory_bytes: 11220
letters = "abcdefghijklmnopqrstuvwxyz"

table = [0]*26

while True:
    try:
        line = input()

        for i in line:
            index = 0
            for j in letters:
                if i == j or i == j.upper():
                    table[index]+=1
                index+=1
    except:
        break

for i in range(len(letters)):
    print("%s : %d"%(letters[i],table[i]))



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

using namespace std;

signed main() {
    int n;
    cin >> n;
    vector<int> dp(3);
    for (int day = 0; day < n; day++) {
        vector<int> new_dp(3, 0), c(3);
        for (int i = 0; i < 3; i++) 
            cin >> c[i];
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                if (i != j) {
                    new_dp[j] = max(new_dp[j], dp[i] + c[j]);
                }
            }
        }
        dp = new_dp;
    }
    cout << max({dp[0], dp[1], dp[2]}) << "\n";
    return false;
}

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

using namespace std;

typedef pair<int, int> iip;
typedef long long ll;
typedef priority_queue<int> ipque;
typedef priority_queue<long long> llpque;
const int inf = 1000000007;

int main() {
  int n, m;
  cin >> n >> m;
  llpque pque;
  rep(i, n) {
    ll a;
    cin >> a;
    pque.push(a);
  }
  rep(i, m) {
    ll tmp = pque.top() / 2;
    pque.pop();
    pque.push(tmp);
  }
  ll ans = 0;
  while(!pque.empty()){
    ans += pque.top();
    pque.pop();
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4320