akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto& (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define sar(a,n) cout<<#a<<":";rep(pachico,n)cout<<" "<<a[pachico];cout<<endl
#define svec(v) cout<<#v<<":";rep(pachico,v.size())cout<<" "<<v[pachico];cout<<endl
#define svecp(v) cout<<#v<<":";each(pachico,v)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl
#define sset(s) cout<<#s<<":";each(pachico,s)cout<<" "<<pachico;cout<<endl
#define smap(m) cout<<#m<<":";each(pachico,m)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 305;

int id[MAX_N][26];
int dp[MAX_N][MAX_N][MAX_N];

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int n = len(s);
    rep(j,26){
        id[n][j] = n;
    }
    rrep(i,n){
        int c = (s[i]-'a');
        rep(j,26){
            if(j == c){
                id[i][j] = i;
            }else{
                id[i][j] = id[i+1][j];
            }
        }
    }
    int K;
    cin >> K;
    rep(i,n){
        rep(j,K+1){
            dp[i][i+1][j] = 1;
        }
    }
    srep(l,1,n){
        rep(i,n-l){
            int j = i+l;
            rep(k,K+1){
                if(k) cmx(dp[i][j+1][k],dp[i][j+1][k-1]);
                cmx(dp[i][j+1][k],dp[i][j][k]);
                if(id[i][s[j]-'a'] < j) cmx(dp[i][j+1][k],dp[id[i][s[j]-'a']+1][j][k]+2);
                if(k < K) cmx(dp[i][j+1][k+1],dp[i+1][j][k]+2);
            }
        }
    }
    cout << dp[0][n][K] << "\n";
    return 0;
}


Measured memory_bytes: 110848
# coding: UTF-8
# ???????????´??°a, b, c?????????????????????????????? a < b < c????????¶????????????????????°"Yes"??????
# ???????????????????????°"No"???????????????????????°?????????????????????????????????

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

if a < b < c:
	print "Yes"
else:
	print "No"

Measured memory_bytes: 6356
#include<iostream>
#define SIZE 1000
using namespace std;

void insertionSort(int (&A)[SIZE],int N){
	int v, i, j, k;
	for(i=0;i<N;i++){
		cout << A[i];
		if(i!=N-1)cout << " ";
		else cout <<endl;
	}	
	for(i=1;i<N;i++){
		v = A[i];
		j = i - 1;
		while(j >= 0 && A[j] > v){
			A[j+1] = A[j];
			j--;
		}
		A[j+1] = v;
		for(k=0;k<N;k++){
			cout << A[k];
			if(k!=N-1)cout << " ";
			else cout <<endl;
		}
	}
	return;
}

int main(){
	int A[SIZE] = {0}, N, i;
	cin >> N;
	for(i=0;i<N;i++){
		cin >> A[i];
	}
	insertionSort(A, N);
	return 0;
}

Measured memory_bytes: 1164
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;

namespace atcorder2
{
    class Program
    {
        public static long Read()
        {
            return long.Parse(Console.ReadLine());
        }

        public static long[] Reads()
        {

            return Console.ReadLine().Split().Select(long.Parse).ToArray();
        }






        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);


            var n = Read();
            var s = Console.ReadLine();
            long ans = 0;
           
            for (int i = 1; i < n; i++)
            {
                if (s[i] == 'E') ans++;
            }
            long memo = ans;
            for (int i = 0; i < n-1; i++)
            {
                if (s[i] == 'E' && s[i + 1] == 'E') memo--;
                if (s[i] == 'W' && s[i + 1] == 'W') memo++;
                ans = Math.Min(ans, memo);
            }

            Console.WriteLine(ans);

            Console.Out.Flush();
        }
    }
}




Measured memory_bytes: 13280
# coding:utf-8

import sys
from collections import Counter, defaultdict

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


def main():
    n = II()
    s = SI()

    cnt = [0] * 27
    res = 0
    for c in s:
        k = ord(c) - 97
        cnt[k] += 1
        tmp = 1
        for i in range(27):
            if not cnt[i]:
                continue
            if i == k:
                continue
            tmp *= cnt[i] + 1
        res += tmp
        res %= MOD

    return res if res else MOD


print(main())


Measured memory_bytes: 3564
s = str(input())
s_list = []
for i in range(len(s)):
  s_list.append(s[i])

#print(s_list)
L = len(s_list)

sum_a = 0
if L == 1:
  print(int(s))
else:
  for k in range(2**(L-1)):
    plus_list = [0]*(L-1)
    p = list(bin(k)[2:])
    for l in range(len(p)):
      plus_list[L-len(p)+l-1] = int(p[l])

    #print("p_list:",plus_list)
    #print("p:",p)
    num_list = []
    start = 0
    for i in range(len(plus_list)):
      if plus_list[i]:
        num_list.append(s_list[start:i+1])
        start = i+1
    num_list.append(s_list[start:])
    ans = 0
    for i in num_list:
      s = ''
      for j in i:
        s = s+j
      ans += int(s)
    sum_a += ans
    #print("num_list:",num_list)
    #print("ans:",ans)
  print(sum_a)

Measured memory_bytes: 3064
S = str(input())

ans = 0
cnt = 0
for i in range(len(S)):
  if (S[i]=='A') or (S[i]=='T') or (S[i]=='C') or (S[i]=='G'):
    cnt += 1
  else:
    ans = max(ans, cnt)
    cnt = 0
ans = max(ans, cnt)
print(ans)

Measured memory_bytes: 9116
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}//a,bの最大公約数(gcd)を求める
ll lcm(ll a,ll b){return abs(a*b)/gcd(a,b);}//a,bの最小公倍数(lcm)を求める
vector<ll> enum_div(ll n){vector<ll> ret;for(int i=1 ; i*i<=n ; i++){if(n%i == 0){ret.push_back(i);if(i!=1 && i*i!=n)ret.push_back(n/i);}}ret.push_back(n);return ret;}
//↑nの約数を求める
vector<bool> IsPrime; void sieve(size_t max){if(max+1 > IsPrime.size())IsPrime.resize(max+1,true);IsPrime[0] = false;IsPrime[1] = false;for(size_t i=2; i*i<=max; ++i)if(IsPrime[i])for(size_t j=2; i*j<=max; ++j)IsPrime[i*j] = false;}
//↑エラトステネスの篩で素数を求める
#define roundup(divisor,dividend) (divisor + (dividend - 1)) / dividend //切り上げ割り算
#define all(x) (x).begin(),(x).end() //xの初めから終わりまでのポインタ
#define size_t ll //size_tは自動でllに変換される
#define pb(x) push_back(x)
#define gre greater //sortを降順にする
#define pri_queue priority_queue //優先度付きキュー
const int MOD = 1000000007;
ll x,y,ans;
const int MAX = 1000001;
long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main(){
  cin >> x >> y;
  COMinit();
  cout << ((x+y)%3 == 0 ? COM(((2*x-y)/3 + (2*y-x)/3),(2*y-x)/3) : 0) << endl;
}


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

