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

int main(){
    unsigned long long N, A, B; cin >> N >> A >> B;
    if (N>=A+B){//入りきるとき
        if (A==0) {
            cout << 0 << endl;
        } else {
            if (N%(A+B)>=A){
                cout << N/(A+B)*A+A << endl;
            } else {
                cout << N/(A+B)*A+N%(A+B) << endl;
            }
        }
    } else {//入りきらないとき
        if (A>=N){
            cout << N << endl;
        } else {
            cout << A << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
n=int(input())
l=list(map(int,input().split()))

for i in range(n):
    l[i]=l[i]-(i+1)

from statistics import mean, median,variance,stdev
z=int(median(l))

x=0
for j in range(n):
    x+=abs(l[j]-z)

print(x)

Measured memory_bytes: 26020
import sys

for line in sys.stdin:
    a, b = sorted(map(int, line.split(' ')))
    gcd = 1
    d = 2
    while a >= d:
        amod, bmod = a % d, b % d
        if amod == 0 and bmod == 0:
            gcd *= d
            a, b = a/d, b/d
            d = 2
            continue
        else:
            d += 1
    lcm = gcd * a * b
    print gcd, lcm

Measured memory_bytes: 4208
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}

int main() {
    int n;
    cin >> n;
    vector<vector<int>>plans(n);

    for (int i=0; i<n; i++){
        vector<int>vec(3);
        for (int j=0; j<3; j++){
            cin >> vec.at(j);
        }
        plans.at(i) = vec; 
    }
    int px, py, t;
    t = 0;
    px = 0;
    py = 0;
    for(int i=0; i<n; i++){
        int dt,dx,dy;
        vector<int>vec = plans.at(i);
        dt = vec.at(0) -t;
        dx = abs(vec.at(1) - px);
        dy = abs(vec.at(2) - py);

        if (dt >= dx+dy and (dt-dx-dy)%2 == 0){
            px = vec.at(1);
            py = vec.at(2);
            t = vec.at(0);
        }
        else {
            cout << "No" << endl;
            return 0;
        }
    }   
    cout << "Yes" << endl;
}

Measured memory_bytes: 5760
import java.util.*;
    class Main {
        public static void main(String[] args){
            Scanner sc = new Scanner(System.in);
            
            int k = sc.nextInt();
            String s = sc.next();
            
            if(s.length() <= k){
                System.out.println(s);
            } else {

              for(int i=0;i<k;i++){
                System.out.print(s.charAt(i));
              }  
              System.out.println("...");
            }

            
            
        }
    } 

Measured memory_bytes: 35524
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, W;
    cin >> n >> W;
    vector<pll> wvs;
    for(int i=0; i<n; i++)
    {
        ll w, v;
        cin >> w >> v;
        wvs.emplace_back(w, v);
    }

    vector<vector<ll>> dp(n+1, vector<ll>(W+1, 0));
    for(int i=1; i<=n; i++)
    {
        pll wv = wvs.at(i-1);
        for(int j=0; j<=W; j++)
        {
            if(j - wv.first >= 0)
            {
                dp.at(i).at(j) = max(dp.at(i-1).at(j), dp.at(i-1).at(j-wv.first) + wv.second);
            }
            else dp.at(i).at(j) = dp.at(i-1).at(j);
        }
        // for(auto &n : dp.at(i)) cout << setw(3) << n << ' ';
        // cout << '\n';
    }
    cout << dp.at(n).at(W) << '\n';

    return 0;
}


Measured memory_bytes: 80256
#include <bits/stdc++.h>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
int parent[4005][4005];

struct path{
    int from;
    int to;
    ll cost;
};

struct UnionFind {
    vector<int> par;
    vector<int> rank;

    UnionFind(int n = 1) {
        init(n);
    }

    void init(int n = 1) {
        par.resize(n + 1); rank.resize(n + 1);
        for (int i = 0; i <= n; ++i) par[i] = i, rank[i] = 0;
    }

    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            return par[x] = r;
        }
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        return true;
    }
};

bool comp(path a, path b){
    if(a.cost > b.cost){
        return true;
    }
    return false;
}

int main() {
    //cout.precision(10);
    int n, m;
    cin >> n >> m;
    vector<path> pathes;
    for(int i = 0; i < m; i++){
        int a, b;
        ll c;
        cin >> a >> b >> c;
        struct path in;
        in.from = a;
        in.to = b;
        in.cost = c;
        pathes.push_back(in);
    }
    sort(pathes.begin(), pathes.end(), comp);
    ll cost[4005];
    UnionFind uni(n + 1);
    ll sum = 0;
    for(int time = 1; time <= n - 1; time++){
        path test;
        while(true){
            test = pathes.back();
            pathes.pop_back();
            if(uni.issame(test.from, test.to)){
                continue;
            }
            break;
        }
        cost[time] = test.cost;
        sum += cost[time];
        uni.merge(test.from, test.to);
        for(int i = 1; i <= n; i++){
            uni.root(i);
        }
        for(int i = 1; i <= n; i++){
            parent[time][i] = uni.root(i);
        }
    }
    int q;
    cin >> q;
    for(int time = 1; time <= q; time++){
        int s, t;
        cin >> s >> t;
        int ok = n - 1;
        int ng = 0;
        while(ok - ng > 1){
            int mid = (ok + ng) / 2;
            if(parent[mid][s] == parent[mid][t]){
                ok = mid;
            } else {
                ng = mid;
            }
        }
        cout << sum - cost[ok] << endl;
    }
    return 0;
}

Measured memory_bytes: 72296
#include <bits/stdc++.h>
//#pragma GCC optimize "-O3"
typedef unsigned long long ull;
typedef unsigned int ui;
typedef unsigned short us;
typedef long long ll;
typedef long double ld;
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll infll=(1ull<<63)-1;
const int inf=(1ull<<31)-1;
int n;
string a;

bool f(){
	if (n&1)
		return false;
	int t=n>>1;
	for (int i=0;i<t;i++)
		if (a[i]!=a[t+i])
			return false;
	return true;
}

