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

int main(){
  string s,t;
  cin >> s >> t;
  int sn=s.size();
  int tn=t.size();
  int n=0;
  rep(i,sn-tn+1){
    int m=0;
    rep(j,tn){
      if(s[i+j]==t[j]){
        m++;
      }
    }
    n=max(n,m);
  }
  cout << tn-n;
  
  return 0;
}

Measured memory_bytes: 3624
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;
//using Debug;
//using static System.Globalization.CultureInfo;
//using Edge = Pair<long, int>;
using System.Text;
class Program
{ 
    static void Main(string[] args)
    {
        Solve();
        //WriteLine(Solve());
    }
    static void Solve()
    {
        var ap = Input.ar;
        WriteLine((ap[0] * 3 + ap[1]) / 2);
    }
}

public class Input
{
    public static string read => ReadLine().Trim();
    public static int[] ar => read.Split(' ').Select(int.Parse).ToArray();
    public  static int num => ToInt32(read);
    public static long[] arL => read.Split(' ').Select(long.Parse).ToArray();
    public  static long numL => ToInt64(read);
    public static char[][] gred(int h) 
        => Enumerable.Repeat(0, h).Select(_ => read.ToCharArray()).ToArray();
    public static int[] ar1D(int n)
        => Enumerable.Repeat(0, n).Select(_ => num).ToArray();
    public static long[] arL1D(int n)
        => Enumerable.Repeat(0, n).Select(_ => numL).ToArray();
    public static int[][] ar2D(int n)
        => Enumerable.Repeat(0, n).Select(_ => ar).ToArray();
    public static long[][] arL2D(int n)
        => Enumerable.Repeat(0, n).Select(_ => arL).ToArray();
    public static T getValue<T>(string g)
    {
        var t = typeof(T);
        if (t == typeof(int))
            return (T)(object)int.Parse(g);
        if (t == typeof(long))
            return (T)(object)long.Parse(g);
        if (t == typeof(string))
            return (T)(object)g;
        if (t == typeof(char))
            return (T)(object)char.Parse(g);
        if (t == typeof(double))
            return (T)(object)double.Parse(g);
        if (t == typeof(bool))
            return (T)(object)bool.Parse(g);
        return default(T);
    }
    public const long Inf = (long)1e18;
    public const double eps = 1e-6;
    public  const string Alfa = "abcdefghijklmnopqrstuvwxyz";
    public  const int MOD = 1000000007;
}


Measured memory_bytes: 13396
#!/usr/bin/env python3

MOD = 1000000007
fact = []

def main():
    h, w, a, b = map(int, input().split())
    init_fact(200000)
    mp = get_list_middle_points(h, w, a, b)
    res = 0
    for y, x in mp:
        res += count(1, 1, x, y) * count(x, y, w, h)
        res %= MOD
    print(res)

def count(x1, y1, x2, y2):
    dx = abs(x1 - x2)
    dy = abs(y1 - y2)
    count = combi(dx + dy, min(dx, dy))
    return count

def get_list_middle_points(h, w, a, b):
    li = []
    y = h - a
    x = b + 1
    while (y >= 1 and x <= w):
        li.append((y, x))
        y -= 1
        x += 1
    return li

def combi(n, k):
    numera = fact[n]
    denomi = (fact[n - k] * fact[k]) % MOD
    return (numera * inv(denomi)) % MOD

def init_fact(maxn):
    assert len(fact) == 0
    fact.append(1)
    for i in range(1, maxn + 1):
        fact.append((fact[i - 1] * i) % MOD)

def inv(n):
    return pow(n, MOD - 2)

def pow(n, p):
    if p == 0:
        return 1
    elif p % 2 == 0:
        x = pow(n, p // 2)
        return (x * x) % MOD
    else:
        x = pow(n, p - 1)
        return (x * n) % MOD

main()


Measured memory_bytes: 59852
import sys
from fractions import gcd
from collections import Counter


def prime_factorization(n):
    """nを素因数分解する

    Return d(dict):
        素因数をキー、素因数の指数部を値とするディクショナリを返す

    Example:
        n=140 -> d = {2: 2, 5: 1, 7: 1}
    """
    d = Counter()
    m = 2
    while m*m <= n:
        while n%m == 0:
            n //= m
            d[m] += 1
        m = m + 1 if m == 2 else m + 2  # m=3からは、m+=2する（偶数は明らかに素数ではないので）

    if n > 1:
        d[n] += 1
    return d


def solve():
    A, B = list(map(int, sys.stdin.readline().split()))
    cd = gcd(A, B)

    if cd == 1:  # コーナーケース
        print(1)
        return

    # (素因数分解の素因数の個数)+1が答え
    prime_d = prime_factorization(cd)
    print(len(prime_d)+1)


if __name__ == "__main__":
    solve()

Measured memory_bytes: 5076
import java.util.*;

public class Main {
    public static void main(String args[]) {
       //値の取得
       Scanner sc = new Scanner(System.in);
       int N = sc.nextInt();
       int[] A = new int[N];
       int max = 0; //繰り返すことができる最大回数
      // int tmp = 0;    //操作するAの値を格納する変数
       
       for(int i = 0; i < N; ++i) {
           A[i] = sc.nextInt();
           
           //操作可能な回数分繰り返す
          // tmp = A[i];
           while(A[i] % 2 == 0) {
               A[i] = A[i] / 2;
               ++max;
           }
       }
       
       //出力
       System.out.println(max);
    }
}


Measured memory_bytes: 48648
import sys
sys.setrecursionlimit(10**5)

def f(hito, zahyo):
  x[hito]=zahyo
  for tsugi in links[hito]:
    if x[tsugi[0]]==None:
      f(tsugi[0], zahyo+tsugi[1])
    else:
      if x[tsugi[0]]!=zahyo+tsugi[1]:
        print('No')
        exit()

N, M=map(int, input().split())
links=[[] for _ in range(N+1)]
for _ in range(M):
  l, r, d=map(int, input().split())
  links[l].append([r, d])
  links[r].append([l, -d])
  
x=[None]*(N+1)
for i in range(1, N+1):
  if x[i]==None:
    f(i, 0)
    
print('Yes')

Measured memory_bytes: 137156
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,ll> pll;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

    int main(){
      int n,h,w;
      cin >> n >> h >> w;
      cout << (n-h+1)*(n-w+1) << endl;
      return 0;}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
char a[101000];
int main()
{
    int cnt1=0,cnt2=0;
    scanf("%s",a);
    for(int i=0;a[i];i++)
    {
        /*if((a[i]=='0'&&a[i+1]=='1')||(a[i]=='1'&&a[i+1]=='0'))
        {
            cnt+=2;
            int j,k;
            for(j=i+2,k=i-1;a[j]&&a[k];j++,k--)
            {
                if((a[j]=='0'&&a[j]=='1')||(a[j]=='1'&&a[k]=='0'))
                {
                    cnt+=2;
                    i++;
                }
                else
                    break;
            }
        }*/
        if(a[i]=='0')
            cnt1++;
        else
            cnt2++;
    }
    cout<<2*min(cnt1,cnt2);
    return 0;
}





Measured memory_bytes: 508
//in the name of god
//if you read this code please search about imam hussain
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

#define pb push_back;
#define X first;
#define Y second;
#define pii pair<int,int>;
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define read freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define int long long

const int maxn=1e5+5;
const int mod=1e9+7;
const int inf=1e9;
const int del=728729;

ll poww(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));
}

