akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
typedef long long int ll;
typedef pair<int,int> P;
const int INF = 1e9+7;

int main(){
    string S;
    cin >> S;
    while(true){
        int t = S.size()-2;
        S = S.erase(t);
        t = S.size()/2;
        string T = S.substr(t);
        string C = S.substr(0,t);
        if(T==C){
            cout << S.size() << endl;
            return 0;
        }
    }
}

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

int main() {
    int N, M;
    cin >> N >> M;
    vector <int> L(M), R(M);
    vector <int> card_list(N + 1, 0);
    for(int i = 0; i < M; i++)
    {
        cin >> L[i] >> R[i];
        card_list[L[i] - 1]++;
        card_list[R[i] + 1 - 1]--;
    }

    for(int i = 0; i < N; i++)
    {
        card_list[i + 1] += card_list[i];
    }
    int count = 0;

    for(int i = 0; i < N + 1; i++)
    {
        if(card_list[i] == M)
         count++;
    }

    cout << count << endl;
    
    return 0;  

}

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

int64_t MOD = 1000000007;
int64_t MAX = 9223372036854775807;
double PI = 3.141592653589793;

int main()
{
    int A, B, C;
    cin >> A >> B >> C;
    cout << min(B / A, C);
}

Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int c,a[3],n,b=0,i,j;
    //scanf("%d%d%d",&a,&b,&c);
    for(i=0;i<3;i++)
    {
        cin>>a[i];
    }
    sort(a,a+3);
    for(i=0;i<2;i++)
    {
        b=b+abs(a[i]-a[i+1]);
    }
    cout<<b<<"\n";
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long 
using namespace std;
int a[100005];
int f[100005];
main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    f[2]=abs(a[2]-a[1]);
    for(int i=3;i<=n;i++)
        f[i]=min(f[i-1]+abs(a[i-1]-a[i]),f[i-2]+abs(a[i-2]-a[i]));
    cout<<f[n];

}


Measured memory_bytes: 1792
///Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>

#define                           int                         long long
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<int,int>
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);




using namespace std;

const int inf=1e18;
const int mod=1e9+7;
const int M=100009;
inline int bigmod(int B,int P){int R=1;while(P>0){if(P&1){R=(R*B)%mod;}P>>=1;B=(B*B)%mod;}return R;}


 main()

{
    fast

   int h,a;
   cin>>h>>a;
   cout<<(h+a-1)/a<<endl;

















    return 0;

}













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

int main(){
    int n,x,i,j,k,ans;
    while(cin>>n>>x,n!=0 || x!=0){
        ans=0;
        for(i=1;i<=n;i++){
            for(j=i+1;j<=n;j++){
                for(k=j+1;k<=n;k++){
                    if(i+j+k==x)ans++;
                }
            }
        }
        cout<<ans<<endl;
    }
}


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

int main() {
    ll a, v, b, w, t;
    cin >> a >> v >> b >> w >> t;

    ll dist = abs(a - b);
    ll speed = v - w;
    if(speed < 1 || dist > speed * t){
        puts("NO");
        return 0;
    }
    puts("YES");
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define all(cont) cont.begin(), cont.end()
#define foreach(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define fore(i,a,b) for(int i=a,almo5t=b;i<almo5t;++i)
#define SZ(x) ((int)x.size())
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define FIN std::ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

const int N = 0;

typedef long long int ll;

using namespace std;


int main(){
    FIN;

    //freopen("../input.txt", "r", stdin);freopen("../output.txt", "w", stdout);
    double a,b,c;cin>>a>>b>>c;
    double x = min(c,b-1);
    ll result = abs(a*floor(x/b)-floor((a*x)/b));
    cout<<result<<"\n";
	return 0;
}

Measured memory_bytes: 3736
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner scan = new Scanner(System.in);
        String str = scan.nextLine();
        scan.close();
        String[] data = str.split(" ");
        int r = 0;
        int d = 0;
        int x = 0;
        int ans[] = {0,0,0,0,0,0,0,0,0,0,0};
        r = Integer.parseInt(data[0]);
        d = Integer.parseInt(data[1]);
        x = Integer.parseInt(data[2]);

        //ans[0] = r * x - d;
        ans[0] = x ;
        for (int i = 1; i < 11; i++) {
            ans[i] = r * ans[i-1] - d;
        }

        for (int i = 1; i < 11; i++) {
            System.out.println(ans[i]);
        }
    }
}

Measured memory_bytes: 21076
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REP2(i, n) for (int i = 1; i <= (int)(n); i++)
#define FOR(i, m, n) for (int i = m; i n; i++)
#define SORT(x) sort(x.begin(), x.end())
#define REVE(x) reverse(x.begin(), x.end())
#define all(x) (x).begin(), (x).end()
struct initon
{
    initon()
    {
        cin.tie(0);
        ios::sync_with_stdio(false);
    };
};
int n, m, a, b, c, d;
string s;
signed main() {
    int kr=0;
    cin >> n >> a >> b >> s;
    REP(i, n)
    {
        if (s[i] == 'a')
        {
            if (c< a + b){
                cout << "Yes"<<endl;
            c++;
            }
            else
                cout << "No"<<endl;
        }
        else if (s[i] == 'b')
        {
            kr++;
            if(c < a + b&&kr<=b){
                c++;
                cout << "Yes"<<endl;
            }
            else
                cout << "No"<<endl;
        }
        else
        {
            cout << "No"<<endl;
        }
      }
  }

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

const int INF = pow(2, 31) - 1;
#define ll long long
#define DEBUG(x) cout << "DEBUG>" << #x << ":" << x << endl;
#define REP(i,n) for(ll i=0;i<(n);i++)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

int main() {
  string s;
  cin >> s;
  int K;
  cin >> K;
  vector<string> S;
  REP(i, K) {
    REP(j, s.size() - i) {
      S.push_back(s.substr(j, i + 1));
    }
  }
  sort(S.begin(), S.end());
  S.erase(unique(S.begin(), S.end()), S.end());
  cout << S[K - 1] << endl;
  return 0;
}


Measured memory_bytes: 1660
import scala.io.StdIn

/**
  * AOJ
  */
object Main {

  def main(args: Array[String]): Unit = {

    val in = StdIn.readLine().split(" ").map(_.toInt)
    val n = in(0)
    val m = in(1)
    val l = in(2)
    val a = readMatrix(n, m)
    val b = readMatrix(m, l)
    val c = getProduct(a,b,n,m,l)
    printOut(c)
  }