namespace ConsoleApp3
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            var days = int.Parse(Console.ReadLine());

            var scoreDownCoefficients = Console.ReadLine().Split(" ")
                .Select((x, i) => (score: long.Parse(x), questionNumber: (long)i + 1))
                .OrderByDescending(x => x.score)
                .ToDictionary(x => x.questionNumber, x => x.score);

            Hoge(days, scoreDownCoefficients);
        }

        private static void Hoge(int days, IReadOnlyDictionary<long, long> scoreDownCoefficients)
        {
            var lastDictionary = new Dictionary<long, long>();

            foreach (var today in Enumerable.Range(1, days))
            {
                var downScoreDictionary = GetAll(today, lastDictionary, scoreDownCoefficients);
                long overallDownScore = downScoreDictionary.Values.Sum();

                var scoreUpNumber = Console.ReadLine().Split(" ")
                    .Select((score, i) => (score: int.Parse(score), questionNumber: i + 1))
                    .OrderByDescending(x =>
                    {
                        lastDictionary.TryGetValue(x.questionNumber, out var lastHeld);

                        return x.score - overallDownScore;
                    })
                    .First();

                lastDictionary[scoreUpNumber.questionNumber] = today;

                Console.WriteLine(scoreUpNumber.questionNumber);
            }
        }

        private static Dictionary<long, long> GetAll(long today, Dictionary<long, long> lastDictionary, IReadOnlyDictionary<long, long> scoreDownCoefficients)
        {
            return Enumerable.Range(1, 26).Select(x =>
                {
                    lastDictionary.TryGetValue(x, out var lastHeld);
                    return (QuestionNumber: (long)x, DownScore: (today - lastHeld) * scoreDownCoefficients[x]);
                })
                .ToDictionary(x => x.QuestionNumber, x => x.DownScore);
        }
    }
}


Measured memory_bytes: 30156
#include <bits/stdc++.h>
#define FASTIO
#define endl "\n" // Since endl forces a buffer flush which slows down large I/O operations.
#define ff first
#define ss second
#define pb push_back
#define input(c, n)             \
	for (int i = 0; i < (n); i++) \
		cin >> (c)[i];
#define exit_message(s) return 0 * printf(s)
#define show(c)           \
	for (auto i : (c))      \
		cout << i << " "; \
	cout << "\n";
#define display(c, n)           \
	for (int i = 0; i < (n); i++) \
		cout << (c)[i] << " ";    \
	cout << "\n";
#define forl(i, a, n) for (int (i) = (a); (i) < (n); (i)++)
#define dugbe(k) cout << "-\t> " << #k << " = " << k << "\n";

/* TIPS FOR DEBUGGING
 * Check if values are not overflowing (use long long where required)
 * Check if ranges are inclusive or not.
 * Check properly if greedy will work or not before using it.
 * Check EDGE CASES!! Seriously, even in 2B, saving 8 points by being
 * 2 minutes faster will bite you in the ass if you don't make sure
 * it works on edge cases.
 * Keep adding to this list.
*/

using namespace std;
typedef long long ll;
typedef pair<int, int> pr;
typedef pair<ll, ll> prll;
typedef vector<int> vi;
typedef vector<ll> vill;
typedef vector<pr> vpr;
ifstream in("input.txt");
const ll mod = 1e9 + 7;

ll mod_pow(ll a, ll b)
{
	if (b == 0)
		return 1LL;

	ll res = mod_pow(a, b >> 1);
	res = (res * res) % mod;
	if (b & 1LL)
		res = (res * a) % mod;

	return res;
}

const int N = 1e5 + 5;

int n, w;
pr p[N];
ll cache[N];

int32_t main()
{
#ifdef FASTIO
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
#endif
	// freopen("in.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);

	for (auto &e: cache)
		e = 1e13;

	cin >> n >> w;
	forl(i, 0, n)
	{
		cin >> p[i].ff >> p[i].ss;
	}

	cache[0] = 0;
	for (int i = 0; i < n; i++)
	{
		for (int j = N - 1; j >= p[i].ss; j--)
		{
			cache[j] = min(cache[j], cache[j - p[i].ss] + p[i].ff);
		}
	}
	ll ans = 0;
	for (int i = 0; i < N; i++)
	{
		// cerr << cache[i] << " ";
		if (cache[i] <= w)
			ans = i;
	}
	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 1024
from collections import deque
def main():
	N,M,*AB=map(int,open(0).read().split())
	to=[[] for _ in range(N)]
	for a,b in zip(*[iter(AB)]*2):
		to[a-1].append(b-1)
		to[b-1].append(a-1)
	q=deque([0])
	r=[0]*N
	while q:
		x=q.popleft()
		for i in to[x]:
			if not r[i]:
				q.append(i)
				r[i]=x+1
	print("Yes",*r[1:],sep="\n")
if __name__=='__main__':
	main()

Measured memory_bytes: 56512
n,m=map(int,input().split())
a=[0]*(n+1)
dp=[0]*(n+1)
mo=10**9+7
for i in range(m):
    a[int(input())]=-1
    
for i in range(n+1):
    if i==0:
        dp[i]=1
    elif i==1:
        if a[1]!=-1:
            dp[i]=1
    elif a[i]!=-1:
        dp[i]=dp[i-1]+dp[i-2]
        dp[i]%=mo
print(dp[n]%mo)


Measured memory_bytes: 44888
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n; cin >> n;
  vector<int>a(n);
  for(int i = 0; i < n; i++){
    cin >> a.at(i);
  }
  int ans = 0;
  for(int i = 0; i < n; i++){
    int b = a.at(i) - 1;
    if(a.at(b) == i + 1) ans++;
  }
  cout << ans/2;
}