signed main(){
    int N, M;
    vector<pair<int, int>> np;
    cin >> N >> M;
    for (int i = 0; i < N; i++)
    {
        int a;
        cin >> a;
        np.push_back(pair<int, int>(a, 1));
    }
    for (int i = 0; i < M; i++)
    {
        int b, c;
        cin >> b >> c;
        np.push_back(pair<int, int>(c, b));
    }
 
    sort(np.begin(), np.end(), greater<pair<int, int>>());
 
    int ans = 0;
    int nans = 0;
    for (int i = 0; i < np.size(); i++)
    {
        int n = np[i].first;
        int nn = np[i].second;
        if (nans + nn < N)
        {
            ans += nn * n;
            nans += nn;
        }
        else
        {
            ans += (N - nans) * n;
            break;
        }
    }
 
    cout << ans << endl;
}



Measured memory_bytes: 6000
#include<bits/stdc++.h>
using namespace std;
int main(){
	int k,x;
  	cin>>k>>x;
  	int a,b;
  	a=x-(k-1);
  	b=x+(k-1);
  if(a<-1000000){
    for(int i=-1000000;i<=b;i++){
      cout<<i<<' ';
     }
  }
     else if(b>1000000){
     for(int i=1000000;i>=a;i--){
     	cout<<i<<' ';
     }
     }
     else {
     for(int i=a;i<=b;i++){
       cout<<i<<' ';
     }
     }

}

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

int main(){
  int n, m;
  int a[1000], b[1000], c[1000];
  int dist[100][100];
  cin >> n >> m;
  for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j++){
      if(i == j) dist[i][j] = 0;
      else dist[i][j] = 1e9;
    }
  }
  for(int i = 0; i < m; i++){
    cin >> a[i] >> b[i] >> c[i];
    a[i]--; b[i]--;
    dist[a[i]][b[i]] = dist[b[i]][a[i]] = c[i];
  }
  for(int k = 0; k < n; k++){
    for(int i = 0; i < n; i++){
      for(int j = 0; j < n; j++){
        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
      }
    }
  }
  int sum = m;
  for(int i = 0; i < m; i++){
    for(int j = 0; j < n; j++){
      if(dist[j][a[i]] + c[i] == dist[j][b[i]]){
        sum -= 1;
        break;
      }
    }
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 256
n, m, k = map(int, input().split())
a = [0] + list(map(int, input().split()))
b = [0] + list(map(int, input().split()))
s = sum(b)
j = m
ans = 0
for i in range(n+1):
    s += a[i]
    while j >= 0 and s > k:
        s -= b[j]
        j -= 1
    if j < 0:
        break
    else:
        ans = max(ans, i+j)
print(ans)

Measured memory_bytes: 120324
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using ll = long long;
using namespace std;

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

    rep(i, s.length()) {
        s[i] += n;
        if(s[i] > 'Z') {
            s[i] -= 26;
        }
    }

    cout << s << endl;
}

Measured memory_bytes: 3632
using System;

