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

#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl
#define rep(i, n) for (int i = (int)(0); i < (int)(n); i++)
#define repp(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define all(v) v.begin(), v.end()
#define dump(v)                  \
    cerr << #v ":[ ";            \
    for (auto macro_vi : v) {    \
        cerr << macro_vi << " "; \
    }                            \
    cerr << "]" << endl;
#define ddump(v)                           \
    cerr << #v ":" << endl;                \
    for (auto macro_row : v) {             \
        cerr << "[";                       \
        for (auto macro__vi : macro_row) { \
            cerr << macro__vi << " ";      \
        }                                  \
        cerr << "]" << endl;               \
    }
using lint       = long long;
const int INF    = 1e9;
const lint LINF  = 1e18;
const lint MOD   = 1e9 + 7;
const double EPS = 1e-10;

int main() {
    int N;
    cin >> N;
    vector<vector<pair<int, int>>> Shogen(N, vector<pair<int, int>>(0));
    rep(i, N) {
        int Ai;
        cin >> Ai;
        rep(j, Ai) {
            int x, y;
            cin >> x >> y;
            x--;
            Shogen[i].push_back(make_pair(x, y));
        }
    }

    int ans = 0;
    for (int bit = 0; bit < (1 << N); bit++) {
        bool isConsistent = true;
        vector<int> HonestOrUnhonest(N, -1); // 1:Honest 0:Unhonest
        rep(i, N) { HonestOrUnhonest[i] = (bit & (1 << i) ? 1 : 0); }
        // dump(HonestOrUnhonest);
        rep(i, N) {
            int AisHonest =
                HonestOrUnhonest[i]; // A:i番目の人がHonestかUnhonestかを確認
            // d(i);
            for (auto state : Shogen[i]) {
                // d("state");
                int human, isHonest; // 1:Honest 0:Unhonest
                tie(human, isHonest) = state;
                // dd(human, isHonest);
                if (AisHonest == 1) {
                    if (not(HonestOrUnhonest[human] == isHonest)) {
                        isConsistent = false;
                    }
                }
            }
        }

        if (isConsistent) {
            int cnt = 0;
            for (int i = 0; i < N; i++) {
                if (HonestOrUnhonest[i] == 1) cnt++;
            }
            ans = max(ans, cnt);
            // dd(bit, cnt);

        } else {
            continue;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
using namespace std;
int a[105];
int main()
{
	int n,d,x;
	cin>>n>>d>>x;
	for(int i=1;i<=n;i++)
	  cin>>a[i];
	for(int i=1;i<=n;i++)
	  {
	  	int m=1,t=0;
	  	do
	  	{
	  		x++;
	  		t=(a[i]*m+1);
	  		m++;
	  	}while(t<=d);
	  }
	  cout<<x<<endl;
	  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 50;
 
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;
}
using namespace std;

void solve(){
    int n;
    string s;
    cin>>n>>s;
    rep(i,s.size()){
        s[i]+=n;
        if(s[i]>'Z')s[i]-=26;
    }
    cout<<s;
}
 
signed main(){
	ios::sync_with_stdio(false);
    cin.tie(0);
	cout<<fixed<<setprecision(15);
	solve();
	return 0;
}


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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()

struct dat {
  string name;
  int pnt, id;
  dat() {}
  dat(string name, int pnt, int id):
    name(name), pnt(pnt), id(id) {}
};

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int n;
  cin >> n;
  int id = 0;
  vector<dat> v(n);
  for (auto &i : v) {
    string name;
    int pnt = 0;
    cin >> name >> pnt;
    i = dat(name, pnt, ++id);
  }
  sort(all(v), [](dat &a, dat &b) -> bool {
    if (a.name == b.name) return a.pnt > b.pnt;
    return a.name < b.name;
  });
  for (auto &i : v) cout << i.id << '\n';
}


Measured memory_bytes: 3624
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#define mm(a,x) memset(a,x,sizeof(a))
#define sync std::ios::sync_with_stdio(false);std::cin.tie(0)
#define ll long long
using namespace std;
char map[110][110];
int dp[110][110];
int main(void)
{
    sync;
    int h,w;
    cin>>h>>w;
    for(int i=1;i<=h;++i)
        for(int j=1;j<=w;++j)
            cin>>map[i][j];
    for(int i=1;i<=h;++i)
        dp[i][1]=dp[i-1][1]+(map[i-1][1]!='#'&&map[i][1]=='#');
    for(int i=1;i<=w;++i)
        dp[1][i]=dp[1][i-1]+(map[1][i-1]!='#'&&map[1][i]=='#');
    for(int i=2;i<=h;++i)
        for(int j=2;j<=w;++j)
            dp[i][j]=min(dp[i-1][j]+(map[i-1][j]!='#'&&map[i][j]=='#'),dp[i][j-1]+(map[i][j-1]!='#'&&map[i][j]=='#'));
    cout<<dp[h][w]<<endl;
    return 0;
}

Measured memory_bytes: 384
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

h1, m1, h2, m2, k = MAP()
print(h2 * 60 + m2 - h1 * 60 - m1 - k)

Measured memory_bytes: 10608
a, b, c = map(int, input().split())
list = []
list1 = []
for i in range(a):
  d = a % (i+1)
  if d == 0:
    list.append(i+1)
  else:
    pass
for k in range(len(list)):
  e = b % list[k]
  if e == 0:
    list1.append(list[k])
  else:
    pass
print(list1[-c])

Measured memory_bytes: 3060
/*
ACplease
　　 ●
　　/⌒ヽ
　 ｜ 　|/⌒ヽ(ヽ
　 (｀　∥ー⌒) |
　|￣||￣￣￣￣￣|
　|―||―――――|
　|　Ｕ　　　　　|
　|￣￣￣￣￣￣￣|
　|＿＿＿＿＿＿＿|
　　|―――――|
　　|―――――|
ｗｗＷｗｗＷｗＷＷｗ
*/
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>
#include <cassert>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repe(i, n) for (int i = 0; i <= (int)(n); i++)
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define ANS cout << ans << endl
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define REVERSE(a) reverse(all(a))
#define KOZYUN(a) sort(all(a),greater<int>())
#define int ll
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORe(i, m, n) for(int i = m;i <= n;i++)
#define VIin(a) for(int i=0; i<a.size(); i++) cin >> a[i]
#define OUT(a) cout << a << endl
#define IN(a) cin >> a
#define INT(a) int a; cin >> a
typedef vector<int> VI;
typedef vector<VI> VVI;
const int MOD=1e9+7;
const long long INF = 1LL << 60;
/*最大公約数*/int gcd(int x, int y) { return y ? gcd(y,x%y) : x;}
/*最小公倍数*/int lcm(int a, int b) { int g = gcd(a, b); return a / g * b; }
/*素数判定*/int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*約数列挙*/vector<int> getDivisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}

//----------------------------------------------
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(15);
    srand((unsigned)time(NULL));
    
    string s; cin >> s;
    rep(i,s.size()) cout <<  "x"; 

    return 0;
}

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

