akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n - 1); i >= 0; --i)

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

const int MAX = 1e5 + 5;
const int INF = 1001001001;
const int MOD = 1e9 + 7;

int main(){
    int N, p;
    string s;
    cin >> N >> p >> s;

    ll ans = 0;
    if (p == 2 || p == 5) {
        rep(i, N) {
            if ((s[i] - '0') % p == 0) ans += i + 1;
        }
        cout << ans << endl;
        return 0;
    }

    vector<int> num(N + 1);
    map<int, int> mp;
    num[N] = 0;
    int m = 1;
    repr(i, N) {
        num[i] = num[i+1] + (s[i] - '0') * m;
        m *= 10;
        num[i] %= p;
        m %= p;
        if (num[i] != 0) {
            ans += mp[num[i]];
            mp[num[i]]++;
        } else {
            mp[num[i]]++;
            ans += mp[num[i]];
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 1668
import java.io.InputStreamReader
import java.io.BufferedReader
import java.util.HashMap

fun main(args: Array<String>) {
  val br = BufferedReader(InputStreamReader(System.`in`))

  br.readLine()

  fun HashMap<Int, Int>.putOrUpdate(key: Int) {
    if(this.containsKey(key)) this.put(key, this.get(key)!!.plus(1))
    else this.put(key, 1)
  }

  val map = hashMapOf<Int, Int>()
  val a = br.readLine().split(" ").map { it.toInt() }
  for(key in a) {
    map.putOrUpdate(key)
  }

  val ans = map.keys.fold(0L) { acc, k ->
    val v: Int = map.get(k)!!
    if(k > v) acc + v else acc + (v - k)
  }

  println(ans)
}

Measured memory_bytes: 74516
//median time 23

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#define all(v) v.begin(), v.end()
#define repi(i, n, init) for (ll i = init; i < (n); i++)
#define repd(i, n, init) for (ll i = (n); i >= init; i--)
#define repm(i, m) for (auto i = m.begin(); i != m.end(); i++)

int main()
{
    ll N;
    cin >> N;
    vector<ll> A(N);
    repi(i, N, 0)
    {
        cin >> A[i];
    }
    ll cnt = 0;
    for (ll i = 0; i < N; i++)
    {
        if (A.at(A.at(i) - 1) == i + 1)
        {
            cnt++;
        }
    }
    cout << cnt / 2 << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define INF LLONG_MAX
#define Int long long
#define rep(i,n) for(int i=0; i<n; ++i)
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if(a>b) {a=b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) { if(a<b) {a=b; return true;} return false;}

int main() {
  int N; cin >> N;
  vector<int> d(N);
  rep(i,N) cin >> d[i];
  sort(d.begin(), d.end());
  d.erase(unique(d.begin(), d.end()), d.end());
  cout << d.size() << endl;
}


Measured memory_bytes: 256
/*
 * main.c
 *
 *  Created on: 2019/12/29
 *      Author: family
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define MAX(a,b) (a > b ? a : b)
#define MIN(a,b) (a > b ? b : a)
typedef long long int ll;

int main()
{
	ll H = 0, ans = 1, exp = 1;
	scanf("%lld", &H);
	while (H > 1) {
		H = H/2;
		ans += pow(2.0, (double)exp);
		exp++;
	}
	printf("%lld\n", ans);
    return 0;
}


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

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

  vector<int> r(n);

  cin >> r.at(0);
  int minv = r.at(0);
  int maxv = -1 * pow(10, 9);

  for (int i = 1; i < n; i++) {
    cin >> r.at(i);
    maxv = max(maxv, r[i] - minv);
    minv = min(minv, r[i]);
  }
  
  cout << maxv << endl;
}


Measured memory_bytes: 3600
#include <iostream>
#include <algorithm>
#include <cmath>
#define rep(i,n) for(ll i=0;i<n;++i)
#define rep1(i,n) for(ll i=1;i<=n;++i)
using namespace std;
typedef long long ll;
ll h,w;
int main()
{
  cin >> h >> w;

  ll res = 1e+9;
  
  rep1(i,h){
    ll a = i * w;
    
    if((h-i)%2==0 || w%2==0){
      ll b = (h-i)*w/2;
      res = min(res,abs(a-b));
    }
    else{
      ll b = (h-i)/2*w,c = (h-i+1)/2*w;
      ll d = max(max(a,b),c) - min(min(a,b),c);
      res = min(res,d);

      b = w/2*(h-i);
      c = (w+1)/2*(h-i);
      d = max(max(a,b),c) - min(min(a,b),c);
      res = min(res,d);      
    }
  }

  rep1(i,w){
    ll a = i * h;
    
    if((w-i)%2==0 || h%2==0){
      ll b = (w-i)*h/2;
      res = min(res,abs(a-b));
    }
    else{
      ll b = (w-i)/2*h,c = (w-i+1)/2*h;
      ll d = max(max(a,b),c) - min(min(a,b),c);
      res = min(res,d);

      b = h/2*(w-i);
      c = (h+1)/2*(w-i);
      d = max(max(a,b),c) - min(min(a,b),c);
      res = min(res,d);      
    }
  }

  cout << res << "\n";
  
  return 0;
}


Measured memory_bytes: 256
import java.io.IOException;
import java.util.Scanner;
public class Main {
	static int[] dice;
	static int a;
	static int b;
	static int c;
	static int d;
	public static void main(String[] args) throws IOException{
		Scanner sc = new Scanner(System.in);

		dice = new int[6];
		for(int i=0; i<6; i++) {
			dice[i] = sc.nextInt();
		}

		String o = sc.next();
		char[] order = o.toCharArray();

		for(int i=0; i<order.length; i++) {
			if(order[i] == 'S') {
				s();
			}else if(order[i] == 'E') {
				e();
			}else if(order[i] == 'W') {
				w();
			}else if(order[i] == 'N') {
				n();
			}
		}

		System.out.println(dice[0]);

		sc.close();
	}

	public static void s() {
		a = dice[0];
		b = dice[1];
		c = dice[4];
		d = dice[5];

		dice[0] = c;
		dice[1] = a;
		dice[4] = d;
		dice[5] = b;
	}

	public static void w() {
		a = dice[0];
		b = dice[2];
		c = dice[3];
		d = dice[5];

		dice[0] = b;
		dice[2] = d;
		dice[3] = a;
		dice[5] = c;
	}

	public static void e() {
		a = dice[0];
		b = dice[2];
		c = dice[3];
		d = dice[5];

		dice[0] = c;
		dice[2] = a;
		dice[3] = d;
		dice[5] = b;
	}

	public static void n() {
		a = dice[0];
		b = dice[1];
		c = dice[4];
		d = dice[5];

		dice[0] = b;
		dice[1] = d;
		dice[4] = a;
		dice[5] = c;
	}
}


Measured memory_bytes: 26396
#include <stdlib.h>
  #include <stdio.h>
  #include <math.h>
  #include <string.h>

  int main()
  {
  
   int K ;
   scanf("%d",&K);
   
   int sum = K/2 *((K+1)/2);
   printf("%d",sum);
  
    return 0;
  }
  



Measured memory_bytes: 128
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cmath>
#define llong long long
#define INF (pow(10, 15) + 1)

using namespace std;

llong n;
llong bn = INF;

llong solve() {
    llong res = n / bn;
    if(n % bn != 0) ++res;
    res += 4;
    return res;
}

int main(int argc, char **argv) {
    scanf("%lld", &n);
    for(int i = 0; i < 5; ++i) {
        llong a;
        scanf("%lld", &a);
        bn = min(bn, a);
    }
    
    printf("%lld\n", solve());
}

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

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		
		int n = stdIn.nextInt();
		int k = stdIn.nextInt(); //選ぶ本数
		int[]h = new int[n];
		
		for(int i = 0; i < n; i++) {
			h[i] = stdIn.nextInt();
		}
		Arrays.sort(h);
		
		int [] dif = new int[n-1];
		long max = Long.MAX_VALUE;
		dif[0] = h[1]-h[0];
		for(int i = 1; i < n-1; i++) {
			dif[i] = h[i+1] - h[i];
		}
		
		int[] s = new int[n];
		s[0] = 0;
		for(int i = 1; i < n; i++) {
			s[i] = s[i-1]+dif[i-1];
		}
		
		
		for(int i = 0; i < n-k+1; i++) {
			max = Math.min(max, s[i+k-1]-s[i]);
		}
		System.out.println(max);
	}

}


Measured memory_bytes: 51172
import sys
MAX_INT = int(10e9)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

A,B,C = IL()
tmp = A-B

if tmp > C:
  print(0)
else:
  print(C-tmp)

Measured memory_bytes: 40208
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define all(a) (a).begin(), (a).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
const int MOD = 1e9+7;
const ll LINF = 1e18;
const int INF = 1e9;
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;

vector<ll> aaa(100100);
int main()
{
    cin >> N;
    vector<ll> arr(N);
    for (ll i = 0; i < N; i++) 
    {
        cin >> A;
        aaa[A]++;
        arr.at(i) = A;
    }
    ll sum = accumulate(all(arr),0LL);
    cin >> Q;

    for (ll i = 0; i < Q; i++)
    {
        cin >> B >> C;

        D = (C-B)*aaa[B];
        aaa[C] += aaa[B];
        aaa[B] = 0;

        sum += D;

        cout << sum << endl;

    }
    

    return 0;
}

Measured memory_bytes: 4824
n = int(input())
li = list(map(int,input().split()))
cnt = 0
ans = 0
for i in range(n-1):
    if li[i]>=li[i+1]:
        cnt+=1
    else:
        if cnt>ans:
            ans = cnt
        cnt = 0
if cnt>ans:
    ans = cnt
print(ans)

Measured memory_bytes: 14252
#include "bits/stdc++.h"
using namespace std;
const int MAX = 700000;
const int MOD = 1000000007;

long long  fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y){
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}
/*逆元計算*/
long long int  modinv(long long a, long long m) {
	long long int b = m, u = 1, v = 0;
	while (b) {
		long long int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
// index が条件を満たすかどうか
vector<long long int >meguru;
bool isOK(int index, int key) {
	if (meguru[index] >= key) return true;
	else return false;
}
// 汎用的な二分探索のテンプレ
int binary_search(int key) {
	int left = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
	int right = (int)meguru.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()
	/* どんな二分探索でもここの書き方を変えずにできる！ */
	while (right - left > 1) {
		int mid = left + (right - left) / 2;

		if (isOK(mid, key)) right = mid;
		else left = mid;
	}
	/* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている */
	return right;
}
long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}
vector<vector<int>>s(100030);
vector<vector<int>>sb(100030);
int tomodati[100030] = {};
int seen[100030] = {};
int namaes[100030] = {};
int main() {
	long long int h, w;
	cin >> h >> w;
	if (h == 1 || w == 1) {
		cout << 1;
		return 0;
	}
	long long int ans = 0;
	ans = ans + ((h + 1) / 2) * ((w + 1) / 2);
	ans = ans + (h / 2) * (w / 2);
	cout << ans;
}


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

#define FOR(a,b,c) for(int a=(b),a##_end__=(c);a<a##_end__;a++)
#define chkmin(a,b) (a)=min((a),(b))
#define chkmax(a,b) (a)=max((a),(b))
#define x first
#define t second
#define ll long long 
#define db double
#define pb push_back
#define SZ(x) ((int)x.size())
#define M 205

char s[M];
int n,ans;

int main(){
    scanf("%s",s);
    n=strlen(s);
    FOR(i,0,n) FOR(j,i+1,n) if(!(i==0 && j==n-1) && (j-i+1)%2==0){
        bool ok=1;
        int mid=(j-i>>1)+1;
        FOR(k,0,mid) if(s[i+k]!=s[i+mid+k]) ok=0;
        if(ok){
            //printf("%d %d\n",i,j);
            chkmax(ans,j-i+1);
        } 
    }
    printf("%d",ans);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
bool ans(const vector<string>& W){
	const int n=W.size();
	for (int i=0;i<n-1;i++){
		if (W[i].back()!=W[i+1].front())
			return false;
	    for (int j=i+1;j<n;j++){
	    	if (W[i]==W[j])
				return false;
		}
	}
	return true;
}
int main(){
	int n;
	cin>>n;
	vector<string> W(n);
	for (int i=0;i<n;i++){
		cin>>W[i];
	}
	if(ans(W))
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
	return 0;
}

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

using namespace std;

#define INF 1000000007
#define int long long
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) FOR(i, 0, n)
#define maxn 15

int gcd(int x, int y)
{
    if (x < y)
        swap(x, y);
    if (y == 0)
        return x;
    return gcd(x % y, y);
}

signed main()
{
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N)
    {
        cin >> A[i];
    }
    sort(A.begin(), A.end());
    vector<int> L(N), R(N);
    rep(i, N - 1)
    {
        L[i + 1] = gcd(L[i], A[i]);
    }
    for (int i = N - 1; i >= 1; i--)
    {
        R[i - 1] = gcd(R[i], A[i]);
    }
    int Max = 1;
    rep(i, N)
    {
        Max = max(Max, gcd(L[i], R[i]));
    }
    cout << Max << endl;
}


Measured memory_bytes: 2560
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))

def binary_search(lis, item):
    low = 0
    high = len(lis) - 1
    inRange = high

    if lis[0] > item:
        return 0

    while low <= high:
        mid = (low + high) //2
        guess1 = lis[mid]
        if mid < inRange:
            guess2 = lis[mid+1]
        else:
            if lis[mid] <= item:
                return len(lis)
            else:
                return len(lis)-1
        if guess1 <= item < guess2:
            return mid+1
        if guess1 > item:
            high = mid-1
        else:
            low = mid+1
    return 0

n,m,k = iim()
a = iil()
cuma = []
if a[0] <= k:
    cuma.append(a[0])
    for i in range(n-1):
        num = cuma[-1]+a[i+1]
        if num > k:
            break
        else:
            cuma.append(num)
#print(len(cuma))
b = iil()
cumb = []
if b[0] <= k:
    cumb.append(b[0])
    for i in range(m-1):
        num = cumb[-1]+b[i+1]
        if num > k:
            break
        else:
            cumb.append(num)
#print(len(cumb))

ans = len(cumb)
#print(ans)
if len(cuma) > 0:
    cnt = len(cuma)
    for i,item in enumerate(cuma[::-1]):
        tmp = cnt-i
        res = k-item
        plus = binary_search(cumb,res)
        ans = max(ans,tmp+plus)
print(ans)
#print(ans)

#print(cuma)
#print(cumb)


Measured memory_bytes: 48872
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <cstring>
#include <ctime>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <algorithm>
#include <functional>
#include <numeric>
#include <limits>
#include <string>
#include <map>
#include <vector>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <array>
#include <tuple>
#include <utility>
#include <cctype>
#include <typeinfo>
using namespace std;

#define len(x)  (int((x).size()))
#define append push_back
#define pp make_pair
#define ff(a, b)    for (int a = 0; a < int(b); ++a)
#define ii(n)    ff(i, n)
#define kk(n)    ff(k, n)
#define mm(n)    ff(m, n)
#define fff(a, b, c) for (int a = int(b); a < int(c); ++a)
#define iii(a, b) fff(i, a, b)
#define kkk(a, b) fff(k, a, b)
#define mmm(a, b) fff(m, a, b)
#define xx first
#define yy second
#define bb begin()
#define ee end()
#define all(x)  (x).bb, (x).ee
#define ite(v)   decltype((v).bb)
#define fe(i, v) for(ite(v) i = (v).bb; i != (v).ee; ++i)
#define err(...)    { fprintf(stderr, __VA_ARGS__); fflush(stderr); }

using LL = long long;
using pii = pair<int, int>;


//const LL INF = 9223372036854775807LL;
const int INF = 2147483647;
   


int solve(vector<string> &field) {
    int N = len(field);
    bool at_least_one = false;
    int black_rows = 0;
    int black_cols = 0;
    ii (N) {
        bool brow = true;
        kk (len(field[i])) {
            if (field[i][k] == '#')
                at_least_one = true;
            else
                brow = false;
        }
        if (brow)
            ++black_rows;
    }
    ff (x, N) {
        bool all_black = true;
        ff (y, N) {
            if (field[y][x] != '#') {
                all_black = false;
                break;
            }
        }
        if (all_black)
            ++black_cols;
    }

    if (!at_least_one) {
        return -1;
    }

    if (black_rows >= 1) {
        return N - black_cols;
    }


    int rr = INF;
    ff (target_row, N) {
        int here = 0;
        ii (N)
            if (field[target_row][i] == '.')
                ++here;
        rr = min(rr, here + N - black_cols + 1);
        ff (source_row, N) {
            if (field[source_row][target_row] == '#')
                rr = min(rr, here + N - black_cols);
        }
    }

    return rr;
}




int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //cout << '\n';
    

    int N;
    cin >> N;
    vector<string> field(N);
    ii (N)
        cin >> field[i];

    cout << solve(field) << '\n';

    return 0;
}



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

int ac,w,h,sx,sy,gx,gy,mp[100][100],vx[4]={1,0,-1,0},vy[4]={0,1,0,-1};

int check(int x,int y) {
	int i;
	mp[y][x]=-1;
	if (x==gx && y==gy) return 1;
	for (i=0;i<4;i++) {
		if (x+vx[i]>=0 && x+vx[i]<w && y+vy[i]>=0 && y+vy[i]<h) {
			if (mp[y+vy[i]][x+vx[i]]==ac) {if (check(x+vx[i],y+vy[i])==1) return 1;}
		}
	}
	return 0;
} 

int main() {
	int i,j,k,n,c,d,x,y;
	while(cin >> w >>  h) {
		if (w==0) break;
	for (i=0;i<h;i++) for (j=0;j<w;j++) mp[i][j]=0;	
	cin >> sx >> sy; 
	cin >> gx >> gy;
	sx--; sy--; gx--; gy--;
	cin >> n;
	for (k=0;k<n;k++) {
		cin >> c >> d >> x >> y;
		for (i=0;i<d*2+2;i++) for (j=0;j<4-d*2;j++) mp[y+i-1][x+j-1]=c;
		}
	ac=mp[sy][sx];
	if (mp[gy][gx]!=ac || ac==0) cout << "NG";  else { if (check(sx,sy)==1) cout << "OK"; else cout << "NG";}
	cout << endl;
	}  
	return 0;
}

Measured memory_bytes: 1196
import java.util.*;

public class Main{
  public static void main (String[] args){
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
    int C = sc.nextInt();
    if(C>=Math.min(A, B)&&C<=Math.max(A, B)){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }
  }
}

Measured memory_bytes: 35488
#include<iostream>
#include<vector>

using namespace std;

int main(){

    vector<int> v;
    int n;

    while (cin >> n)
    {
        if (n == 0){
            cout << v.back() << endl;
            v.pop_back();
        }
        else
        {
            v.push_back(n);
        }
    } 

    return 0;
}

Measured memory_bytes: 1208
def max2(x,y):
    return x if x > y else y

R, L, K = map(int, input().split())
V = [[0]*R for _ in range(L)]
for _ in range(K):
    r, c, v = map(int, input().split())
    V[c-1][r-1] = v
A, B, C, D = [[0]*(R+1) for _ in range(4)]
for i in range(L):
    for j in range(R):
        A[j] = max(A[j-1], B[j-1], C[j-1], D[j-1])
        v = V[i][j]
        if v != 0:
            D[j], C[j], B[j] = max2(C[j] + v, D[j]), max2(B[j] + v, C[j]), max2(A[j] + v, B[j])

print(max(A[-2], B[-2], C[-2], D[-2]))

Measured memory_bytes: 147028
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

n=int(input())
a=lnii()
b=lnii()

plus=[]
minus=0
ans=0
for i in range(n):
  if a[i]<b[i]:
    minus+=b[i]-a[i]
    ans+=1
  else:
    plus.append(a[i]-b[i])

if minus==0:
  print(0)
  exit()

plus.sort(reverse=True)
for i in range(len(plus)):
  minus-=plus[i]
  ans+=1
  if minus<=0:
    print(ans)
    exit()

print(-1)

Measured memory_bytes: 24304
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    int pos = 0, mn = n + 1;
    for(int i = 1; i <= n; i++){
        int x;
        cin >> x;
        if(x <= mn) pos++, mn = x;
    }
    cout << pos << endl;
}

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