int main()
{
	//freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
	ios_base::sync_with_stdio(false); cin.tie(0);cout.precision(18);
	cin>>n>>a;
	if (f())
		cout<<"Yes";
	else 
		cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

int a[50][2];
int b[50][10];

int main()
{
  while (1) {
    int m, t, p, r, i, j;
    vector <pair<int, pair<int, int> > > v;

    scanf("%d %d %d %d", &m, &t, &p, &r);

    if (m == 0 && t == 0 && p == 0 && r == 0) break;

    for (i = 0; i < t; i++) a[i][0] = a[i][1] = 0;
    for (i = 0; i < t; i++) {
      for (j = 0; j < p; j++) {
        b[i][j] = 0;
      }
    }

    for (i = 0; i < r; i++) {
      int m, t, p, j;

      scanf("%d %d %d %d", &m, &t, &p, &j);

      t--;
      p--;

      if (j == 0) {
        a[t][0]++;
        a[t][1] += b[t][p];
        a[t][1] += m;
      } else {
        b[t][p] += 20;
      }
    }

    for (i = 0; i < t; i++) v.push_back(make_pair(a[i][0], make_pair(-a[i][1], i + 1)));

    sort(v.begin(), v.end());
    reverse(v.begin(), v.end());

    printf("%d", v[0].second.second);

    for (i = 1; i < v.size(); i++) {
      if (v[i].first == v[i - 1].first && v[i].second.first == v[i - 1].second.first) {
        putchar('=');
      } else {
        putchar(',');
      }

      printf("%d", v[i].second.second);
    }

    puts("");
  }

  return 0;
}

Measured memory_bytes: 1052
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <cstring>
#include <cstdlib>
#include <algorithm>

using namespace std;

#define mp make_pair
#define pb push_back
#define x first
#define y second

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vpii;

int dp[2010][2010],g[2010],head[2010];
int n,k,ans;

struct edge
{
	int to,next;
}e[4010];

bool v[2010];

void push(int k,int x,int y)
{
	e[k].to=y;e[k].next=head[x];head[x]=k;
}

void dfs(int x)
{
	int p=head[x];v[x]=1;dp[x][0]=1;
	for (int j=1;j<=k+1;j++) dp[x][j]=0;
	v[x]=1;
	while (p)
	{
		if (!v[e[p].to])
		{
		dfs(e[p].to);
		
		g[0]=dp[x][0];
		for (int j=1;j<=k+1;j++) g[j]=min(g[j-1],dp[x][j]);
		for (int j=1;j<=k+1;j++) dp[x][j]=n;
		for (int j=1;j<=min(k+1,dp[x][0]);j++)
			for (int w=0;w<=min(k,dp[e[p].to][0]);w++)
				if (j-1+w<=k) dp[x][max(j,w+1)]=min(dp[x][max(j,w+1)],g[j]+dp[e[p].to][w]);
		dp[x][0]+=dp[e[p].to][0];
		}
		p=e[p].next;
	}
	for (int j=1;j<=k+1;j++) dp[x][j]=min(dp[x][j],dp[x][j-1]);
	ans=min(ans,n-dp[x][0]+dp[x][k+1]);
}

int main()
{
	scanf("%d%d",&n,&k);
	for (int i=1;i<n;i++)
	{
		int x,y;scanf("%d%d",&x,&y);
		push(2*i-1,x,y);push(2*i,y,x);
	}
	memset(v,0,sizeof(v));
	ans=n;
	dfs(1);
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 16000
#include <cstdio>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
using namespace std;

const int MAX_N = 100;
const int MAX_M = 20;

typedef pair<int, int> P;
struct edge{ int to, cap, cost, rev; };
int V;

int N, F, T;
int ls[MAX_N];
int xs[MAX_N][MAX_M], ys[MAX_N][MAX_M], cs[MAX_N][MAX_M];

set<pair<int,int> > ss;

const int MAX_V = 2 + 100*20*2*3;
const int INF = 1<<29;

vector<edge> G[MAX_V];
int h[MAX_V];
int dist[MAX_V];
int prevv[MAX_V], preve[MAX_V];

void add_edge(int from, int to, int cap, int cost){
	G[from].push_back((edge){to,cap,cost,G[to].size()});
	G[to].push_back((edge){from,0,-cost,G[from].size()-1});
}

pair<int,int> min_cost_flow(int s, int t, int ff){
	int res = 0;
	int f = ff;
	fill(h, h+V, 0);
	while(f > 0){
		priority_queue<P, vector<P>, greater<P> > que;
		fill(dist, dist+V, INF);
		dist[s] = 0;
		que.push(P(0,s));
		while(!que.empty()){
			P p = que.top(); que.pop();
			int v = p.second;
			if(dist[v] < p.first) continue;
			for(int i=0; i<G[v].size(); i++){
				edge &e = G[v][i];
				if(e.cap > 0 && dist[e.to] > dist[v] + e.cost + h[v] - h[e.to]){
					dist[e.to] = dist[v] + e.cost + h[v] - h[e.to];
					prevv[e.to] = v;
					preve[e.to] = i;
					que.push(P(dist[e.to],e.to));
				}
			}
		}
		if(dist[t] == INF){
			return make_pair(ff - f, res);
		}
		for(int v = 0; v<V; v++) h[v] += dist[v];

		int d = f;
		for(int v=t; v != s; v = prevv[v]){
			d = min(d, G[prevv[v]][preve[v]].cap);
		}
		f -= d;
		res += d*h[t];
		for(int v=t; v!=s; v=prevv[v]){
			edge &e = G[prevv[v]][preve[v]];
			e.cap -= d;
			G[v][e.rev].cap += d;
		}
	}
	return make_pair(ff, res);
}

bool init(){
	scanf("%d", &N);
	if(N == 0){
		return false;
	}
	for(int i=0; i<MAX_V; i++){
		G[i].clear();
	}
	ss.clear();
	for(int i=0; i<N-1; i++){
		scanf("%d", ls+i);
		for(int j=0; j<ls[i]; j++){
			scanf("%d%d%d", xs[i]+j, ys[i]+j, cs[i]+j);
		}
	}
	scanf("%d", &F);

	return true;
}

void compress(){
	ss.insert(make_pair(0, -1));
	for(int i=0; i<N-1; i++){
		for(int j=0; j<ls[i]; j++){
			int x = xs[i][j], y = ys[i][j];
			ss.insert(make_pair(i, x));
			ss.insert(make_pair(i+1, y));
		}
	}
	T = ss.size();
}

void solve(){
	compress();
	V = 2 * T + 2;
	const int source = 2*T, sink = source + 1;

	add_edge(source, 1, INF, 0);

	vector<pair<int,int> > tbl;
	int k = 0;
	for(set<pair<int,int> >::iterator itr=ss.begin(); itr!=ss.end(); ++itr){
		tbl.push_back(*itr);
	}

	for(int i=0; i<T; i++){
		add_edge(i*2+0, i*2+1, 1, 0);
		if(i < T - 1){
			if(tbl[i].first == tbl[i+1].first){
				add_edge(i*2+1, (i+1)*2+1, INF, 0);
			}
		}
		else{
			add_edge(i*2+1, sink, INF, 0);
		}
	}

	map<pair<int,int>,int > dict;
	for(int i=0; i<T; i++){
		dict[tbl[i]] = i;
	}

	for(int i=0; i<N-1; i++){
		for(int j=0; j<ls[i]; j++){
			int x = xs[i][j], y = ys[i][j];
			pair<int,int> cur(i, x), tar(i+1, y);
			add_edge(dict[cur]*2+1, dict[tar]*2+0, 1, cs[i][j]);
		}
	}

	pair<int,int> r = min_cost_flow(source, sink, F);
	printf("%d %d\n", r.first, r.second);
}

int main(){
	for(;init();){
		solve();
	}

	return 0;
}

Measured memory_bytes: 1728
#include<stdio.h>

int main(void) {

	int date[3] = {0};

	for (int i = 0; i < 3; i++) {
		scanf("%d", &date[i]);
		//printf("%d\n", date[i]);	//デバック用
	}

	while (1) {

		for (int i = 0; i < 2; i++) {

			if (date[i] > date[i + 1]) {
				//selection_sort
				int temp = date[i];
				date[i] = date[i + 1];
				date[i + 1] = temp;
				//printf("%d %d\n", date[i], date[i + 1]);	//デバック用

				break;
			}
		}

		int flag = 0;

		for (int i = 0; i < 2; i++) {

			if (date[i] > date[i + 1]) {
				flag = 1;
			}
		}

		if (flag == 0) {
			break;
		}
	}

	for (int i = 0; i < 3; i++) {
		if (i != 2) {
			printf("%d ", date[i]);
		}
		else {
			printf("%d", date[i]);
		}
	}

	printf("\n");

	return 0;
}


Measured memory_bytes: 2104
#include<iostream>
#include<cmath>
using namespace std;

bool isPrime(int n){
    if(n<2) return false;
    if(n==2) return true;
    if(n%2==0) return false;
    for(int i=3;i<=sqrt(n);i+=2){
        if(n%i==0) return false;
    }
    return true;
}

int main(){
    int n;
    int i=2;
    cin>>n;
    cout<<n<<":";
    if(isPrime(n)){
        cout<<' '<<n<<endl;
        return 0;
    }
    while(n>1){
        while(n%i!=0 && !isPrime(i)) i++;
        while(n%i==0){
            cout<<' '<<i;
            n/=i;
        }
        i+=1;
    }
    cout<<endl;
    return 0;
}



Measured memory_bytes: 3108
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  char f[10];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
template<class T> inline T GCD_L(T a,T b){
  T r;
  while(a){
    r=b;
    b=a;
    a=r%a;
  }
  return b;
}
template<class S, class T> inline S chmax(S &a, T b){
  if(a<b){
    a=b;
  }
  return a;
}
int N;
int A[100000];
int lef[100001];
int rig[100001];
int main(){
  int i, res=0;
  rd(N);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=0;Lj4PdHRW<N;Lj4PdHRW++){
      rd(A[Lj4PdHRW]);
    }
  }
  for(i=0;i<N;i++){
    lef[i+1] =GCD_L(lef[i], A[i]);
  }
  for(i=0;i<N;i++){
    rig[i+1] =GCD_L(rig[i], A[N-1-i]);
  }
  for(i=0;i<N;i++){
    chmax(res,GCD_L(lef[i], rig[N-1-i]));
  }
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190601-1

// --- original code ---
// int N, A[1d5];
// int lef[100001], rig[100001];
// {
//   int i, res = 0;
//   rd(N,A(N));
//   rep(i,N) lef[i+1] = gcd(lef[i], A[i]);
//   rep(i,N) rig[i+1] = gcd(rig[i], A[N-1-i]);
//   rep(i,N) res >?= gcd(lef[i], rig[N-1-i]);
//   wt(res);
// }


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


int main() {
  vector<int> mod2;
  mod2.push_back(0);
  mod2.push_back(2);
  int i;
  for (i = 1; i < 100; i++) {
    mod2.push_back(mod2[i] * 2);
  }
  int n;
  cin >> n;
  if (n < 2) {
    cout << n << endl;
  } else {
    for (i = 0; i < n; i++) {
      if (mod2[i] > n) {
        cout << mod2[i - 1] << endl;
        break;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
# import time,random,resource

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)
def IF(c, t, f): return t if c else f

def scc(n, e, re):
    v = [None] * n
    t = []
    def dfs(i):
        v[i] = 0
        for b in e[i]:
            if v[b] is None:
                dfs(b)
        t.append(i)

    for i in range(n):
        if v[i] is None:
            dfs(i)

    r = [None] * n
    def dfs2(i, p):
        r[i] = p
        for b in re[i]:
            if r[b] is None:
                dfs2(b, p)

    for c in t[::-1]:
        if r[c] is None:
            dfs2(c, c)

    return r


def main():
    n,m = LI()
    ab = [LI() for _ in range(m)]

    e = collections.defaultdict(set)
    re = collections.defaultdict(set)
    for a,b in ab:
        e[a].add(b)
        re[b].add(a)

    sc = scc(n,e,re)
    d = {}
    ci = collections.defaultdict(list)
    for i,c in enumerate(sc):
        ci[c].append(i)
        d[i] = c

    cs = list(ci.keys())
    se = collections.defaultdict(set)
    sre = collections.defaultdict(set)
    for a,b in ab:
        if d[a] == d[b]:
            continue
        se[d[a]].add(d[b])
        sre[d[b]].add(d[a])

    rr = []
    q = []
    for c in cs:
        if len(sre[c]) == 0:
            q.append(c)

    qi = 0
    while qi < len(q):
        c = q[qi]
        qi += 1
        rr.append(JA([len(ci[c])] + ci[c], " "))
        for nc in se[c]:
            sre[nc].remove(c)
            if len(sre[nc]) == 0:
                q.append(nc)

    return JA([len(rr)] + rr, "\n")


print(main())




Measured memory_bytes: 868548
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
class Program
{   
    public void Slove()
    {
        long n = long.Parse(Console.ReadLine());
        long a = 1;
        foreach(long i in Enumerable.Range(1, (int)Math.Sqrt(n)).Reverse())
        {
            if(n % i == 0)
            {
                a = i;
                break;
            }
        }
        long b = n / a;
        int result = Math.Max(a.ToString().Length, b.ToString().Length);
        System.Console.WriteLine(result);
    }
    
    static void Main(string[] args)
    {
        new Program().Slove();
    }
}


Measured memory_bytes: 12000
n = int(input())
t, a = map(int, input().split())
hs = list(map(int, input().split()))
ts = [t - 0.006 * h for h in hs]

temp = int(10**9)
res = 0
for i, t in enumerate(ts):
    d = abs(a - t)
    if d < temp:
        res = i
        temp = d
print(res + 1)

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

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

    int maxi = 0;
    int x = 0;

    for(int i=0;i<n;i++){
        if(s.at(i) == 'I'){
            x++;
        }else{
            x--;
        }
        maxi = max(maxi,x);
    }

    cout << maxi << endl;
}


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

int main() {
  int n; cin >> n;
  vector<string> vec(n);
  for(int i=0; i<n; i++) cin >> vec[i];
  sort(vec.begin(), vec.end());
  vec.erase(unique(vec.begin(), vec.end()), vec.end());
  cout << vec.size() << endl;
}

Measured memory_bytes: 9524
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const ll mod = 1e9+7;
const int N=2e5+9;
int main()
{
    FASTINOUT;
    ll x,y,c=0;
    cin>>x>>y;
    while (x<=y)
        x*=2LL,c++;
    cout<<c;
    return 0;
}


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

vector<int> divisor(int n){ //約数列挙
    vector <int> v;
    for(int i=1;i*i<=n;i++){
        if(n%i==0){
            v.push_back(i);
            if(i!=n/i) v.push_back(n/i);
        }
    }
    return v;
}

signed main(){
    int n,m;
    cin >> n >> m;
    vector<int> v;
    v=divisor(m);
    sort(v.begin(),v.end(),greater<int>());
    int ans=0;
    for(int x:v){
        if(x*n>m) continue;
        if((m-x)%x==0){
            ans=x;
            break;
        }
    }

    cout << ans << endl;

}

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

using ll = long long;
const ll MOD = 998244353;
const ll INF = 1e18;

int main() {
    string S, T;
    cin >> S >> T;
    int f[26];
    rep(i, 26) f[i] = -1;
    rep(i, S.size()) {
        int x = S[i] - 'a', y = T[i] - 'a';
        if (f[x] == -1) {
            f[x] = y;
            continue;
        }
        if (f[x] == y) continue;
        cout << "No" << endl;
        return 0;
    }
    rep(i, 26) f[i] = -1;
    rep(i, S.size()) {
        int x = S[i] - 'a', y = T[i] - 'a';
        if (f[y] == -1) {
            f[y] = x;
            continue;
        }
        if (f[y] == x) continue;
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 776
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <utility>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cstdio>
#include <math.h>
#include <stdio.h>

using namespace std;

#define REP(i,n,m) for( long long int i = (n); i < (m); i++ )
#define ll long long
#define ALL(a) (a).begin(), (a).end()
#define SORT(v) sort( ALL(v) );
#define LAST(v) v[v.size()-1]
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,-1,sizeof(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define pi pair<int, int>
#define MP make_pair
#define PB push_back
#define IIN(a) int a; cin >> a;
#define LIN(a) ll a; cin >> a;
#define SIN(a) string a; cin >> a;
#define EPS (1e-10)
#define INF 1000000000000LL

int MOD=1000000007;
int dx[4] = {0, 0, -1, 1};
int dy[4] = {1, -1, 0, 0};
//I ASCII code: '0' = 48; 'A' = 65; 'a' = 97



signed main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    LIN(n)
    LIN(m)
    vector< pair< ll, ll> > p(n);
    REP(i,0,n){
      cin>>p[i].first>>p[i].second;
    }
    ll ans = 0;
    SORT(p);

    REP(i,0,n){
      ans+=p[i].first * fmin(p[i].second, m );
      m -= fmin( p[i].second,m );
      if( m <= 0 )break;
    }


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


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

int main(){
  double W, H, x, y;
  cin >> W >> H >> x >> y;
  
  double S = 0;
  S = W * H / 2;
  
  if(x == W/2 && y == H/2){
    printf("%lf %d", S, 1);
  }
  else{
    printf("%lf %d", S, 0);
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<ll, ll, ll> T;

ll N;

int main(void){
    
    scanf("%lld", &N);
    ll n = sqrt(N);
    printf("%lld\n", n * n);
    
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main{
    /*標準入力
    n
    a_1 a_2 a_3 ... a_n
    */
    public static void main(String[] args){
        //入力部分
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();

        //本体
        String ans = "";
        for (int i=0; i<N; i++){
            ans += "ACL";
        }
        //出力部分
        System.out.print(ans);
        sc.close();

    }
}


Measured memory_bytes: 27108
import numpy as np
import sys
from scipy.sparse.csgraph import floyd_warshall


def use_fast_io():
    global input
    import io
    import sys
    f = io.BytesIO(sys.stdin.buffer.read())
    input = f.readline


use_fast_io()


def solve():
    n, m, le = map(int, input().split())
    g1 = (le + 1) * np.zeros((n, n))
    for _ in range(m):
        a, b, c = map(int, input().split())
        if c <= le:
            g1[a - 1, b - 1] = c
            g1[b - 1, a - 1] = c

    fw1 = floyd_warshall(g1, directed=False)

    g2 = 1000 * np.zeros((n, n))
    g2[fw1 <= le] = 1

    fw2 = floyd_warshall(g2, directed=False)

    q = int(input())
    res_list = [-1] * q
    for i in range(q):
        s, t = map(int, input().split())
        res = fw2[s - 1, t - 1]
        if res <= n:
            res_list[i] = int(res - 1)

    for r in res_list:
        print(r)


if __name__ == "__main__":
    solve()

Measured memory_bytes: 19676
#!/usr/bin/env python3
from collections import Counter
from functools import reduce
import sys


def fc(n: int):
    for p in range(2, n + 1):
        while 1:
            q, r = divmod(n, p)
            if r != 0:
                break
            yield p
            n = q
        if n == 1:
            break


MOD = 1000000007  # type: int


def solve(N: int):
    fs = Counter()
    for i in range(1, N + 1):
        fs.update(fc(i))
    print(reduce(lambda a, b: a * (b + 1) % MOD, fs.values(), 1))


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3564
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
typedef long long ll;

const int MAX_N=1e5;

int N,C,K,T[MAX_N];

int main(){
	cin>>N>>C>>K;
	REP(i,N){
		cin>>T[i];
	}
	sort(T,T+N);
	int ite=0;
	int ans=0;
	while(ite<N){
		int t=T[ite];
		ans++;
		int c=0;
		while(ite<N && c<C && T[ite]-t<=K){
			ite++;
			c++;
		}
	}
	cout<<ans<<endl;
	return 0;
}


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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for(int i = m; i < n; i++) 

typedef long long int ll;

int main(){
    int A,B;
    cin>>A>>B;
    if(A<10&&B<10){
        cout<<A*B<<endl;
    }else{
        cout<<-1<<endl;
    }

    return 0;
}


Measured memory_bytes: 256
import math
import itertools
import sys

def main():
  while True:
    n = int(input())
    if n == 0:
      break

    S = list(map(int, input().split()))
    len_S = len(S)

    m = 0
    for i in S:
      m += i
    m /= len_S

    a_2 = 0
    for i in S:
      a_2 += (i - m) ** 2
    a_2 /= len_S
    a_2 = math.sqrt(a_2)

    print(a_2)

if __name__ == '__main__':
  main()


Measured memory_bytes: 5784
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int n,k,s;
  cin>>n>>k>>s;
  if(s < 1e9){
  for(int i = 0;i < n;i++)
  {
    if(i < k)
      cout<<s<<" ";
    else
      cout<<s+1<<" ";
  }}
  else if(s == 1e9)
  {
    for(int i = 0;i < n;i++)
    {
      if(i < k)
        cout<<s<<" ";
        else
          cout<<1<<" ";
    }
  }
  return 0;
}

Measured memory_bytes: 1280
#include <cstdio>
#include <cmath>
using namespace std;

#define EPS 1e-2

class P
{
public:
	double x,y,z;
	
	P()
	{}
	
	P(double x, double y, double z)
	:x(x),y(y),z(z)
	{}
};

double dist(P a, P b)
{
	return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)+(a.z-b.z)*(a.z-b.z));
}

bool isequal(double r1, double r2, double r3)
{
	return (fabs(r1-r2) < EPS && fabs(r2-r3) < EPS);
}

int M;
double QR,RP,PQ;
P pt[30];

void calc()
{
	for(int i=0; i<M; i++)
	for(int j=0; j<M; j++)
	{
		if(i==j) continue;
		for(int k=0; k<M; k++)
		{
			if(i==k||j==k) continue;
			
			double tQR=dist(pt[j], pt[k]);
			double tRP=dist(pt[k], pt[i]);
			double tPQ=dist(pt[i], pt[j]);
			
			if(isequal(tQR/QR,tRP/RP,tPQ/PQ))
			{
				printf("%d %d %d\n", i+1,j+1,k+1);
				return;
			}
		}
	}
}

int main()
{
	int N;
	scanf("%d", &N);
	while(N--)
	{
		scanf("%lf%lf%lf", &QR, &RP, &PQ);
		
		scanf("%d", &M);
		
		for(int i=0; i<M; i++)
		{
			double x,y,z;
			scanf("%lf%lf%lf", &x,&y,&z);
			
			x*=9.461; y*=9.461; z*=9.461;
			
			pt[i]=P(x,y,z);
		}
		
		calc();
	}
}

Measured memory_bytes: 0
#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

class State
{
public:
	int No,ok,pena;
	State(int No = 0,int ok = 0, int pena = 0):
	No(No),ok(ok),pena(pena){}

	bool operator < (const State &ano) const{
		if(ok > ano.ok)return true;
		else if(ok == ano.ok && pena < ano.pena)return true;
		else if(ok == ano.ok && pena == ano.pena && No < ano.No)
			return true;
			return false;
	}
};

int main()
{
	int T,P,R;

	while(cin >> T >> P >> R, T){
		int **d = new int *[T];
		State *a = new State[T];
		for(int i = 0; i < T; i++){
			d[i] = new int [P];
			a[i].No = i+1,a[i].ok = 0,a[i].pena = 0;

			for(int j = 0; j < P; j++)
				d[i][j] = 0;
		}

		int team,prog,time;
		string str;
		while(R > 0){
			R--;
			cin >> team >> prog >> time >> str;

			if(str == "WRONG")
				d[team-1][prog-1]++;
			else {
				a[team-1].pena += d[team-1][prog-1]*1200+time;	//ペナルティ
				a[team-1].ok++;	//正解数
			}
		}

		sort(a,a+T);

		for(int i = 0; i < T; i++)
			printf("%d %d %d\n",a[i].No,a[i].ok, a[i].pena);

			



	}

	return 0;
}

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll N, M;
    cin >> N >> M;

    vector<vector<bool>> graph(N, vector<bool>(N, false));
    rep(i, M) {
        ll a, b;
        cin >> a >> b;
        a--;
        b--;
        graph[a][b] = true;
        graph[b][a] = true;
    }
    vector<vector<ll>> dp(1 << N, vector<ll>(N, 0));
    dp[1][0] = 1;
    rep(s, 1 << N) {
        rep(from, N) {
            if ((s & (1 << from)) == 0) continue;
            rep(to, N) {
                if ((s & (1 << to)) == 0 && graph[from][to]) dp[s | (1 << to)][to] += dp[s][from];
            }
        }
    }
    ll ans = 0;
    rep2(i, 1, N) {
        ans += dp[(1 << N) - 1][i];
    }
    cout << ans << '\n';
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cctype>
#include<algorithm>
using namespace std;
const int N=2e5+5;
int n,ans,a[N],f[N];
inline int read()
{
	int x=0,w=1;
	char c=getchar();
	while (!isdigit(c)&&c!='-') c=getchar();
	if (c=='-') c=getchar(),w=-1;
	while (isdigit(c))
	{
		x=(x<<1)+(x<<3)+c-'0';
		c=getchar();
	}
	return x*w;
}
int main()
{
	n=read();
	for (int i=1;i<=n;a[i++]=read());
	for (int i=1;i<=n;i++)
	  f[a[i]]=f[a[i]-1]+1;
	for (int i=1;i<=n;i++)
	  ans=max(ans,f[i]);
	printf("%d\n",n-ans);
	return 0;
}

Measured memory_bytes: 1664
#include <iostream>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>
 
using namespace std;

int main() {
	stack<int> S1;
	stack<pair <int,int> > S2;
	char ch;
	int sum=0;
	for(int i=0;cin>>ch;i++){
		if(ch=='\\') S1.push(i);
		else if(ch=='/' && S1.size()>0){
			int j=S1.top();S1.pop();
			sum+=i-j;
			int a=i-j;
			while(S2.size()>0 && S2.top().first > j){
				a+=S2.top().second;S2.pop();
			}
			S2.push(make_pair(j,a));
		}
	}
	
	vector<int> ans;
	while(S2.size()>0){
		ans.push_back(S2.top().second);
		S2.pop();
	}
	reverse(ans.begin(),ans.end());
	cout<<sum<<endl;
	cout<<ans.size();
	for(int i=0;i<ans.size();i++){
		cout<< " ";
		cout<<ans[i]; 
	}
	cout<<endl;
	
	return 0;
}

Measured memory_bytes: 3236
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <functional>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define Repr(e, b, i) for(int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n-1, i)
#define repr(n, i) Repr(n-1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define uniq(x) (x).erase(unique(all(x)),(x).end())

typedef long long ll;
typedef pair<ll, ll> llP;
typedef pair<int, int> P;
typedef std::priority_queue<int> IntPrioQueue; //Z->A
typedef std::priority_queue<int, std::vector<int>, std::greater<int> > IntReversePrioQueue; //A->Z

const int MAX = 100010;

int path[MAX];

void solve(void){
    int N, M;
    cin >> N >> M;
    rep(M, i) {
        int a, b;
        scanf("%d %d\n", &a, &b);
        path[a-1]++;
        path[b-1]++;
    }
    bool f = true;
    rep(N, i) f = f && (path[i]%2==0);
    cout << (f?"YES":"NO") << endl;
}

int main(void){
  solve();
  return 0;
}


Measured memory_bytes: 640
#include <stdio.h>

int main(void){
	long x, count = 0;

	scanf("%ld", &x);

	if(x % 11 > 6)
		count = 2*(x / 11) + 2;
	else if(x % 11 > 0)
		count = 2*(x / 11) + 1;
	else
		count = 2*(x / 11);
	printf("%ld", count);

	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include<list>
#include <algorithm>
#include <string>
#include <math.h>
#include<map>
#include <utility>
#include <iomanip>
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)

#define INF (1e5)

typedef long long unsigned int ll;

#define MOD 998244353

ll c=0;
int N;
int a[300];






int main()
{

	cin >> N;
	int A[N];
	int m;
	REP(i, N)
	{
		cin >> A[i];
		if(A[i]<0){
			m += 1;
		}
	}

	long long ans = 0;
	REP(i,N){
		ans += abs(A[i]);
	}

	if(m%2==0){
		cout << ans << endl;
	}else{
		
		ans -= abs(A[0]) * 2;
		long long tmp = ans;
		
		for (int i = 1; i < N;i++)
		{
			tmp += abs(A[i-1]) * 2;
			
			tmp -= abs(A[i]) * 2;
			if(tmp>ans){
				ans = tmp;
			}
			
		}

		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define All(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()   //reverse
#define strall(v) (v).cbegin(),(v).cend() //const_itterator
#define IN(a, b, x) (a<=x&&x<b)
using namespace std;
using ll = long long;
using Pair = pair<int,int>;
using Graph = vector<vector<ll>>;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<typename t, typename u, typename Comp=less<>>
bool chmax(t& xmax, const u& x, Comp comp={}) { if(comp(xmax, x)) { xmax = x; return true; } return false;}
template<typename t, typename u, typename Comp=less<>>
bool chmin(t& xmin, const u& x, Comp comp={}) { if(comp(x, xmin)) { xmin = x; return true;} return false;}
const int INF = 1e9;
const ll infl = ll(1e18)+5;

/*
*ios::sync_with_stdio(false);
*cin.tie(0);
*/
int main(){
   ll a;
   cin >> a ;
   cout << a + a*a + a*a*a << endl;;   
}

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

int main(int argc, char **argv)
{
	int n, i, j, x, y, tmp, nn, t = 1;
	int **array;
	
	while(1){
		scanf("%d", &n);
		nn = n*n;
		if(n == 0){
			break;
		}
		
		array = (int **)calloc(n+1, sizeof(int));
		for(i = 0; i <= n; i++){
			array[i] = (int *)calloc(n+1, sizeof(int));
		}
		x = j = array[0][0] = 1;
		tmp = 2;
		y = 0;
		i = -1;
		while(tmp <= nn){
			array[y][x] = tmp++;
			x += i;
			y += j;
			
			if(x < 0 || y < 0 || y >= n || x >= n){
				x -= i;
				y -= j;
				i = -i;
				j = -j;
				
				if((y == 0 || y == n-1)&& x < n-1){
					x++;
				} else {
					y++;
				}
			}
		}
		
		printf("Case %d:\n", t++);
		for(i = 0; i < n; i++){
			for(j = 0; j < n; j++){
				printf("%3d", array[i][j]);
			}
			printf("\n");
		}
		
		for(i = 0; i <= n; i++){
			free(array[i]);
		}
		free(array);
	}
	
	
	return 0;
}

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

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

  sort(s.begin(), s.end());


  if(s[0] == s[1] && s[2] == s[3]) {
    b = true;
  }

  if(s[0] == s[1] && s[0] == s[2] && s[0] == s[2] && s[0] == s[3]) b = false;

  if(b) {
    cout << "Yes" << endl;
  } 
  else {
    cout << "No" << endl;
  }
   

  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
	int amount;
	int days = 0;
	int i;

	amount = 100000;

	scanf("%d",&days);

	for(i=0; i<days; i++){
		amount = amount * 1.05 + 999;
		amount = amount / 1000;
		amount = amount * 1000;
	}

	printf("%d\n",amount);

	return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define FOR(i, a, b) for (ull i=a; i<(b); i++)
#define range(a) a.begin(), a.end()
#define endl "\n"
#define Yes() cout << "Yes" << endl
#define No() cout << "No" << endl
using Graph = vector<vector<int>>;
const unsigned long long mod = 1e9 + 7;
const long long INF = 1LL<<60;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
void chmin(long long &a, long long b) { if (a > b) a = b; }
void chmax(long long &a, long long b) { if (a < b) a = b; }

int main(void){
	ios::sync_with_stdio(0);
	cin.tie(0);
	ull N, K, sum=0;	cin>>N>>K;
	FOR(i,K,N+2){
		sum+=i*(N-i+1)+1;
		sum%=mod;
	}

	cout<<sum<<endl;

    return 0;
}



Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
// typedef
using ll  = long long;
using str = string;
using PL  = pair<ll, ll>;
using P   = pair<int, int>;
using VL  = vector<ll>;
using VI  = vector<int>;
using VS  = vector<str>;
using VP  = vector<P>;
using VPL = vector<PL>;
using VVL = vector<VL>;
using VVI = vector<VI>;

// const num
const ll INF         = 1e18 + 18;
const ll MAX         = 100005;
const ll MOD         = 1000000007;
const long double PI = acosl(-1.0);

// loop
#define REP(i, a, b) for(ll(i) = (a); (i) < (b); (i)++)
#define RREP(i, a, b) for(ll(i) = (a); (i) >= (b); (i)--)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) RREP(i, n, 0)

// YesNo
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
// All
#define ALL(v) v.begin(), v.end()
#define deduplicate(v) (v).erase(unique(ALL(d)), (v).end())

int main(void) {
	int n;
	int a[110];
	int cnt = 0;
	cin >> n;
	rep(i, n) {
		cin >> a[i];
	}
	for(int i = 0; i < n; i += 2) {
		if(a[i] % 2 == 1) {
			cnt++;
		}
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vll = vector<vl>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9+7;
const ll INF = 2e15;
template<class T> void print(const T& t){ cout << t << endl; }
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; }
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

int main(){
  ll h,w;
  cin>>h>>w;
  vll c(10,vl(10));
  rep(i,10){
      rep(j,10){
          cin>>c[i][j];
      }
  }
  vll a(h,vl(w));
  rep(i,h){
      rep(j,w){
          cin>>a[i][j];
      }
  }
  for (int k = 0; k < 10; k++){       // 経由する頂点
    for (int i = 0; i < 10; i++) {    // 始点
      for (int j = 0; j < 10; j++) {  // 終点
        c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
      }
    }
  }
  ll sum=0;
  rep(i,h){
      rep(j,w){
          if(a[i][j]!=-1){
              sum+=c[a[i][j]][1];
          }
      }
  }
  print(sum);
}


Measured memory_bytes: 3960
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr int INF = 2000000000;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
# define ALL(x)     (x).begin(),(x).end()
# define UNIQ(c)    (c).erase(unique(ALL((c))), end((c)))
# define mp         make_pair
# define eb         emplace_back
# define FOR(i,a,b) for(int i=(a);i<(b);++i)
# define REP(i,n)   FOR(i,0,n)
# define INIT       std::ios::sync_with_stdio(false);std::cin.tie(0);
typedef pair<LL, LL> P;
typedef pair<LL, P> PP;
int n, m;
LL dp[150][10][80];
vector<P>v[150];
LL ans = LINF;

int main() {
	while (cin >> n >> m && (n || m)) {
		ans = LINF;
		for (int i = 0; i < 150; i++) {
			if (i)for (int j = 0; j < 10; j++)for (int k = 0; k < 80; k++) {
				dp[i][j][k] = HINF;
			}
			v[i].clear();
		}
		for (int i = 0; i < n; i++) {
			int a;
			cin >> a;
			for (int j = 0; j < a; j++) {
				int b, c;
				cin >> b >> c;
				b--;
				v[i].eb(mp(b, c));
			}
		}
		for (int i = 0; i < v[0].size(); i++)dp[1][i][m - 1] = 0;
		if (m > 0)for (int i = 0; i < v[1].size(); i++)dp[1][i][m - 1] = 0;

		for (int i = 0; i < n - 1; i++) {
			for (int j = 0; j < v[i].size(); j++) {
				for (int k = 0; k <= m; k++) {
					if (i == n - 1 && k > 0)continue;
					for (int l = 0; l < v[i + 1].size(); l++) {
						LL cost = (v[i][j].second + v[i + 1][l].second)*abs(v[i][j].first - v[i + 1][l].first);
						dp[i + 1][l][k] = min(dp[i + 1][l][k], dp[i][j][k] + cost);
					}
					if (k > 0) {
						for (int l = 0; l < v[i + 2].size(); l++) {
							LL cost = (v[i][j].second + v[i + 2][l].second)*abs(v[i][j].first - v[i + 2][l].first);
							dp[i + 2][l][k - 1] = min(dp[i + 2][l][k - 1], dp[i][j][k] + cost);
						}
					}
				}
			}
		}
		for (int i = 0; i < v[n - 1].size(); i++)for (int j = 0; j <= m; j++)ans = min(ans, dp[n - 1][i][j]);
		if (m > 0)for (int i = 0; i < v[n - 2].size(); i++)for (int j = 1; j <= m; j++)ans = min(ans, dp[n - 2][i][j]);
		cout << ans << endl;
	}
}

Measured memory_bytes: 4048
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
using namespace std;

const int N = 2e5+10;
ll a[N],suf[N];
int main(){
    int n;
    int flag = 0;
    cin >> n ;
    for (int i=0;i<=n;++i){
        cin >> a[i];
    }
    if(n == 0){
        return puts(a[0]==1?"1":"-1"),0;
    }
    if(a[0]!=0) return puts("-1"),0;
    for(int i=n-1;i>=1;--i) suf[i] = suf[i+1]+a[i];
    ll cur = 1, ans = 1;
    for(int i=1;i<n;++i){
        cur *= 2;
        if(cur < a[i]){
            return puts("-1"),0;
        }
        cur = min(cur,a[n]+suf[i]);
        ans += cur, cur -= a[i];
    }
    if(a[n] >= cur && a[n] <= cur * 2)  
        cout << ans + a[n];
    else 
        cout << -1 ;
    puts("");
    return 0;
}

Measured memory_bytes: 5164
import java.util.Scanner;
import java.util.Arrays;

class Main
{
	public static void main(String args[])
	{
		Scanner sc = new Scanner(System.in).useDelimiter("[,\n]");
		
		while (true)
		{
			int hands[] = new int[5];
			try
			{
				for (int i = 0; i < 5; i++)
				{
					hands[i] = sc.nextInt();
				}
			}
			catch (Exception e)
			{
				break;
			}
			Arrays.sort(hands);
			JUDGE:
			{
				int count = 0;
				
				for (int i = 0; i < 2; i++)
				{
					if (hands[i] == hands[i+1] && hands[i] == hands[i+2] && hands[i] == hands[i+3])
					{
						System.out.println("four card");
						break JUDGE;
					}
				}
				
				count = 0;
				for (int i = 0; i< 3; i++)
				{
					if (hands[0] == hands[i])
						count++;
				}
				if (count == 2 || count == 3)
				{
					int subcount = 0;
					for (int i = count; i < 5; i++)
					{
						if (hands[count] == hands[i])
							subcount++;
					}
					if (subcount == ((count == 2) ? 3 : 2))
					{
						System.out.println("full house");
						break JUDGE;
					}
				}
				
				count = 0;
				for (int i = 0; i < 5; i++)
				{
					if (hands[0] + i == hands[i])
						count++;
				}
				if (count == 5)
				{
					System.out.println("straight");
					break JUDGE;
				}
				if (hands[0] == 1 && hands[1] == 10 && hands[2] == 11 && hands[3] == 12 && hands[4] == 13)
				{
					System.out.println("straight");
					break JUDGE;
				}
				
				for (int i = 0; i< 3; i++)
				{
					if (hands[i] == hands[i+1] && hands[i] == hands[i+2])
					{
						System.out.println("three card");
						break JUDGE;
					}
				}
				
				count = 0;
				for (int i = 0; i < 5; i++)
				{
					for (int j = i + 1; j < 5; j++)
					{
						if (hands[i] == hands[j])
							count++;
						if (count == 2)
						{
							System.out.println("two pair");
							break JUDGE;
						}
					}
				}
				if (count == 1)
				{
					System.out.println("one pair");
					break JUDGE;
				}
				
				System.out.println("null");
			}
		}
	}
}

Measured memory_bytes: 12000
n = int(input())
A = []
for _ in range(n):
    a, b = map(int, input().split())
    A += [(a, b)]

from operator import itemgetter

A = sorted(A, key=itemgetter(1))

t = 0
ans = 'Yes'

for a, b in A:
    t += a
    if t > b:
        ans = 'No'
        break

print(ans)


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

int main(){
    int n,m;

    cin >> n;
    int h[n];

    if(n==1){
        puts("Yes");
        return 0;
    }

    rep(i,n)    cin >> h[i];

    m = h[0]-1;
    for(int i=1;i<n;i++){
        if(m>h[i]){
            
            puts("No");
            return 0;
        }else{
            m = max(m,h[i]-1);
        }
        
    }
    puts("Yes");
}

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

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

	for(int i=0;i<M;i++)
	{
		N -= A[i];
		if(N<0)
		{
			cout << -1 << endl;
			return 0;
		}
	}

	cout << N << endl;
	return 0;
}

Measured memory_bytes: 3668
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const N = parseInt(arg[0]);
    const A = arg[1].split(" ").map(n=>parseInt(2 * n));
    
    let offset = 0;
    
    for(let i=0; i<N; i++) {
        offset = A[i] - offset;
    }
    
    let x = offset / 2;
    
    let cur = x;
    
    let answer = [];
    
    for(let i=0; i<N; i++) {
        answer.push(cur);
        cur = A[i] - cur;
    }
    
    console.log(answer.join(" "));
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 38196
// 2017/12/11 Tazoe

#include <iostream>
#include <string>
using namespace std;

int main()
{
	while(true){
		string s1;
		cin >> s1;

		if(s1==".")
			break;

		string s2;
		cin >> s2;

		if(s1==s2){				// ?????¨?????????????????°
			cout << "IDENTICAL" << endl;
			continue;
		}

		string t1 = s1;
		string t2 = s2;

		while(true){
			size_t d1b = t1.find('\"');	// t1???"????§???????
			if(d1b==string::npos)
				break;
			t1.replace(d1b, 1, "@");

			size_t d1e = t1.find('\"');	// t1???"????????????
			t1.replace(d1e, 1, "@");

			size_t d2b = t2.find('\"');	// t2???"????§???????
			if(d2b==string::npos)
				break;
			t2.replace(d2b, 1, "@");

			size_t d2e = t2.find('\"');	// t2???"????????????
			t2.replace(d2e, 1, "@");

			string u1 = s1;
			u1.replace(d1b+1, d1e-d1b-1, "");	// u1?????????????????°?????????
			string u2 = s2;
			u2.replace(d2b+1, d2e-d2b-1, "");	// u2?????????????????°?????????

			if(u1==u2){
				t1 = u1;
				t2 = u2;
				break;
			}
		}

		if(t1==t2){				// ?????????????????°??????????????°
			cout << "CLOSE" << endl;
		}
		else{					// ????????\???
			cout << "DIFFERENT" << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 3152
n = int(input())
d = {}
for i in range(n):
    s = input()
    if not s in d:
        d[s] = 1
    else:
        d[s] += 1
largest = max(d.values())
common_values = []
for key in d.keys():
    if d[key] == largest:
        common_values.append(key)
common_values = sorted(common_values)
for val in common_values:
    print(val)

Measured memory_bytes: 143396