akhauriyash/Code-Regression huggingface dataset:
n = int(input())
s = [input() for i in range(n)]

ac = 0
wa = 0
tle = 0
re = 0

for i in s:
    if i == "AC":
        ac += 1
    elif i == "WA":
        wa += 1
    elif i == "TLE":
        tle += 1
    elif i == "RE":
        re += 1

print("AC" + " x " + str(ac))
print("WA" + " x " + str(wa))
print("TLE" + " x " + str(tle))
print("RE" + " x " + str(re))

Measured memory_bytes: 16324
/**
  * @brief atcoder
  * @author yao
  */
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <utility>
#include <algorithm>
#include <functional>
#include <climits>
#include <cmath>
#define ft first
#define sd second
#ifdef DBG
#   define dbg_pri(x...) fprintf(stderr,x)
#else
#   define dbg_pri(x...) 0
#   define NDEBUG
#endif //DBG
#include <cassert>

typedef unsigned int uint;
typedef long long int lli;
typedef unsigned long long int ulli;

#define N 512
#define M 32
#define K 1048576
#define T 256

int c[M];
int s[N][M];
int t[N];
int l[M];
int sc;

const int n = 365, m = 26;

int count()
{
    int ct = 0;
    memset(l,-1,sizeof(l));
    int res = 0;
    for(int i=0;i<n;++i)
    {
        ct += sc;
        ct -= (i-l[t[i]]) * c[t[i]];
        l[t[i]] = i;
        res += s[i][t[i]];
        res -= ct;
    }
    return res;
}

int main()
{
    int d;
    scanf("%d", &d);
    assert(d == 365);
    for(int i=0;i<m;++i) scanf("%d", &c[i]), sc += c[i];
    for(int i=0;i<n;++i)for(int j=0;j<m;++j) scanf("%d", &s[i][j]);
    //t[0] = 0, t[1] = 16, t[2] = 12, t[3] = 13, t[4] = 12;
    for(int i=0;i<n;++i) t[i] = rand() % m;
    int val = count();
    dbg_pri("poi 1: %d\n", val);
    int ca=0, cb=0;
    for(int i=0;i<K;++i)
    {
        int x = rand()%n, k = rand()%m;
        int pre_t = t[x];
        t[x] = k;
        int nxt_v = count();
        if(nxt_v >= val || rand() <= (int)(exp((double)(nxt_v-val)/T)*((lli)RAND_MAX+1)))
        {
            (nxt_v < val ? ca : cb) ++;
            val = nxt_v;
            dbg_pri("poi 2: %d %d\n", i, val);
        }
        else t[x] = pre_t;
    }
    for(int i=0;i<n;++i) printf("%d\n", t[i]+1);
    dbg_pri("poi 3: %d %d %d\n", val, ca, cb);
    return 0;
}


Measured memory_bytes: 2828
import java.io.*;
class Main{
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String id1 = br.readLine();
        String id2 = br.readLine();
        if(id1.length() != id2.length() -1) {
            System.out.println("No");
            return;
        }
        String subString = id2.substring(0,id2.length()-1);
        if(id1.equals(subString)){
            System.out.println("Yes");
            return;
        }
        System.out.println("No");
    }
}

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

int main(void)
{
    char s[100], t[100];
    cin >> s >> t;
    int flag2 = 0;

    //cout << (int)strlen(s) - 1 << endl;
    //cout << (int)strlen(t) << endl;

    for(int i = (int)strlen(s) - 1; i - (int)strlen(t) + 1 >= 0; i--){
        //cout << " " << i << " " << i - (int)strlen(t) + 1 << endl;
        flag2 = 1;
        for(int j = i - (int)strlen(t) + 1; j <= i; j++){
            //cout << j - i + (int)strlen(t) << endl;
            if(s[j] != '?' && s[j] != t[j - i + (int)strlen(t) - 1]){
                flag2 = 0;
                break;
            }
        }

        if(flag2){
            for(int j = i - (int)strlen(t) + 1; j <= i; j++){
                //cout  << i << " "<< j << " " << endl;
                s[j] = t[j - i + (int)strlen(t) - 1];
                //cout << s[j] << " ";
                //cout << s << " " << t << endl;
            }
            break;
        }
    }
    //cout << s << endl;
    
    for(int i = 0; s[i] != '\0'; i++){
        if(s[i] == '?') s[i] = 'a';
    }

    if(flag2){
        cout << s << endl;
    }else{
        cout << "UNRESTORABLE" << endl;
    }
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
	int N, M, i;
	if(scanf("%d%d", &N, &M));
	for(i=N; i<=M/21; i++){
		if(M%i==0){
			printf("%d\n", M/i);
			return 0;
		}
	}
	if(M%20==0 && M/19>=N){printf("20\n");return 0;}
	if(M%19==0 && M/19>=N){printf("19\n");return 0;}
	if(M%18==0 && M/18>=N){printf("18\n");return 0;}
	if(M%17==0 && M/17>=N){printf("17\n");return 0;}
	if(M%16==0 && M/16>=N){printf("16\n");return 0;}
	if(M%15==0 && M/15>=N){printf("15\n");return 0;}
	if(M%14==0 && M/14>=N){printf("14\n");return 0;}
	if(M%13==0 && M/13>=N){printf("13\n");return 0;}
	if(M%12==0 && M/12>=N){printf("12\n");return 0;}
	if(M%11==0 && M/11>=N){printf("11\n");return 0;}
	if(M%10==0 && M/10>=N){printf("10\n");return 0;}
	if(M%9==0 && M/9>=N){printf("9\n");return 0;}
	if(M%8==0 && M/8>=N){printf("8\n");return 0;}
	if(M%7==0 && M/7>=N){printf("7\n");return 0;}
	if(M%6==0 && M/6>=N){printf("6\n");return 0;}
	if(M%5==0 && M/5>=N){printf("5\n");return 0;}
	if(M%4==0 && M/4>=N){printf("4\n");return 0;}
	if(M%3==0 && M/3>=N){printf("3\n");return 0;}
	if(M%2==0 && M/2>=N){printf("2\n");return 0;}
	printf("1\n");
	return 0;
}


Measured memory_bytes: 128
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import bisect

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

def LI(): return list(map(int, sys.stdin.readline().split()))
N = int(input())
B = LI()