int main()
{
  string s ="";
  cin >> s;
  int counter = 0;
  int Max = 0;

  for(int i = 0;i < s.size();i++){
    int counter = 0;
    for(int j = i;j < s.size();j++){
      if(s[j] == 'A' || s[j] == 'C' || s[j] == 'G' || s[j] == 'T'){
        counter ++;
      }else{
        break;
      }
    }
    Max = max(Max,counter);
  }

  cout << Max << endl;
  return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>
#include <map>
#include <list>
#include <climits>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>

// #define cerr if(false)cerr
#define watch(x) cerr << "> " << #x << ": " << x << "\n";

using namespace std;

template <typename T>
std::ostream &operator <<(std::ostream &out, vector<T> &v) {
	for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
		out << v[i] << " ";
	out << "\n";
    return out;
}
template <typename T, typename N>
std::ostream &operator <<(std::ostream &out, vector<pair<T, N> > &v) {
	for (size_t i = 0; i < v.size(); ++i)
		out << "(" << v[i].first << ", " << v[i].second << ") ";
	out << "\n";
    return out;
}
template <typename T>
std::ostream &operator <<(std::ostream &out, vector<vector<T> > &v) {
	for (size_t i = 0; i < v.size(); ++i) {
		for (size_t j = 0; j < v[i].size(); ++j) {
			out << v[i][j] << " ";
		}
		out << "\n";
	}
   	return out;
}

int main() {

	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int k;
	cin >> k;

	queue<long long> lunlun;
	for (int i = 1; i <= 9; ++i) {
		lunlun.push(i);
	}

	int c = 1;
	long long curr_lunlun = lunlun.front();
	lunlun.pop();
	while (c != k) {
		long long m = curr_lunlun % 10;
		if (m % 10 != 0) {
			lunlun.push(curr_lunlun * 10 + m - 1);
		}

		lunlun.push(curr_lunlun * 10 + m);

		if (m % 10 != 9) {
			lunlun.push(curr_lunlun * 10 + m + 1);
		}

		curr_lunlun = lunlun.front();
		lunlun.pop();
		++c;
	}

	cout << curr_lunlun << "\n";

	return 0;

}

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

int main()
{
    int h,w;
    cin >> h >> w;
    char a[h][w];
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            cin >> a[i][j];
        }
    }
    for(int i = 0; i < w + 2; i++){
        cout << '#';
    }
    cout << endl;
    for(int i = 0; i < h; i++){
        cout << '#';
        for(int j = 0; j < w; j++){
            cout << a[i][j];
        }
        cout << '#' << endl;;
    }
    for(int i = 0; i < w + 2; i++){
        cout << '#';
    }
    cout << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <string>