namespace ITP1_8_D
{
    class Program
    {
        static void Main(string[] args)
        {
            string input1 = Console.ReadLine();
            string input2 = Console.ReadLine();

            string circle = input1 + input1;

            if (circle.Contains(input2))
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}

Measured memory_bytes: 9740
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
  int n,x,y;
  cin>>n>>x>>y;
  int count[n];
  for(int i=0;i<=n;i++)
    count[i]=0;
  for(int i=0;i<n;i++)
  {
    for(int j=0;j<n;j++)
    {
      int s=j-i;
      int k=abs(x-i-1)+1+abs(j-y+1);
      int u=abs(y-i-1)+1+abs(j-x+1);
      int v=((s<k)&&(s<u))?s:(k<u)?k:u;
      count[v]++;
    }
  }
  for(int i=1;i<n;i++)
    cout<<count[i]<<"\n";
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <utility>
using namespace std;
using ll = long long;
 
int main() {
	ll a,b,m;
	cin >> a >> b >> m;
	vector <ll> ax (a);
	vector <ll> bx (b);
	ll minA = 0;
	ll minB = 0;
	ll minSum;
	for (ll i=0;i<a;i++) {
		cin >> ax[i];
		if (minA == 0) {
			minA = ax[i];
		}
		minA = min(minA,ax[i]);
	}
	for (ll i =0;i <b;i++) {
		cin >> bx[i];
		if (minB == 0) {
			minB = bx[i];
		}
		minB = min(minB, bx[i]);
	}
	minSum = minA + minB;

	ll c,d,e;
	for (ll i =0; i< m;i++) {
		cin >> c >> d >> e;
		ll value;
		value = ax[c-1] + bx[d-1] - e;
		minSum = min (minSum, value);
	}
	cout << minSum << endl;
	return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <algorithm>
#include <set>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define ll long long
#define P pair<int, int>

using namespace std;
int mod = 1000000007;

int N;
int main() {
  cin >> N;
  ll suma = 0;
  vector<int> a(N);
  rep(i, N) {
    cin >> a.at(i);
    suma += a.at(i);
  }
  vector<int> b(N);
  ll sumb = 0;
  rep(i, N) {
    cin >> b.at(i);
    sumb += b.at(i);
  }

  ll numcount = sumb - suma;
  ll count = 0;
  ll cnt = 0;
  bool odd = false;
  rep(i, N) {
    if (a.at(i) < b.at(i)) {
      count += b.at(i) - a.at(i);
      if ((b.at(i) - a.at(i))%2 != 0) {
        count--;
      }
    }
    if (b.at(i) < a.at(i)) {
      count -= 2*(a.at(i)-b.at(i));
    }
  }
  cout << ((count>=0) ? "Yes" : "No") << endl;
}


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

const int INF = (1<<29);

const int dy[2][6] = {{1,0,-1,-1,-1,0},{1,1,0,-1,0,1}};
const int dx[6] = {0,1,1,0,-1,-1};
int wmin,hmin,wmax,hmax;

class state{
public:
  int y,x,t,cost;
  state(int y=0, int x=0, int t=0, int c=0):y(y),x(x),t(t),cost(c){}
  bool operator < (const state &s) const {
    return cost > s.cost;
  }
};

bool check(int y, int x){
  if(y < hmin || y > hmax) return false;
  if(x < wmin || x > wmax) return false;
  return true;
}

int main(){
  int sx,sy,gx,gy;
  while(cin >> sx >> sy >> gx >> gy){
    sx += 100;
    sy += 100;
    gx += 100;
    gy += 100;
    int n, h, w, a[6][201][201], ans=INF;
    state u(sy,sx,0,0), v;
    priority_queue<state> Q;
    for(int i=0;i<6;i++) for(int j=0;j<201;j++) for(int k=0;k<201;k++) a[i][j][k] = INF;
    a[0][sy][sx] = 0;

    cin >> n;
    for(int i=0;i<n;i++){
      int x,y;
      cin >> x >> y;
      x += 100;
      y += 100;
      for(int j=0;j<6;j++) a[j][y][x] = -1;
    }
    cin >> w >> h;
    wmin = 100 - w;
    wmax = 100 + w;
    hmin = 100 - h;
    hmax = 100 + h;

    for(Q.push(u); !Q.empty();){
      u = Q.top();
      Q.pop();
      if(u.y == gy && u.x == gx || ans <= u.cost){
	ans = min(ans,u.cost);
	break;
      }
      
      int next = abs((u.x-100) * (u.y-100) * u.t) % 6;
      v = u;
      v.y += dy[u.x%2][next];
      v.x += dx[next];
      v.t++;
      if(check(v.y,v.x) && a[v.t%6][v.y][v.x] > v.cost){
	a[v.t%6][v.y][v.x] = v.cost;
	Q.push(v);
      }

      v = u;
      v.t++;
      v.cost++;
      if(check(v.y,v.x) && a[v.t%6][v.y][v.x] > v.cost){
	a[v.t%6][v.y][v.x] = v.cost;
	Q.push(v);
      }

      for(int i=0;i<6;i++){
	v = u;
	v.y += dy[u.x%2][i];
	v.x += dx[i];
	v.t++;
	v.cost++;
	if(check(v.y,v.x) && a[v.t%6][v.y][v.x] > v.cost){
	  a[v.t%6][v.y][v.x] = v.cost;
	  Q.push(v);
	}
      }
    }

    if(ans == INF) cout << -1 << endl;
    else cout << ans << endl;
  }
}

Measured memory_bytes: 2324
/*
    Washief Hossain Mugdho
    17 September 2020
    Educational DP Coins
*/

#ifndef DEBUG
#pragma GCC optimize("O3")
#endif

#include <bits/stdc++.h>
#define ull unsigned long long
#define ll long long
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define fastio ios_base::sync_with_stdio(0)
#define untie cin.tie(0)
#define ms(a, b) memset(a, b, sizeof a)
using namespace std;
bool visited[3005][3005];
double memo[3005][3005];
double arr[3005];
int n;

double dp(int a, int b)
{
    if (a >= n && b != 0)
        return 0.0;
    if (visited[a][b])
        return memo[a][b];
    visited[a][b] = 1;
    if (b == 0)
    {
        double res = 1.0;
        for (int i = a; i < n; i++)
            res *= (1 - arr[i]);
        return memo[a][b] = res;
    }
    return memo[a][b] = (1.0 - arr[a]) * dp(a + 1, b) + arr[a] * dp(a + 1, b - 1);
}

int main()
{
#ifdef LOCAL_OUTPUT
    freopen(LOCAL_OUTPUT, "w", stdout);
#endif
#ifdef LOCAL_INPUT
    freopen(LOCAL_INPUT, "r", stdin);
#endif
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> arr[i];
    int m = n / 2 + 1;
    double res = 0.0;
    for (int i = m; i <= n; i++)
        res += dp(0, i);
    cout << fixed << setprecision(12) << res << endl;
}


Measured memory_bytes: 79288
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<set>
#include<map>
typedef long long int ll;
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
#define EREP(i,n) for (int i=1;i<=(n);i++)
#define ALL(a) (a).begin(),(a).end()
//#define EVEL 1

#ifdef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const ll MOD = 1000000007;
const int INF = 2000000000;

    ll N,M;
    ll A,B,C;
    std::string S,T;
    bool F=true;
    ll ans=0;
    ll a[10010],b[10010];
    //解説AC 合計操作回数に注目する一般的なテクニック！！！！！
int main(){
    ios_base::sync_with_stdio(false);
    cin>>N;
    REP(i,N){cin>>a[i];A-=a[i];}
    REP(i,N){cin>>b[i];A+=b[i];}
    REP(i,N){
        if(a[i]<b[i]){
            B+=(b[i]-a[i]+1)/2;
        }
        if(a[i]>b[i]){C+=(a[i]-b[i]);}
    }
    cout<<(A>=0&&max(B,C)<=A?"Yes":"No")<<endl;
    return 0;
}


Measured memory_bytes: 384
#include <cstdio>
#include <cstring>

int main(){
	int n;
	char S[50][52];
	char A[256];

	int alpha[50][26];
	int min[26];

	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%s",S[i]);
	}

	for(int i=0;i<n;i++){
		for(int j=0;j<26;j++){
			alpha[i][j] = 0;
			min[j] = 0;
		}
	}

	for(int i=0;i<n;i++){
		for(int j=0;j<strlen(S[i]);j++){
			alpha[i][S[i][j]-'a'] += 1;
		}
	}

	for(int i=0;i<26;i++){
		min[i] = alpha[0][i];
		for(int j=0;j<n;j++){
			if(min[i]>alpha[j][i]){
				min[i] = alpha[j][i];
			}
		}
	}

	for(int i=0;i<26;i++){
		for(int j=0;j<min[i];j++){
			printf("%c",('a'+i));
		}
	}
	printf("\n");

	return 0;
}


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


mod = 10 ** 9 + 7
N = 10 ** 6

#逆元テーブル
inv_t = [0]+[1]
for i in range(2, N):
  inv_t += [inv_t[mod % i] * (mod - int(mod / i)) % mod]

#階乗計算
kai = [1, 1]
rev_kai = [1, inv_t[1]]
for i in range(2, N):
	kai.append(kai[-1] * i % mod)
	rev_kai.append(rev_kai[-1] * inv_t[i] % mod)

# コンビネーション計算
def cmb(n,r):
    res = 1
    for i in range(r):
        res *= n * inv_t[r]
        res %= mod
        n -= 1
        r -= 1
    return res

def calc(n):
    res = 0
    for i in range(1, n):
        res += (n - i) * i
        res %= mod
    return res

ans = 0
ans += m * m * cmb(n*m -2, k-2) * calc(n)
ans %= mod

ans += n * n * cmb(n*m -2, k-2) * calc(m)
ans %= mod

print(ans)


Measured memory_bytes: 122176
h, w = map(int, input().split())
a = [
    input().rstrip()
    for _ in range(h)
]

hh = []
for y in range(h):
    f = True
    for x in range(w):
        if a[y][x] == '#':
            f = False
            break
    if f:
        hh.append(y)

ww = []
for x in range(w):
    f = True
    for y in range(h):
        if a[y][x] == '#':
            f = False
            break
    if f:
        ww.append(x)

ans = []
for y in range(h):
    if y in hh:
        continue
    aa = ''
    for x in range(w):
        if x in ww:
            continue
        aa += a[y][x]
    ans.append(aa)

for aa in ans:
    print(aa)

Measured memory_bytes: 9144
#![allow(unused_imports)]
use proconio::{input, fastout};
use proconio::marker::*;

#[fastout]
fn main() {
    input! {
    s: Chars,
    k: usize
    }
    for i in 0..k {
        if s[i] != '1' {
            println!("{}", s[i]);
            return
        }
    }
    println!("1");
}


Measured memory_bytes: 2144
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
int a[205][205],n,m,x,s;
int b[11][11];
 
int main()
{
	cin>>n>>m;
	for(int i=0;i<=9;i++)
	for(int j=0;j<=9;j++)
	cin>>b[i][j];
	
	for(int k=0;k<=9;k++)
	for(int i=0;i<=9;i++)
	for(int j=0;j<=9;j++)
	{
		if(b[i][j]>b[i][k]+b[k][j])
		b[i][j]=b[i][k]+b[k][j];
	}
	
	for(int i=1;i<=n;i++)
	for(int j=1;j<=m;j++)
	{
		cin>>x;
		if(x!=-1&&x!=1)
		s+=b[x][1];
	}
	cout<<s;
	
	
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    char ch[1001];
    int i, sum;
    
    while(scanf("%s\n", ch) && ch[0] != '0'){
        sum = 0;
        for(i = 0; i < 1001; i++){
            if(ch[i] == 0) break;
            sum += (ch[i] - '0');
        }
        printf("%d\n", sum);
    }
    
    return 0;
}



Measured memory_bytes: 2040
import java.io.*;
import java.util.*;
public class Main {
    public static void main(String args[]) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int s = sc.nextInt();
        