  def readMatrix(n:Int,m:Int):Array[Array[Int]] = {
    val matrix = Array.ofDim[Int](n, m)
    for(i <- 0 until n){
      matrix(i) = StdIn.readLine().split(" ").map(_.toInt)
    }
    matrix
  }

  def getProduct(a:Array[Array[Int]], b:Array[Array[Int]],n:Int,m:Int,l:Int):Array[Array[Long]] = {
    val matrix = Array.ofDim[Long](n, l)
    for(i <- 0 until n; j <- 0 until l; k <- 0 until m){
      matrix(i)(j) += a(i)(k) * b(k)(j)
    }
    matrix
  }

  def printOut(c:Array[Array[Long]]): Unit ={
    for(e <- c){
      println(e.mkString(" "))
    }
  }
}

Measured memory_bytes: 54288
#!/usr/bin/env python3
 
from fractions import gcd
 
def all_gcd(numbers):
    result = numbers[0]
    for v in numbers:
        result = gcd(result, v)
    return result
 
def main():
    n = int(input())
    a = list(map(int, input().split()))
    # x[i] = gcd 0 to i
    x = []
    for i in range(n):
        prev = 0 if i == 0 else x[i - 1]
        x.append(gcd(a[i], prev))
    # y[i] = gcd i to n
    y = [0] * n
    y[n-1] = a[n-1]
    for i in range(2, n + 1):
        y[n-i] = gcd(y[n-i+1], a[n-i])

    max_gcd = 0
    for i in range(n):
        if i == 0:
            now_gcd = y[1]
        elif i == n-1:
            now_gcd = x[n-2]
        else:
            now_gcd = gcd(x[i-1], y[i+1])
        if now_gcd > max_gcd:
            max_gcd = now_gcd
    print(max_gcd)
 
if __name__ == '__main__':
    main()


Measured memory_bytes: 16152
#include <iostream>
#include <cstdio>
#define N 200005
using namespace std;

typedef long long ll;
ll M = 1e9 + 7;
ll n, a, b, ans = 1;
ll fac[N] = {1, 1}, inv[N] = {1, 1}, fiv[N] = {1, 1};

ll pow(ll p) {
	ll re;
	if (p == 0) return 1;
	re = pow(p / 2);
	re = re * re % M;
	if (p % 2 == 1) re = re * 2 % M;
	return re;
}

ll com(ll p, ll q) {
    ll i, re = 1;
    for (i = 0; i < q; i++) {
		re = re * (p - i) % M;
    }
    return re * fiv[q] % M;
}

int main()
{
	ll i;
	cin >> n >> a >> b;
	for (i = 2; i <= max(a, b); i++) {
		fac[i] = fac[i - 1] * i % M;
		inv[i] = inv[M % i] * (M - M / i) % M;
		fiv[i] = fiv[i - 1] * inv[i] % M;
	}
	ans = pow(n);
	ans--;
	ans = (ans + 2 * M - com(n, a) - com(n, b)) % M;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4992
#include<iostream>
using namespace std;
 
void call(int n){
    int i = 1, x;
    do{
        x = i;
        if(x % 3 == 0){
            cout << " " << i;
        }else{
            do{
                if(x % 10 == 3){
                    cout << " " << i;
                    break;
                }
                x /= 10;
            }while(x);
        }
    }while(++i <= n);
    cout << endl;
}
 
int main(){
    int n;
    cin >> n;
    call(n);
     
    return 0;
}

Measured memory_bytes: 3092
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<functional>
#include<vector>
#include<map>

using namespace std;
#define endl '\n'
#define pb push_back
#define fst first
#define scd second
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MOD (1e9 + 7)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define REP(i,n) for(int i = 0;i < (n);i++)
#define FOR(i,a,b) for(int i = (a);i <= (b);i++)
#define YES(n) cout << ((n) ? "YES" : "NO" ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No" ) << endl


typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vector<int>> vii;

template <class T = int> T in() { T x; cin >> x; return (x); }
template <class T = int> void out(T x) { cout << (x) << endl; }

int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }

void solve() {

	int a[3];

	cin >> a[0] >> a[1] >> a[2];

	vi d(3);
	d[0] = fabs(a[0] - a[1]);
	d[1] = fabs(a[1] - a[2]);
	d[2] = fabs(a[2] - a[0]);

	sort(ALL(d));

	out(d[0] + d[1]);

	return;

}

int main() {

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

	solve();

	return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000000007;
using ll = long long;
using namespace std;

int main(){
	int n; cin >> n;
	vector<pair<int, int>> s;
	for( int i = 0; i < n; ++i ){
		int t; cin >> t;
		s.emplace_back(t, i+1);
	}
	sort(s.begin(), s.end());
	for( auto p : s ){
		cout << p.second << endl;
	}
}

Measured memory_bytes: 1780
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

#include <fstream>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <bitset>
#include <numeric>
#include <unordered_set>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <numeric>
#include <cstdlib>
#include <random>
#include <bits/stdc++.h>


using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
//typedef vector<ll> vec;
//typedef vector<vec> mat;

const ll mod=1000000007ll;
const ll inf=1000000000000000ll;

const ll MAX_N=100;

ll N,M,X,v[MAX_N],a;

int main(){
  cin>>N>>M>>X;
  for(ll i=0;i<M;i++){
    cin>>a;
    v[a]++;
  }
  ll tmp1=0,tmp2=0;
  for(ll i=0;i<X;i++){
    tmp1+=v[i];
  }
  for(ll i=X;i<N;i++){
    tmp2+=v[i];
  }
  cout<<min(tmp1,tmp2)<<endl;
  return 0;
}


Measured memory_bytes: 256
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}

void main()
{
  int k, n; readV(k, n);

  auto ans = new int[](n), s = n;

  if (k%2 == 0) {
    ans[0] = k/2;
    ans[1..$][] = k;
  } else {
    ans[] = (k+1)/2;
    foreach (i; 0..n/2) {
      if (ans[s-1] == 1) {
        --s;
      } else {
        ans[s-1]--;
        ans[s..n][] = k;
        s = n;
      }
    }
  }

  foreach (i; 0..s) {
    write(ans[i]);
    if (i < s-1) write(" ");
  }
  writeln;
}


Measured memory_bytes: 4860
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")

N = k()
count = 0
for i in range(1,N+1):
    t = N//i
    count += i * t*(t+1)/2