int main()
{
  	char a, b;
  	cin>>a>>b;
  	bool c, d;
  	c = (a == 'H')?true:false;
  	d = (b == 'H')?true:false;
  	if((c^d) == false)
  	    cout<<'H';
  	else
  	    cout<<'D';
	return 0;
}

Measured memory_bytes: 256
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }

long mod = 10^^9 + 7;
//long mod = 998_244_353;
//long mod = 1_000_003;
void moda(T)(ref T x, T y) { x = (x + y) % mod; }
void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(T)(ref T x, T y) { x = (x * y) % mod; }
void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }

void main()
{
	auto D = RD;
	auto c = RDA;
	auto s = new long[][](D);
	foreach (i; 0..D)
		s[i] = RDA;

	auto index = c.MAKE_IDX!("a > b");
	foreach (i; 0..D)
		writeln(index[i%26]+1);

	/*foreach (i; 0..D)
	{
		writeln(s[i].MIN_POS!"a > b" + 1);
	}*/

	stdout.flush;
	debug readln;
}


Measured memory_bytes: 3260
if __name__ == '__main__':


    while True:


        n = int(raw_input())

        if n == 0:
            break

        for num in range(n):

            a,b,c = map(int, raw_input().split(' '))

            if a == 100 or b == 100 or c == 100:

                print 'A'

            elif (a+b)/2 >= 90:
                print 'A'

            elif (a+b+c)/3 >= 80:

                print 'A'

            elif (a+b+c)/3 >= 70:
                print 'B'

            elif (a+b+c)/3 >= 50:

                if a >= 80 or b >= 80:
                    print 'B'
                
                else:
                    print 'C'

            else:
                print 'C'

Measured memory_bytes: 4220
#include <stdio.h>

int n,k;
struct eee{
    int to,next;
}edge[4010];
int box[2010];
int flag[2010];
int ee1[2010],ee2[2010];
int fin(int now ,int dis ,int maxdis)
{
    flag[now]=1;
    if (maxdis==dis){
        return 0;
    }
    for (int temp=box[now];temp>0;temp=edge[temp].next)
        if(flag[ edge[temp].to ]==0) fin(edge[temp].to,dis+1,maxdis);
}

int main1()
{
    int ans=n;
    for (int i=1;i<=n;i++)
    {
        for (int j=1;j<=n;j++) flag[j]=0;
        flag[i]=1;
        fin(i,0,k/2);
        int temp=0;
        for (int j=1;j<=n;j++) temp+=flag[j];
        if (n-temp<ans) ans=n-temp;
    }
    printf("%d\n",ans);
}
int main2()
{
    int ans=n;
    for (int i=1;i<n;i++)
    {
        for (int j=1;j<=n;j++) flag[j]=0;
        flag[ee1[i]]=flag[ee2[i]]=1;
        fin(ee1[i],0,(k-1)/2 );fin(ee2[i],0,(k-1)/2);
        int temp=0;
        for (int j=1;j<=n;j++) temp+=flag[j];
        if (n-temp<ans) ans=n-temp;
    }
    printf("%d\n",ans);
}