#include <string.h> 
#include <cstdio>
using namespace std;
#define MAX 200000
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define IN(n) scanf("%d",&n);
#define OUT(n) printf("%d",n);
#define IN2(n,k) scanf("%d%d",&n,&k);
#define OUT2(n,k) printf("%d%d",n,k);
#define IN3(n,k,s) scanf("%d%d%d",&n,&k,&s);
#define OUT3(n,k,s) printf("%d%d%d",n,k,s);
int main(){
    int n,a[100000],j,sum;
    bool b[100000]={};
    IN(n);
    REP(i,n)IN(a[i]);
    j=sum=0;
    while(1){        
        j=a[j];
        sum++;
        if(j==2){
            printf("%d",sum);
            return 0;
        }
        else if(b[--j]==1){
            printf("-1\n");
            return 0;
        }     
        b[j]=1;   
    }
    return 0;
}

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

constexpr int D = 365;
constexpr int T = 26;
int c[D];
int s[D][T];

int maxday[T];
int last[T];
int score = 0;
vector<int> ans;

void Input() {
    int tmp; cin >> tmp;
    REP(i, T) cin >> c[i];
    REP(i, D) REP(j, T) cin >> s[i][j];
    return;
}

int CalcMaxDay(int type) {
    int max_profit = s[type][0], argmax = 0;
    REP(day, D) {
        if(s[type][day] > max_profit) {
            max_profit = s[type][day];
            argmax = day;
        }
    }
    return argmax;
}