print(int(count))


Measured memory_bytes: 10496
// Problem : A - Station and Bus
// Contest : AtCoder Beginner Contest 158
// URL : https://atcoder.jp/contests/abc158/tasks/abc158_a
// Memory Limit : 1024.000000 MB 
// Time Limit : 2000.000000 milisec 
// Powered by CP Editor (https://github.com/coder3101/cp-editor2)

#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define REP(i,n) for (ll i = 0; i < n; i++)
#define REPR(i,n) for(ll i = n-1; i >= 0; i--)
#define FOR(i,a,b) for (ll i = a; i < b; i++)
#define FORR(i,a,b) for(ll i = a-1; i>= b; i--)
#define ff first
#define ss second
#define MAXN (ll)1000002
#define MODN (ll)1000000007
#define mp make_pair
#define pb push_back
#define LN(x) (ll)x.length()
#define SZ(x) (ll)x.size()
#define bg(x) (x.begin())
#define rbg(x) (x.rbegin())
#define ENDL cout<<endl
ll n,t=1,tmp;
ll arr[MAXN];
int main() {
   string s;
cin>>s;
if(s[0] == s[1] && s[1] == s[2]) {
	cout<<"No";
} else cout<<"Yes";
}

Measured memory_bytes: 256
#include<string>
#include<iostream>
#include <algorithm>
#include<vector>
#include<functional>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <numeric>
#include <math.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(ll)n;i++)
using namespace std;



int main() {
    ll K;
    string S;
    cin >>K>> S;
    if (S.size() <= K) cout << S << endl;
    else {
        rep(i, K) cout << S[i];
        cout << "..." << endl;
    }
    return 0;

}


Measured memory_bytes: 3628
a,b,c,d,e,f = list(map(int, input().split()))
maxn = -1
ans = ()
for at in range(0,31):
    for bt in range(0,31-at):
        water = (at * a + bt * b) * 100
        if water > f:
            continue

        # 溶け残らないように砂糖を選ぶ
        maxsugar = water * e // 100
        for ct in range(0, (maxsugar+1)//c + 1):
            for dt in range(0, (maxsugar-ct*c+1)//d + 1):
                sugar = ct * c + dt * d

                if 0 < sugar + water <= f and sugar <= (at * a + bt * b) * e:
                    # 水１００に対して溶けている砂糖の量
                    n = 100 * sugar / water
                    if n == e:
                        print(water + sugar, sugar)
                        exit()
                    if n > maxn:
                        ans = water + sugar, sugar
                        maxn = n
print(*ans)

Measured memory_bytes: 9220
import java.util.Scanner; 
import java.util.Arrays; 
import java.util.Collections; 
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();
      int i,p=0;
      for(i=a;i<=b;i++){
          if(c % i == 0) p++;
      }
     System.out.println(p);
    sc.close();
  }
}


Measured memory_bytes: 26312
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
using namespace std;
typedef long long int ll;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)