ans = B[0]
for i in range(N-1):
    if i == N-2:
        ans += B[-1]
    else:
        ans += min(B[i],B[i+1])
print(ans)


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

vector<int> to[200005];
vector<int> ans;

void dfs(int v,int p=-1){
    for(int u: to[v]){
        if(u==p) continue;
        ans[u] += ans[v];
        dfs(u,v);
    }
}

int main(){
    int n,q;cin>>n>>q;
    rep(i,n-1){
        int a,b;
        cin >> a >> b;
        a--;b--;
        to[a].push_back(b);
        to[b].push_back(a);                                                      }                                                                            ans.resize(n);
    rep(i,q){
        int p,x;
        cin >> p >> x;
        --p;
        ans[p] += x;
    }
    dfs(0);
    rep(i,n){
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 23424
using System;
class Program
{
    static void Main(string[] args)
    {
        string[] input = Console.ReadLine().Split(' ');
        int a = int.Parse(input[0]);
        int b = int.Parse(input[1]);

        if (a <= 9 && b <= 9)
        {
            Console.WriteLine(a * b);
        }
        else
        {
            Console.WriteLine(-1);
        }
    }
}

Measured memory_bytes: 11092
result = []
ary = readlines.map(&:chomp)
ary.delete_at(0)

r_a = 0
r_b = 0
ary.each_with_index do |v, k|
  a, b = v.split(" ").map(&:to_i)

  if k == 0
    r_a = a
    r_b = b
  else
    if a > r_a
      r_a = a
    end
    if b < r_b
      r_b = b
    end
  end
end

p (r_a..r_b).to_a.size

Measured memory_bytes: 16636
// ナップザック問題を解く //
// 未解決
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;

// 構造体と配列のどっちがいいのかわからない //
int N, W, i, c;
int treasure[1010][2];


int main()
{
  cin >> N >> W;
  for(int k=1; k<=N; k++){
    cin >> treasure[k][0] >> treasure[k][1]; // k番目の価値、重さ
  }
  int val[1010][10010]; // i, c i番目の品物までの重さcでの最大価値

  for(int i=0; i<=N; i++){ //いわゆる初期化？
    val[i][0] = 0;
  }
  for(int c=0; c <=W; c++){
    val[0][c] = 0;
  }

  for(int i=1; i<=N; i++){
    for(int c=1; c<=W; c++){

      if(c<treasure[i][1]){
        val[i][c] = val[i-1][c]; //重さcにはi番目ははいらない
      }
      else{
        val[i][c] = max(val[i-1][c-treasure[i][1]] + treasure[i][0], val[i-1][c]);
      }
    }
  }
  cout << val[N][W] <<endl;
  return 0;
}



Measured memory_bytes: 7056
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
int n;
const int maxN = (int)1e5 + 100;
bool touched[maxN];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    //freopen("input.txt", "r", stdin);
    cin >> n;
    vector < ll > all(n);
    for (int i = 0; i < n; i++) {
        cin >> all[i];
    }
    ll sum = 0;
    for (int i = 0; i < n; i++) {
        int b;
        cin >> b;
        all[i] -= b;
        sum += all[i];
    }
    if (sum < 0) {
        cout << -1;
        return 0;
    }
    sort(all.begin(), all.end());
    int i = 0;
    while (i < all.size()) {
        if (all[i] >= 0) break;
        touched[i] = true;
        if (all.back() + all[i] > 0) {
            touched[all.size() - 1] = true;
            all.back() += all[i];
            i++;
            continue;
        }
        else {
            touched[all.size() - 1] = true;
            all[i] += all.back();
            all.pop_back();
            continue;
        }
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (touched[i]) ans++;
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
const long long INF = 1e15;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);

    ll n;
    cin >> n;
    vector<vector<ll>> a(3,vector<ll>(n));

    for(ll i = 0; i < 3; i++){
        for(ll j = 0; j < n; j++){
            cin >> a[i][j];
        }
        sort(a[i].begin(),a[i].end(),greater<ll>());
        
    }

    vector<ll> cnt(n,n);
    ll now = 0;

    for(ll i = 0; i < n; i++){
        for(ll j = now; j < n; j++){
            if(a[2][j] <= a[1][i]){
                cnt[i] = j;
                break;
            }
            now++;
        }
    }
    ll ans = 0;
    now = 0;

    vector<ll> sum(n,0);
    ll tmp = 0;

    for(ll i = 0; i < n; i++){
        tmp += cnt[i];
        sum[i] += tmp;
    }

    ll can = 0;
    for(ll i = 0; i < n; i++){
        if(a[1][n-1] > a[0][i]){
            ans += sum[n-1];
            continue;
        }
        for(ll j = now; j < n; j++){
            if(a[1][j] <= a[0][i]){
                ans += can;
                break;
            } else can = sum[j];
            now++;
        }

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

Measured memory_bytes: 7032
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <limits.h>
#include <math.h>

#include <iostream>
#include <string>
#include <vector>
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>

using namespace std;

#define FOR(i,s,e) for((i)=(s);(i)<(int)(e);(i)++)

typedef long long ll;
double EPS = 1e-6;
const double g = 9.8;
const int N = 50;
int n, v, X, Y;
int L[N], R[N], T[N], B[N];

//速度vyで上に打ち出した際のt秒後の位置を計算
double calc(double vy, double t) {
	return vy*t - g*t*t*0.5;
}

//aのlb,ubに対する相対位置関係(lbより下:-1, lb以上ub以下:0, ubより上:1)
int relPos(double lb, double ub, double a) {
	return a < lb+EPS ? -1 : (a > ub-EPS ? 1 : 0);
}

//点(x,y)を通るように打ち出したときに豚に卵をぶつけられるか判定
bool success(double x, double y) {
	double a = g*g*0.25, b = g*y-v*v, c = x*x+y*y;
	double D = b*b - a*c*4.0;

	if (D<0.0 && D>-EPS) D = 0.0;
	if (D<0.0) return false;

	for (int d=-1; d<=1; d+=2) {
		double t2 = (-b + d*sqrt(D)) / (a*2.0);
		if (t2<=0) continue;
		double t = sqrt(t2);
		double vx = x / t, vy = (y + g*t*t*0.5) / t;

		double yt = calc(vy, X / vx);
		if (yt < Y-EPS) continue;

		bool ok = true;
		for (int i=0; i<n; i++) {
			if (L[i]>=X) continue;

//			if (L[i]<=X && X<=R[i] && Y<=T[i] && B[i]<=yt) ok = false;
			if (X==R[i] && Y<=T[i] && B[i]<=yt) ok = false;

			int yL = relPos(B[i], T[i], calc(vy, L[i]/vx));
			int yR = relPos(B[i], T[i], calc(vy, R[i]/vx));
			int xH = relPos(L[i], R[i], vx*(vy/g));
			int yH = relPos(B[i], T[i], calc(vy, vy/g));

			if (xH==0 && yH>=0 && yL<0) ok = false;
			if (yL*yR<=0) ok = false;
		}
		if (ok) return true;
	}
	return false;
}

int main() {

	scanf("%d%d%d%d ", &n, &v, &X, &Y);
	for (int i=0; i<n; i++)
		scanf("%d%d%d%d ", L+i, B+i, R+i, T+i);

//
	for (int i=0; i<n; i++)
		R[i] = min(R[i], X);



	bool ok = success(X, Y);

	for (int i=0; i<n; i++) {
		ok |= success(L[i], T[i]);
		ok |= success(R[i], T[i]);
	}

	puts(ok ? "Yes" : "No");
    
	return 0;
}

Measured memory_bytes: 1172
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
 
int main() {
    string S;
    cin >> S;
    vector<string> a={"SUN","MON","TUE","WED","THU","FRI","SAT","SUN"};
    rep(i,7){
        if(S==a.at(i)){
            cout << 7-i << endl;
            break;                }
    }
}

Measured memory_bytes: 256
import java.util.*;
import java.util.Collections;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    String S = sc.next();
    int cnt = 0;
    int max = 0;
    for (int i = 0; i < N; i++) {
      if (S.charAt(i) == 'I') {
        cnt++;
        max = Math.max(cnt, max);
      } else {
        cnt--;
      }
    }
    System.out.println(max);
  }
}


Measured memory_bytes: 21332
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		String ans = "" + s.charAt(0) + (s.length()-2) + s.charAt(s.length()-1);

		System.out.println(ans);
	}

}