        int a = 10000, b = 5000, c = 1000;

        for(int x = 0; x <= n; x++) {
            for(int y = 0; y <= n; y++) {
                int curSum = x * a + y * b + (n - x - y) * c;
                if(curSum == s && (n - x - y) >= 0) {
                    System.out.println(x + " " + y + " " + (n - x - y));
                    return;
                }

            }
        }

        System.out.println("-1 -1 -1");
    }
}

Measured memory_bytes: 23636
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define in insert
#define er erase
#define fr first
#define sc second
const int inf=INT_MAX;
const int nmax=1e5+5;
const int mod=1e9+7;
typedef long long ll;
using namespace std;
int n,i,idx;
ll x,a[nmax];
map<ll,int>mp;
int main()
{
	ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
	//freopen("sol.in","r",stdin);
	cin>>n;
	for(i=1;i<=n;i++)
	{
		cin>>x;
		if(!mp[x])a[++idx]=x;
		mp[x]++;
	}
	sort(a+1,a+idx+1);
	x=0;
	for(i=idx;i>=1;i--)
	{
		if(mp[a[i]]>=4 && !x)rc(a[i]*a[i]);
		else if(mp[a[i]]>=2 && x)rc(a[i]*x);
		else if(mp[a[i]]>=2 && !x)x=a[i];
	}
	rc(0);
	//return 0;
}

Measured memory_bytes: 7296
#include <iostream>
#include <algorithm>
#include <cmath>
#include <queue>
#include <utility>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <climits>
#include <vector>
#include <set>
#include <string>
#include <numeric>


#define FAST_IO ios_base::sync_with_stdio(false), cin.tie(nullptr)
#define DEBUG freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
//#define int long long
using namespace std;

signed main() {
    FAST_IO;
    //DEBUG;

    int n;
    cin >> n;
    int jumps[n + 1];
    vector<int> dp(n + 1, 0);
    for (int i = 1; i <= n; i++) cin >> jumps[i];
    //dp[1] = jumps[1];
    dp[2] = abs(jumps[2] - jumps[1]);
    for (int i = 3; i <= n; i++)
        dp[i] = min(abs(jumps[i] - jumps[i - 1]) + dp[i - 1], abs(jumps[i] - jumps[i - 2]) + dp[i - 2]);
    cout << dp[n];
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>

using namespace std;

int main()
{
  int b=0;
  string s;
  cin >> s;

  for(int i=0;i<s.size();i++){
    if(s[i]=='+')b++;
    else b--;
  }

  cout << b << endl;

  return 0;
}

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

int main(){
    int N;
    int M;
    int i;
    int j;
    float Sum;
    float sikii;
    cin >> N >> M;
    vector<float> A(N,0);

    for(i=0;i<N;i++){
        cin >> A.at(i);
    }


    for(i=0;i<N;i++){
        Sum = Sum + A.at(i);
    }
    sikii = Sum /(4 * M);

    sort(A.begin(), A.end(), greater<int>());

    int hantei = 0;
    string result;
    int good = 0;
    for(i=0;i<M;i++){
            //cout << "A:" << (float)A.at(i) << endl;
            //cout << "sikii:" << sikii << endl;
        if(A.at(i) >= sikii){
            good++;
        }
    }
    
    if(good==M){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
// B - Foods Loved by Everyone
#include <bits/stdc++.h>
using namespace std;
#define rp(i,n) for(int i=0;i<(n);i++)

int in(){int x;cin>>x;return x;}

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

	map<int,int> A;
	rp(i, N){
		int k = in();
		rp(j,k) A[in()]++;
	}

	int count = 0;
	for(auto e:A) if(e.second==N) count++;
	cout<< count <<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,L;
int result = 0;
  int mini = 10000;
  cin >> N >> L;
  for(int a = 0;a < N;a++){
    result += a + L;
    if(abs(mini) > abs(a + L))mini = a + L;
    
    
    
  }
  cout << result - mini << endl;
}

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

enum inf3 = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;




void main() {
    int n;
    scan(n);
    auto v = readln.split.to!(double[]);

    auto bh = new BinaryHeap!(Array!double, "a > b")();

    foreach (i ; 0 .. n) {
        bh.insert(v[i]);
    }

    foreach (i ; 0 .. n - 1) {
        auto a = bh.front; bh.popFront();
        auto b = bh.front; bh.popFront();
        bh.insert((a + b) / 2.0);
    }

    auto ans = bh.front;

    writefln("%.12f", ans);
}




















int[][] readGraph(int n, int m, bool isUndirected = true, bool is1indexed = true) {
    auto adj = new int[][](n, 0);

    foreach (i; 0 .. m) {
        int u, v;
        scan(u, v);
        if (is1indexed) {
            u--, v--;
        }
        adj[u] ~= v;
        if (isUndirected) {
            adj[v] ~= u;
        }
    }

    return adj;
}

alias Edge = Tuple!(int, "to", int, "cost");

Edge[][] readWeightedGraph(int n, int m, bool isUndirected = true, bool is1indexed = true) {
    auto adj = new Edge[][](n, 0);

    foreach (i; 0 .. m) {
        int u, v, c;
        scan(u, v, c);
        if (is1indexed) {
            u--, v--;
        }
        adj[u] ~= Edge(v, c);
        if (isUndirected) {
            adj[v] ~= Edge(u, c);
        }
    }

    return adj;
}

void yes(bool b) {
    writeln(b ? "Yes" : "No");
}

void YES(bool b) {
    writeln(b ? "YES" : "NO");
}

T[] readArr(T)() {
    return readln.split.to!(T[]);
}

T[] readArrByLines(T)(int n) {
    return iota(n).map!(i => readln.chomp.to!T).array;
}

void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}


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

int main()
{
	double a,b,c,d,e,f;
	double x,y;
	
	while (1) {
		cin>>a>>b>>c>>d>>e>>f;
		if (cin.eof())break;
		y = (c * d - a * f) / (b * d - e * a);
		x = (c - (b * y)) / a;
		cout<<setprecision(3)<<setiosflags(ios::fixed)<<x<<" "<<y<<endl;
	}	
	return 0;
}

Measured memory_bytes: 0
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>

using namespace std;

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

const ll INF = 1e15;
ll n, m, l, q;
vector<P> edge[330];
ll dist[330][330];

void dijkstra (ll s) {
  priority_queue<P, vector<P>, greater<P>> pq;

  for (int i = 0; i < n; i++) {
    dist[s][i] = INF;
  }

  dist[s][s] = 0;
  pq.push(P(0, s));

  while (pq.size()) {
    P p = pq.top();
    pq.pop();
    ll u = p.second;
    if (dist[s][u] < p.first) continue;
    for (P p: edge[u]) {
      ll v = p.first;
      ll cost = p.second;
      if (dist[s][v] > dist[s][u] + cost) {
        dist[s][v] = dist[s][u] + cost;
        pq.push(P(dist[s][v], v));
      }
    }
  }
}

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

  for (int i = 0; i < m; i++)
  {
    ll a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    edge[a].push_back(P(b, c));
    edge[b].push_back(P(a, c));
  }

  for (int i = 0; i < n; i++) {
    dijkstra(i);
  }
  
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (dist[i][j] > l) {
        dist[i][j] = INF;
      } else {
        dist[i][j] = 1;
      }
    }
  }
  
  for (int k = 0; k < n; k++) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
      }
    }
  }
  
  cin >> q;
  while (q--) {
    ll s, t;
    cin >> s >> t;
    s--, t--;
    if (dist[s][t] == INF) dist[s][t] = 0;
    cout << dist[s][t] - 1 << endl;
  }
  
  return 0;
}