int main(){
  int a,b;cin >> a >> b;
  int tmp,ans=10000;
  int cnt =0;
  rep(i,10000){
    if(int(i*0.08)==a && int(i*0.1)==b){
       tmp = i;
       ans = min(ans,tmp);
    }else{
      cnt++;
    } 
  }
  if(cnt == 10000){
    cout << -1 << endl;
    return 0;
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 256
<?php
list($n,$m)=explode(' ',trim(fgets(STDIN)));
for($i=0;$i<$n;$i++) $a[$i]=explode(' ',trim(fgets(STDIN)));
for($i=0;$i<$m;$i++) $b[$i]=trim(fgets(STDIN));
 
for($i=0;$i<$n;$i++){
  $c=0;
  for($j=0;$j<$m;$j++) $c+=$a[$i][$j]*$b[$j];
  $o[]=$c;
}
print implode(PHP_EOL,$o);
?>

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

int matrix[11][11];

int main(void){
	int i,j;
	int n,temp;

	while(scanf("%d",&n)!=EOF){
		if(n==0) break;
		for(i=0;i<11;i++){
			for(j=0;j<11;j++) matrix[i][j]=0;
		}
		temp=0;
		for(i=0;i<n;i++){
			for(j=0;j<n;j++){
				scanf("%d",&matrix[i][j]);
				matrix[i][n]+=matrix[i][j];
				matrix[n][j]+=matrix[i][j];
				temp+=matrix[i][j];
			}
		}
		matrix[n][n]=temp;
		
		for(i=0;i<=n;i++){
			for(j=0;j<=n;j++) printf("%5d",matrix[i][j]);
			printf("\n");
		}
	}

	return 0;
}

Measured memory_bytes: 616
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <vector>
#include <set>
#include <map>

using namespace std;

const int N = 100100;


int main() {
  int a, b, c; cin >> a >> b;
  for(int i = 1; i <= 3; i++) {
    if(a * b * i % 2 == 1){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}

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

int main()
{
    int H, W;
    cin >> H >> W ;
    while(H!=0 || W!=0){
        for (int h = 0; h< H; h++){
            for ( int w = 0; w < W; w++){
                if (h==0 || h==H-1 ||w==0 ||w==W-1){
                    cout << '#';
                }else
                {
                    cout << '.';
                }
                
                
            }
            cout << endl;
        }
        cout << endl;
        cin >> H >> W ;
    }

}


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

string s;

int main(){
  cin >> s;
  long long int n = s.size();
  long long int cnt = 0, sum = 0;
  for(long long int i = 0; i < n; i++){
    if(s.at(i) == 'W'){
      sum += i - cnt;
      cnt++;
    }
  }
  cout << sum << endl;
  return 0;
}

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

#pragma ide diagnostic ignored "OCUnusedGlobalDeclarationInspection"
#pragma ide diagnostic ignored "OCUnusedMacroInspection"
using namespace std;

#define sqr(a) ((a)*(a))
#define forn(i, n) for(int i = 0; i < (int)n; ++i)
#define rep(i, k, n) for(int i = (int)k; i <= (int)n; ++i)
#define nrof(i, n) for(int i = (int)n - 1; i >= 0; --i)
#define x first
#define y second
#define mp make_pair
#define sz(a) (int)(a.size())
#define pb push_back
#define eb emplace_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef double dd;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int N = 1e6 + 9;
const int M = 3e3 + 9;
const int INFINT = 1e9 + 9;
const ll INFLL = 1e18 + 9;
const ll MOD = (ll) (1000000007);

ll a[M][M], dp[M][M][4];

void solve() {
    int r, c, k;
    cin >> r >> c >> k;
    forn(i, k) {
        int x, y, w;
        cin >> x >> y >> w;
        a[x - 1][y - 1] = w;
    }
    for (int i = 0; i <= r; ++i) {
        for (int q = 0; q < 4; ++q) {
            for (int j = 0; j <= c; ++j) {
                if (j + 1 <= c) dp[i][j + 1][q] = max(dp[i][j + 1][q], dp[i][j][q]);
                if (j + 1 <= c && q + 1 < 4) dp[i][j + 1][q + 1] = max(dp[i][j + 1][q + 1], dp[i][j][q] + a[i][j]);
                if (i + 1 <= r) dp[i + 1][j][0] = max(dp[i + 1][j][0], dp[i][j][q]);
                if (i + 1 <= r && q != 3) dp[i + 1][j][0] = max(dp[i + 1][j][0], dp[i][j][q] + a[i][j]);
            }
        }
    }
    ll ans = 0;
    forn(q, 4) {
        ans = max(ans, dp[r][c][q]);
    }
    cout << ans << endl;
}

int main() {
    //  freopen("input.txt", "r", stdin);
    //  freopen("output.txt", "w", stdout);

    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int t;
    t = 1;
    //cin >> t;
    while (t--) {
        solve();
    }

    return 0;
}


Measured memory_bytes: 356364
#include <cstdio>

using namespace std;

int main(){

while(1){

	int n,m,ans = 0,ch=0;
	
	int mem[502] = {0};
	int lis[10003][2] = {0};
	
	scanf("%d%d",&n,&m);
	
	if(n == 0) break;
	
	for(int i = 0;i < m;i++){
	int t1,t2;
	scanf("%d%d",&t1,&t2);
	
	if(t1 == 1){
	mem[t2] = 1;
	ans++;
	}else if(t2 == 1){
	mem[t1] = 1;
	ans++;
	}else{
	lis[ch][0] = t1;
	lis[ch][1] = t2;
	ch++;
	}
	}
	
	for(int i = 0;i < ch;i++){
		if(mem[lis[i][0]] == 1 && mem[lis[i][1]] == 0){
		ans++;
		mem[lis[i][1]] = 2;
		}else if(mem[lis[i][1]] == 1 && mem[lis[i][0]] == 0){
		ans++;
		mem[lis[i][0]] = 2;
		}
	}
	
	printf("%d\n",ans);
	
	}
	
	return 0;
	
}


Measured memory_bytes: 1116
#include "iostream"
#include "random"
#include "ctime"
#include "chrono"
#include "string"
#include "bitset"
#include "algorithm"
#include "map"

using namespace std;


int main() {
	int N;
	cin >> N;
	vector<int>v(N);
	int ans = -1;
	for (int i = 0; i < N; i++) {
		cin >> v[i];
	}
	for (int i = 0; i < N; i++) {
		for (int j = i + 1; j < N; j++) {
			int box = v[i] * v[j];
			string s = to_string(box);
			bool flag = true;
			for (int k = 1; k < s.size(); k++) {
				if (s[k - 1] + 1 != s[k]) {
					flag = false;
				}
			}
			if (flag) {
				ans = max(ans, box);
			}
		}
	}
	cout << ans << endl;
	return 0;
}


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

using namespace std;

constexpr int MAXN = 100000;

vector<int> adj1[MAXN + 2], adj2[MAXN + 2];
int col[MAXN + 2], sz[MAXN + 2];

int main() {
	int N, M, K;
	cin >> N >> M >> K;
	for(int i = 0; i < M; i++) {
		int u, v;
		cin >> u >> v;
		adj1[u].push_back(v);
		adj1[v].push_back(u);
	}
	for(int i = 0; i < K; i++) {
		int u, v;
		cin >> u >> v;
		adj2[u].push_back(v);
		adj2[v].push_back(u);
	}
	int c = 1;
	for(int i = 1; i <= N; i++) {
		if(!col[i]) {
			queue<int> q;
			q.push(i);
			col[i] = c;
			do {
				int u = q.front();
				q.pop();
				for(int v : adj1[u]) {
					if(!col[v]) {
						q.push(v);
						col[v] = c;
					}
				}
			} while(!q.empty());
			c++;
		}
	}
	for(int i = 1; i <= N; i++)
		sz[col[i]]++;
	for(int i = 1; i <= N; i++) {
		int ans = sz[col[i]] - adj1[i].size() - 1;
		for(int u : adj2[i])
			if(col[u] == col[i])
				ans--;
		cout << ans << ' ';
	}
	cout << '\n';
}


Measured memory_bytes: 12664
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(i = 0; i < n; i++)
//2D::rep(i,j)rep(j,j)cin>>bin[i][j];
//vector<int> a(n)
#define Graph vector<vector<int>>
#define A1 cout<<"No"<<endl
#define A2 cout<<"Yes"<<endl
#define A3 cout<<ans<<
#define AA(i) cout<<i<<endl;
const int U=2e5+5;
const ll MOD=1000000007;
const int INF = 1001001001;

int main(){
    int N,K; cin >> N >> K;
    vector<int> p(N);
    int i;
    rep(i,N) cin >> p[i];
    sort(p.begin(), p.end());
    int ans = 0;
    rep(i,K) ans += p[i];
    AA(ans);
    return 0;
}

Measured memory_bytes: 3628
def main():
    n = int(input())

    A = list(map(int, input().split()))


    if (0 in A):
        print(0)
        return

    ret = 1

    for a in A:
        ret *= a
        if ret > 1000000000000000000:
            print(-1)
            return;

    print(ret)
    return


if __name__ == "__main__":
    main()


Measured memory_bytes: 21636
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
	int a,b;
	cin>>a>>b;
	if(a>0)cout<<"Positive"<<endl;
	else if(a<=0&&b>=0)cout<<"Zero"<<endl;
	else if(int(abs(b)-abs(a))%2!=0)cout<<"Positive"<<endl;
	else cout<<"Negative"<<endl;
    return 0;
}

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

string ans(string x){
    int nno=0, sno=0, wno=0, eno=0;
    for (int i = 0;i<x.length(); i++){
        string sub = x.substr(i,1);
        if (sub == "N") nno++;
        if (sub == "E") eno++;
        if (sub == "S") sno++;
        if (sub == "W") wno++;
    }
    char exn,exe,exs,exw;
    if(nno>0){
        exn = 'y';
    } else {
        exn = 'n';
    }
    if(eno>0){
        exe = 'y';
    } else {
        exe = 'n';
    }
    if(wno>0){
        exw = 'y';
    } else {
        exw = 'n';
    }
    if(sno>0){
        exs = 'y';
    } else {
        exs = 'n';
    }
    if(exn =='y' & exe == 'y' & exs =='y' & exw == 'y'){
        return("Yes");
    }
    if (exn =='y' & exe == 'y' & exs =='y' & exw == 'n' || exn =='y' & exe == 'y' & exs =='n' & exw == 'y' || exn =='y' & exe == 'n' & exs =='y' & exw == 'y' || exn =='n' & exe == 'y' & exs =='y' & exw == 'y'){
        return("No");
    }
    if (exn =='y' & exe == 'y' & exs =='n' & exw == 'n' || exn =='n' & exe == 'y' & exs =='y' & exw == 'n' || exn =='y' & exe == 'n' & exs =='n' & exw == 'y' || exn =='n' & exe == 'n' & exs =='y' & exw == 'y'){
        return("No");
    }
    if (exn =='y' & exe == 'n' & exs =='y' & exw == 'n' || exn =='n' & exe == 'y' & exs =='n' & exw == 'y'){
        return("Yes");    
    }
    if (exn =='y' & exe == 'n' & exs =='n' & exw == 'n' || exn =='n' & exe == 'y' & exs =='n' & exw == 'n' || exn =='n' & exe == 'n' & exs =='y' & exw == 'n' || exn =='n' & exe == 'n' & exs =='n' & exw == 'y'){
        return("No");
    }
}

int main(){
    string S;
    cin >> S;
    cout << ans(S);
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        for(int i = 1; ; i++)
        {
            int x = sc.nextInt();
            if(x == 0)
                break;
            else
            {
                System.out.println("Case " + i + ": " + x);
            }
        }
    }
}


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

int main()
{
    int n;
    int index;
    string s;

    cin >> n;
    cin.ignore();

    for(int i=0; i < n; i++)
    {
        getline(cin, s);

        while(true)
        {
            index = s.find("Hoshino");

            if(index == string::npos)
                break;
            else
                s.replace(index, 7, "Hoshina");
        }
        cout << s << endl;
    }

    return 0;
}

Measured memory_bytes: 3056
#include<iostream>
#include<math.h>
#include <algorithm>
#include<float.h>
using namespace::std;
int main(){
  string S;
  cin>>S;
  int check=0;
  if(S[0]==S[1]){
    check=1;
  }else if(S[1]==S[2]){
    check=1;
  }else if(S[2]==S[3]){
    check=1;
  }
  if(check==1){
    cout<<"Bad";
  }else{
    cout<<"Good";
  }

}

Measured memory_bytes: 256
h, w = [int(x) for x in raw_input().split()]
c = [[int(x) for x in raw_input().split()] for l in xrange(10)]
a = [[int(x) for x in raw_input().split()] for l in xrange(h)]
for t in xrange(10):
    for i in xrange(10):
        for j in xrange(10):
            for k in xrange(10):
                c[i][j] = min(c[i][j], c[i][k] + c[k][j])
print sum([c[a[x][y]][1] for x in xrange(h) for y in xrange(w) if a[x][y] != -1])

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

const long long MOD = 1e9 + 7;

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

  long long res = 0;
  for (int k = 0; k < 60; ++k) {
    long long one = 0;
    long long zero = 0;
    for (int i = 0; i < n; ++i) {
      if (a[i] & (1LL << k))
        ++one;
      else
        ++zero;
    }
    long long tmp = one * zero;
    tmp %= MOD;
    // tmp *= ((1LL << k) % MOD);
    for (int h = 0; h < k; ++h)
      tmp = 2 * tmp % MOD;
    tmp %= MOD;
    res += tmp;
    res %= MOD;
  }

  std::cout << res << std::endl;
}


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

using namespace std;

#define rep(i, n) for(int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()
#define endl "\n"

using ll = long long;
using P = pair<int,int>;

const int MOD = 1e9 + 7;
const int INF = 1001001001;

int main (){
    int a, b;
    cin >> a >> b;

    if(a+b >= 10){
        cout << "error" << endl;
    }else{
        cout << a+b << endl;
    }


    return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"math"
)

func main() {
	var a, b, h, m float64
	fmt.Scan(&a, &b, &h, &m)

	ha := 30*h + 0.5*m
	ma := 6 * m

	switch {
	case math.Abs(ha-ma) == 180:
		fmt.Println(a + b)
	case ha == ma:
		fmt.Println(math.Abs(a - b))
	default:
		ang := math.Max(ha-ma, ma-ha)
		if ang > 180 {
			ang = 360 - ang
		}

		ans := math.Pow(a, 2) + math.Pow(b, 2) - (2 * a * b * (math.Cos(ang * math.Pi / 180)))
		fmt.Println(math.Sqrt(ans))
	}
}


Measured memory_bytes: 1824
l = sorted(map(int, input().split()))
p = (l[0]%2 != l[1]%2) or (l[1]%2 != l[2]%2)

p=(l[0]%2!=l[1]%2)or(l[1]%2!=l[2]%2)
l[0],l[1],l[2]=sorted([l[0]+((l[0]%2==l[1]%2)^(l[0]%2==l[2]%2)),l[1]+((l[1]%2==l[0]%2)^(l[1]%2==l[2]%2)),l[2]+((l[2]%2==l[0]%2)^(l[2]%2==l[1]%2))])
print((l[2]-l[0])//2+(l[2]-l[1])//2+p)

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

using ll = long long;
using ld  = long double;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;
const int INF=1e9+7;
const ll LINF=9223372036854775807;
const ll MOD=1e9+7;
const ld PI=acos(-1);
const ld EPS = 1e-10; //微調整用（EPSより小さいと0と判定など）

int ii() { int x; if (scanf("%d", &x)==1) return x; else return 0; }
long long il() { long long x; if (scanf("%lld", &x)==1) return x; else return 0; }
string is() { string x; cin >> x; return x; }
char ic() { char x; cin >> x; return x; }
void oi(int x) { printf("%d ", x); }
void ol(long long x) { printf("%lld ", x); }
void od_nosp(double x) { printf("%.15f", x); } // 古い問題用
void od(double x) { printf("%.15f ", x); }
// long doubleで受け取り、fをLfなどに変えて出力すると、変な数値が出る
// それをなんとかするには独自の出力を作らなければならなそう
void os(const string &s) { printf("%s ", s.c_str()); }
void oc(const char &c) { printf("%c ", c); }
#define o_map(v){cerr << #v << endl; for(const auto& xxx: v){cout << xxx.first << " " << xxx.second << "\n";}} //動作未確認
void br() { putchar('\n'); }

// #define gcd __gcd //llは受け取らない C++17~のgcdと違うので注意
// int lcm(int a, int b){return a / gcd(a, b) * b;}
#define begin_end(a) a.begin(),a.end() //sort(begin_end(vec));
#define REP(i,m,n) for(ll i=(ll)(m) ; i < (ll)(n) ; i++ )
#define DREP(i,m,n) for(ll i=(ll)(m) ; i > (ll)(n) ; i-- )
#define rep(i,n) REP(i,0,n)
#define m_p(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define p_b push_back
#define SZ(x) ((int)(x).size) //size()がunsignedなのでエラー避けに


// coutによるpairの出力（空白区切り）
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << " " << p.second << ")";}
// coutによるvectorの出力（空白区切り）
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i]; if (i < len - 1) s << " "; //"\t"に変えるとTabで見やすく区切る
  }
  return s;
}
// coutによる多次元vectorの出力（空白区切り）
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i] << endl;
  }
  return s;
}