double lambda2 = 6.1; // 6.0 is better

int FindMaxProfitContest(int day) {
    double max_profit = -1e9;
    int argmax = -1;
    REP(type, T) {
        double profit = 0;
        profit += s[day - 1][type];
        // if(maxday[type] == day) profit += lambda1 * s[day - 1][type];
        profit += lambda2 * c[type] * (day - last[type]);
        if(profit > max_profit) {
            max_profit = profit;
            argmax = type;
        }
    }
    return argmax;
}

void Commit(int day, int contest) {
    ans.push_back(contest);
    last[contest] = day;
    score += s[day - 1][contest];
    REP(type, T) score -= c[type] * (day - last[type]);
    return;
}



void ReverseClimbing() {

}

void Output() {
    for(auto contest: ans) cout << contest + 1 << endl;
    return;
}

int main() {
    Input();
    REP(i, T) maxday[i] = CalcMaxDay(i);
    for(int day = 1; day <= D; day++) {
        int contest = FindMaxProfitContest(day);
        Commit(day, contest);
    }
    Output();
    // cerr << score << endl;
    return 0;
}


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

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<int, int> P;

const int MOD = 1000000007;
const int INF_32 = 1LL << 30;
const int64_t INF_64 = 1LL << 60;

// 各マスについて，そこまでの最短経路のCの足し引きの和で-80から80の値を作れるかどうか記録していく
const int D = 80 * 160 + 10;
bool dp[82][82][D * 2 + 5];
int A[82][82];
int B[82][82];
int C[82][82];
int main()
{
    int H, W;
    cin >> H >> W;
    for (int row = 0; row < H; row++) {
        for (int col = 0; col < W; col++) {
            cin >> A[row][col];
        }
    }
    for (int row = 0; row < H; row++) {
        for (int col = 0; col < W; col++) {
            cin >> B[row][col];
        }
    }

    for (int row = 0; row < H; row++) {
        for (int col = 0; col < W; col++) {
            C[row][col] = A[row][col] - B[row][col];
        }
    }

    dp[0][0][C[0][0] + D] = true;
    dp[0][0][-C[0][0] + D] = true;

    rep(row, H)
    {
        rep(col, W)
        {
            // もらうdpで書く（配るdpで書くほうが賢そうだが）
            for (int sum = -D; sum <= D; sum++) {
                int prev_sum1 = sum + C[row][col];
                int prev_sum2 = sum - C[row][col];
                if (row > 0) {
                    dp[row][col][sum + D] |= ((-D <= prev_sum1) && (prev_sum1 <= D) && dp[row - 1][col][prev_sum1 + D]);
                    dp[row][col][sum + D] |= ((-D <= prev_sum2) && (prev_sum2 <= D) && dp[row - 1][col][prev_sum2 + D]);
                }
                if (col > 0) {
                    dp[row][col][sum + D] |= ((-D <= prev_sum1) && (prev_sum1 <= D) && dp[row][col - 1][prev_sum1 + D]);
                    dp[row][col][sum + D] |= ((-D <= prev_sum2) && (prev_sum2 <= D) && dp[row][col - 1][prev_sum2 + D]);
                }
            }
        }
    }

    int ans = INF_32;
    for (int sum = -D; sum <= D; sum++) {
        if (dp[H - 1][W - 1][sum + D]) {
            ans = min(ans, abs(sum));
        }
    }

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


Measured memory_bytes: 166144
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static int INF = 1 << 30;
	static long LINF = 1L << 55;
	static int MOD = 1000000007;
	static int[] mh4 = { 0, -1, 1, 0 };
	static int[] mw4 = { -1, 0, 0, 1 };
	static int[] mh8 = { -1, -1, -1, 0, 0, 1, 1, 1 };
	static int[] mw8 = { -1, 0, 1, -1, 1, -1, 0, 1 };

	static class TaskX {

		public void solve(int testNumber, InputReader in, PrintWriter out) {

			int n = in.nextInt();
			out.println(n*(n+1)/2);

		}
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

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

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

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

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public int[] nextIntArrayDec(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt() - 1;
			}
			return res;
		}

		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public long[] nextLongArrayDec(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong() - 1;
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}
	}

}