Measured memory_bytes: 4504
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		int N = sc.nextInt();
		int A = sc.nextInt();
		int[] x = sc.nextIntList(N);

		long[][] dp = new long[N + 1][2601];
		dp[0][0] = 1;

		for (int i = 1; i <= N; i++) {
			for (int j = 0; j <= 2500; j++) {
				dp[i][j + A] += dp[i - 1][j];
				dp[i][j + x[i - 1]] += dp[i - 1][j];
			}
		}

		System.out.println(dp[N][A * N] - 1);

	}

}

class FastScanner {
	public static String debug = null;

	private final InputStream in = System.in;
	private int ptr = 0;
	private int buflen = 0;
	private byte[] buffer = new byte[1024];
	private boolean eos = false;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				if (debug != null) {
					buflen = debug.length();
					buffer = debug.getBytes();
					debug = "";
					eos = true;
				} else {
					buflen = in.read(buffer);
				}
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen < 0) {
				eos = true;
				return false;
			} else 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;
	}

	private void skipUnprintable() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
	}

	public boolean isEOS() {
		return this.eos;
	}

	public boolean hasNext() {
		skipUnprintable();
		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() {
		return (int) nextLong();
	}

	public long[] nextLongList(int n) {
		return nextLongTable(1, n)[0];
	}

	public int[] nextIntList(int n) {
		return nextIntTable(1, n)[0];
	}

	public long[][] nextLongTable(int n, int m) {
		long[][] ret = new long[n][m];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				ret[i][j] = nextLong();
			}
		}
		return ret;
	}

	public int[][] nextIntTable(int n, int m) {
		int[][] ret = new int[n][m];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				ret[i][j] = nextInt();
			}
		}
		return ret;
	}
}