Measured memory_bytes: 23636
using System;

namespace AtCoderBeginerContest146_A_Can_t_Wait_for_Holiday
{
    class Program
    {
        static void Main(string[] args)
        {
            string S=Console.ReadLine();
            if (S == "SUN") 
            {
                Console.WriteLine(7);
            }
            else if (S == "MON")
            {
                Console.WriteLine(6);
            }
            else if (S == "TUE")
            {
                Console.WriteLine(5);
            }
            else if (S == "WED")
            {
                Console.WriteLine(4);
            }
            else if (S == "THU")
            {
                Console.WriteLine(3);
            }
            else if (S == "FRI")
            {
                Console.WriteLine(2);
            }
            else if (S == "SAT")
            {
                Console.WriteLine(1);
            }
            Console.ReadKey();
        }
    }
}

Measured memory_bytes: 11092
#include <iostream>
#include<string>
#include<math.h>
#include<stdio.h>
#include <algorithm>
using namespace std;
int main(void){
    // Here your code !
  int x[1000],y[1000];
  int n;
  double D1=0,D2=0,D3=0,D=0;
  
  cin>>n;
 for(int i=0;i<n;i++){
 cin>>x[i];
 }
  for(int i=0;i<n;i++){
 cin>>y[i];
 }
 
  for(int i=0;i<n;i++){
 D1=D1+pow(abs(x[i]-y[i]),1);
 D2=D2+pow(abs(x[i]-y[i]),2);
 D3=D3+pow(abs(x[i]-y[i]),3);
 if(D<abs(x[i]-y[i])) D=abs(x[i]-y[i]);
 } 
 D2=pow(D2,(double)1/2);
 D3=pow(D3,(double)1/3);
 printf("%.6f\n",D1);
  printf("%.6f\n",D2);
   printf("%.6f\n",D3);
    printf("%.6f\n",D);

return 0;
}

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

using namespace std;

typedef long long int ll;

const int N = 1e3 + 5;

vector < vector < pair < int, int > > > adj (N);
vector < ll > d (N, LLONG_MAX);
vector < int > color (N);

void dfs (int u) {
  color[u] = 1;
  for (auto edge : adj[u]) {
    int to = edge.first, len = edge.second;
    if (d[to] == LLONG_MIN) continue;
    if (d[u] == LLONG_MIN || d[u] + len < d[to]) {
      if (color[to] == 1 || d[u] == LLONG_MIN) {
        d[to] = LLONG_MIN;
      } else {
        d[to] = d[u] + len;
      }
      dfs (to);
    }
  }
  color[u] = 2;
}

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

  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int u, v, wt;
    cin >> u >> v >> wt;
    adj[u].push_back ({v, -wt});
  }

  for (int i = 1; i < N; i++) {
    sort (adj[i].begin(), adj[i].end(), [] (const pair < int, int > lhs, const pair < int, int > rhs) -> bool {
            return lhs.second < rhs.second;
          });
  }

  d[1] = 0;
  dfs (1);

  if (d[n] == LLONG_MIN) cout << "inf\n";
  else cout << -d[n] << '\n';
}


Measured memory_bytes: 3752
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
using ll = long long;