Measured memory_bytes: 21204
N = int(input())

d = {}

for i in range(N):
  key = input()
  try:
    d[key] += 1
  except KeyError:
    d[key] = 1
    
d = sorted(d.items(), key=lambda x: x[1], reverse=True)

ans = []
max = 0
for i in d:
  if i[1] >= max:
    ans.append(i[0])
    max = i[1]
  else:
    break
    
for i in sorted(ans):
  print(i)

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

int main(){
    ll n, k;
    vector<ll> p, c;

    cin >> n >> k;
    p.assign(n+1,0);
    c.assign(n+1,0);
    for(int i=1;i<=n;i++){
        cin >> p[i];
    }
    for(int i=1;i<=n;i++){
        cin >> c[i];
    }

    vector<ll> best(n+1,0);
    for(int i=1;i<=n;i++){
        best[i] = c[p[i]];
    }
    for(int i=1;i<=n;i++){
        vector<ll> d(n+1,0), visited(n+1,0);
        ll cnt = 0, j=i;
        ll answ=0, last=i;
        while(cnt<k && visited[j]==false){
            visited[j] = ++cnt;
            d[j] = answ;
            last = j;
            j = p[j];
            answ+=c[j];
            best[i] = max(best[i],answ);
        }
        
        ll k1 = max(k-cnt,0ll), cycle = visited[last]-visited[j]+1, qtd;
        qtd = max(k1/cycle-1,0ll);
        answ += 1ll*(answ-d[j])*1ll*(qtd);
        best[i] = max(best[i],answ);
        k1 = k1%cycle + (qtd>0)*cycle;
        while(k1--){
            j = p[j];
            answ+=c[j];
            best[i] = max(best[i],answ);
        }
    }

    ll resp=best[1];
    for(int i=1;i<=n;i++){
        resp = max(resp,best[i]);
    }
    
    cout << resp <<"\n";

    return 0;
}