Measured memory_bytes: 3752
import java.util.Scanner;

public class Main {

	static int w,h,xs,ys,xg,yg,n,c;
	static boolean f;
	static int[][] field;
	static int[] v1={0,1,0,-1};
	static int[] v2={1,0,-1,0};
	public static void main(String[] args) {
		Scanner cin  = new Scanner(System.in);
		while(true){
			f=false;
			w=cin.nextInt();
			h=cin.nextInt();
			if(w+h==0){
				break;
			}
			field=new int[w+2][h+2];
			xs=cin.nextInt();
			ys=cin.nextInt();
			xg=cin.nextInt();
			yg=cin.nextInt();
			n=cin.nextInt();
			for(int i = 0;i<n;i++){
				int c = cin.nextInt();
				int d = cin.nextInt();
				int x = cin.nextInt();
				int y = cin.nextInt();
				if(d==0){
					for(int j = 0;j<4;j++){
						for(int k = 0;k<2;k++){
							field[j+x][k+y]=c;
						}
					}
				}
				else{
					for(int j = 0;j<2;j++){
						for(int k = 0;k<4;k++){
							field[j+x][k+y]=c;
						}
					}
				}
			}
			for(int i = 0;i<w+2;i++){
				for(int j = 0;j<h+2;j++){
					//System.out.print(field[j][i]);
				}
				//System.out.println();
			}
			c = field[xs][ys];
			if(c==0){
				System.out.println("NG");
				continue;
			}
			dfs(xs,ys);
			if(f){
				System.out.println("OK");
			}
			else{
				System.out.println("NG");
			}
				
		}
	}
	static void dfs(int x,int y){
		//System.out.println(field[x][y]+" " + x+" " + y);
		field[x][y]=0;
		if(x==xg&&y==yg){
			f=true;
		}
		for(int i = 0;i<4;i++){
			int xx=x+v1[i];
			int yy=y+v2[i];
			if(field[xx][yy]==c){
				dfs(xx,yy);
			}
		}
	}
}

Measured memory_bytes: 12000
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
#define inf 1e9

ll divisors(ll n){
    ll res = 0;
    for(ll i=1;i*i<=n;i++){
	if( n%i != 0) continue;
	res += i;
	if(n/i==i) continue;
	res += n/i;
    }
    return res-n;
}

int main(){
    while(1){
	ll n ;
	cin>>n;
	if(n==0) break;
	ll s = divisors(n);
	if( n==s){
	    cout<<"perfect number"<<endl;
	}else if( n > s){
	    cout<<"deficient number"<<endl;
	}else{
	    cout<<"abundant number"<<endl;
	}
    }
	return 0;
}



Measured memory_bytes: 3016
#include <iostream>
#include <stdio.h>
#include <cmath>

#define FOR(i, a, b) for (int i = a; i < b; i++)
#define FORN(i, a, b) for (int i = a; i <= b; i++)

using namespace std;

//
// Created by karayuu on 2019-01-02.
//

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

    int w[50] = {};
    FORN(i, 1, m) {
        int a, b;
        cin >> a >> b;
        w[a]++;
        w[b]++;
    }

    FORN(i, 1, n) {
        cout << w[i] << endl;
    }
}

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

int main() {
  int k, n;
  cin >> k >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];

  vector<int> diff(n);
  diff[0] = a[0] + (k - a[n - 1]);
  for (int i = 1; i < n; i++)
  {
    diff[i] = a[i] - a[i - 1];
  }

  vector<int>::iterator iter =max_element(diff.begin(), diff.end());
  size_t idx = distance(diff.begin(), iter);

  int sum_dis = accumulate(diff.begin(), diff.end(), 0);
  int ans = sum_dis - diff[idx];

  cout << ans << endl;

  return 0;
}


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

int main(void){
    int a,b,t;
    scanf("%d%d%d",&a,&b,&t);
    printf("%d\n",b*(t/a));
    return 0 ;
}

Measured memory_bytes: 128
#include <cstdio>
#include <algorithm>    
#include <iostream>
#include <vector>
#include <queue>
// #include <map>
#include <iomanip>
#include <cstring>
#include <cmath>
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long LL;
typedef long double LD;
typedef unsigned int uii;
typedef pair<int,int> pii;
typedef unsigned long long uLL; 
typedef vector<int> vii; 
const int maxn = 3333;
double d[maxn][maxn], a[maxn];

int main(int argc, char const *argv[])	
{
#ifndef ONLINE_JUDGE
	// freopen("in.txt", "r", stdin);
	// freopen("out.txt", "w", stdout);
#endif
	int n;
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i){
		scanf("%lf", &a[i]);
	}
	d[0][0] = 1;
	for(int i = 1; i <= n; ++i){
		for(int j = 0; j <= i; ++j){
			d[i][j] = d[i - 1][j] * (1 - a[i]) + d[i - 1][j - 1] * a[i];
		}
	}
	double res = 0;
	for(int i = (n + 1) / 2; i <= n; ++i){
		res += d[n][i];
	}
	printf("%.10f\n", res);
	return 0;
}

Measured memory_bytes: 78464
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
typedef vector<ll> vel;
typedef vector<str> ves;
#define REP(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define rep(i, b) REP(i, 0, b)
const ll mod = 1000000007;
const double pi = 3.14159265358979;