const long double PI = acos(-1.0);
const int MOD = 1e9 + 7;

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

    int ans = 0;
    if(n <= 2) {
        ans = 0;
        cout << ans << endl;
        return 0;
    }

    for(int i = 0; i < n - 2; i++) {
        for(int j = i + 1; j < n - 1; j++) {
            for(int k = j + 1; k < n; k++) {
                if(l[i] == l[j] || l[j] == l[k] || l[k] == l[i]) continue;
            
                ll wa = l[j] + l[k];
                ll sa = abs(l[j] - l[k]);
                if(sa < l[i] && l[i] < wa) {
                    // cout << l[i] << l[j] << l[k] << endl;
                    ans++;
                }
                
                
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3592
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <unordered_set>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
#include <numeric>
#include <algorithm>
#include <utility>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;


// 68 11 55 - rank 3
// 69 12 19 - rank 3
// 70 12 34 - rank 100
// 71 12 58 - rank 4
// 72 13 24 - rank 20
// 73 13 39

ull gcd(ull a, ull b) {
    while (b != 0) {
        auto na = a % b;
        a = b;
        b = na;
    }
    return a;
}


void oneCase() {
    int n;
    cin >> n;
    map<int, int> cnt;
    for (int i =0; i < n; ++i) {
        int a;
        cin >> a;
        ++cnt[a];
    }
    int ans = 0;
    for (auto p : cnt) {
        ans += p.second % 2;
    }
    cout << ans << "\n";
}


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

    return 0;
}

ll fact(ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        res = (res * n) % mod;
        --n;
    }
    return res;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
int main()
{
    bool chk=true;
    vector<int> A(5);
    int k;
    for (int i = 0; i < 5; i++)
    {
        cin >> A.at(i);
    }
    cin >> k;
    for(int i=0; i<5; i++)
    {
        for (int j = 0; j < 5; j++)
        {
            if(k<abs(A.at(i)-A.at(j)))
            {
                chk=false;
            }
        }
    }
    if(chk)
    {
        cout << "Yay!" << endl;
    }
    else
    {
        cout << ":(" << endl;
    }
    
}


Measured memory_bytes: 3564
#include<stdio.h>
#include<string.h>

int main(){
  
  char s[100],t[100];
  char temp;
  scanf("%s %s",s,t);

  int len_s,len_t;
  len_s = strlen(s);
  len_t = strlen(t);
  int count = 0;
  
  if(len_s > len_t){
    count = len_s;
  }else{
    count = len_t;
  }

//  printf("%d %d",len_s,len_t);

  for(int i=1; i<len_s; i++){
    for(int j=1; j<len_s; j++){
      if(s[j-1] > s[j]){
        temp = s[j-1];
        s[j-1] = s[j];
        s[j] = temp;
      }
    }
  }

  for(int i=1; i<len_t; i++){
    for(int j=1; j<len_t; j++){
      if(t[j-1] < t[j]){
        temp = t[j-1];
        t[j-1] = t[j];
        t[j] = temp;
      }
    }
  }

//  printf("%s\n%s\n",s,t);

  for(int i=0; i<count; i++){
    if(s[i] == '\0'){
      printf("Yes");
      return 0;
    }else if(t[i] == '\0'){
      printf("No");
      return 0;
    }

    if(s[i] < t[i]){
      printf("Yes");
      return 0;
    }else if(s[i] > t[i]){
      printf("No");
      return 0;
    }
  }

  printf("No");

}

Measured memory_bytes: 128
int main(){
  int a,b=0;
  scanf("%d",&a);
  for(int i=1;i<=50000;i++){
    if((int)(i*1.08)==a){
      printf("%d",i);
      b=1;
      break;
    }
  }
  if(b==0)printf(":(");
  return 0;
}

Measured memory_bytes: 128
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.NoSuchElementException;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		int N = sc.nextInt();
		for (int i = 1; i < 10; i++) {
			int ans = i*100 + i*10 + i;
			if (ans - N < 111 && ans - N >= 0) { 
				System.out.println(ans);
				return;
			}
		}
	}
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte())
            return buffer[ptr++];
        else
            return -1;
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr]))
            ptr++;
        return hasNextByte();
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext())
            throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }

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

Measured memory_bytes: 21204
#include <bits/stdc++.h>
#define LLI long long int
#define FOR(v, a, b) for(LLI v = (a); v < (b); ++v)
#define FORE(v, a, b) for(LLI v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(LLI v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define fst first
#define snd second
#define popcount __builtin_popcount
#define UNIQ(v) (v).erase(unique(ALL(v)), (v).end())
#define bit(i) (1LL<<(i))
#define sz(v) ((LLI)(v).size())

#ifdef DEBUG
#include <misc/C++/Debug.cpp>
#else
#define dump(...) ((void)0)
#endif

#define gcd __gcd

using namespace std;
template <class T> constexpr T lcm(T m, T n){return m/gcd(m,n)*n;}

template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}
template <typename T, typename U> istream& operator>>(istream &is, pair<T,U> &p){is >> p.first >> p.second; return is;}

template <typename T, typename U> bool chmin(T &a, const U &b){return (a>b ? a=b, true : false);}
template <typename T, typename U> bool chmax(T &a, const U &b){return (a<b ? a=b, true : false);}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}

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

  int N,L;
  while(cin >> N >> L){
    vector<int> t(N);
    REP(i,N) t[i] = L+i;

    int ans = accumulate(ALL(t),0) - *min_element(ALL(t), [](int a, int b){return abs(a) < abs(b);});

    cout << ans << endl;
  }

  
  return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.*;
import java.util.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Collections;
import java.io.Serializable;

public class Main {
	public static void main(final String[] args){
    
        Scanner sc = new Scanner(System.in);

        int x = sc.nextInt();
        int count = 0;

        for(int i = 1 ; i < 10 ; i++){
            for(int j = 1 ; j < 10 ; j++){
                if(i * j == x){
                    count++;
                }
            }
        }

        if(count == 0){
            System.out.println("No");
        }else{
            System.out.println("Yes");
        }
        

        


    }
}

Measured memory_bytes: 22996
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define divup(a,b) ( ( (a) + ( (b) - 1u) ) / (b) ) // a/b の余り切り上げ
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
const ll mod = 1000000007;
const ll mod9 = 1000000009;