//最大値、最小値の更新。更新したor等しければtrueを返す
template<typename T>
bool chmax(T& a, T b){return (a = max(a, b)) == b;}
template<typename T>
bool chmin(T& a, T b){return (a = min(a, b)) == b;}

//4近傍（上下左右） rep(i, 2) にすると右・下だけに進む
vector<int> dx_4 = {1, 0, -1, 0};
vector<int> dy_4 = {0, 1, 0, -1};

// -------- template end - //


// - library ------------- //




// --------- library end - //


int main(){

  ll N = il();

  vector<ll> ss;
  rep(i, N){
    ss.push_back(il());
  }
  sort(begin_end(ss));

  ll ans = 0;
  ll Q = il();
  rep(i, Q){
    ll t = il();
    if (*lower_bound(begin_end(ss), t) == t) ans++;
  }

  cout << ans << endl;

}


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


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

    vector<int> m(M,0);

    for(int i=0;i<N;i++){
        //cout << i;
        int k;
        cin >> k;
        for(int j=0;j<k;j++){
            //cout << j;
            int l;
            cin >> l;
            l--;
            m[l]++;
        }
    }
    int syurui = 0;
    for(int i=0;i<30;i++){
        if(m[i]==N)
        syurui++;
    }
    cout << syurui << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <string>