int main() {
    ll A, B, C, D;
    cin >> A >> B >> C >> D;
    if (A * B < C * D) {
        cout << C * D << endl;
    }
    else {
        cout << A * B << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>

unsigned gaps[] = {1,8,23,77,281,1073,4193,16577,65921,262913,1050113};
// generated from pow(4,i)+3*pow(2,i-1)+1 (prefixed with 1)

unsigned insertion_sort(unsigned a[], unsigned n, unsigned gap){
  unsigned count = 0;
  for(unsigned i = gap; i < n; i++){
    unsigned v = a[i];
    int j = i - gap;
    while(j >= 0 && a[j] > v){
      a[j+gap] = a[j];
      j -= gap;
      count++;
    }
    a[j+gap] = v;
  }
  return count;
}

void shell_sort(unsigned a[], unsigned n){
  unsigned gap_num = 0;
  while(gaps[++gap_num] < n);
  gap_num--;

  unsigned count = 0;
  for(int i = gap_num; i >= 0; i--) count += insertion_sort(a,n,gaps[i]);

  std::cout << (gap_num+1) << '\n';

  for(int i = gap_num; i; i--) std::cout << gaps[i] << ' ';
  std::cout << gaps[0] << '\n';

  std::cout << count << '\n';
}

int main(){
  std::ios::sync_with_stdio(false);
  unsigned n;
  std::cin >> n;
  auto a = new unsigned[n];
  for(unsigned i = 0; i < n; i++) std::cin >> a[i];
  shell_sort(a,n);
  for(unsigned i = 0; i < n; i++) std::cout << a[i] << '\n';
  delete[](a);
}

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

#define for_(i,a,b) for(int i=(a);i<(b);++i)

int N, M, A, B, D[1010];

void solve() {
	int cur = 0;
	while (D[cur] >= A) ++cur;
	
	if (N - cur < M) {
		while (cur > 0 && D[cur - 1] <= B) --cur;
	}
	
	cout << cur << endl;
}

int main() {
	cin >> N >> M >> A >> B;
	for_(i,0,N) cin >> D[i];
	solve();
}

Measured memory_bytes: 3092
#include <bits/stdc++.h>
#define ll long long
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define repm(i,a,b) for(ll i=(ll)(a);i>(ll)(b);i--)
#define all(v) v.begin(), v.end()
#define rall(x) (x).rbegin(),(x).rend()
#define pll pair<long long,long long>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define vc vector<char>
#define vvc vector<vc>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<long long>;
using vvll = vector<vll>;
using vb =vector<bool>;
using vvb=vector<vb>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
//snippets:tmp,cl,cvl,cs,co,coy,con,cov,setp

int main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    ll d;
    cin >> d;
    vll c(26);
    rep(i, 26) cin >> c[i];
    vvll s(d,vll(26));
    rep(i,d){
        rep(j,26) cin>>s[i][j];
    }
    vll t(d);
    rep(i, d) cin >> t[i];
    ll v=0;
    vector<set<int>>set(26);
    rep(i,26) set[i].insert(0);
    rep(i,d){
        v+=s[i][t[i]-1];
        set[t[i]-1].insert(i+1);
        rep(j,26){
            v-=c[j]*(i+1-(*(--set[j].end())));
        }
        cout<<v<<endl;
    }
}

Measured memory_bytes: 3768
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int W, H, x, y, r;
  cin >> W >> H >> x >> y >> r;
  if(x < r || y < r || x > W-r || y > H-r){
    cout << "No" << endl;
  }else{
    cout << "Yes" << endl;
  }
}



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

using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const long long INF = 1LL << 60;
long long dp[100100];