signed main(){
    ll x,y;
    cin>>x>>y;
    bool f=0;
    rep(i,x+1){
        if(2*i+4*(x-i)==y){
            f=1;
        }
    }
    if(f) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


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

using namespace std;
using ll = long long;
using pint = pair<int, int>;

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

	int ans = 1;
	double sq = sqrt(X);

	for (int b = 1; b <= X; ++b) {
		int tmp = b;
		for (int p = 2; p <= 10; ++p) {
			tmp *= b;

			if (tmp <= X) {
				ans = max(ans, tmp);
			}
			else {
				break;
			}
		}
	}

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


Measured memory_bytes: 3676
#include<iostream>
#include<algorithm>
using namespace std;
static const int MAX = 1000;
static const int VMAX = 10000;

int n, A[MAX], s;
int B[MAX], T[VMAX + 1];

int solve() {
	int ans = 0;


	bool V[MAX];
	for (int i = 0; i < n; i++) {
		B[i] = A[i];
		V[i] = false;


	}
	sort(B, B + n);
	for (int i = 0; i < n; i++) T[B[i]] = i;
	for (int i = 0; i < n; i++) {
		if (V[i])continue;
		int cur = i;
		int S = 0;
		int m = VMAX;
		int an = 0;
		while (1) {
			V[cur] = true;
			an++;
			int v = A[cur];
			m = min(m, v);
			S += v;
			cur = T[v];
			if (V[cur])break;

		}
		ans += min(S + (an - 2)*m, m + S + (an + 1)*s);
	}
	return ans;
}


int main() {
	cin >> n;
	s = VMAX;
	for (int i = 0; i < n; i++) {
		cin >> A[i];
		s = min(s, A[i]);

	}

	int ans = solve();
	cout << ans << endl;

}


Measured memory_bytes: 3176
N = int(input())
Mat = [[0]*10 for _ in range(10)]
for i in range(1,N+1):
    s = str(i)
    Mat[int(s[0])][int(s[-1])] +=1
ans = 0
for i in range(10):
    for j in range(10):
        ans += Mat[i][j]*Mat[j][i]
print(ans)

Measured memory_bytes: 3064
package main

import "fmt"

func main() {
	var n, m int
	fmt.Scan(&n, &m)

	if n == 1 && m == 1 {
		fmt.Println(1)
		return
	}
	if n == 1 && m > 1 {
		fmt.Println(m - 2)
		return
	}
	if n > 1 && m == 1 {
		fmt.Println(n - 2)
		return
	}
	fmt.Println((n - 2) * (m - 2))
}


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

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

  int W, a, b;
  cin >> W >> a >> b;

  cout << (abs(a - b) <= W ? 0 : abs(a - b) - W) << endl;
  return 0;
}


Measured memory_bytes: 256
#include "stdio.h"
int main()
{
  int a,b,c;
  scanf("%d%d%d",&a,&b,&c);
  if(a==b)
  {
    if(a==c)
      printf("No\n");
    else
      printf("Yes\n");
  }
  else
  {
    if(a==c||b==c)
      printf("Yes\n");
    else
      printf("No\n");
  }
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
const int maxn = 4000 + 10;
typedef long long ll;
const ll mod = 998244353;
ll bin[maxn], fac[maxn], inv[maxn], facinv[maxn], a[maxn];
void init()
{
	bin[0] = 1;
	for(int i = 1; i < maxn; ++i)
		bin[i] = bin[i - 1] * 2 % mod;
	fac[0] = 1;
	for(int i = 1; i < maxn; ++i)
		fac[i] = fac[i - 1] * i % mod;
	inv[1] = 1;
	for(int i = 2; i < maxn; ++i)
		inv[i] = (mod - mod / i) * inv[mod % i] % mod;
	facinv[0] = facinv[1] = 1;
	for(int i = 2; i < maxn; ++i)
		facinv[i] = facinv[i - 1] * inv[i] % mod;
}
ll C(int n, int m) { return n < m ? 0 : fac[n] * facinv[n - m] % mod * facinv[m] % mod;}
int main()
{
	init();
	int K, N;
	scanf("%d%d", &K, &N);
	for(int k = 2; k <= 2 * K; ++k)
	{
		if(K + 1 < k)
		{
			a[k] = a[2 * K + 2 - k];
			continue;
		}
		int num = (k + 1) / 2;
		ll sum = 0;
		for(int i = 0; i <= num; ++i)
		{
			ll tmp = C(num - (k & 1), i) * bin[i] % mod;
			if((k & 1) && i)
				tmp = (tmp + C(num - 1, i - 1) * bin[i - 1]) % mod;
			tmp = tmp * C(N + K - k - 1, i + K - k - 1) % mod;
			sum = (sum + tmp) % mod;
		}
		a[k] = sum;
	}
	for(int i = 2; i <= 2 * K; ++i)
		printf("%lld\n", a[i]);
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n,k,i,sum = 1;
	cin >> n >> k ;
	for (int i=1;i<=n;i++){
		if ((2*sum)>(sum+k)){
			sum = sum + k;
		} else {
			sum = sum * 2;
		}
		
	}cout << sum <<  endl;
	

}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#define ALL(a)    a.begin(), a.end() 
#define rep(i, K, N)  for(int i = K; i < N; i++)
#define ll long long int
using namespace std;
int main() {
ll N, total = 0;cin >> N;
vector<ll> A(N);

rep(i, 0, N){
cin >> A[i];

if(i == 0)total += abs(0 - A[i]);

else total += abs(A[i] - A[i - 1]);

}

total+=abs(A[N - 1]);

rep(i, 0, N){

if(i == 0)cout << total - abs(0 - A[i]) - abs(A[i] - A[i + 1]) + abs(0 - A[i + 1]) << endl;

if(i != 0 && i != N - 1)cout << total - abs(A[i - 1]  - A[i]) - abs(A[i + 1] - A[i]) + abs(A[i - 1] - A[i + 1]) << endl;

if(i == N - 1)cout << total - abs(A[i - 1] - A[i]) - abs(A[i]) + abs(A[i - 1]) << endl;

}

}

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

int d[100];
int n,k;
 
int gd(int n) {
  while (n) {
    int x=n%10;
    n/= 10;
    rep(i, k) {
      if (x==d[i]) return 0;
	}
  }
  return 1;
}
 
int main() {
  cin>>n>>k;
  rep(i, k) cin>>d[i];
  while (!gd(n)) n++;
  cout << n << "\n";
  return 0;
}


Measured memory_bytes: 256
using static System.Math;
using System;

class Modulo
{
    private const int MOD = 1000000007;
    private readonly int[] m_facs;
    public int Mul(int a, int b) => (int)(Math.BigMul(a, b) % MOD);
    public Modulo(int n)
    {
        m_facs = new int[n + 1];
        m_facs[0] = 1;
        for (int i = 1; i <= n; ++i)
            m_facs[i] = Mul(m_facs[i - 1], i);
    }
    public int Fac(int n) => m_facs[n];
    public int Pow(int a, int m)
    {
        switch (m)
        {
            case 0:
                return 1;
            case 1:
                return a;
            default:
                int p1 = Pow(a, m / 2);
                int p2 = Mul(p1, p1);
                return ((m % 2) == 0) ? p2 : Mul(p2, a);
        }
    }
    public int Div(int a, int b) => Mul(a, Pow(b, MOD - 2));
    public int Ncr(int n, int r)
    {
        if (n < r) return 0;
        if (n == r) return 1;
        int res = Fac(n);
        res = Div(res, Fac(r));
        res = Div(res, Fac(n - r));
        return res;
    }
}

public class Hello
{
    public const int MOD = 1000000007;
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = int.Parse(line[0]);
        var a = int.Parse(line[1]);
        var b = int.Parse(line[2]);
        var c = new Modulo(Max(a, b));
        var ans1 = c.Pow(2, n) - 1;
        var ans2 = c.Div(getFac(n, a), c.Fac(a));
        var ans3 = c.Div(getFac(n, b), c.Fac(b));
        long ans = (ans1 - ans2 - ans3) % MOD;
        if (ans < 0) ans += MOD;
        Console.WriteLine(ans);
    }
    static int getFac(int n, int a)
    {
        var ans = 1L;
        for (int i = n - a + 1; i <= n; i++)
        {
            ans *= i;
            ans %= MOD;
        }
        return (int)ans;
    }
}