Measured memory_bytes: 3780
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <numeric>
#include <map>
#include <vector>
#include <string>
#include <vector>
#include <cassert>
#include <cmath>
#include <cctype>
#include <queue>
#include <algorithm>
#include <memory>
#include <memory.h>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> PP;
typedef pair<P,P> P2;
const int INF = 1 << 30;
const double EPS = 1E-9;

P p[4];
vector<P> mv;
bool used[4][4];

int calc(int p){
	while(p < 16 && used[p/4][p%4]) p++;
	if(p == 16){
		return 1;
	}
	int count = 0;
	used[p/4][p%4] = true;
	int y = p / 4;
	int x = p % 4;
	for(int i = 0; i < (int)mv.size(); i++){
		int x2 = x + mv[i].first;
		int y2 = y + mv[i].second;
		if(x2 >= 0 && x2 < 4 && y2 >= 0 && y2 < 4 && !used[y2][x2]){
			used[y2][x2] = true;
			count += calc(p+1);
			used[y2][x2] = false;
		}
	}
	used[y][x] = false;
	return count;
}

int main(){ 
	while(cin >> p[0].first && p[0].first < 5){
		cin >> p[0].second;
		mv.clear();
		for(int i = 1; i < 4; i++) cin >> p[i].first >> p[i].second;
		for(int i = 0; i < 4; i++){
			mv.push_back(p[i]);
		}
		memset(used, false, sizeof(used));
		cout << calc(0) << endl;
	}
}

Measured memory_bytes: 0
import java.util.Scanner;
class Main {
    int x,y;
    public void suzuki(){
        Scanner sc = new Scanner(System.in);

        x = sc.nextInt();
        y = sc.nextInt();

        System.out.println(x * y + " " + 2 * (x + y));
    }
    public static void main(String[] args){

        new Main().suzuki();
    }

}

Measured memory_bytes: 17160
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
c.append(0)
get=0
for i in range(n):
    get+=b[a[i]-1]
    if a[i-1]+1==a[i] and i>0:
        get+=c[a[i-1]-1]
print(get)
              

Measured memory_bytes: 9124
#define pb push_back
#define ff first
#define ss second
#define ll long long
#define maxn 10004
#define mod 1000000007
#include <bits/stdc++.h>
using namespace std;