int main() {
    int N; cin >> N;
    vector<int> A(N);
    for(int i = 0; i < N; i++) {
        cin >> A[i];
        if(i != N-1) cout << A[i] << " ";
        else cout << A[i] << endl;
    }

    int v, j;
    for(int i = 1; i < N; i++) {
        v = A[i];
        j = i - 1;
        while(j >= 0 && A[j] > v) {
            A[j+1] = A[j];
            j--;
        }
        A[j+1] = v;
        for(int k = 0; k < N; k++) {
            if(k != N-1) cout << A[k] << " ";
            else cout << A[k] << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 3112
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <numeric>
#include <cmath>
#include <cassert>
#include <iomanip>
#include <bitset>


using namespace std;

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

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

const ll mod = 1e9+7;
const ll INF = 1e9;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

ll f(int x,vector<ll> s){
	ll ret = 0;
	int n = s.size();
	ll ma = 0;

	for (int k = 1; k <= (n-1)/x; k++){
		if((n-1)%x==0 &&  n-1-(k-1)*x<=(k-1)*x) break;
		ret += s[n-1-(k-1)*x]+s[(k-1)*x];
		ma = max(ret,ma);
	}
	return ma;
}

int main()
{
	int n;
	cin>>n;
	vector<ll> s(n);
	rep(i,n) cin>>s[i];
	ll ans=0;
	for (int x = 1; x < n; x++){

		ll ret = 0;
		// ll ma = 0;

		for (int k = 1; k <= (n-1)/x; k++){
			if((n-1)%x==0 &&  n-1-(k-1)*x<=(k-1)*x) break;
			ret += s[n-1-(k-1)*x]+s[(k-1)*x];
			ans = max(ret,ans);
		}
		// ans = max(ans,f(x,s));
	}
	cout<<ans<<endl;
	return 0;
}

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

int main() {
    long n, m, d, t;
    string ans = "YES";
    scanf("%ld", &n);
    unordered_map<long, long> mp;
    for (long i = 0; i < n; i++) {
        scanf("%ld", &d);
        if (mp.find(d) != mp.end()) {
            mp[d]++;
        } else mp[d] = 1;
    }
    scanf("%ld", &m);
    for (long i = 0; i < m; i++) {
        scanf("%ld", &t);
        if (mp.find(t) != mp.end()) {
            mp[t]--;
            if (mp[t] == 0) mp.erase(t);
        } else ans = "NO";
    }
    cout << ans << endl;
}

Measured memory_bytes: 11492
/*
 
dunjen_master
 
*/
 
 
 
 
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
 
using namespace std;
 
const int MAX_N = int(1e6) + 10;
const long long int MOD=1e9+7;
const long long int INF=1e18;
 
typedef long long int ll;
typedef unsigned long long int llu;
 
 
 
inline ll mul(ll a,ll b){
 
    a=(a+MOD)%MOD;
    b=(b+MOD)%MOD;
    ll c=a*b;
    c=(c+MOD)%MOD;
    return c;
}
inline ll add(ll a,ll b){
    a=(a+MOD)%MOD;
    b=(b+MOD)%MOD;
    ll ans=(a+b);
    ans=(ans+MOD)%MOD;
    return ans;
}
ll power(ll a,ll b,ll c=0){
    ll ans=1;
    while(b){
        if(b&1){
            ans=mul(ans,a);
        }
        a=mul(a,a);
        b=b/2;
    }
    return ans;
}
 
  
 
 
#define all(x) (x).begin(),(x).end()
 
/* ordered_set A;
   A.insert(x);
   A.erase(x);
   A.order_of_key(x) // no of elements less than (<) x
   *A.find_by_order(k-1) // kth smallest element
*/
// int n;
// ll dp[200005][205];
// ll ans=0;
// int a[200005];
// int req;
// ll neg=-1e15;
 
 
// ll fun(int indx,int last){
//    // cout<<indx<<" "<<last<<" "<<req<<endl;
//     if(indx==n){
//         if(last==req){
//             return 0;
//         }else{
//             return neg;
//         }
//     }
 
//     if(dp[indx][last]!=-1){
//         return dp[indx][last];
//     }
    
//     ll ans=neg;
 
//     ans=max(ans,fun(indx+1,last));
 
//     if(last==0)ans=max(ans,1+fun(indx+1,a[indx]));
//     if(last==a[indx])ans=max(ans,1+fun(indx+1,a[indx]));
//     if(a[indx]==req)ans=max(ans,1+fun(indx+1,a[indx]));
 
//     return dp[indx][last]=ans;
 
 
// }
 

 
 
int main(){

int a,b,k;
cin>>k>>a>>b;

for(int i=a;i<=b;i++){
    if(i%k==0){
        cout<<"OK"<<endl;
        return 0;
    }
}

cout<<"NG"<<endl;
return 0;

 
 
    
 
    
 
    
 
 
 
 
 
 
 
 
 
   
 
 
 
    
    
 
    
 
    
 
  
    
 
 
 
    
 
 
    
    
    
    
 
    
}


Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
const int maxx=1e6+10;
struct node{
	int w;
	int v;
}in[105];
long long dp[maxx]={0};
int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++){
		scanf("%d%d",&in[i].w,&in[i].v);
	}
	for(int j=0;j<n;j++){
		for(int i=m;i>=0;i--){
			if(in[j].w<=i){
				dp[i]=max(dp[i],dp[i-in[j].w]+in[j].v);
			}
		}
	}
	printf("%lld",dp[m]);
}

Measured memory_bytes: 1024
s=input()
k=int(input())
if s=="1"*len(s):
  print(1)
else:
  i=0
  while True:
    if s[i]!="1":
      n=s[i]
      break
    else:
      i+=1
  if k-1<i:
    print(1)
  else:
    print(s[i])

Measured memory_bytes: 3060
using System;

namespace A_Product {
    class Program {
        static void Main(string[] args) {
            var num = Console.ReadLine().Split(' ');

            string a = (num[0]).ToString();
            string b = (num[1]).ToString();

            int c = int.Parse(a + b);

            string answer = "No";

            double d = Math.Sqrt(c);

            int e = (int)d;

            if (d == e) {
                answer = "Yes";
            }

            Console.WriteLine(answer);
        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std; 
typedef long long lli;
#define mod 1000000007
const int INF = 1e6;
const int MAX = 1e5+10;
#define fori(n) for(int i=0;i<n;i++)
#define forj(n) for(int j=0;j<n;j++)
#define forli(n) for(lli i=0;i<n;i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define vi vector<int>
#define vli vector<lli>
#define fast ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define endl "\n"
#define print(a) cout<<a<<endl
#define print2(a,b) cout<<a<<" "<<b<<endl
#define print3(a,b,c) cout<<a<<" "<<b<<" "<<c<<endl
#define sortvec(a) sort(a.begin(),a.end())
#define pdd pair<lli,lli>
 
//FUNCTONS
lli llipower(lli x, lli y){lli res = 1;x = x % mod; while (y > 0){if (y & 1) res = (res*x) % mod; y = y>>1;x = (x*x) % mod;}return res;}
lli gcd(lli a, lli b){ if (!a) return b; return gcd(b%a,a);}
lli binarySearch(vector<int> arr, int l, int r, int x){ 
	if (r >= l) { 
		lli mid = l + (r - l) / 2; 
		if (arr[mid] == x) return mid; 
		if (arr[mid] > x) return binarySearch(arr, l, mid - 1, x); 
		return binarySearch(arr, mid + 1, r, x); 
	} 
	return -1;
}

template <typename T>
void printvec(vector<T> inp){
	for(int i=0;i<inp.size();i++){
		cout<<inp[i]<<" ";
	}
	cout<<endl;
}
template <typename T>
T ceildiv(T x, T y){
	return 1 + ((x - 1) / y);
}

int main(){
	int n,r;

	cin>>n>>r;
	if(n>=10) cout<<r<<endl;
	else{
		cout<<r+(100*(10-n))<<endl;
	}
}
 
 

Measured memory_bytes: 256
#include <iostream>
using namespace std;
typedef long long ll;
ll n, a[55], sho[55], ans;
int main(void){
    // Your code here!
    cin >> n;
    for(ll i = 0; i < n; i++) cin >> a[i];
    while(true){
        ll shosum = 0;
        for (ll i = 0; i < n; i++){
            sho[i] = a[i] / n;
            shosum += a[i] / n;
            a[i] %= n;
        }
        for (ll i = 0; i < n; i++){
            a[i] += shosum - sho[i];
        }
        ans += shosum;
        if (shosum == 0) break;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
import math

s = input().split(' ')
a = int(s[0])
b = int(s[1])
a1 = a / 0.08
a += 0.9999
a2 = a / 0.08
b1 = b / 0.1
b += 0.9999
b2 = b / 0.1

# print(a1, a2, b1, b2)
if a2 < b1 or b2 < a1:
    print(-1)
elif a1 >= b1:
    print(int(math.ceil(a1)))
else:
    print(int(math.ceil(b1)))


Measured memory_bytes: 3060
#include <iostream>
#include <cmath>

using namespace std;

int n,a,b;

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

    if(b>=100)
    {
        n=a*1000+b;
    }
    else if(b>=10)
    {
        n=a*100+b;
    }
    else
    {
        n=a*10+b;
    }
    int sq = sqrt(n);
    if(sq*sq==n)
        cout<<"Yes";
    else
        cout<<"No";
    return 0;
}


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

int main() {
    int n, k;
    cin >> n >> k;
    vector< int> in(n);
    for (int &i : in) {
        cin >> i;
        i %= k;
    }
    long long res = 0;
    map< int, int> mp;
    int s = 0;
    for(int i = 0; i < n; ++i) {
       mp[s]++;
       s += in[i];
       s %= k;
       res += mp[s];
    }

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

Measured memory_bytes: 3584
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;

int main(){
    int n;cin>>n;
    vector<int> p(n);
    vector<int> q(n);
    vector<int> v(n);
    for(int i=1;i<n+1;i++) v[i-1]=i;
    for(int i=0;i<n;i++) cin>>p[i];
    for(int i=0;i<n;i++) cin>>q[i];
    int count=0;
    int a,b;
    do{
        count++;
        for(int i=0;i<n;i++){
            if(v[i]!=p[i]) break;
            if(i==n-1){
                a=count;
            }
        }
        for(int i=0;i<n;i++){
            if(v[i]!=q[i]) break;
            if(i==n-1){
                b=count;
            }
        }
    }while(next_permutation(v.begin(),v.end()));
    cout<<abs(a-b)<<endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define INF 1<<30
#define LINF 1LL<<60
ll N, M;
vector<vector<int>> G;
set<int> l, r;
bool check(int n,bool k,vector<int>& used) {
	if (k == false) {
		//if (!r.empty() && r.find(n) != r.end()) return false;
		l.insert(n);
		used[n] = 1;
		for (auto next : G[n]) {
			if (used[next] == 1) return false;
			if (used[next] == 2)continue;
			if (!check(next, !k, used)) return false;
		}
	}
	else {
		//if (!l.empty() && l.find(n) != l.end()) return false;
		r.insert(n);
		used[n] = 2;
		for (auto next : G[n]) {
			if (used[next] == 1)continue;
			if (used[next] == 2)return false;
			if (!check(next, !k, used))return false;
		}
	}
	return true;
}

int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	cin >> N >> M;
	G.resize(N);
	for (int i = 0; i < M;i++) {
		int A, B; cin >> A >> B;
		A--; B--;
		G[A].push_back(B);
		G[B].push_back(A);
	}
	vector<int> used(N, 0);
	bool f = check(0, false, used);
	if (f) {
		//cout << l.size() << " " << r.size() << endl;
		cout << l.size() * r.size() - M << endl;
	}
	else {
		cout << (N*(N - 1)) / 2 - M << endl;
	}
	return 0;
}

Measured memory_bytes: 11136
#include <iostream>
#include <stdio.h>
#include <bits/stdc++.h>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

typedef long long ll;
typedef long double ld;

/*int main()
{
    ll h,w,x,y;
    ld ans;

    cin>>h>>w>>x>>y;
    bool yes = x+x==h&&y+y==w;
    cout<<yes<<endl;
    //ans = double(h)*double(w)/2.0;
    double s=double(w)*double (h)/2.0;
    printf("%lf\n",s);
    return 0;

}
*/
int main(){
  ll a,b,h,w;
  cin >> w >> h >> a >> b;
  double s=double(w)*double (h)/2.0;
  printf("%lf ",s);
  if (a*2==w && h==2*b) printf("1\n");
  else printf("0\n");
  return 0;
}


Measured memory_bytes: 256
//#include "stdafx.h"
#include <stdio.h>
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <string>
#include <cstring>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <tuple>
#include <numeric>
#include <assert.h>
#include <functional>
#include <unordered_map>
#include <cstdint>

using namespace std;

/*-----------------------------------------------------------------------------
　定義
 -------------------------------------------------------------------------------*/
#define REP(i, n)				for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n)			for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define ALL(a)					(a).begin(),(a).end()
#define INF						2e9
#define MOD						(1000 * 1000 * 1000 + 7)
#define Ceil(x, n)				(((((x))+((n)-1))/n))		/* Nの倍数に切り上げ割り算 */
#define CeilN(x, n)				(((((x))+((n)-1))/n)*n)		/* Nの倍数に切り上げ */
#define FloorN(x, n)			((x)-(x)%(n))				/* Nの倍数に切り下げ */
#define IsOdd(x)				(((x)&0x01UL) == 0x01UL)			
#define IsEven(x)				(!IsOdd((x)))						
#define ArrayLength(x)			(sizeof( x ) / sizeof( x[ 0 ]))
#define	MAX_QWORD				((QWORD)0xFFFFFFFFFFFFFFFF)
#define M_PI					3.14159265358979323846
typedef long long				ll;
typedef unsigned long long int	QWORD;
typedef unsigned long long		SQWORD;
typedef pair<ll, ll>			P;

/*-----------------------------------------------------------------------------
　処理
 -------------------------------------------------------------------------------*/
int main()
{
	int N;
	cin >> N;
	vector<ll> A(N);
	REP(i, N) cin >> A[i];
	
	ll ans = 0;
	REP(i, N) {
		REPN(j, i, N) {
			ans = max(ans, abs(A[i] - A[j]));
		}
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
)
var n int


func main()  {
	var reader = bufio.NewReader(os.Stdin)
	var writer = bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	fmt.Fscanf(reader, "%d", &n)
	var ret = int64(0)

	for i := 1; i <= n; i++ {
		if i % 3 == 0 || i % 5 == 0 {
			continue
		}
		ret += int64(i)
	}
	fmt.Fprintf(writer, "%d", ret)
}


Measured memory_bytes: 1828
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <bitset>
#include <map>
#include <string>
#include <utility>

#define repd(i,a,b) for(ll i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;

using namespace std;

int inputValue(){
	int a;
	cin >> a;
	return a;
}

void inputArray(int *p,int a){
	rep(i,a){
		cin >> p[i];
	}
}

void inputVector(vector<int> *p,int a){
	rep(i,a){
		int input;
		cin >> input;
		p -> push_back(input);
	}
}

template <typename T>
void output(T a,int precision){
	if(precision > 0){
		cout << setprecision(precision) << a << "\n";
	}else{
		cout << a << "\n";
	}
}

int main(){
	//source
	int a,b;
	cin >> a >> b;
	int out=0;
	rep(i,2){
		if(a>=b){
			out+=a;
			a--;
		}else{
			out+=b;
			b--;
		}
	}
	cout << out << endl;
	return 0;
}


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

using namespace std;
using P = pair<int, int>;

int N, M;
bool adj[700][700];
int state[700];
bool dp[702];
bool dptmp[702];


template <typename T,typename U>                                                   
pair<T,U> operator+(const pair<T,U> & l,const pair<T,U> & r) {   
    return {l.first+r.first,l.second+r.second};                                    
}

P dfs(int i, int taka = 1) {
    // cout << "    now on "<< i + 1 <<" col:"  << taka << endl; 
    state[i] = taka;
    bool fl = true;
    P ans = make_pair(0, 0);
    for (int k = 0; k < N; ++k) {
        if (!adj[i][k]) {
            //cout << k + 1 << endl;
            if (state[k] != 0) {
                if (state[k] != taka * -1) {
                    return make_pair(-1, -1);
                }
                continue;
            }
            fl = false;
            P recv = dfs(k, taka * -1);
            if (recv.first == -1) return make_pair(-1, -1);
            ans = ans + recv;
        }
    }
    P cur = taka == 1 ? make_pair(1, 0) : make_pair(0, 1);
    if (fl) {
        return cur;
    }
    return ans + cur;
}

int genans(int p) {
    int t = p;
    int h = N - p;
    return t * (t - 1) / 2 + h * (h - 1) / 2;
}

int main(){
    cin >> N >> M;
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < N; ++j) {
            adj[i][j] = false;
        }
        adj[i][i] = true;
    }
    for (int i = 0; i < M; ++i) {
        int A, B;
        cin >> A >> B;
        A--;
        B--;
        adj[A][B] = true;
        adj[B][A] = true;
    }
    for (int i = 0; i < N; ++i) state[i] = 0;

    // for (vector<int> adji : adj) {
    //     if (adji.size() == 0) continue;
    //     for (int tmp : adji) {
    //         cout << tmp << " ";
    //     }
    //     cout << endl;
    // }

    if (M == N * (N - 1) / 2) {
        cout << genans(N / 2) << endl;
        return 0;
    }

    vector<int> v;
    int sm = 0;
    for (int i = 0; i < N; ++i) {
        if (state[i] == 0) {
            //cout << "recv from " << i + 1 << endl;
            P tmp = dfs(i, 1);
            //cout << tmp.first << ", " << tmp.second << endl;
            if (tmp.first == -1) {
                cout << -1 << endl;
                return 0;
            }
            sm += tmp.first;
            v.push_back(tmp.second - tmp.first);
        }
    }
    //for (int vi : v) {
    //    cout << vi << endl;
    //}
    for (int i = 0; i < 702; i++) {
        dp[i] = false;
    }
    dp[sm] = true;
    for (int vk : v) {
        for (int i = 0; i < 702; ++i) {
            dptmp[i] = false;
            int prev = i - vk;
            if (prev >= 0 && prev < 702 && dp[prev])
                dptmp[i] = true;
        }
        for (int i = 0; i < 702; ++i) {
            dp[i] |= dptmp[i];
        }
    }

    for (int i = N / 2; i < N; i++) {
        if (dp[i] || dp[N - i]) {
            cout << genans(i) << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
void debug() {cout<<endl;}
template<typename T,typename... Args>
void debug(T x,Args... args) {cout<<x<<" ";debug(args...);}
#define forn(i,a,b) for(int i=a;i<b;++i)
#define pb push_back
#define F first
#define S second
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;


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

	int n, m, x, k;
	cin >> n >> m;
	vector<int> food(m);
	forn(i, 0, n){
		cin >> k;
		forn(j, 0, k){
			cin >> x;
			x--;
			food[x]++;
		}
	}
	int ans = 0;
	forn(i, 0, m)if(food[i] == n)ans++;
	cout << ans << endl;


}




Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
using namespace std;
typedef long long ll;
typedef pair<ll,ll>P;

vector<P>E[200000];
ll a[200000],b[200000];//y=am+b
ll M=LLONG_MAX;

void dfs(int v){
	for(P u:E[v]){
		ll A=(a[v]==1?-1:1),B=u.first-b[v];
		if(a[u.second]==INFL){
			a[u.second]=A;
			b[u.second]=B;
			dfs(u.second);
		}
		else{
			if(a[u.second]!=A||b[u.second]!=B){
				if(a[u.second]==A){
					puts("0");exit(0);
				}
				ll e=b[u.second]-B;
				if(e%2){
					puts("0");exit(0);
				}
				ll f=e/(A-a[u.second]);
				if(M!=LLONG_MAX&&M!=f){
					puts("0");exit(0);
				}
				M=f;
			}
		}
	}
}
int main(){
	int n,m;scanf("%d%d",&n,&m);
	rep(i,m){
		int u,v,s;scanf("%d%d%d",&u,&v,&s);u--;v--;
		E[u].push_back(P(s,v));
		E[v].push_back(P(s,u));
	}
	memset(a,0x3f,sizeof(a));
	a[0]=1;b[0]=0;
	dfs(0);
	ll Min=1;
	ll Max=LLONG_MAX;
	rep(i,n){
		//a=-1,b<=0
		if(a[i]==-1&&b[i]<=0){
			puts("0");return 0;
		}
		//a=-1,b>0
		if(a[i]==-1&&b[i]>0){
			Max=min(Max,b[i]-1);
		}
		//a=1,b<=0
		if(a[i]==1&&b[i]<=0){
			Min=max(Min,1-b[i]);
		}
		//a=1,b>0
	}
	if(Min>Max){
		puts("0");
	}
	else{
		if(M!=LLONG_MAX){
			if(Min<=M&&M<=Max)puts("1");
		}
		else cout<<Max-Min+1<<endl;
	}
}

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

int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};

char grid[25][25];

int main()
{
    int h,w;
    cin>>h>>w;
    for(int i=0;i<h;i++)
    {
        cin>>grid[i];
    }
    
    auto is_good=[&](int row,int col){
        return 0<=row && row<h && 0<=col && col<w && grid[row][col]=='.';
    };
    
    int ans=0;
    
    for(int row=0;row<h;row++)
    {
        for(int col=0;col<w;col++)
        {
            if(is_good(row,col))
            {
                vector<pair<int,int>>q;
                q.emplace_back(row,col);
                vector<vector<int>>dis(h,vector<int>(w));
                vector<vector<bool>>vis(h,vector<bool>(w));
                vis[row][col]=true;
                for(int i=0;i<(int)q.size();i++)
                {
                    pair<int,int>ax=q[i];
                    for(int j=0;j<4;j++)
                    {
                        int x=ax.first+dx[j];
                        int y=ax.second+dy[j];
                        if(is_good(x,y)&&!vis[x][y])
                        {
                            vis[x][y]=true;
                            dis[x][y]=dis[ax.first][ax.second]+1;
                            ans=max(ans,dis[x][y]);
                            q.emplace_back(x,y);
                        }
                    }
                }
            }
        }
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
s = input()
a = 0
count = 0

i = 0
while i < len(s)-1:
  if s[i]=='A':
    a += 1
    i += 1
  elif s[i]=='B' and s[i+1]=='C':
    count += a
    i += 2
  else:
    a = 0
    i += 1
print(count)

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

int main()
{
	vector<char>s(3);
	vector<char>t(3);
	int ans = 0;

	for (int i = 0; i < 3; i++)
	{
		cin >> s.at(i);
	} 
	for (int i = 0; i < 3; i++)
	{
		cin >> t.at(i);
	}
	for (int i = 0; i < 3; i++)
	{
		if (s.at(i) == t.at(i))ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <cstdlib>

using namespace std;
//DP用
template<class T> inline bool chmin(T& a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
const long long INF = 1LL << 60;

int main() {
    int n;
    cin >> n;
    int a[n];
    int total = 0;
    for(int i = 0; i < n; i++) {
        cin >> a[i];
        total += a[i]-1;
    }
    cout << total;
    return 0;
}


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

bool isPrime(int a){
  if(a == 0) return 0;
  if(a == 1) return 0;
  for(int i=2;i*i<=a;i++){
    if(a%i == 0) return 0;
  }
  return 1;
}

bool isLike(int a){
  return isPrime(a)&isPrime((a+1)/2);
}

int main(){
  vector<int> sum(100000+5,0);
  rep1(i,100000){
    sum[i] = sum[i-1] + isLike(i);
  }
  int q;
  cin >> q;
  rep(i,q){
    int l,r;
    cin >> l >> r;
    cout << sum[r] - sum[l-1] << endl;
  }
}

Measured memory_bytes: 1024
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

//Code Short
#define REP(i,n) for(int i = 0;i < n;++i)
#define PB(s) push_back(s)
#define DSORT(n) sort(n.begin(),n.end())
#define QECHO(n) cout << n
#define QECHOS(n) cout << n << " "

//Define Math
const double EPS = 1e-10;
const double PI  = acos(-1.0);

using namespace std;
typedef long long ll;
/* prototype */
int EDSum(ll);//各桁の和
vector<int> SOE(int,int);//素数 (Min,Max)
int MinCM(int,int);//最小公倍数(num1,num2)
int MaxCD(int,int);//最大公約数(num1,num2)
vector<int> igets(int);//cin * N
ll nPr(ll,ll); //(n,r)
ll nE(ll); //(n)
ll nCr(ll,ll); //(n,r)

void solve(){
    //START
    int a,b;
    cin >> a >> b;
    cout << 2*b-a << endl;
    
}

int main(void){cin.tie(0);ios::sync_with_stdio(false);solve();}
int EDSum(ll number) {
  int ans = 0;
  while (1) {
    ans += number % 10;
    number /= 10;
    if (number == 0) break;
  }
  return ans;
}

vector < int > SOE(int min, int max) {
  if (min < 2) min = 2;
  vector < int > int_array;
  for (int i = min; i <= max; i++) int_array.push_back(i);
  vector < int > sosu;
  double stop = sqrt(max);
  while (true) {
    sosu.push_back(int_array.front());
    int_array.erase(int_array.begin());
    if (stop < (double)(sosu.back())) break;
    for (int i = 0; i < (int) int_array.size(); i++) {
      if (int_array[i] % sosu.back() == 0)
        int_array.erase(int_array.begin() + i);
    }
  }
  sosu.insert(sosu.end(), int_array.begin(), int_array.end());
  return sosu;
}

int MinCM(int a, int b) {
  int c = a * b;
  if (a < b)
    swap(a, b);
  int r = a % b;
  while (r != 0) {
    a = b;
    b = r;
    r = a % b;
  }
  return c / b;
}

int MaxCD(int a, int b) {
  if (a < b)
    swap(a, b);
  int r = a % b;
  while (r != 0) {
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}
vector < int > igets(int N) {
  vector < int > A;
  int temp;
  for (int i = 0; i < N; ++i) {
    cin >> temp;
    A.push_back(temp);
  }
  return A;
}

ll nPr(ll n, ll r) {
  ll ans = 1;
  r = n - r;
  while (n != r) {
    ans *= n;
    --n;
  }
  return ans;
}

ll nE(ll n) {
  return nPr(n, n);
}

ll nCr(ll n, ll r) {
  if (r == 0) return -1;
  else {
    if (0 != n - r && n - r < r) r = n - r;
    return nPr(n, r) / nE(r);
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
using namespace std;


int main(){
int a, b, d, r;
double f;
cin >> a >> b;

  d = a / b;
  r = a % b;
  f = (double)a / b;


//cout << d << " " << r << " " << f << endl;
printf("%d %d %lf\n",d,r,f);

return 0;

}

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

int main() {
  int N, K;
  cin >> N >> K;
  double ans = 0.0;
  for (int i = 1; i <= N; i++) {
    double A = 1.0 / N;
    int x = i;
    while (x < K) {
      A *= 0.5;
      x *= 2;
    }
    ans += A;
  }
  cout << fixed << setprecision(15) << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
    static const double pi = 3.141592653589793;
 typedef pair<int64_t,int64_t> P;
#define rep(i, n) for (int i = 0; i < (n); i++)
 #define all(v) (v).begin(),(v).end()
 using ll = long long;
using Graph = vector<vector<int>>;
const int MAX = 510000;
const int MOD = 1000000007;
 
 
 
int main(){
ll a,b,c;
  cin>>a>>b>>c;
if(c-a-b<0) cout<<"No";
 else if(4*a*b<(c-a-b)*(c-a-b)) cout<<"Yes";
  else cout<<"No";
 
 
  }


Measured memory_bytes: 256
import collections
n = int(input())
a = list(map(int,input().split()))
c = collections.Counter(a)
l = []
for k in c:
  if c[k] >= 4:
    l += [k, k]
  elif c[k] >= 2:
    l += [k]
l.sort()
l.reverse()
if len(l)<2:
  print(0)
else:
  print(l[0]*l[1])

Measured memory_bytes: 18592