int main()
{
    scanf("%d%d",&n,&k);
    for (int i=1;i<=n;i++) box[i]=-1;
    for (int i=1;i<n;i++)
    {
        int a,b;scanf("%d%d",&a,&b);
        ee1[i]=a;ee2[i]=b;
        edge[i*2-1].to=b;edge[i*2-1].next=box[a];box[a]=i*2-1;
        edge[i*2].to=a;edge[i*2].next=box[b];box[b]=i*2;
    }

    if (k%2==0) main1();else main2();
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
int main()
{
    int a[105],n,i,sum=0,ans=0;
    scanf("%d",&n);
    for(i=0;i<n;i++)
        scanf("%d",&a[i]);
    for(i=1;i<n;i++)
    {
        if(a[i]==a[i-1]) sum++;
        else {ans+=(sum+1)/2;sum=0;}
    }ans+=(sum+1)/2;
    printf("%d",ans);
    return 0;
}


Measured memory_bytes: 128
import sys
from collections import deque
sys.setrecursionlimit(1000000)
input = sys.stdin.readline
mod = 10**9+7
def dfs():
    stack = deque([[-1,0]])
    visited = set()
    case_num=1
    while stack:
        fr,n = stack.pop()
        if(n in visited):continue
        visited.add(n)
        color = 0
        if(fr==-1):
            color = K-1
        else:
            color = K-2
        if(K<len(edges[n])):
            return 0
        else:
            for e in edges[n]:
                if(e==fr):continue
                case_num*=color
                color-=1
                stack.append([n,e])
                case_num%=mod
    return case_num%mod

if(__name__=='__main__'):
    N,K = [int(x) for x in input().split()]
    edges = [[] for _ in range(N)]
    for _ in range(N-1):
        s,d = [int(x) for x in input().split()]
        edges[s-1].append(d-1)
        edges[d-1].append(s-1)
    ans = K*dfs()
    print(ans%mod)

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

int main(){
    int H,W;
    cin >> H >> W;
 
    int a,b,c; //a:|||,≡; b:|=; c:Π;
    if(H%3==0 || W%3==0) a=0;
    else a=min(H,W);
 
    int wl=W/3;
    b=min((H-H/2)*(W-wl)-wl*H,(wl+1)*H-H/2*(W-wl-1));
 
    int hl=H/3;
    c=min((W-W/2)*(H-hl)-hl*W,(hl+1)*W-W/2*(H-hl-1));
 
    cout << min(a,min(b,c)) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <climits>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
using namespace std;
// scanf
#pragma warning(disable: 4996)
// v:vector  type:型  order:greater or less
#define _sort(v,type,order) do { sort(v.begin(),v.end(),order<type>()); } while(0)
// v:vector  default_value:初期値
#define _sum(v,default_value) accumulate(v.begin(),v.end(),default_value )
// 丸め
#define _round(v) round(v)
// 2乗 / 3乗
#define _square(v) pow(v,2)
#define _cube(v)   pow(v,3)
// 大小判定
#define _max(x,y) max(x,y)
#define _min(x,y) min(x,y)

int main()
{
	uint32_t n;
	cin >> n;
	vector<int32_t> v((uint32_t)1e5,0);

	int32_t temp;
	uint32_t result = 0;
	for (uint32_t i = 0; i < n; i++) {
		cin >> temp;
		if (temp > (uint32_t)1e5) {
			result++;
			continue;
		}
		v[temp]++;
	}
	for (int32_t i = 1; i <= (uint32_t)1e5; i++) {
		if (!v[i]) { continue; }
		if (i == v[i]) { continue; }
		result += i > v[i] ? v[i] : v[i] - i;
	}

	cout << result;

	return 0;
	//	std::cout << "Hello World!\n"; 
}


Measured memory_bytes: 640
import scala.io.StdIn.readLine

object Main {
  val gesIndex = Map("Rock"->0,"Fire"-> 1, "Scissors" -> 2, "Snake" -> 3,
                    "Human"->4, "Tree"->5, "Wolf"->6, "Sponge"->7,
                    "Paper"->8, "Air"->9, "Water"->10, "Dragon"->11,
                    "Devil"->12, "Lightning"->13, "Gun" -> 14)

  def scan(list:Array[Int],i:Int,n:Int):String = {
    if(i==n) "Draw"
    else {
      val win = (list((i+1)%n)-list(i)+15)%15
      val lose = (list(i)-list((i+n-1)%n)+15)%15
      if(win<=7 && lose>7) gesIndex.find(_._2==list(i)).map(_._1).get
      else scan(list,i+1,n)
    }
  }

  def main(args:Array[String]) = {
    var n = 0
    while({n=readLine.trim.toInt;n}!=0) {
      val list = {for(i<-1 to n) yield gesIndex(readLine.trim)}.toArray.sorted
      println(scan(list,0,list.length))
    }
  }
}

Measured memory_bytes: 56020
n,k = gets.split.map(&:to_i)
ary = Array.new(k){0}
ans = 0

(1..n).each{|i| ary[i%k]+=1}
(0...k).each do |a|
  b = (k-a)%k
  c = (k-a)%k
  next if (b+c)%k != 0
  ans += ary[a] * ary[b] * ary[c]
end

puts(ans)

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

typedef long long ll;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1e9 + 7;

void print(){ std::cout << std::endl; }
template <typename Head> void print(Head&& head) { std::cout << head << std::endl; }
template <typename Head, typename... Tail> void print(Head&& head, Tail&&... tail)
{
  std::cout << head << " ";
  print(std::forward<Tail>(tail)...); // or print(tail...);
}

int main(int argc, char* argv[])
{
  std::string s;
  std::cin >> s;

  ll size = (ll)s.size();
  ll ans = size;
  for (ll i = 1; i < size; i++) {
    if (s[i-1] != s[i]) {
      ans = std::min(ans, std::max(size - i, i));
    }
  }

  print(ans);
  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define endl "\n"

int main()
{
  i64 N;
  string c;
  cin >> N >> c;
  i64 cnt = 0;
  for (i64 i = 0; i < N; i++)
    if (c[i] == 'R')
      cnt++;
  i64 ans = cnt;
  for (i64 i = 0; i < cnt; i++)
    if (c[i] == 'R')
      ans--;
  cout << ans << endl;
  return 0;
}


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

int main(){
  string cards,mae,usiro;
  int num; 
  int times;
  
  while (1) {
    cin >> cards;
    if (cards == "-") break;
    cin >> times;
    while (times) {
      times--;
      cin >> num;
      mae = cards.substr(0,num); //[0]からnum個を返す
      //cout << mae << endl;
      usiro = cards.substr(num,cards.size());
      //cout << usiro << endl;
      cards.replace(0,cards.size()-num,usiro);
      cards.replace(cards.size()-num,cards.size(),mae);
      
    }
    cout << cards << endl;
  }
  return 0;
}


Measured memory_bytes: 3216
#include <iostream>
#include <vector>
#include <algorithm>


int main()
{
    int n,q;
    std::cin>>n;
    std::vector<long long> a;

    for(int i = 0; i < n; i++)
    {
        int hoge;
        std::cin>>hoge;
        a.push_back(hoge);
    }

    std::cin>>q;

    for(int i = 0; i < q; i++)
    {
        int k;
        std::cin>>k;
        std::cout <<std::lower_bound(a.begin(), a.end(),k)-a.begin()<< std::endl;
    }
    return 0;
}



Measured memory_bytes: 3916
#include<bits/stdc++.h>
#define Fail puts("NO"),exit(0);
#define eps 1e-10
#define maxn 505
#define maxm 100010
#define inf 1000000007
#define mod 1000000007
#define pi acos(-1)
#define mp(x,y) make_pair(x,y)
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int>pii;
typedef bitset<maxn> bit;
int read()
{
    int x=0,f=1;
    char ch=getchar();
    while(ch-'0'<0||ch-'0'>9){if(ch=='-') f=-1;ch=getchar();}
    while(ch-'0'>=0&&ch-'0'<=9){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int n;
int a[maxn][maxn];
ll f[maxn][maxn],g[maxn][maxn];
ll dp[maxn][maxn];
ll calc(int i,int j,int k)
{
    return f[k][j]-f[k][i-1];
}
int main()
{
    n=read();
    for(int i=1;i<=n;i++)
      for(int j=1;j<=n;j++)
        if(i!=j)  a[i][j]=read();
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
        {
            f[i][j]=f[i][j-1];
            for(int k=i;k<=n;k++)  f[i][j]+=a[k][j];
        }
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=i;j<=n+1;j++)
        {
            g[i][j]=g[i][j-1];
            for(int k=i;k<=j;k++)  g[i][j]+=a[k][j];
        }
    }
    memset(dp,0x3f,sizeof(f));
    dp[0][0]=0;
    for(int i=0;i<=n;i++)
    {
        for(int j=i;j<=n;j++)
        {
            if(dp[i][j]<1e18)
            {
                for(int k=j+1;k<=n+1;k++)
                {
                    dp[j][k]=min(dp[j][k],dp[i][j]+g[j+1][k]+calc(i+1,j,k+1));
                }
            }
        }
    }
    ll ans=1e18;
    for(int i=0;i<=n;i++)  ans=min(ans,dp[i][n+1]);
    cout<<ans<<endl;
    return 0;
}

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

using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<double> p(n);
    for (int i = 0; i < n; i++){
        cin >> p[i];
    }
    vector<double> dp(n + 1);
    dp[0] = 1;
    for (int i = 0; i < n; i++){
       for (int j = i + 1; j >= 0; j--){
            dp[j] = (j >= 1 ? dp[j - 1] * p[i] : 0) + dp[j] * (1 - p[i]);
       }
    }
    double ans = 0.0;
    for (int i = (n + 1) / 2; i <= n; i++){
        ans += dp[i];
    }
    cout << setprecision(10) << fixed << ans;
    return 0;
}


Measured memory_bytes: 384
from collections import defaultdict
from heapq import heappop, heappush
from itertools import combinations

class Graph:
    def __init__(self, n, edges, weight=False):
        self.n = n
        self.adj = [[] for _ in range(n)]
        self.degree = [0] * n
        self.weight = defaultdict(lambda: 10**18)
        if weight:
            for u, v, weight in edges:
                self.adj[u].append(v)
                self.adj[v].append(u)
                self.degree[v] += 1
                self.weight[(u, v)] = weight
                self.weight[(v, u)] = weight
        else:
            for u, v in edges:
                self.adj[u].append(v)
                self.adj[v].append(u)
                self.degree[v] += 1
                self.weight[(u, v)] = 1
                self.weight[(v, u)] = 1

    def dijkstra(self, start, goal=None):  # O((n+m)log(n))
        INF = 10**18
        dist = [INF] * self.n
        dist[start] = 0
        heap = [(0, start)]  # (dist, v)
        sp_prev = [None] * self.n  # previous node in shortest path (sp)
        while heap:
            dist_v, v = heappop(heap)
            if dist[v] < dist_v:
                continue
            for adj in self.adj[v]:
                edge_weight = self.weight[(v, adj)]
                if dist[v] + edge_weight < dist[adj]:
                    dist[adj] = dist[v] + edge_weight
                    sp_prev[adj] = v
                    heappush(heap, (dist[adj], adj))

        if goal is not None:
            if dist[goal] == INF:
                return dist, []
            else:
                path = [goal]
                v = goal
                while v != start:
                    v = sp_prev[v]
                    path.append(v)
                path.reverse()
                return dist, path
        else:
            return dist, sp_prev

    def warshall_floyd(self):  # O(n^3)
        # dist[u][v]: uからvへの最短距離
        INF = 10**18
        dist = [[INF] * self.n for _ in range(self.n)]
        for u in range(self.n):
            dist[u][u] = 0
            for v in self.adj[u]:
                dist[u][v] = self.weight[(u, v)]
        for k in range(self.n):
            for u in range(self.n):
                for v in range(self.n):
                    dist[u][v] = min(dist[u][v], dist[u][k] + dist[k][v])
        return dist

# ---------------------- #

n = int(input())
A = [tuple(int(x) for x in input().split()) for _ in range(n)]
dist = []
for i in range(n):
    for j in range(n):
        if i < j:
            dist.append((i, j, A[i][j]))

G = Graph(n, dist, weight=True)
wf = G.warshall_floyd()

for i in range(n):
    for j in range(n):
        if A[i][j] != wf[i][j]:
            print(-1)
            exit()

ans = 0
for i, j in combinations(range(n), 2):
    for k in range(n):
        if i == k or j == k:
            continue
        if A[i][j] == A[i][k] + A[k][j]:
            break
    else:
        ans += A[i][j]

print(ans)


Measured memory_bytes: 104228
import numpy as np
a = []
a.append([int(x) for x in input().split()])
a.append([int(x) for x in input().split()])
a.append([int(x) for x in input().split()])
n = int(input())
b = []
for i in range(n):
  b.append(int(input()))

ans = 'No'
for i in range(3):
  if set(np.array(a)[:, i]) <= set(b) or set(np.array(a)[i, :]) <= set(b):
    ans = 'Yes'

if set([a[0][0], a[1][1], a[2][2]]) <= set(b) or set([a[2][0], a[1][1], a[0][2]]) <= set(b):
  ans = 'Yes'
print(ans)

Measured memory_bytes: 12428
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <math.h>
using namespace std;
int main(){
  cin.tie(NULL);
  ios::sync_with_stdio(false);
  int a[3],ans=0,b=0;
  for(int i=0;i<3;i++){
    cin>>a[i];
    for(int j=0;j<i;j++){
      if(a[i]==a[j]){
	b++;
      }
    }
    if(b==0){
      ans++;
    }
    b=0;
  }
  cout<<ans<<"\n";
  return 0;
}

Measured memory_bytes: 3632
#include <stdio.h>
#define V_MAX 200000
#define E_MAX 399998
int score[V_MAX + 1];
int first[V_MAX + 1];
int next[E_MAX + 1];
int dest[E_MAX + 1];
void dfs(int curr, int par) {
	for(int i = first[curr]; i; i = next[i]) {
		if(dest[i] != par) {
			score[dest[i]] += score[curr];
			dfs(dest[i], curr);
		}
	}
	return;
}
int main(int argc, char **argv) {
	int n, q;
	scanf("%i%i", &n, &q);
	int m = (n - 1) * 2;
	int k = 1;
	while(k <= m) {
		int a, b;
		scanf("%i%i", &a, &b);
		next[k] = first[a];
		dest[first[a] = k++] = b;
		next[k] = first[b];
		dest[first[b] = k++] = a;
	}
	while(q--) {
		int p, x;
		scanf("%i%i", &p, &x);
		score[p] += x;
	}
	dfs(1, 0);
	for(int i = 1; i <= n; ++i) {
		printf("%i", score[i]);
		i == n ? printf("\n") : printf(" ");
	}
	return 0;
}


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

int main(){
	string s,t;
	cin>>s>>t;
	string res="~";
	for(int i=0;i<s.size()-t.size()+1;i++){
		bool flag=true;
		string s2=s;
		for(int j=0;j<t.size();j++){
			if(s2[i+j]!='?'&&s2[i+j]!=t[j]){
				flag=false;
				break;
			}
			else if(s2[i+j]=='?'){
				s2[i+j]=t[j];
			}
		}
		if(!flag)continue;
		for(int j=0;j<s2.size();j++){
			if(s2[j]=='?')s2[j]='a';
		}
		res=min(res,s2);
	}
	if(res=="~"){
		cout<<"UNRESTORABLE"<<endl;
		return 0;
	}
	cout<<res<<endl;
	return 0;
}

Measured memory_bytes: 256
from collections import deque
A=deque(list(input()+"A"))
B=deque(list(input()+"B"))
C=deque(list(input()+"C"))
x=A.popleft()
while(True):
  if x == "a":
    x = A.popleft()
  elif x == "b":
    x = B.popleft()
  elif x == "c":
    x = C.popleft()
  else:
    break
print(x)

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

int main() {
  string str;
  cin >> str;
  int a,b,c,d;
  a = str.at(0) - '0';
  b = str.at(1) - '0';
  c = str.at(2) - '0';
  d = str.at(3) - '0';
  int op1,op2,op3;
  vector<int> ops = {-1, 1};
  vector<char> opstr = {'-', '+'};
  for (int i = 0; i < 2; i++) {
    op1 = ops.at(i);
    for (int j = 0; j < 2; j++) {
      op2 = ops.at(j);
      for (int k = 0; k < 2; k++) {
        op3 = ops.at(k);
        if (a + op1*b + op2*c + op3*d == 7) {
          cout << a << opstr.at(i) << b << opstr.at(j) << c << opstr.at(k) << d << "=7" << endl;
          return 0;
        }
      }
    }
  }
  
  return 0;
}
         
  
      

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Created on Sun Feb  2 17:39:27 2020

@author: H_Hoshigi
"""

def is_prime(n):
    if n <= 1:
        return False
    else:
        i = 2
        while i**2 <= n:
            if n%i == 0:
                return False
            else:
                pass
            i += 1
        return True

if __name__ == "__main__":
    X = int(input())
    p = X
    while not(is_prime(p)):
        p += 1
    print(p)



Measured memory_bytes: 3064
def main():
    A = [int(i) for i in input().split()]
    B = [False]*5

    for a in A:
        if a == 0:
            continue
        B[a-1] = True

    for i, b in enumerate(B):
        if not b:
            print(i+1)
            break


if __name__ == '__main__':
    main()


Measured memory_bytes: 8836
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for (int i = (n)-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = (s); i < (n); ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<P>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class T> istream& operator>>(istream& is,vector<T>& v) { for(T& t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream& os,const vector<T>& v) { rep(i,v.size())os<<v[i]<<(i==v.size()-1?"\n":" "); return os; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YES(bool b) { cout << (b ? "YES" : "NO") << endl; }
template<class T> inline bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> inline bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

class Bipartite_matching {
    int n;
    vvi G;
    vi match;
    vb used;
    bool dfs(int v) {
        used[v] = true;
        for(int u : G[v]) {
            int w = match[u];
            if(w < 0 || !used[w] && dfs(w)) {
                match[v] = u;
                match[u] = v;
                return true;
            }
        }
        return false;
    }

public:
    Bipartite_matching(int n):n(n),G(n),match(n),used(n) {}
    void add_edge(int v,int u) {
        G[v].pb(u);
        G[u].pb(v);
    }
    int max_matching() {
        int res = 0;
        match.assign(n,-1);
        rep(i,n) {
            if(match[i] >= 0) continue;
            used.assign(n,false);
            if(dfs(i)) res++;
        }
        return res;
    }
};

int Min_path_cover(const vvi &v) {
    int n = v.size();
    Bipartite_matching bp(2*n);
    rep(i,n) for(int j : v[i]) bp.add_edge(i,j+n);
    return n-bp.max_matching();
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    int n;
    cin >> n;
    vi x(n);
    cin >> x;
    auto f = [&](vi v) {
        int sz = v.size();
        vvi G(sz);
        rep(i,sz) rep(j,sz) {
            if(i == j) continue;
            if(x[v[j]]%x[v[i]] == 0) G[i].pb(j);
        }
        return Min_path_cover(G);
    };
    vi init;
    rep(i,n) init.pb(i);
    int t = f(init);
    vi ans;
    set<int> se;
    rep(i,n) se.insert(i);
    rep(now,n) {
        if(!se.count(now)) continue;
        se.erase(now);
        vi temp;
        for(int i : se) {
            if(x[i]%x[now] == 0) continue;
            if(x[now]%x[i] == 0) continue;
            temp.pb(i);
        }
        int j = f(temp);
        if(j >= t-1) {
            t--;
            ans.pb(now+1);
            vi er;
            for(int i : se) {
                if(x[i]%x[now] == 0 || x[now]%x[i] == 0) er.pb(i);
            }
            for(int i : er) se.erase(i);
        }
    }
    cout << ans;
}


Measured memory_bytes: 3256
#include <map>
#include <queue>
#include <cmath>
#include <ctime>
#include <vector>
#include <cstdio>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <tr1/unordered_map>
#define mo 1000000007
#define num(x) (x>='0' && x<='9')
typedef unsigned long long ull;
typedef long long ll;
using namespace std::tr1;
using namespace std;
int read(){
    int p=0, q=1;
    char ch=getchar();
    while (!num(ch))
        (ch=='-'?q=-1:0),
        ch=getchar();
    while (num(ch)) p=p*10+ch-'0', ch=getchar();
    return p*q;
}
int power(ll a, int b){
	ll c=1;
	while (b){
		if (b&1) c=c*a%mo;
		a=a*a%mo;
		b>>=1;
	}
	return c;
}
int main(){
	int l=read()-1, r=read(), d=read();
	cout<<r/d-l/d<<endl;
    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
int main() {
    char si;
    int n,mi;
    int v[4][14]={0};
	std::cin >> n;
    for(int a=0;a<n;a++){
        std::cin >> si >> mi;
        if(si=='S')v[0][mi]=1;
        if(si=='H')v[1][mi]=1;
        if(si=='C')v[2][mi]=1;
        if(si=='D')v[3][mi]=1;
    }
    for(int s=0;s<4;s++){
        for(int m=0;m<14;m++){
            if(v[s][m]!=1 && m!=0){
                if(s==0)std::cout << "S " << m << std::endl;
                if(s==1)std::cout << "H " << m << std::endl;
                if(s==2)std::cout << "C " << m << std::endl;
                if(s==3)std::cout << "D " << m << std::endl;
            }
        }
    }

	return 0;
}

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

using namespace std;

int main(){
    int n, q;
    string str;
    cin >> n >> q >> str;
    
    int first[n+2];
    int count = 0;
    
    first[0] = 0;
    for(int i = 0; i < n; i++) {
        if(str.substr(i, 2) == "AC") {
            count++;
        }
        first[i+1] = count;
    }
    first[n+1] = count;
    //for(auto b: first) {
    //    cout << b ;
    //}
    
    for(int i = 0; i < q; i++) {
        int l, r;
        cin >> l >> r;
        // cout << first[r+1] - first[l-1] << endl;
        // cout << first[r+1] - first[l] << endl;
        // cout << first[r+1] - first[l+1] << endl;
        
        // cout << first[r] - first[l-1] << endl;
        // cout << first[r] - first[l] << endl;
        // cout << first[r] - first[l+1] << endl;
        
        cout << first[r-1] - first[l-1] << endl;
        // cout << first[r-1] - first[l] << endl;
        // cout << first[r-1] - first[l+1] << endl;
    }
}

Measured memory_bytes: 1408
//Solution By SlavicG
#include "bits/stdc++.h"
using namespace std;
 
#define ll                          long long
 
#define forn(i,n)                   for(int i=0;i<n;i++)
#define all(v)                      v.begin(), v.end()
#define rall(v)                     v.rbegin(),v.rend()
	
#define pb                          push_back
#define sz(a)                       (int)a.size()
 
#define   endl                       "\n"
#define fastio                       ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

int  main()
{
	int n,m;
	cin >> n >> m;
	int a[n];
	vector<int> adj[n];
	forn(i,n)
	{
		cin >> a[i];
	}
	forn(i,m)
	{
		int x,y;
		cin >> x >> y;
		x--, y--;
		adj[x].pb(y);
		adj[y].pb(x);
	}
	int ans = n;
	for(int i=  0;i < n;i++)
	{
		bool del = false;
		for(auto x : adj[i])
		{
			if(a[i] <= a[x])
			{
				del = true;
			}
		}
		if(del)ans--;
	}
	cout << ans << endl;
}

Measured memory_bytes: 9076
#include <stdio.h>
#include <stdlib.h>

int H, W, *is_used, *is_chosen;
char **S, **T;

int sym(int j, int k){
	int i;
	for(i = 0; i < H; i++){
		if(T[i][j] != T[H - 1 - i][k]){
			return 0;
		}
	}
	return 1;
}

int solve(int set_num){
	int i, j, k, res;
	if(set_num == H){
/*		printf("\n");
		for(i = 0; i < H; i++){
			printf("%s\n", T[i]);
		}
*/		int alone_num = 0;
		for(j = 0; j < W; j++){
			is_chosen[j] = 0;
		}
		for(j = 0; j < W; j++){
			if(is_chosen[j] == 0){
//				printf("j = %d\n", j);
				for(k = j + 1; k < W; k++){
					if(is_chosen[k] == 0){
						if(sym(j, k) == 1){
							is_chosen[j] = 1;
							is_chosen[k] = 1;
							break;
						}
					}
				}
				if(is_chosen[j] == 0){
					if(sym(j, j) == 0 || alone_num > 0){
						return 0;
					}
					else{
						is_chosen[j] = 1;
						alone_num++;
					}
				}
			}
//			printf("alone_num = %d\n", alone_num);
		}
		return 1;
	}
	else{
		if(set_num == 0 && H % 2 == 1){
			for(i = 0; i < H; i++){
				T[H / 2] = S[i];
				is_used[i] = 1;
				res = solve(set_num + 1);
				is_used[i] = 0;
				if(res == 1){
					return 1;
				}
			}
			return 0;
		}
		for(i = 0; is_used[i] == 1; i++){}
		T[set_num / 2] = S[i];
		is_used[i] = 1;
		for(k = i + 1; k < H; k++){
			if(is_used[k] == 0){
				T[H - 1 - set_num / 2] = S[k];
				is_used[k] = 1;
				res = solve(set_num + 2);
				is_used[k] = 0;
				if(res == 1){
					is_used[i] = 0;
					return 1;
				}
			}
		}
		is_used[i] = 0;
		return 0;
	}
}

int main(){
	int i, j;
	scanf("%d%d", &H, &W);
	S = (char **)malloc(sizeof(char *) * H);
	for(i = 0; i < H; i++){
		S[i] = (char *)malloc(sizeof(char) * (W + 1));
		scanf("%s", S[i]);
	}
	is_used = (int *)malloc(sizeof(int) * H);
	T = (char **)malloc(sizeof(char *) * H);
	for(i = 0; i < H; i++){
		is_used[i] = 0;
	}
	is_chosen = (int *)malloc(sizeof(int) * W);
	if(solve(0) == 1){
		printf("YES\n");
	}
	else{
		printf("NO\n");
	}
	return 0;
}

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

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcount

using namespace std;

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

template <typename T> T id(T b) {return b;};
template <class It> bool all(It f,It l){return std::all_of(f,l,id<bool>);}
template <class It> bool any(It f,It l){return std::any_of(f,l,id<bool>);}
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}

const int MAX_N = 100000;
int n;
vector<pii> g[MAX_N];
int col[MAX_N];

void dfs(int u, int p, int c) {
  col[u] = c;
  for (auto t : g[u]) {
    if (p == t.fst) continue;
    dfs(t.fst,u,(t.snd%2==0)?c:1-c);
  }
}

int main()
{
#ifdef FASTIO
  ios_base::sync_with_stdio(false); cin.tie(nullptr);
#endif

  cin >> n;
  forn(i,n-1) {
    int u,v,w;
    cin >> u >> v >> w;
    u--,v--;
    g[u].push_back(mp(v,w));
    g[v].push_back(mp(u,w));
  }

  dfs(0,-1,0);

  forn(i,n)
    cout << col[i] << "\n";


  return 0;
}


Measured memory_bytes: 9088
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for (ll i = 0; i < (ll)n; i++)
#define all(x) (x).begin(), (x).end()
#define unique(x) x.erase(unique(x.begin(), x.end()), x.end());
// map<int,int> mp;

int main() {
  int N;
  cin >> N;
  vector<int> P(N);
  REP(i, N) cin >> P[i];

  int cmin = 1e9;
  int ans = 0;

  REP(i, N){
    cmin=min(cmin,P[i]);
    if(cmin==P[i]) ans++;
  }
  cout << ans << endl;
}

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

namespace AtCoder.Abc
{
    class QuestionD
    {
        public static void Main(string[] args)
        {
            var inputLongArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i));
            long a = inputLongArray.ElementAt(0);
            long b = inputLongArray.ElementAt(1);

            Dictionary<long, long> aDic = GenerateDic(a);
            Dictionary<long, long> bDic = GenerateDic(b);
            Dictionary<long, long> resultDic = new Dictionary<long, long>();

            foreach(long key in aDic.Keys)
            {
                if(bDic.ContainsKey(key))
                {
                    long count = Math.Min(aDic[key], bDic[key]);
                    resultDic.Add(key, count);
                }
            }

            Console.WriteLine(resultDic.Keys.Count + 1);
        }

        public static Dictionary<long, long> GenerateDic(long n)
        {
            Dictionary<long, long> dic = new Dictionary<long, long>();
            foreach (long i in PrimeFactors(n))
            {
                if (dic.ContainsKey(i))
                {
                    dic[i]++;
                }
                else
                {
                    dic.Add(i, 1);
                }
            }
            return dic;
        }

        public static IEnumerable<long> PrimeFactors(long n)
        {
            long i = 2;
            long tmp = n;

            while (i * i <= n) //※1
            {
                if (tmp % i == 0)
                {
                    tmp /= i;
                    yield return i;
                }
                else
                {
                    i++;
                }
            }
            if (tmp != 1) yield return tmp;//最後の素数も返す
        }
    }
}


Measured memory_bytes: 13396
#include<stdio.h>
int main()
{
    int n,i,a[3],k,l,j,temp;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        for(j=0;j<3;j++){
            scanf("%d",&a[j]);
        }
        for(k=0;k<3;k++){
            for(l=0;l<3;l++){
                if(a[k]<a[l]){
                    temp=a[l];
                    a[l]=a[k];
                    a[k]=temp;
                }
            }
        }
        if((a[0]+a[1])>a[2] && ((a[0]*a[0])+(a[1]*a[1]))==(a[2]*a[2])){
            printf("YES\n");
        }
        else{
            printf("NO\n");
        }
    }
    return 0;
}



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

using namespace std;
typedef long long int lli;

int n;

lli sum;
lli ans;

int main()
{
	scanf("%d",&n);

	for(int i = 1 ; i <= n ; i++)
	{
		int v;
		scanf("%d",&v);

		if( v == 0 )
		{
			ans += sum/2;
			sum = 0;
		}
		else sum += v;
	}

	ans += sum/2;

	printf("%lld\n",ans);
}

Measured memory_bytes: 256
<?php
// Your code here!
    $input = trim(fgets(STDIN));
    
    $array = str_split($input);
    
    $row = 0;
    
    foreach($array as $key => $value){
        if($value == 'R'){
            if(!$row){
                $row++;
            }elseif($array[$key - 1] == 'R'){
                    $row++;
            }
        }
    }
    
    echo $row;
?>


Measured memory_bytes: 16276
import Control.Applicative
import Control.Monad
import Data.List

main = do
  n <- (read::String -> Int) <$> getLine
  arr <- map (read::String -> Int) . words <$> getLine
  print $ foldl (
    \acc i -> if ((arr !! i) - (arr !! (i + 1))) * ((arr !! (i + 2)) - (arr !! (i + 1))) < 0 
      then acc + 1 
      else acc
      ) 0 [0..(n - 3)]

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

using namespace std;

using EdgeItr = unordered_multimap<uint64_t, pair<uint64_t, uint64_t>>::iterator;

int main()
{
  uint64_t N;
  cin >> N;
  
  unordered_multimap<uint64_t, pair<uint64_t, uint64_t>> edges;
  for (uint64_t n = 0; n < N - 1; ++n) {
    uint64_t u, v, w;
    cin >> u >> v >> w;
    
    edges.emplace(u - 1, make_pair(v - 1, w));
    edges.emplace(v - 1, make_pair(u - 1, w));
  }
  
  vector<uint32_t> nodes(N, 0);
  
  vector<bool> visited(N, false);
  queue<pair<uint64_t, uint64_t>> q;
  q.emplace(0, 0);
  while (!q.empty()) {
    pair<uint64_t, uint64_t> p = q.front(); q.pop();
    
    visited[p.first] = true;
    if ((p.second & 1) == 1) {
      nodes[p.first] = 1;
    }
    
    pair<EdgeItr, EdgeItr> itrs = edges.equal_range(p.first);
    for (EdgeItr itr = itrs.first; itr != itrs.second; ++itr) {
      if (!visited[itr->second.first]) {
        q.emplace(itr->second.first, p.second + itr->second.second);
      }
    }
  }
  
  for (uint64_t n = 0; n < N; ++n) {
    cout << nodes[n] << endl;
  }
  
  return 0;
}

Measured memory_bytes: 12232
//---------------------------------------------------------------
#include <bits/stdc++.h>
using namespace std;
#include <iostream>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <math.h>
#include <sstream>
#include <numeric>
#include <cctype>
#include <bitset>
#include <cassert>
#include<algorithm>
//---------------------------------------------------------------
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define SIZE 100005
#define INF 1000000000000000LL
#define all(x) x.begin(),x.end()
#define fi first
#define se second
using pint = pair<int,int>;
using vec = vector<int>;
using ll=long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
//---------------------------------------------------------------
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; }
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
//---------------------------------------------------------------

//↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓


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

    ll n,k;
    cin>>n>>k;
    vll h(n);
    rep(i,n) cin>>h[i];
    sort(all(h));
    ll ans=1e9;
    rep(i,n-k+1){
        ans=min(ans,h[i+k-1] - h[i]);
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 3984
#include <bits/stdc++.h>
using namespace std;
#ifdef __LOCAL
#define debug(x) cerr << __LINE__ << ": " << #x << " = " << x << endl
#define debugArray(x, n)                             \
  cerr << __LINE__ << ": " << #x << " = {";          \
  for (long long hoge = 0; (hoge) < (n); ++(hoge)) { \
    cerr << ((hoge) ? "," : "") << x[hoge];          \
  }                                                  \
  cerr << "}" << endl
#else
#define debug(x) (void(0))
#define debugArray(x, n) (void(0))
#endif

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  long long P;
  cin >> N >> P;
  string S;
  cin >> S;
  long long ans = 0;
  if (P == 2 || P == 5) {
    for (long long i = 0; i < N; i++) {
      if ((S[i] - '0') % P == 0) ans += i + 1;
    }
  } else {
    long long sum = 0;
    long long cnt[P];
    fill(cnt, cnt + P, 0);
    long long pw10 = 1;
    for (int i = N - 1; i >= 0; i--) {
      sum = (sum + pw10 * (S[i] - '0')) % P;
      cnt[sum]++;
      pw10 = pw10 * 10 % P;
      debug(sum);
    }
    debugArray(cnt, P);
    ans = cnt[0];
    for (int i = 0; i < P; i++) ans += cnt[i] * (cnt[i] - 1) / 2;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3728
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
int main(){
    ll n; cin>>n;
    for(ll i=-400;i<=400;i++){
        for(ll j=-400;j<=400;j++){
            if(abs(pow(i,5)-pow(j,5))==n){
                cout<<max(i,j)<<" "<<min(i,j);
                return 0;
            }
        }
    }
    
    return 0;
}


Measured memory_bytes: 3984
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;



int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    cout << fixed << setprecision(16);

    int n, m, d;
    cin >> n >> m >> d;


    long double res = 0;
    if (d == 0) {
        res = n;
    } else if (d * 2LL <= n) {
        res += 2LL * d;
        res += (n - 2LL * d) * 2LL;
    } else {
        res += 2LL * (n - d);
    }

    res /= n;
    res /= n;
    res *= (m - 1);

    cout << res << '\n';

    return 0;
}

Measured memory_bytes: 256