#include <typeinfo>
#include <random>
#include <vector>
 
using namespace std;
typedef long long ll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<vector<bool>> vvb;
typedef vector<vector<int>> vvi;
 
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define all(a) (a).begin(), (a).end()
 
int median(vi &a){
	int n=a.size();
	sort(all(a));
	return a.at((n-1)/2);
}

int lookUp(vi &a,int x){
	rep(i,a.size()){
		if(a.at(i)==x){
			return i;
		}
	}
	return -1;
}
 
int main()
{
	int n;
	cin>>n;
	vi x(n),sorted(n);
	rep(i,n){
		cin>>x.at(i);
		sorted.at(i)=x.at(i);
	}
	sort(all(sorted));
	rep(i,n){
		if(x.at(i)<sorted.at(n/2)){
			cout<<sorted.at(n/2)<<endl;
		}else{
			cout<<sorted.at(n/2-1)<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3712
#include <iostream>

using namespace std;
const int MAX_N = 100;

int main() {
  int n, a[MAX_N];

  cin >> n;
  for (int i = 0; i < n; ++i)
    {
      cin >> a[i];
    }

  for (int i = n-1; i > 0; --i)
    {
      cout << a[i] << " ";
    }

  cout << a[0] <<endl;
}

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

int MAX_N=262144;
vector<vector<int64_t>> seg(MAX_N*2-1,vector<int64_t>(2));
int64_t qu(int t,int a,int b,int k,int l, int r){
  if(r<=a||b<=l){
    return -1;
  }
  else if(a<=l&&r<=b){
    return seg[k][t];
  }
  else{
    int64_t X=qu(t,a,b,k*2+1,l,(l+r)/2);
    int64_t Y=qu(t,a,b,k*2+2,(l+r)/2,r);
    return max(X,Y);
  }
}

void chmax(int t,int64_t a,int b){
  int D=MAX_N-1+b;
  seg[D][t]=a;
  while(D>0){
    D--;
    D/=2;
    seg[D][t]=max(seg[2*D+1][t],seg[2*D+2][t]);
  }
}


int main(){
  int64_t N,Q;
  cin>>N>>Q;
  int64_t Z=(N-2)*(N-2);
  chmax(0,N,N-2);
  chmax(1,N,N-2);
  for(int i=0;i<Q;i++){
    int t,b,T;
    cin>>t>>b;
    t--;
    T=(t+1)%2;
    int l=0,r=N;
    while(r-l>1){
      int D=(l+r)/2;
      if(qu(T,0,D,0,0,MAX_N)>=b-1){
        r=D;
      }
      else{
        l=D;
      }
    }
    Z-=l;
    chmax(t,l,b-2);
  }
  cout<<Z<<endl;
}

Measured memory_bytes: 31780
#pragma target("avx")
#pragma optimize("O3")
#include<bits/stdc++.h>
using ll = int_fast64_t;
using P = std::pair<ll,ll>;
using PP = std::pair<ll,P>;
using V = std::vector<ll>;
template<typename T> using pq = std::priority_queue<T>;
template<typename T> using rpq = std::priority_queue<T, std::vector<T>, std::greater<T>>;

#define REP(i,b,e) for(ll i=b; i<e; i++)
#define ALL(vec) vec.begin(),vec.end()
#define PRINT(vec) printf("[ ");for(auto &i:vec)printf("%ld ",i);puts("]");
#define SCAN(vec) for(auto &i:vec)scanf("%ld",&i)
#define fi first
#define se second

const int MOD = 1e9+7;
const ll INF = 1e18;
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

int main(){
	int a=0, b=0;
	char c;
	while((c=getchar())!='\n'){
		if(c=='0') a++;
		else b++;
	}
	printf("%d\n", std::min(a,b)*2);
	return 0;
}



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

int daikei(int a,int b,int h){
    return (a+b)*h/2;
}

int main(){
  int a,b,h;

  cin>>a;
  cin>>b;
  cin>>h;

  cout<<daikei(a,b,h)<<endl;

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int l,r,O,p,i;
string s;
int main(){cin>>l;
for(i=0;i<l;i++){p=0;O=0;r=0;
  while(O<3){cin>>s;
    if(s=="HOMERUN"){p+=r+1;r=0;}
    if(s=="OUT"){O++;}
    if(s=="HIT"){if(r==3){p++;}else{r++;}}
}cout<<p<<"\n";}}

Measured memory_bytes: 1208
open Batteries
module EnumL = Enum.Labels
module ListL = List.Labels
module ArrayL = Array.Labels

let dbg0 x = Printf.eprintf "[debug]%s\n" @@ dump x
let dbg1 x = dbg0 x; x

let id = identity

let (++) n m = if n <= m then  List.range n `To m else []
let (++-) n m = if n >= m then List.range n `Downto m else []
let (++^) n m = if n < m then List.range n `To (pred m) else []

module ModOp = struct
  let prime = 1_000_000_007
  let (-) a b = (a + prime - b) mod prime
  let (+) a b = (a + b) mod prime
  let ( * ) a b = (a * b) mod prime

  let rec pow x n =
    if n = 0 then 1
    else if n mod 2 = 0 then pow (x*x) (n/2)
    else x * pow (x*x) (n/2)
end

let scan fmt = Scanf.sscanf (read_line ()) fmt

let scan_lines n fmt f =
  if n = 0 then []
  else List.map (fun _ -> scan fmt f) (1 ++ n)

let scan_list ?sep cnv =
  let line = read_line () in
  (match sep with
   | None -> List.map String.of_char @@ String.to_list line
   | Some sep -> String.split_on_char sep line)
  |> List.map cnv

let scan_array ?sep cnv = Array.of_list @@ scan_list ?sep cnv

let scan_matrix n m e ?sep conv =
  let arr = Array.make_matrix n m e in
  ListL.iter (0 ++^ n)
    ~f:(fun i -> arr.(i) <- Array.of_list @@ scan_list ?sep conv);
  arr

let atoi c = Char.code c - Char.code '0'
let itoa n = Char.chr (n + Char.code '0')

let rec powerset = function
  | [] -> [[]]
  | hd::tl ->
    let pws =  powerset tl in
    pws @ ListL.map pws ~f:(fun pw -> hd::pw)

let permutations l =
  let rec interleave x = function
    | [] -> [[x]]
    | (hd::tl) as l ->
      (x::l) :: (interleave x tl |> ListL.map ~f:(fun l -> hd::l)) in
  let rec aux = function
    | [] -> [[]]
    | a::rest ->
      aux rest |> ListL.map ~f:(interleave a) |> List.concat in
  aux l

let intersection l =
  EnumL.filter ~f:(fun x -> EnumL.exists ~f:((=) x) @@ Enum.clone l)

let zip l m =
  let n = min (List.length l) (List.length m) in
  List.combine (List.take n l) (List.take n m)

let lower_bound n f =
  let rec aux l u =
    if u - l > 1 then
      let m = (l + u) / 2 in
      if f m then aux l m
      else aux m u
    else u in aux (-1) n

let between n x m = n <= x && x < m

let n = scan "%d" id
let a = scan_list ~sep:' ' Int.of_string

let () =
  0::(ListL.mapi a ~f:(fun i v ->
      if i mod 2 = 0 && v mod 2 = 1 then 1 else 0
    ))
  |> List.sum
  |> Printf.printf "%d\n"


Measured memory_bytes: 5476
N,M,K=map(int,input().split())  
par=[i for i in range(N)]
rank=[0]*(N)
friend=[0]*N
block=[0]*N
size=[1]*N
def find(x):
  if par[x]==x:
    return x
  else:
    par[x]=find(par[x])
    return par[x]

#同じ集合か判定
def same(x,y):
  return find(x)==find(y)

def union(x,y):
  x=find(x)
  y=find(y)
  if x==y:
    return 
  if rank[x]>rank[y]:
    par[y]=x
    size[x]+=size[y]
  else:
    par[x]=y
    size[y]+=size[x]
    if rank[x]==rank[y]:
      rank[y]+=1


for i in range(M):
  a,b=map(int,input().split())
  a-=1
  b-=1
  union(a,b)
  friend[a]+=1
  friend[b]+=1

for i in range(K):
  c,d=map(int,input().split())
  c-=1
  d-=1
  if same(c,d):
    block[c]+=1
    block[d]+=1
    
ans=[]
for i in range(N):
  ans.append(size[find(i)]-friend[i]-block[i]-1)
print(*ans)

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

bool func(const pair< int, pair<int,int> > a, const pair< int, pair<int, int> > b){
    return a.first < b.first;
}

int main(void){
    int N, M;
    while(cin >> N >> M, N | M){
        vector<bool> v(N, false);
        v[0] = true;
        vector< pair< int, pair<int, int> > > p(M);
        for(int i = 0; i < M; i++){
            int a, b, c; cin >> a >> b >> c;
            b--; c--;
            p[i].first = a;
            p[i].second.first = b;
            p[i].second.second = c;
        }
        sort(p.begin(), p.end(), func);
        for(int i = 0; i < M; i++) v[ p[i].second.second ] = v[ p[i].second.second ] || v[ p[i].second.first ];
        int ans = 0;
        for(int i = 0; i < N; i++){
            if(v[i] == true) ans++;
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3248
/* ***********************************************
Author        :caowushang
Created Time  :2016/8/3 19:18:25
TASK		  :新建.cpp
LANG          :C++
************************************************ */

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdlib>
#define inf 99999999
#define cl(x,v) memset(x,v,sizeof(x))
#define PI 3.14159265358979323
#define LL long long int
using namespace std;
const int MX=1e5+10;
const int mod=1e9+7;
int N[MX];
int n;
int main()
{
    //freopen("in.txt","r",stdiin);
    //freopen("out.txt","w",stdout);
    while(cin >> n)
	{
		long long ans=0;
		for(int i=0;i<n;i++)
		{
			scanf("%d",&N[i]);
		}
		ans+=N[0]/2;
		for(int i=1;i<n;i++)
		{
			if(N[i-1]&1&&N[i]>=1)
				N[i]--,ans++;
			ans+=N[i]/2;
		}
		cout << ans << endl;
	}	
    return 0;
}


Measured memory_bytes: 640
import sys

def solve(n,k,ar):

    dp = [sys.maxsize]*n
    dp[0] = 0

    for i in range(n):
        for k in range(1,k+1):
            if i+k <= n-1:
                dp[i+k] = min(dp[i+k], dp[i] + abs(ar[i]-ar[i+k]))

    print(dp[n-1])



if __name__ == '__main__':
    n,k = map(int,input().split())
    ar = list(map(int,input().split()))

    solve(n,k,ar)

Measured memory_bytes: 84860
#![allow(
  non_snake_case,
  unused_variables,
  unused_assignments,
  unused_mut,
  unused_imports,
  unused_macros,
  dead_code
)]
use proconio::fastout;
use proconio::input;
use proconio::marker::*;
use std::cmp::*;
use std::collections::*;
//use std::collections::VecDeque;
macro_rules! debug {
  ($($a:expr),* $(,)*) => {
      #[cfg(debug_assertions)]
      eprintln!(concat!($("| ", stringify!($a), "={:?} "),*, "|"), $(&$a),*);
  };
}
#[fastout]
fn main() {
  input! {
    N:usize,
    A:[usize;N]
  }
  let N: usize = N;
  let mut nmax = 1000_000usize;
  let mut h = vec![0usize; nmax + 1];
  for i in 0..N {
    h[A[i]] += 1;
  }
  let mut mx = 0;
  let mut isprime = vec![true; nmax + 1];
  isprime[0] = false;
  isprime[1] = false;
  let mut i = 2;
  while i * i <= nmax {
    if isprime[i] {
      let mut j = 2;
      while i * j <= nmax {
        isprime[i * j] = false;
        j += 1;
      }
      let mut f = 0usize;
      for q in 1..=nmax / i {
        let a = i * q;
        f += h[a];
      }
      mx = max(mx, f);
    }
    i += 1;
  }
  let mut pflag = true;
  for p in i + 1..=nmax {
    if isprime[p] {
      let mut f = 0usize;
      for q in 1..=nmax / p {
        let a = p * q;
        f += h[a];
      }
      mx = max(mx, f);
    }
  }
  if mx <= 1 {
    println!("pairwise coprime");
    return;
  } else if mx < N {
    println!("setwise coprime");
  } else {
    println!("not coprime")
  }
}


Measured memory_bytes: 25156
n, k = map(int, input().split())

import math
ans = 0
for i in range(1,n+1):
  if i < k:
    t = math.log10(k/i)/math.log10(2)
    if t == int(t):
      ans += 1/(2**t)
    else:
      ans += 1/(2**(int(t+1)))
  else:
    ans += 1
  
print(ans/n)

Measured memory_bytes: 9196
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr<<#x<<": "<<x<<endl

int main(){
    ll n;
    cin >> n;
    vector<ll> s(n);
    for(int i = 0; i < n; i++){
        cin >> s[i];
    }

    ll ans = 0;
    for(int c = 0; c < n; c++){
        ll score = 0;
        vector<bool> used(n,false);
        for(int k = 0; k < n; k++){
            ll a = n-1 -k*c;
            ll b = a-c;
            if(a<=0 || b<=0){break;}
            if(used[k*c]){break;}
            score += s[k*c];
            used[k*c] = true;
            if(used[n-1-k*c]){break;}
            score += s[n-1-k*c];
            used[n-1-k*c] = true;
            ans = max(ans, score);
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
    string a;
    cin>>a;
    string b=a;
    reverse(a.begin(),a.end());
    for(int i=0;i<a.size();i++)
    {
        if(a[i]=='b') a[i]='d';
        else if(a[i]=='d') a[i]='b';
        else if(a[i]=='p') a[i]='q';
        else if(a[i]=='q') a[i]='p';
    }
    if(a==b) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 512
from collections import Counter
H,W,N = map(int,input().split())
Bs = []
for i in range(N):
    x,y = map(int,input().split())
    for xx in range(3):
        for yy in range(3):
            tx,ty = x-xx,y-yy
            if 1<=tx and tx<=H-2 and 1<=ty and ty<=W-2:
                Bs.append((tx,ty))
C = [0]*10
for (x,y),v in Counter(Bs).most_common():
    C[v] += 1
C[0] = (H-2)*(W-2)-sum(C)
for i in range(10):
    print(C[i])
    

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


void solve(long long N, std::vector<std::string> s){
  for (auto &&str : s) {
    std::sort(str.begin(), str.end());
  }

  unordered_map<string, uint64_t> res;

  uint64_t ans = 0;
  for (auto &&str : s) {
    ++res[str];
    if (res[str] > 1) ans += res[str] - 1;
  }

  std::cout << ans << std::endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<std::string> s(N);
    for(int i = 0 ; i < N ; i++){
        std::cin >> s[i];
    }
    solve(N, std::move(s));
    return 0;
}


Measured memory_bytes: 17700
#include<iostream>
using namespace std;
int main(){
 int a,b;
 char op;
	while(cin>>a){
		cin>>op>>b;
			if(op=='?'){
				break;
			}
			if(op=='+'){
				cout<<a+b<<endl;	
			}
			else if(op=='-'){
				cout<<a-b<<endl;
			}
			else if(op=='*'){
				cout<<a*b<<endl;
			}
			else if(op=='/'){
				cout<<a/b<<endl;
			}
	}
return 0;
}

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

bool c[300001];
int d, a;

bool solve(int p){

  if(p > d) return false;
  if(c[p]) return true;

  return solve(p+a);
}

int main(){

  int n, q, k;
  cin >> n >> q;

  for(int i=0;i<n;i++){
    cin >> k;
    c[k] = true;
    d = max(k, d);
  }

  while(q--){
    cin >> a;

    for(int i=a-1;i>=0;i--){
      if(solve(i)){
	cout << i << endl;
	break;
      }
    }

  }
}

Measured memory_bytes: 1452
n = int(input())
m = [[0] * n for i in range(n)]
for i in range(n):
    line = [int(v) for v in input().split()]
    u = line[0] - 1
    for v in line[2:]:
        v -= 1
        m[u][v] = 1

for row in m:
    print(' '.join([str(v) for v in row]))


Measured memory_bytes: 5668