Measured memory_bytes: 11616
import numpy as np
def getNearestValue(Q, num):
    idx = np.abs(np.asarray(Q) - num).argmin()
    return Q[idx]

XN = list(map(int,input().split()))
X = XN[0]
N = XN[1]
if N == 0:
    print(X)
else:
    P = list(map(int,input().split()))
    Q = list(range(-100,200,1))
    for i in range(0,N):
        Q.remove(P[i])
    print(getNearestValue(Q,X))

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

using namespace std;

using ll = long long;

int main(int argc, const char *argv[]) {
  int n;
  cin >> n;
  vector<ll> va(n);
  for (int i = 0; i < n; ++i) {
    cin >> va[i];
  }

  ll ans = 0;
  for (int i = 0; i < n; ++i) {
    ans += va[i] - 1;
  }

  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 256
import sys
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def II(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def SI(): return input()
YN = lambda b: print('YES') if b else print('NO')
yn = lambda b: print('Yes') if b else print('No')

li = []
for i in range(5):
    li.append(II())
k = II()

if li[-1] - li[0] > k:
    print(':(')
    sys.exit()

print('Yay!')


Measured memory_bytes: 3064
import re

s = input()

set_s = set(s)
flag = 0

if len(s) == 2:
    if s[0] == s[1]:
        print(1,2)
        flag = 1
    else:
        flag = 1
        print(-1,-1)


for x in set_s:
    regex1 = re.compile(x+x +r"\w")
    regex2 = re.compile(x +r"\w" + x)
    mo1 = regex1.search(s)
    mo2 = regex2.search(s)
    if mo1:
        #print(mo1.group())
        print(mo1.start()+1,mo1.end())
        flag = 1
        break
    elif mo2:
        #print(mo2.group())
        print(mo2.start()+1,mo2.end())
        flag = 1
        break

if not flag:
    print(-1,-1)

Measured memory_bytes: 3444
#include <iostream>
#include<time.h>
#include<string>
#include<cstring>
#include <cstdio>
#include<utility>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<bitset>
#include<queue>
#include<stack>
#include<set>
#include <limits>
#include <climits>
#include <numeric>
#include<cassert>
#include<cctype>
#include<iterator>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef vector<ll>VI;
typedef vector<bool>VB;
typedef pair<ll,ll>P;
typedef pair<double,double>P_D;
#define VV(T) vector<vector<T>>
#define PI 3.1415926535897932384626433832795
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define reprev(i, n) for (ll i = (ll)n - 1; i >= 0; i--)
#define bitrep(bit,A) for(int bit=A; ;bit=(bit-1)&A)
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) (ll)((a).size())
#define c_max(a, b) (((ll)a)>((ll)b)?(a):(b))
#define c_min(a,b) (((ll)a)<((ll)b)?(a):(b))
#define chmax(x,a) x=c_max(x,a)
#define chmin(x,a) x=c_min(x,a)
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define SORT(c) stable_sort(ALL(c))
#define $(x) {cout<<#x<<" = " <<(x)<<endl;}
#define fi first
#define se second
#define MAX 100100//5
#define MAX2 200100
#define MAX_6 1001001//6
#define MAX_7 10010010//7
#define SENTINEL 2000000000//9
#define NIL -1
#define MOD 1000000007
#define INF 1<<30
#define INFTY 1000000000000000001LL
#define MAX_INT INT_MAX
#define Endl '\n'
#define greater greater<int>()
int main(){
    ll l,r;cin>>l>>r;
    ll t=r-l;
    ll ans=INF;
    if(t>=2019){cout<<0<<endl;return 0;}
    for(ll i=l;i<r;++i)
    for(ll j=i+1;j<=r;++j){
        chmin(ans,i%2019*j%2019);
    }
    cout<<ans<<endl;
}

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

int main()
{
    int A , B;
    cin >> A >> B;

    int k = ceil(double(B - 1) / (A - 1));
    cout << k << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define typeof(x) __typeof__(x)
#define int long long int
#define double long double
#define mod(x) ((x % MOD) + MOD) % MOD
#define REP(i,a,b) for(int i=(a);i<(b);++i)
#define RREP(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define ALL(c) (c).begin(),(c).end()
#define RALL(c) (c).rbegin(),(c).rend()
#define SZ(c) (int)((c).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define LB(c,x) (int)(lower_bound(ALL(c),x)-(c).begin())
#define UB(c,x) (int)(upper_bound(ALL(c),x)-(c).begin())
#define COUNT(c,x) (UB(c,x)-LB(c,x))
#define UNIQUE(c) SORT(c); (c).erase(unique(ALL(c)),(c).end());
#define COPY(c1,c2) copy(ALL(c1),(c2).begin())
#define EXIST(s,e) (s).find(e)!=(s).end()
#define PB push_back
#define MP make_pair
#define vec vector
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define NL cerr << endl;

using namespace std;

typedef pair<int,int> P;
struct edge { int from, to; int cost; };
ostream& operator << (ostream& s, const edge& e) {
   s << "(" << e.from << "->" << e.to << ": " << e.cost << ")";
   return s;
}
bool operator< (const edge &edge1, const edge &edge2){
   return edge1.cost < edge2.cost;
};

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

template<typename T> ostream& operator << (ostream& s, const vector<T>& v) {
   s << "[";
   for (int i = 0; i < v.size(); i++) { s << v[i]; if (i < v.size() - 1) s << " "; }
   s << "]";
   return s;
}
template<typename T> ostream& operator << (ostream& s, const set<T>& se) {
   s << "{";
   for (auto i = se.begin(); i != se.end(); ++i) {
      s << *i;
      if (next(i) != se.end()) s << ", ";
   }
   s << "}";
   return s;
}
template<typename T1, typename T2> ostream& operator << (ostream& s, const pair<T1,T2>& p) {
   s << "(" << p.first << "," << p.second << ")";
   return s;
}
template<typename T1, typename T2> ostream& operator << (ostream& s, const map<T1,T2>& m) {
   s << "{";
   for (auto i = m.begin(); i != m.end(); ++i) {
      s << i->first << ":" << i->second;
      if (next(i) != m.end()) s << ", ";
   }
   s << "}";
   return s;
}

signed main()
{
   int N; cin >> N;
   vec<int> A(N), B(N);
   REP(i, 0, N) {
      cin >> A[i] >> B[i];
   }

   vec<P> C(N);
   REP(i, 0, N) {
      C[i] = MP(A[i] + B[i],i);
   }
   RSORT(C);

   int ans = 0;
   REP(i, 0, N) {
      if (i % 2 == 0) {
         ans += A[C[i].second];
      } else {
         ans -= B[C[i].second];
      }
   }
   cout << ans << endl;

   return 0;
}


Measured memory_bytes: 3328
import java.util.Scanner;

class Main{
 public static void main(String[] args){
  Scanner sc = new Scanner(System.in);

  int S = sc.nextInt();

  int h = S / 3600;
  S = S % 3600;

  int m = S / 60;
  S = S % 60;

  System.out.println( h + ":" + m + ":" + S);
 }
}



Measured memory_bytes: 26252
/*
god taekyu
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n,h,w;
    cin>>n>>h>>w;
        cout<<(n-h+1) * (n-w+1);
    return 0;
}

/*
god taekyu
*/


Measured memory_bytes: 256
from collections import Counter
from itertools import permutations

n, c = map(int, input().split())
d = [list(map(int, input().split())) for _ in range(c)]
a = [[] for _ in range(3)]
for i in range(n):
    for j, x in enumerate(map(lambda x: int(x)-1, input().split())):
        a[(i+j) % 3].append(x)

cnt = list(map(lambda x: Counter(x), a))
ans = float("inf")

for cp in permutations(range(c), 3):
    res = 0
    for i, x in enumerate(cp):
        for px in cnt[i].keys():
            res += d[px][x] * cnt[i][px]
    ans = min(res, ans)

print(ans)


Measured memory_bytes: 57488
#include <stdio.h>
#define MAX_N 1000

int main(void) {
  int n, i, j, k, ans, temp;
  int dp[MAX_N][MAX_N];
  char a[MAX_N][MAX_N];

  while (1) {
    scanf("%d", &n);
    if (n == 0) return 0;

    for (i = 0; i < n; i++) {
      scanf("%s", a[i]);
    }

    for (i = 0; i < n; i++) {
      for (j = 0; j < n; j++) {
	if (a[i][j] == '.') dp[i][j] = 1;
	else dp[i][j] = 0;
      }
    }

    for (i = 1; i < n; i++) {
      for (j = 1; j < n; j++) {
	if (dp[i][j] == 0) continue;
	int temp = dp[i - 1][j - 1];
	if (temp > dp[i][j - 1]) temp = dp[i][j - 1];
	if (temp > dp[i - 1][j]) temp = dp[i - 1][j];
	
	dp[i][j] = temp + 1;
      }
    }

    int ans = 0;
    for (i = 0; i < n; i++) {
      for (j = 0; j < n; j++) {
	if (dp[i][j] > ans) ans = dp[i][j];
      }
    }

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

Measured memory_bytes: 5484
while (True):
    N = input()
    
    if N=='0000':
        break
    
    if N==N[0]*4:
        print('NA')
        continue
    
    cnt = 0
    
    while N!='6174':
        l = [int(Ni) for Ni in N]
        l.sort()
        L = 1000*l[3]+100*l[2]+10*l[1]+l[0]
        S = 1000*l[0]+100*l[1]+10*l[2]+l[3]
        N = str(L-S)
        N = '0'*(4-len(N))+N
        cnt += 1
    
    print(cnt)


Measured memory_bytes: 5616
#include <stdio.h>
int main(void){
    int x,y;
    while(1){
    scanf("%d %d", &x, &y);
    if ( x == 0 && y == 0 ) break;
    if (x<y){
        printf("%d %d\n",x,y);
    } else {
        printf("%d %d\n",y,x);
    }
 
}
    return 0;
}


Measured memory_bytes: 2064
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,a,b) for(int i=a;i<b;i++)
#define each(it,v) for(auto it : v)
#define mod 1000000007
#define all(v) (v).begin(),(v).end()
#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define vpii vector<pair<int,int>>
#define vv vector<vector<int>>
using namespace std;

main()
{
    int n; cin>>n;
    vi l(n);
    each(&it,l)cin>>it;
    sort(all(l));
    int ans=0;
    rep(i,n-2)rep2(j,i+1,n-1)rep2(k,j+1,n)
    {
        if(l[i]+l[j]<=l[k])break;
        if(l[i]<l[j]+l[k])if(l[j]<l[k]+l[i])ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#pypyでだすとどうだ？

s=input()
n=len(s)
ss=''

def even_strings(a):
  n=len(a)
  if n%2!=0:
    return False
  
  if a[0:n//2]==a[n//2:n]:
    return True
  else:
    return False

for i in range(n-1): #手前までやる､最後まではやらない 1文字以上だから
  ss+=s[i]
  if even_strings(ss):
    ret=i
    
print(ret+1)
    

Measured memory_bytes: 38384
n, c = map(int, input().split())
cost = [list(map(int, input().split())) for _ in range(c)]
grid = [list(map(int, input().split())) for _ in range(n)]

lst_0 = []
lst_1 = []
lst_2 = []
for i in range(n):
    for j in range(n):
        if (i+j+2) % 3 == 0:
            lst_0.append(grid[i][j])
        elif (i+j+2) % 3 == 1:
            lst_1.append(grid[i][j])
        else:
            lst_2.append(grid[i][j])

cost0 = []
for i in range(1, c+1):
    C = 0
    for j in lst_0:
        if j != i:
            C += cost[j-1][i-1]
    cost0.append(C)

cost1 = []
for i in range(1, c+1):
    C = 0
    for j in lst_1:
        if j != i:
            C += cost[j-1][i-1]
    cost1.append(C)

cost2 = []
for i in range(1, c+1):
    C = 0
    for j in lst_2:
        if j != i:
            C += cost[j-1][i-1]
    cost2.append(C)

min_cost = 10**100
for i in range(c):
    for j in range(c):
        for k in range(c):
            if i != j and j != k and k != i:
                min_cost = min(min_cost, cost0[i]+cost1[j]+cost2[k])
print(min_cost)

Measured memory_bytes: 56924
n, q = map(int, input().split())
Tree = [[] for _ in range(n+1)]
Counter = [0 for _ in range(n+1)]
AB = (tuple(map(int, input().split())) for _ in range(n-1))
PX = (tuple(map(int, input().split())) for _ in range(q))

for a,b in AB:
  Tree[a].append(b)
  Tree[b].append(a)
  
for p,x in PX:
  Counter[p] += x

P = [-1]*(n+1)

nodes = [1]
while nodes:
  parent = nodes.pop()
  for node_i in Tree[parent]:
    if P[parent]==node_i:
      continue
    P[node_i] = parent
    nodes.append(node_i)
    Counter[node_i] += Counter[parent]

print(*Counter[1:])

Measured memory_bytes: 58072
#include <iostream>

int main()
{
	int a, b, n;
	
	while (std::cin >> a >> b >> n) {
		int s = 0;
		for (int i = 0; i < n; ++i) {
			a = 10 * (a % b);
			s += a / b;
		}
		std::cout << s << std::endl;
	}
	
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
 
long int calk(int X){
  long int i, A;
  
    i = 0;
  while(1){
    A = X + i;
    if(A == 2){
      return 2;
    }
    
    for(int j = 2;j < sqrt(A) + 1;j++){
      if(A % j == 0){
        break;
      }
      if(j > sqrt(A)){
        return A;
      }
    }
    i++;
  }
}
  
int main() {
  long int X, ans, i, A;
  cin >> X;

  cout << calk(X) << endl;

}

Measured memory_bytes: 256
N = int(raw_input())
As = [(int(i), 2) for i in raw_input().split(" ")]
Bs = [(int(i), 1) for i in raw_input().split(" ")]
Cs = [(int(i), 0) for i in raw_input().split(" ")]

l = sorted(As + Bs + Cs)


count = [0, 0, 0, 1]
for i in l:
    count[i[1]] += count[i[1] + 1]
print count[0]

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

typedef long long ll;
#define type(a) typeid(a).name();
#define pop() pop_back()
#define push(n) push_back(n)
#define print(arr) cout << "[" ;for(unsigned int i=0;i<(unsigned int) arr.size();i++){ (i==arr.size()-1)?cout << arr[i]:cout << arr[i] << ",";}cout << "]" << endl
#define Arr(arr,l) cout << "[" ;for(unsigned int i=0;i<(unsigned int) l;i++){ (i==l-1)?cout << arr[i]:cout << arr[i] << ",";}cout << "]" << endl

int main(){
 int l;
 cin >> l;
 vector<int> n(l);
 for(int i=0;i<l;++i){
	 int w;
	 cin >>w;
	 n[i] = w;
 }
  int i=0;
  ll summed = 0;
  while (i<l){
	  for(int k=i+1;k<l;++k){
		  summed += n[i]*n[k];
	  }
	  i++;
  }
  cout << summed;
 
}  

















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

map <int,int> asd;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
	int z,x,c;
	cin>>z>>x>>c;
	
	if(z%2==1 || x%2==1 || c%2==1)
	{
		cout<<0<<endl;
	}
	else if(z==x && z==c)cout<<-1<<endl;
	else
	{
		int temp=0;
		int temp1,temp2,temp3;
		while(z%2==0 && x%2==0 && c%2==0)
		{
			temp1=x/2 + c/2;
			temp2=z/2 + c/2;
			temp3=z/2 + x/2;
			z=temp1;
			x=temp2;
			c=temp3;
			temp++;
		}
		
		cout<<temp<<endl;
	}
}

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

using namespace std;
typedef long long ll;

#define INF (long long)(1e9+7)
#define REP(i,n) for(ll i = 0; i < n; i++)
#define REP1(i,n) for(ll i = 1; i <= n; i++)

ll gcd(ll a, ll b)
{
  if(b == 0) return a;
  return gcd(b, a % b);
}



int main(void)
{
  double l;
  cin >> l;
  printf("%.10f\n",(l * l * l / 27.0));
}


Measured memory_bytes: 256
mod = 10**9+7
n,a,b = map(int,input().split())
def comb(k):
  m = 1
  c = 1
  for i in range(k):
    m = m*(n-i)%mod
    c = c*(i+1)%mod
  return (m*pow(c,mod-2,mod)%mod)
print((pow(2,n,mod)-1-comb(a)-comb(b))%mod)

Measured memory_bytes: 9136
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
s=[0]
ans=0
for i in range(n):
    s.append(s[-1]+a[i])  #sの最後とa[i]を足していく
c=Counter(s)    #Counter({4: 2, 2: 2, 1: 1, 0: 1})
for n in dict(c).values():    #{1: 1, 4: 2, 0: 1, 2: 2}のvalueを順に取り出す
    ans+=n*(n-1)//2     #nC2を計算する
print(ans)


'''
from collections import Counter
N = int(input())
A = [int(i) for i in input().split()]
l = [0]
ans = 0
for a in A:
    l.append(l[-1]+a)
c = Counter(l)
print(l)
for n in dict(c).values():
    ans += n*(n-1)//2
print(ans)
'''

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

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

    int N, M;
    cin >> N >> M;

    int c[100010] = {};
    int sum[100010] = {};

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

    int ans = (c[0] == M ? 1 : 0);
    sum[0] = c[0];
    for (int i=1; i<N; ++i) {
        sum[i] = sum[i-1] + c[i];
        if (sum[i] == M) {
            ans ++;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024