Measured memory_bytes: 8916
n,k=gets.split(' ').map(&:to_i)
#h=gets.split(' ').map(&:to_i)
#tajigen = Array.new(4) { Array.new(2,0) }
if n==k
  puts 0

elsif n>k
  if (n%k)==0
    puts 0
  else
    puts k - n%k
  end
elsif n<k
  if (k-n)<n
      puts k-n
    else
      puts n
  end
end


Measured memory_bytes: 1788
#include<iostream>
#include<math.h>
#include<vector>
#include<array>
#include<algorithm>
#include<numeric>
#include<map>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vector<ll>> mat;

ll p=pow(10,9)+7;
//行列のサイズ
int m;

//DPの更新
vec matmul(vec& dp,mat& mt){
    vec ret(m,0);
    for(int i=0;i<m;i++){
        for(int j=0;j<m;j++)
            ret[i]+=(mt[i][j]*dp[j])%p;
    }
    return ret;
}

//遷移行列の更新
mat update(mat& mt){
    mat ret(m,vec(m,0));
    for(int i=0;i<m;i++){
        for(int j=0;j<m;j++){
            for(int k=0;k<m;k++)
                ret[i][j]+=(mt[i][k]*mt[k][j])%p;
        }
    }
    return ret;
}

//累乗
void matpow(vec& dp,mat& mt,int k){
    m=dp.size();
    while(k>0){
        if(k & 1)dp=matmul(dp,mt);
        mt=update(mt);
        k/=2;
    }
}

vec n(200010),n_rev(200010);

void fuct(int N){
    n[0]=1;int i=1;
    while(i<=N){
        n[i]=((ll)i*n[i-1])%p;
        i++;
    }
}
void fuct_rev(int N){
    n_rev[1]=1;
    vec dp(1);mat mt(1,vec(1));
    for(int i=2;i<=N;i++){
        dp[0]=1;
        mt[0][0]=n[i];
        matpow(dp,mt,p-2);
        n_rev[i]=dp[0];
    }
}

ll comb(int N,int r){  
    if(r==0 || N==r)return 1;
    return (((n[N]*n_rev[r])%p)*n_rev[N-r])%p;
}