int main() {
    int tc = 1;
    while(tc--){
        double n, m, mx, sum;
        cin >> n >> m;
        mx = sum = 0.0;
        vector<double> v;
        for(int i=1;i<=n;i++){
            double x;
            cin >> x;
            sum += x;
            v.pb(x);
        }
        sort(v.rbegin(), v.rend());
        bool res =  true;
        double vote = sum/(4.0*m);
        for(int i=0;i<m;i++){
            if(v[i] < vote) res = false;
        }

        if(res) cout << "Yes" << endl;
        else cout << "No" << endl;

    }
    return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.par = [-1 for _ in range(n)]

    def same(self, x, y):
        return self.root(x)==self.root(y)

    def root(self, x):
        if self.par[x]<0:
            return x
        self.par[x] = self.root(self.par[x])
        return self.par[x]

    def unite(self,x,y):
        x = self.root(x)
        y = self.root(y)
        if x==y:
            return

        if self.par[x]>self.par[y]:
            x,y = y,x

        self.par[x] += self.par[y]
        self.par[y] = x

    def size(self,x):
        return -self.par[self.root(x)]

n,k,l = map(int, input().split())
road = UnionFind(n)
for _ in range(k):
    p,q = map(int, input().split())
    road.unite(p-1, q-1)

rail = UnionFind(n)
for _ in range(l):
    r,s = map(int, input().split())
    rail.unite(r-1, s-1)

d = {}
for i in range(n):
    x = (road.root(i), rail.root(i))
    if x not in d:
        d[x] = 0
    d[x] +=1

res = [d[(road.root(i), rail.root(i))] for i in range(n)]
print(*res)


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

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

c1 = 0
c2 = 0
c3 = 0

for i in range(n):
    if p[i] <= a:
        c1 += 1
    elif (a+1 <= p[i]) and (p[i] <= b):
        c2 += 1
    else:
        c3 += 1

print(min(c1, c2, c3))


Measured memory_bytes: 3064
from collections import Counter
N = int(input())
A = list(map(int, input().split()))

c = Counter(A)
ans = sum(v * (v - 1) // 2 for v in c.values())

for a in A:
    v = c[a]
    add = (v - 1) * (v - 2) // 2
    sub = v * (v - 1) // 2
    print(ans-sub+add)

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

int main(int argc, const char * argv[]) {
    // insert code here...
    int a;
    cin >> a;
  double l;
  l= 2*M_PI*a;
    cout<< l <<endl;
    
}



Measured memory_bytes: 3788
MODC = 1000000007

n,k = gets.strip.split.map(&:to_i)
a = gets.strip.split.map(&:to_i)
if k != n
  a.sort_by!{|e|e.abs}.reverse!
  zero = false
  mns = 0
  k.times do |i|
    case a[i] <=> 0
    when -1
      mns += 1
    when 0
      zero = true
      break
    end
  end
  if zero
    p 0
    exit
  end
  if mns % 2 != 0
    cntn = true
    k1 = k-1
    k2 = false
    (k-2).downto(0) do |i|
      if a[k1] * a[i] < 0
        k2 = i
        break
      end
    end
    k1a = false
    k.upto(n-1) do |i|
      if a[k1] * a[i] < 0
        k1a = i
        break
      elsif a[i] == 0
        zero = true
        break
      end
    end
    if !k1a && !k2
      if zero
        p 0
        exit
      else
        ans = 1
        k.times do |i|
          ans *= a[n-1-i]
          ans %= MODC
        end
        p ans
        exit
      end
    elsif !k1a
      a[k], a[k2] = a[k2], a[k]
    elsif !k2 || k1a == k
      a[k1], a[k1a] = a[k1a], a[k1]
    elsif (a[k] * a[k1]).abs < (a[k2] * a[k1a]).abs
      a[k1], a[k1a] = a[k1a], a[k1]
    else
      a[k], a[k2] = a[k2], a[k]
    end
  end
end
ans = 1
k.times do |i|
  ans *= a[i]
  ans %= MODC
end
p ans


Measured memory_bytes: 36172
#include<iostream>
using namespace std;
int main(){
  int N;
  cin >> N;
  int i;
  char a;
  
  for(i=0;i<N;i++){
    cin>>a;
    if (a=='Y'){
      cout<<"Four";
      return 0;
    }
  }
  cout<<"Three";
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
double dist(double x, double y){
  return sqrt(x * x + y * y);
}

int main(){
  int N;
  int CASE = 1;
  while(cin>>N && N){
    printf("Case %d: ", CASE++);
    double x[14][2], y[14][2];
    double d[14];
    REP(i, N){
      REP(j, 2) cin>>x[i][j]>>y[i][j];
      d[i] = dist(x[i][0] - x[i][1] , y[i][0] - y[i][1]);
    }
    double dp[1<<14][14][2];
    REP(i, 1<<14)REP(j, 14)REP(k, 2) dp[i][j][k] = INF;
    REP(i, N)REP(k, 2) dp[1<<i][i][k] = d[i];
    REP(S, 1<<N){
      REP(from, 2 * N){
        int f_i = from / 2;
        int f_j = from % 2;
        if(dp[S][f_i][f_j] >= INF) continue;
        REP(to, 2 * N){
          int t_i = to / 2;
          int t_j = to % 2;
          if(S & (1<<t_i)) continue;
          dp[S | (1<<t_i)][t_i][t_j] = min(dp[S | (1<<t_i)][t_i][t_j],
              dp[S][f_i][f_j] + dist(x[f_i][f_j] - x[t_i][(t_j + 1) % 2], y[f_i][f_j] - y[t_i][(t_j + 1) % 2]) + d[t_i]);
        }
      }
    }
    double ans = 1e16;
    REP(i, N)REP(j, 2) ans = min(ans, dp[(1<<N) - 1][i][j]);
    
    printf("%.5f\n", ans);
  }
  return 0;
}

Measured memory_bytes: 4832
#include <bits/stdc++.h>
using namespace std;
int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  if ((A+B) > (C+D)){
    cout << "Left" <<endl;
  }
  else if ((A+B) == (C+D)){
    cout << "Balanced" << endl;
  }
  else if ((A+B) < (C+D)){
    cout << "Right" << endl;
  }
}


Measured memory_bytes: 256
import Data.List
import Data.Char
import Data.Maybe
import Control.Monad
import qualified Data.ByteString.Char8 as BS8
import Data.Map.Strict ((!))
import qualified Data.Map.Strict as MapS

main=do
    [s, t] <- words<$>getLine
    [a, b] <- unfoldr (BS8.readInt . BS8.dropWhile isSpace) <$> BS8.getLine
    u <- getLine
    
    let m = MapS.fromList [(s, a), (t, b)]
        ans = MapS.insert u ((m ! u) - 1) m
    
    putStrLn $ unwords $ map show [ans ! s, ans ! t]


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

int main() {
  int N;
  cin >> N;
  vector<int> a(N),b(N),c(N);
  for(int i=0;i<N;i++){
    cin >> a[i] >> b[i] >> c[i];
  }
  vector<vector<int>> dp(N,vector<int>(3));
  dp[0][0]=a[0];
  dp[0][1]=b[0];
  dp[0][2]=c[0];
  
  for(int i=1;i<N;i++){
    dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a[i];
    dp[i][1]=max(dp[i-1][0],dp[i-1][2])+b[i];
    dp[i][2]=max(dp[i-1][0],dp[i-1][1])+c[i];
  }
  
  cout << max(max(dp[N-1][0],dp[N-1][1]),dp[N-1][2]) << endl;
                              
}


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

int main(){
  int N;
  string answer = "No";
  cin >> N;
  vector<int> a(2*N);
  for(int i=0;i<2*N;i++){
    cin >> a.at(i);
  }
  for (int i = 0; i < 2*N-5; i += 2) {
    if(a.at(i)==a.at(i+1)&&a.at(i+2)==a.at(i+3)&&a.at(i+4)==a.at(i+5)){
      answer = "Yes";
      break;
    }
  }
  cout << answer << endl;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using pii=pair<ll,ll>;
#define For(i,a,b) for(ll i=a;i<=b;i++)
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define sz(x) ((ll)x.size())
#define MOD (ll)(1e9+7)
#define INF (9e18)
#define EPS (1e-6)
#ifdef LOCAL_TEST
#define debug(...) do{\
	cerr<<__PRETTY_FUNCTION__<<" - "<<__LINE__<<\
	" : ("#__VA_ARGS__<<") = ";\
	_OUT(__VA_ARGS__);\
}while(0)
template<typename T>void _OUT(T x){cerr<<x<<endl;}
template<typename T,typename...I>void _OUT(T x,I ...tail){cerr<<x<<", ";_OUT(tail...);}
#else
#define debug(...)
#endif

void INIT(){
#ifdef LOCAL_TEST
	freopen("D:\\input.in","r",stdin);
	freopen("D:\\output.out","w",stdout);
	freopen("D:\\error.out","w",stderr);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0);
}

int gcd(int a,int b) { return b==0?a:gcd(b,a%b); }
int lcm(int a,int b) { return a/gcd(a,b)*b; }
int fpow(int b,int p){
	b%=MOD;
	int ans=1;
	while(p>0){
		if(p&1) ans=(ans*b)%MOD;
		p/=2;
		b=(b*b)%MOD;
	}
	return ans;
}

int32_t main() {
	INIT();
	//code...
	int n,m; cin>>n>>m;
	vector<string> a(n),b(m);
	for(auto &i:a) cin>>i;
	for(auto &i:b) cin>>i;
	For(x,0,n-m) For(y,0,n-m){
		bool ac=true;
		For(i,x,x+m-1) For(j,y,y+m-1){
			if(a[i][j]!=b[i-x][j-y]){
				ac=false;
				goto END;
			}
		}
	END:
		if(ac){
			cout<<"Yes\n";
			return 0;
		}
	}
	cout<<"No\n";
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdlib.h>
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)

using namespace std;

int main()
{
    int N, x, y, h;
    int ans[101][101];
    int hmax[101][101];

    cin >> N;
    REP(l, 101) REP(w, 101)
    {
        ans[l][w] = -1;
    }
    REP(l, 101) REP(w, 101)
    {
        hmax[l][w] = 1000000300;
    }

    REP(i, N)
    {
        cin >> x >> y >> h;

        REP(l, 101) REP(w, 101) if (ans[l][w] != -2)
        {
            int estimated_top = h + abs(l - x) + abs(w - y);
            if (h > 0)
            {
                if (ans[l][w] == -1) ans[l][w] = estimated_top;
                else if (ans[l][w] != estimated_top) ans[l][w] = -2;
            }
            else
            {
                if (estimated_top < hmax[l][w]) hmax[l][w] = estimated_top;
            }
        }
    }

    REP(l, 101) REP(w, 101) if (ans[l][w] > 0 && hmax[l][w] >= ans[l][w]) cout << l << " " << w << " " << ans[l][w] << endl;
}


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

int main() {
  int a,b,c,d; cin >> a >> b >> c >> d;
  while(a>0 && c>0){
    c-=b;
    a-=d;
  }
  if(a<=0 && c<=0){
    cout << "Yes" << endl;
  }
  else if(a>0 && c<=0){
    cout << "Yes" <<endl;
  }
  else if(a<=0 && c>0){
    cout << "No" << endl;
  }
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
#define rrep(i,n) for(int (i) = (n) - 1; (i) >= 0; --(i)) //Reversi rep
#define nfor(i,a,b) for(int (i) = (a); (i) < (b); ++(i)) //Natural for
#define rfor(i,a,b) for(int (i) = (b) - 1; (i) >= (a); --(i)) //Reversi for
#define ll long long
#define mod (1000000007)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define yes cout << "yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;
#define no cout << "no" << endl;

int asc(const void *a, const void *b) {
    return *(int *)a - *(int *)b;
}

int desc(const void *a, const void *b) {
    return *(int *)b - *(int *)a;
}

int main()
{
    int n,ans = 0;
    cin >> n;
    if (n == 100000 || n == 10000 || n == 1000 || n == 100 || n == 10) {
        cout << 10 << endl;
    }else{
        for (; n > 0; ) {
            ans += n % 10;
            n = n / 10;
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        int a, b, count;
        count = 0;
        Scanner sc = new Scanner(System.in);
        a = sc.nextInt();
        b = sc.nextInt();
        for (int i = 1; i <= a; i++) {
            for (int j = 1; j <= 31; j++) {
                if (a == b) { 
                    if (i == j) {
                        count++;
                    }
                } else if (a > b) { 
                    if (i < a) {
                        if (i == j) count++;
                    } 
                } else { 
                    if (i == j) count++;
                }
            }
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 21844
module Main where

import Data.Functor

type Dice = (Int,Int,Int,Int,Int,Int)

top :: Dice -> Int
top (t,_,_,_,_,_) = t

type Roll = Char

roll :: Dice -> Roll -> Dice
roll (t,s,e,w,n,b) 'E'
   = (w,s,t,b,n,e)
roll (t,s,e,w,n,b) 'N'
   = (s,b,e,w,t,n)
roll (t,s,e,w,n,b) 'W'
   = (e,s,b,t,n,w)
roll (t,s,e,w,n,b) 'S'
   = (n,t,e,w,b,s)

getInts :: IO [Int]
getInts = map read . words <$> getLine

main :: IO ()
main = do
  { [t,s,e,w,n,b] <- getInts
  ; rolls         <- getLine
  ; print $ top $ foldl roll (t,s,e,w,n,b) rolls
  }

Measured memory_bytes: 3588
#include <iostream>
#include <string>
#include <cctype>

using namespace std;

typedef string::const_iterator State;

/*
  <num> ::= '1'|'2'|...|'0'
  <term> ::= <num or kakko> ('*' or '/' ) <num or kakko>
  <exp> ::= <term> ('+' or '-' ) <term>
  <kakko> ::= '(' <exp> ')'
  <factor> ::= <num> or <kakko>
*/

int number(State&);
int kakko(State&);
int factor(State&);
int term(State&);
int expression(State&);

int main(){
  string input;
  int n,ret;
  cin >> n;
  cin.ignore();
  for(int i = 0;i < n;i++){
    getline(cin, input);
    State begin = input.begin();
    ret = expression(begin);
    cout << ret << endl;
  }
  return 0;
}


int number(State &begin){
  int ret = 0;
  while(isdigit(*begin)){
    ret *= 10;
    ret += *begin - '0';
    ++begin;
  }
  return ret;
}

int factor(State &begin){
  int ret = 0;
  if(*begin == '('){
    begin++;
    ret += expression(begin);
    begin++;
  }else{
    return number(begin);
  }
  return ret;
}

int term(State &begin){
  int ret = factor(begin);
  while(true){
    if(*begin == '*'){
      ++begin;
      ret *= factor(begin);
    }else if(*begin == '/'){
      ++begin;
      ret /= factor(begin);
    }else{
      break;
    }
  }
  return ret;
}

int expression(State &begin){
  int ret = term(begin);
  while(true){
    if(*begin == '+'){
      ++begin;
      ret += term(begin);
    }else if(*begin == '-'){
      ++begin;
      ret -= term(begin);
    }else{
      break;
    }
  }
  return ret;
}

Measured memory_bytes: 0