int main(){
    fuct(200005);fuct_rev(200005);
    int H,W,A,B;cin>>H>>W>>A>>B;
    ll ans=0;
    int i=H-A-1,j=B;
    while(i>=0 && j<=W-1){
        ans+=(comb(i+j,i)*comb(H+W-2-i-j,H-i-1))%p;
        ans=ans%p;
        i--;j++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3328
// Author: pankaj_m05 

#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
#define f_in(file) freopen(file, "r", stdin)
#define f_out(file) freopen(file, "w", stdout)
#define sz(a) int((a).size())
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(c) c.begin(), c.end()
#define tr(c,i) for(typeof(c).begin() i = c.begin(); i != c.end(); i++)
#define present(c,x) (c.find(x) != c.end())  // Set and Maps
#define cpresent(c,x) (find(allc,x) != c.end()) // Vectors
using namespace std;

typedef vector< int > vi;
typedef vector< vi > vvi;
typedef pair< int, int > ii;
typedef long long ll;

const int mod = 1e9 + 7;
const int mxN = 2 * 1e5;
const int mxA = 1e6;
int n, a[mxN]; 
int cnt[mxA + 1];   
            	
void testcase() {
	cin >> n;
	int mx = -1; 
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
		mx = max(mx, a[i]);
	}
	for (int i = 0; i < n; ++i) {
		int t = a[i];
		if(cnt[t] >= 1) {
			++cnt[t];
			continue; 
		}
		while (t <= mx) {
			++cnt[t];
			t += a[i];
		}
	}
	int ans = 0;
	for (int i = 0; i < n; ++i) {
		if (cnt[a[i]] <= 1) ++ans;
	}
	cout << ans << '\n';
}

int main(void) { 
	fast     
	testcase();
	return 0;
}                                          

Measured memory_bytes: 8256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <cmath>
using namespace std;

#define int long long
#define endl "\n"
#define all(v)  v.begin(),v.end()
#define fir first
#define sec second
#define m_p make_pair
#define rep(i,n)  for(int i=0; i<(int) (n); i++)
#define vecin(v) for(int i=0; i<(int)v.size(); i++)cin>>v[i];
#define vecout(v,n) for(int i=0; i<n; i++)cout<<v[i]<<" "; cout<<endl;

const int mod = 1000000007;
const int INF = 2000000015;
const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
int jousu(int x00, int y00) {
	int z00 = 1;
	for (int i = 0; i < y00; i++) {
		z00 *= x00;
	}
	return z00;
}
int keta(int x00) {
	int z00 = x00;
	int w00 = 0;
	while (z00 != 0) {
		z00 /= 10;
		w00++;
	}
	return w00;
}
int krag(double xx) {
	return INF - (int)(INF - xx);
}


int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
int modpow(int a, int n) {
	int res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}
int com(int xx, int yy) {
	int zz = 1;
	for (int i = xx; i > xx - yy; i--) {
		zz *= i;
		zz %= mod;
	}
	for (int i = 1; i <= yy; i++) {
		zz *= modinv(i, mod);
		zz %= mod;
	}
	return zz;
}
int gcd(int xx, int yy) {
	int p = xx;
	int q = yy;
	if (q > p)swap(p, q);
	while (p % q != 0) {
		p %= q;
		swap(p, q);
	}
	return q;
}
int lcm(int xx, int yy) {
	return xx * yy / gcd(xx, yy);
}
bool prime(int xx) {
	int a = xx;
	for (int i = 2; i * i <= xx; i++) {
		if (xx % i == 0) {
			return 0;
		}
	}
	return 1;
}



signed main() {
	int a, b;
	cin >> a >> b;
	cout << max(a + b, max(a - b, a * b)) << endl;
}



Measured memory_bytes: 256
x, k, d = map(int, input().split())

first_step = abs(x // d)
rem_k = k - first_step

now = x
if k < first_step:
    if x < 0:
        now = x + (d * k)
    else:
        now = x - (d * k)
else:
    if x < 0:
        now = x + (d * first_step)
        if rem_k % 2 == 1:
            if now < 0:
                now += d
            else:
                now -= d
    else:
        now = x - (d * first_step)
        if rem_k % 2 == 1:
            if now < 0:
                now += d
            else:
                now -= d

print(abs(now))


Measured memory_bytes: 9192
import java.util.*;

public class Main{
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    double ans = 0.0;
    if(N%2==0){
      ans = 0.5;
    }else{
      ans = (double)((N/2)+1)/N;
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 23764
def levenshtein(str1, str2):
    if len(str1) == 0 or len(str2) == 0: return max(len(str1), len(str2))
    # init
    dp = [[None for i in range(len(str2)+1)] for i in range(len(str1)+1)]
    for i in range(len(str1)+1): dp[i][0] = i
    for j in range(len(str2)+1): dp[0][j] = j

    for i in range(1, len(str1)+1):
        for j in range(1, len(str2)+1):
            val = dp[i-1][j-1] if str1[i-1] == str2[j-1] else dp[i-1][j-1]+1
            dp[i][j] = min(val, dp[i-1][j]+1, dp[i][j-1]+1)
    return dp[-1][-1]

s1 = input()
s2 = input()

print(levenshtein(s1, s2))



Measured memory_bytes: 42900
#include <bits/stdc++.h>
#define N 100020
#define ll long long
using namespace std;
inline int read(){
  int x=0,f=1;char ch=getchar();
  while(ch>'9'||ch<'0')ch=='-'&&(f=0)||(ch=getchar());
  while(ch<='9'&&ch>='0')x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
  return f?x:-x;
}
int a[N];
vector<int> son[N];

int resolve(int x) {
  vector<int> dps;
  for (size_t i = 0; i < son[x].size(); ++ i) {
    dps.push_back(resolve(son[x][i]));
  }
  sort(dps.begin(), dps.end());
  int mxdep = 1;
  for (size_t i = 0; i < dps.size(); ++ i) {
    mxdep = max(mxdep, (int) (dps[i] + dps.size() - i));
  }
  return mxdep;
}

int main(int argc, char const *argv[]) {
  // freopen("../../temp/.in", "r", stdin);
  int n = read();
  for (int i = 2; i <= n; ++ i) {
    a[i] = read();
    son[a[i]].push_back(i);
  }

  printf("%d\n", resolve(1) - 1);

  return 0;
}

Measured memory_bytes: 13952
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
typedef long long int ll;
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
#define EREP(i,n) for (int i=1;i<=(n);i++)
#define ALL(a) (a).begin(),(a).end()
#define EVEL 1

#ifndef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const int MOD = 1000000007;
const ll INF = 200000000000;


    ll W,H,N;
    ll sum;
    ll ans=0;
    ll A[110];
    bool f=false;
int main(){
    ios_base::sync_with_stdio(false);
    cin>>N;
    REP(i,N){cin>>A[i];sum+=A[i];if(A[i]%10!=0)f=true;}
    sort(A,A+N);
    if(!f)cout<<"0";
    else{
        if(sum%10!=0){
            cout<<sum;
        }else{
            REP(i,N){
                if(A[i]%10!=0){sum-=A[i];break;}
            }
            cout<<sum;
        }
    }


    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin,(obj).end()
#define SORT(list) sort(ALL((list)));
using namespace std;
using ll = long long;
int main(){
    ll n,m;
    cin >> n >> m;
    ll x[m];
    REP(i,m)cin >> x[i];
    sort(x,x+m);
    vector<ll> dist(m-1);
    int j=0;
    if(n>=m){
        cout << 0 << endl;
        return 0;
    }
    REP(i,m-1){
        dist[i]=x[i+1]-x[i];
    }
    sort(dist.begin(),dist.end());
    reverse(dist.begin(),dist.end());
    int answer = 0;
    int diff = 0;
    int full = x[m-1]-x[0];
    REP(i,n-1){
        diff += dist[i];
    }
    //cout << full << "  " << diff << endl;
    answer=full-diff;
    cout << answer << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <vector>
#include <list>
#include <algorithm>
#include <cmath>
#include <stack>
#include <map>
#include <numeric>
#include <sstream>
#include <queue>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int (i)=0; (i)<(n); (i)++)
#define FOR(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define PUSH(n,v) for(int i=0; i<(n); i++) {int j; cin >> j; v.push_back(j);}
#define ALL(v) v.begin(), v.end()
#define print(s) cout << (s) << endl

void solve87(string s) {
    stringstream ss;
    ss << s;
    stack<double> st;
    string cmd;
    double i, j;
    while(ss >> cmd) {
        if (cmd == "-") {
            j = st.top(); st.pop();
            i = st.top(); st.pop();
            st.push(i - j);
        }else if (cmd == "+") {
            j = st.top(); st.pop();
            i = st.top(); st.pop();
            st.push(i + j);
        }else  if (cmd == "*") {
            j = st.top(); st.pop();
            i = st.top(); st.pop();
            st.push(i * j);
        }else  if (cmd == "/") {
            j = st.top(); st.pop();
            i = st.top(); st.pop();
            st.push(i / j);
        }else {
            st.push(stoi(cmd));
        }
    }
    printf("%.6f\n", st.top());
}

int main() {
    string s;
    while(getline(cin, s)) {
        solve87(s);
    }
    return 0;
}

Measured memory_bytes: 3248
N = int(input())
B = list(map(int,input().split(" ")))

#最適なAの値を求めていく
A = []

A.append(B[0])

for i in range(N-1):
    if(i == N-2):
        A.append(B[i])
    else:
        if B[i] > B[i+1]:
            A.append(B[i+1])
        else:
            A.append(B[i])

print(sum(A))

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

int main() {
    int n;
    double d;
    cin>>n; cin>>d;
    int c=0;
    while(n--){
        
        long x; long y;
        cin>>x; cin>>y;
        
        double a = sqrt( (x*x) + (y*y));
        if(a<=d){
            c++;
        }
    }
    
    cout<<c;
    
    
}


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

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

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; }
typedef long long ll;

const long long INF = 1LL << 60;

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

    int cnt = (X - A) / B;
    cout << (X - A) - B * cnt << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        try (Scanner in = new Scanner(System.in)) {
            int[] time = new int[5];
            for (int i = 0; i < time.length; i++) {
                time[i] = in.nextInt();
            }

            int min = (int) 1e9;
            boolean[] used = new boolean[5];
            for (int i = 0; i < time.length; i++) {
                used[i] = true;
                int t1 = time[i];
                while (t1 % 10 != 0) {
                    t1++;
                }
                for (int i2 = 0; i2 < time.length; i2++) {
                    if (used[i2]) {
                        continue;
                    }
                    used[i2] = true;
                    int t2 = t1 + time[i2];
                    while (t2 % 10 != 0) {
                        t2++;
                    }
                    for (int i3 = 0; i3 < time.length; i3++) {
                        if (used[i3]) {
                            continue;
                        }
                        used[i3] = true;
                        int t3 = t2 + time[i3];
                        while (t3 % 10 != 0) {
                            t3++;
                        }
                        for (int i4 = 0; i4 < time.length; i4++) {
                            if (used[i4]) {
                                continue;
                            }
                            used[i4] = true;
                            int t4 = t3 + time[i4];
                            while (t4 % 10 != 0) {
                                t4++;
                            }
                            for (int i5 = 0; i5 < time.length; i5++) {
                                if (used[i5]) {
                                    continue;
                                }
                                int t5 = t4 + time[i5];
                                if (t5 < min) {
                                    min = t5;
                                }
                            }
                            used[i4] = !true;
                        }
                        used[i3] = !true;
                    }
                    used[i2] = !true;
                }
                used[i] = !true;
            }
            System.out.println(min);
        }
    }
}


Measured memory_bytes: 22996
#include <bits/stdc++.h>
#define ll long long
#define PB push_back
#define MP make_pair

#define REP(i, n) for(int i=0;i<(int)(n);++i)
#define FOR(i,l,h) for(int i=(int)(l);i<=(int)(h);++i)
#define FORD(i,h,l) for(int i=(int)(h);i>=(int)(l);--i)

#define max(a,b) a>b?a:b
#define min(a,b) a>b?b:a

ll gcd(ll a, ll b) { return !b ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
using namespace std;
// ceil(2.3) = 3
// floor(2.3) = 2

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin>>s;
     int len = s.length();
    ll int n,a1 = 0,a2 = 0;
    cin>>n;
    int flag =1;
    for(int i =1 ;i<len;i++){
        if(s[i] != s[i-1]){
            flag = 0;
            break;
        }
    }
    if(flag == 1){
        cout<<len*n/2;
    }
    else{
     for( int j=1;j<s.length();j++){

            if(s[j-1] == s[j]){
                a1 += 1;
                j++;
            }
        }
        s = s+s;
     for(int i = 1;i<2*len;i++){
         if(s[i-1] == s[i]){
             a2 += 1;
             i++;
         }
     }
     // so it is like AP term is a1,a1+d,a1+2d......;
     ll int d = abs(a1-a2);
     //cout<<a1<<" "<<a2<<" "<<d<<"\n";
     cout<<a1 + d*(n-1);  // AP formula for nth term
   }

    return 0;
}


Measured memory_bytes: 256