akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <string.h>
#include <ctype.h>
using namespace std;
 
int main(){
    
    string S;
    int l,j=0,p;
    cin >> S;
    l = S.length();

    if(S[0]!='A'){
        cout << "WA" <<endl;
        return 0;
    }//A始まりでない

    for(int i=1;i<=(l-1);i++){
        if(S[i]=='C'){
            j+=1;
            p=i;
        }else if(isupper(S[i])){
            cout << "WA" << endl;
            return 0;
        }
    }

    if(j!=1){
        cout << "WA" <<endl;
        return 0;//Cが1文字でない
    }else if(p<=1||p==(l-1)){
        cout << "WA" <<endl;
        return 0;
    }
    cout << "AC" <<endl;

    return 0;

}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
  int n,ans=999;
  cin >> n;
  for(int i=0;i<n;i++){
    int a; cin >> a;
    int count = 0;
    while(a%2==0){
      a = a/2;
      count++;
    }
    if(count<=ans) ans = count;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
n = gets.to_i
p = gets.split.map(&:to_i)

ans = 0
i = 0
while i < n do
  if p[i] == i + 1
    if i == n - 1
      p[i], p[i - 1] = p[i - 1], p[i]
    else
      p[i], p[i + 1] = p[i + 1], p[i]
    end
    ans += 1
  end
  i += 1
end

puts ans



Measured memory_bytes: 8076
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
#include <memory>

#include <queue>


using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (long long int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (long long int LoopVariable = (numberOFbegin)-1; (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(long long int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;

int main(){

    long long int n,m;
    cin>>n>>m;
    long long int tmp;
    priority_queue<long long int> pq;
    REP(i,n){
        scanf("%lld",&tmp);
        pq.push(tmp);
    }
    REP(i,m){
        tmp = pq.top();
        tmp /= 2;
        pq.pop();
        pq.push(tmp);
        if(pq.top()==0){
            cout << 0 << endl;
            return 0;
        }
    }

    long long int result = 0;
    REP(i,n){
        if(pq.top()==0){
            break;
        }
        result += pq.top();
        pq.pop();
        
    }
    cout << result << endl;

    return 0;
}


Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repb(i, n) for (int i = (n-1); i >= 0; i--)
#define rea(i, a, b) for (int i = (a); i < (b); i++)
#define reab(i, a, b) for (int i = (a)-1; i >= (b); i--)
#define ALL(a) (a).begin(),(a).end()
#define SZ(x) ((int)(x).size())
#define PRINT(V) for (auto v:(V)) {cerr << v << " ";} cerr << endl
#define dump(x) cerr << #x << " : " << (x) << endl
#define dump2(x, y) cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")" << endl
inline ll GCD(ll a, ll b){return b ? GCD(b, a % b) : a;}
const int MOD = 1000000007;
/* END OF TEMPLATE */

int ans = 0;
bool f = true;

void dfs(vvi& g, int N, int depth, int node, int node2, vi visited){
    vi v = visited;
    if(find(ALL(visited), node) != visited.end()){
        return;
    }
    if(node == node2){
        f = false;
        return;
    }
    rep(i, N){
        if(g[node][i]){
            v.emplace_back(node);
            dfs(g, N, depth + 1, i, node2, v);
            v.pop_back();
        }
    }
}

int main(){
    int N, M;
    cin >> N >> M;
    if(!M){
        cout << 0 << endl;
        return 0;
    }
    vi a(M), b(M);
    vvi g(N, vi(N, 0));
    rep(i, M){
        cin >> a[i] >> b[i];
        g[a[i]-1][b[i]-1] = 1;
        g[b[i]-1][a[i]-1] = 1;
    }
    vi visited;
    rep(i, M){
        g[a[i]-1][b[i]-1] = 0;
        g[b[i]-1][a[i]-1] = 0;
        dfs(g, N, 1, a[i]-1, b[i]-1, visited);
        if(f){
            ans++;
        }else{
            f = true;
        }
        g[a[i]-1][b[i]-1] = 1;
        g[b[i]-1][a[i]-1] = 1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf = 2e9 + 7;

int store[100007];

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

    for (int i = 0; i < n; i++) scanf("%d", &store[i]);

    sort(store, store+n);

    int diff = inf;
    for (int i = 0; i+k-1 < n; i++) {
        diff = min(diff, store[i+k-1] - store[i]);
    }

    cout << diff << "\n";
}


Measured memory_bytes: 640
#表計算を行うプログラムを作成。

r,c=gets.split(" ").map(&:to_i)
h = Array.new(r+1).map{Array.new(c+1,0)} 

for i in 0..r-1                                       # 変数 i を1からr-1まで増やして繰り返し処理する。(arrayゼロから始めるから)
    
a= gets.split.map(&:to_i)
    for j in 0..c-1                                   # 変数 i を0からc-1回まで増やして繰り返し処理する。
    h[i][j] =  a[j]                                   # array のループひとつづつ足していく
    h[i][c] += a[j]
    h[r][j] += a[j]
    h[r][c] += a[j]
    end
end
for i in 0..r                                       #本ループをくりかえす   row 
    for j in 0..c                                   #本ループをくりかえす   column
      print " " unless j == 0
      print h[i][j]                                 #全体結果
    end
    puts
  end




Measured memory_bytes: 7056
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A,B,C;
    cin >> A >> B >> C;
    int K;
    cin >> K;
    while(K--){
        if(A>=B) B *= 2;
        else if(B>=C) C *= 2;
    }
    cout << ((A<B && B<C)? "Yes\n":"No\n");
}

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

#define stirng string
#define vvi vector<vector<int>>
#define vi vector<int>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

const int inf = 1e9 + 7;

int main() {
  int n;
  string s;
  int k;
  cin >> n >> s >> k;
  for(int i=0;i<n;i++){
    if(s[i] != s[k-1]){
      s[i] = '*';
    }
  }
  cout << s << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
const int N=510;
struct dat{
    int x,y,id;
    dat(){}
    dat(int x,int y,int id):
        x(x),y(y),id(id){}
}a[N];
int n,mod,cnt=0;
long long ans=0ll;
long long f[N][N];
inline bool cmp(dat x,dat y)
{
    if(x.x^y.x) return x.x<y.x;
    else return x.y<y.y;
}
inline long long add(long long x,long long y)
{
    return x+y>=mod?x+y-mod:x+y;
}
inline long long sub(long long x,long long y)
{
    return x-y<0?x-y+mod:x-y;
}
int main()
{
//    freopen("1.in","r",stdin);
    scanf("%d%d",&n,&mod);
    for(int k=0;k<2*n;k++)
    {
        int l=max(0,(int)ceil(sqrt(n*n-k*k))),r=min(2*n-1,(int)sqrt(n*n*4-k*k));
        if(k<n) a[++cnt]=dat(l-1,r,k);
        else a[++cnt]=dat(r,0,k);
    }
    sort(a+1,a+1+cnt,cmp);
    for(int k=0;k<=n;k++)
    {
        memset(f,0,sizeof f);
        f[0][0]=1ll;
        int x=0;
        for(int i=1;i<=cnt;i++)
        {
            for(int j=0;j<=k;j++)
            {
                if(a[i].id<n)
                {
                    if(a[i].x+1-x-(j-1)>0&&j)
                        f[i][j]=add(f[i][j],f[i-1][j-1]*(a[i].x+1-x-(j-1))%mod);
                    if(a[i].y+1-k-n-(i-1-x-j)>0)
                        f[i][j]=add(f[i][j],f[i-1][j]*(a[i].y+1-k-n-(i-1-x-j))%mod);
                }
                else
                {
                    if(a[i].x+1-x-j>0)
                        f[i][j]=f[i-1][j]*(a[i].x+1-x-j)%mod;
                }
            }
            if(a[i].id>=n) x++;
        }
        if(k&1) ans=sub(ans,f[cnt][k]);
        else ans=add(ans,f[cnt][k]);
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 5908
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <utility>
#include <string>
#include <math.h>
#include <algorithm>
#include <cstring>
#include <cctype>
 
using namespace std;

int main() {
	int N;
  cin >> N;
    vector<int> A,B;
  int b;
  for(int i=0;i<N;i++){
  	cin >> b;
    A.push_back(b);
    B.push_back(b);

  }
  int cnt=0;
  sort(A.begin(),A.end());
  for(int i=0;i<N;i++){
  	cnt += (A[i]!=B[i]?1:0);
  }
  if(cnt==2 || cnt ==0){
  cout << "YES" << endl;
  }else{
  cout << "NO" << endl;
  }

  
}

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

using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1LL<<60;

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

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; }

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

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

  string s;
  cin >> s;
  int n;
  n = s.length();

  if(s[n-1] != '0'){
    cout << -1 << endl;
    return 0;
  }
  if(s[0] == '0'){
    cout << -1 << endl;
    return 0;
  }

  for(int i = 0; i < n/2; i++){
    if(s[i] != s[n-2-i]){
      cout << -1 << endl;
      return 0;
    }
  }
  // あとは0, ..., n-2まで考えればよくて、
  // 具体的には n/2までかんがえればよい
  vector<vector<int>> G(n);
  int now = 0;
  int cnt = 0;
  for(int i = 0; i < n/2; i++){
    if(s[i] == '1'){
      G[now].push_back(i+1);
      G[i+1].push_back(now);
      now = i+1;
      cnt++;
    }else{
      G[now].push_back(i+1);
      G[i+1].push_back(now);
      cnt++;
    }
  }
  int hub = now;
  for(int i = n/2+1; i < n; i++){
    G[hub].push_back(i);
    G[i].push_back(hub);
  }

  rep(i, n){
    rep(j, G[i].size()){
      int st = i;
      int go = G[i][j];
      if(st < go){
        cout << st+1 << " " << go+1 << endl;
      }
    }
  }

  return 0;
}


Measured memory_bytes: 7244
import java.util.Scanner;

public class Main {
    final static int MOD = 1000000007;
    
    public static void main(String[] args) {
        MyScanner in = new MyScanner();
        String s = in.nextLine();
        if (s.contains("A") && s.contains("B")) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
        
    }
    
    static class MyScanner {
        static Scanner sc = new Scanner(System.in);
        
        String next() {
            return sc.next();
        }
        
        String nextLine() {
            return sc.nextLine();
        }
        
        int nextInt() {
            return Integer.parseInt(sc.next());
        }
        
        double nextDouble() {
            return Double.parseDouble(next());
        }
        
        long nextLong() {
            return Long.parseLong(next());
        }
        
        int[] nextIntArray(int n) {
            int[] array = new int[n];
            for (int i = 0; i < n; i++) {
                array[i] = nextInt();
            }
            return array;
        }
        
        double[] nextDoubleArray(int n) {
            double[] array = new double[n];
            for (int i = 0; i < n; i++) {
                array[i] = nextDouble();
            }
            return array;
        }
        
        long[] nextLongArray(int n) {
            long[] array = new long[n];
            for (int i = 0; i < n; i++) {
                array[i] = nextLong();
            }
            return array;
        }
        
        String[] nextLineArray(int n) {
            String[] array = new String[n];
            for (int i = 0; i < n; i++) {
                array[i] = nextLine();
            }
            return array;
        }
        
        int[][] nextIntMatrix(int n, int m) {
            int[][] matrix = new int[n][m];
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    matrix[i][j] = nextInt();
                }
            }
            return matrix;
        }
        
        double[][] nextDoubleMatrix(int n, int m) {
            double[][] matrix = new double[n][m];
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    matrix[i][j] = nextDouble();
                }
            }
            return matrix;
        }
        
        long[][] nextLongMatrix(int n, int m) {
            long[][] matrix = new long[n][m];
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    matrix[i][j] = nextLong();
                }
            }
            return matrix;
        }
    }
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
struct un
{
    string s;
    int d;
    int v;
};
un a[109];
int n;
bool tmp(un x, un y)
{
    if(x.s == y.s) return x.d > y.d;
    else return x.s < y.s;
}
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);
    cin >> n;
    for(int i = 1; i <= n; ++ i)
    {
        cin >> a[i].s >> a[i].d;
        a[i].v = i;
    }
    sort(a + 1, a + 1 + n, tmp);
    for(int i = 1; i <= n; ++ i)
    {
        cout << a[i].v << '\n';
    }
    return 0;
}


Measured memory_bytes: 256
from collections import deque
from enum import Enum
import sys
import math
 
BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001
 
 
N,K = map(int,input().split())
 
table = [0]*N
max_W = 0
 
for i in range(N):
    table[i] = int(input())
    max_W = max(max_W,table[i])
 
 
left = max_W;right = 10000*100000;mid = (left+right)//2;
ans = right
 
 
def is_ok(tmp_P):
 
    num_track = 1
    tmp_sum = 0
    for i in range(N):
 
        if tmp_sum+table[i] <= tmp_P:
            tmp_sum += table[i]
        else:
            num_track += 1
            tmp_sum = table[i]
            if num_track > K:
                return False
 
    return True
 
 
while left <= right:
 
    if is_ok(mid) == True:
        ans = mid
        right = mid-1
    else:
        left = mid+1
 
    mid = (left+right)//2;
 
 
print("%d"%(ans))


Measured memory_bytes: 9972
//https://agc024.contest.atcoder.jp/tasks/agc024_c

#include <bits/stdc++.h>

using namespace std;

signed main()
{
    long long n;
    cin>>n;

    long long a[n+1];
    for(long long i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    if(a[1]!=0)
    {
        cout<<-1;
        return 0;
    }
    long long result = 0;
    for(long long i=1;i<=n;i++)
    {
        if(a[i-1]<a[i])
        {
            if(a[i]==a[i-1]+1)
                result += 1;
            else
            {
                cout<<-1;
                return 0;
            }
        }
        else
        {
            result += a[i];
        }
    }

    cout<<result;
}


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

#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int main() {
	double d; cin >> d;

	double ans = sqrt(2) * d;
	if (d >= 1)
		ans = max(ans, floor(d) + 1);

	cout << fixed << setprecision(12) << ans << endl;
}



Measured memory_bytes: 3276
#include<bits/stdc++.h>
#define INF 1e9
using namespace std;
struct Info{int nu,ne;}a1[110],a2[110],a3[110];
int t,n,ansn,va[53],vb[53],ua[53],ub[53],f[53],b1[53],b2[53],b3[53],num1,num2,num3,su,p[53];
bool vi[53][53],fi[53];
void jb1(int x,int y){a1[++num1].nu=y;a1[num1].ne=b1[x];b1[x]=num1;}
void jb2(int x,int y){a2[++num2].nu=y;a2[num2].ne=b2[x];b2[x]=num2;}
void jb3(int x,int y){a3[++num3].nu=y;a3[num3].ne=b3[x];b3[x]=num3;}
void dfs(int x,int fa){
	fi[x]=true;su++;
	for (int y=b2[x];y;y=a2[y].ne)
		if (a2[y].nu!=fa&&vi[x][a2[y].nu])dfs(a2[y].nu,x);
}
void dfs1(int x,int fa){
	for (int y=b1[x];y;y=a1[y].ne){
		if (a1[y].nu!=fa){
			if (!fi[x])jb3(x,a1[y].nu);
			dfs1(a1[y].nu,x);
		}
	}
}
void dfs2(int x,int fa){
	for (int y=b2[x];y;y=a2[y].ne){
		if (a2[y].nu!=fa){
			if (!fi[x])jb3(a2[y].nu,x);
			dfs2(a2[y].nu,x);
		}
	}
}
bool dfs3(int x,int co){
	p[x]=co;
	for (int y=b3[x];y;y=a3[y].ne){
		if (p[a3[y].nu]==0){
			if (!dfs3(a3[y].nu,co))return false;
		}else{
			if (p[a3[y].nu]==co)return false;
		}
	}
	p[x]=n+1;
	return true;
}
bool pan(){
	int l=0;
	for (int i=1;i<=n;i++)p[i]=0;
	for (int i=1;i<=n;i++){
		if (p[i]==0){
			if (!dfs3(i,++l))return false;
		}
	}
	return true;
}
int work(int x){
	for (int i=1;i<=n;i++)b1[i]=0,b2[i]=0,b3[i]=0;num1=num2=num3=su=0;
	for (int i=1;i<n;i++){jb1(va[i],ua[i]);jb1(ua[i],va[i]);}
	for (int i=1;i<n;i++){vi[va[i]][ua[i]]=true;vi[ua[i]][va[i]]=true;}
	for (int i=1;i<n;i++){jb2(vb[i],ub[i]);jb2(ub[i],vb[i]);}
	for (int i=1;i<=n;i++) fi[i]=false;
	dfs(x,0);dfs1(x,0);dfs2(x,0);
	for (int i=1;i<n;i++){vi[va[i]][ua[i]]=false;vi[ua[i]][va[i]]=false;}
	if (pan()){return n-su;}return INF;
}
int main(){
	cin>>t;
	while (t--){
		cin>>n;ansn=INF;memset(f,0,sizeof(f));memset(vi,false,sizeof(vi));
		for (int i=1;i<n;i++){scanf("%d %d",&va[i],&ua[i]);f[va[i]]++;f[ua[i]]++;}
		for (int i=1;i<n;i++)scanf("%d %d",&vb[i],&ub[i]);
		for (int i=1;i<=n;i++)ansn=min(ansn,work(i));
		for (int i=1;i<=n;i++)
			if (f[i]==1)for (int j=1;j<=n;j++)
				if (i!=j)for (int k=1;k<=n;k++){
						if (va[k]==i){int p=ua[k];ua[k]=j;ansn=min(ansn,work(i)+1);ua[k]=p;}
						if (ua[k]==i){int p=va[k];va[k]=j;ansn=min(ansn,work(i)+1);va[k]=p;}
					}
		if (ansn==INF) cout<<"-1"<<endl;else cout<<ansn<<endl;
	}
	return 0;
}
/*
1
7
1 2
1 3
2 4
2 5
3 6
3 7
1 2
2 3
3 4
4 5
2 6
3 7
*/

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int i,n;
	for (i=1;i<=10000;i++)
	{
		scanf("%d",&n);
		if (n != 0)
		printf("Case %d: %d\n",i,n);
		else break;
	
	}


	return 0;
	
}


Measured memory_bytes: 2032
# 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 <bitset>
# include <complex>
#include<limits.h>
#include<random>
#include<deque>
#include<cstdio>
#include<fstream>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N = 2000100;
const int mod = (int)pow(10, 9) + 7;
const ll INF = 1LL << 60;
#define rep(i,n) for(ll i=(ll)0;i<(ll)n;++i)
#define ALL(x) x.begin(),x.end()
#define pp pair<ll,ll>
#define ppp pair<pp,ll>
#define fi first
#define se second
#define pb push_back
#define fix(n) fixed<<setprecision(n)
#define itr vector<ll>::iterator
#define print(s) cout<<s<<endl
#define inp(s) cin>>s
string yn(bool b) { return (b ? "Yes" : "No"); }
string YN(bool b) { return (b ? "YES" : "NO"); }
ll n, m,ans;
map<ll, ll>mp;
vector<ll>v;
int main() {
	cin >> n >> m;
	ll a,sum=0;
	rep(i, n) {
		cin >> a;
		sum += a;
		if (sum%m == 0)++ans;
		mp[sum%m]++;
		sum %= m;
		if(mp[sum%m]==1)v.push_back(sum%m);
	}
	rep(i, v.size()) {
		if (mp[v[i]] > 1)ans += mp[v[i]]*(mp[v[i]]-1)/2;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4728
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
	ios::sync_with_stdio(0);cin.tie(0);
	ll n;
	cin>>n;
	vector<ll> v(n+1,0);
	for(ll x = 1;x < sqrt(n);x++)
		for(ll y = 1;y < sqrt(n);y++)
		{
			if(x*x + y*y + x*y > n)break; 
			for(ll z = 1;z < sqrt(n);z++)
			{
				ll idx = x*x + y*y + z*z + x*y + y*z + z*x;
				if(idx>n)break;
				v[idx]++;
			}
		}
	for(ll i=1;i<=n;i++)
		cout<<v[i]<<'\n';
}


Measured memory_bytes: 3620
#include<stdio.h>
int main(void){
int c,a,b,n;
scanf("%d",&n);
scanf("%d",&a);
scanf("%d",&b);
if(a>n&&b>n&&b>a){
printf("A\n");}
else if(n>a&&n>b&&a<b){
puts("B");}

if(a<n&&n<b){
	if(n-a>b-n){
	puts("B");}
	else{
	puts("A");}
}
if(b>n&&a>n&&a>b){
printf("B\n");}
else if(n>b&&n>a&&b<a){
puts("A");}

if(b<n&&n<a){
	if(n-b>a-n){
	puts("A");}
	else{
	puts("B");}
}



return 0;
}

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

int main(){
  double w, h, x, y;
  cin >> w >> h >> x >> y;
  double menseki = w*h/2;
  
  int condition =0;
  if(x==w/2 && y==h/2) condition=1;
  
  printf("%.10f %d", menseki, condition);
  return 0;
  
}

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

int main(){
  long long T[2], A[2], B[2];
  cin >> T[0] >> T[1] >> A[0] >> A[1] >> B[0] >> B[1];
  for(int i = 0; i < 2; ++i){
    B[i] -= A[i];
    A[i] = 0;
  }
  if(T[0]*B[0]+T[1]*B[1] == 0){
    puts("infinity");
    return 0;
  }
  if(B[0] < 0) B[0] *= -1, B[1] *= -1;
  long long t = -(T[0]*B[0]+T[1]*B[1]);
  if(t < 0){
    cout << 0 << endl;
    return 0;
  }
  long long ans = 2*(T[0]*B[0]/t);
  if((B[0]*T[0])%t){
    ++ans;
  }
  cout << ans << endl;
}


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

using namespace std;

static int FindGCD(int x, int y) {
  int a = 0;
  int b = 0;
  if (x >= y) {
    a = y;
    b = x % y;
  } else {
    a = x;
    b = y % x;
  }

  while (b) {
    const int r = a % b;
    a = b;
    b = r;
  }
  return a;
}

int main() {
  int x, y;
  cin >> x >> y;
  cout << FindGCD(x, y) << endl;
  return 0;
}

Measured memory_bytes: 3084
#include<bits/stdc++.h>
using namespace std;
#define int long long
int abs(int a,int b){
  int c=max(a,b)-min(a,b);
  return c;
}
int d[1000];
int c[1000];
signed main(){
  cin.tie(NULL);
  ios::sync_with_stdio(false);
  string a,b;
  int q=1,z=0,x=0;
  cin>>a>>b;
  z=max(a.size(),b.size());
  for(int i=a.size();i>=0;i--) c[z-x]=(int)a[i]-48,x++;
  x=0;
  for(int i=b.size();i>=0;i--) d[z-x]=(int)b[i]-48,x++;
  for(int i=0;i<max(a.size(),b.size());i++){ 
	if(c[i]<d[i]){
      cout<<"LESS";
      q=0;
      break;
    }
    if(c[i]>d[i]){
      cout<<"GREATER";
      q=0;
      break;
    }
  }
  if(q) cout<<"EQUAL";
  cout<<"\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define N 1000000
#define pb push_back
#define mp make_pair
#define int long long
vector<vector<int>> gph;
vector<int> U,V;

void dfsU(int u,int t)
{
    U[u]=t;
    t++;
    for(auto i:gph[u])
    {
        if(U[i]!=-1) continue;
        dfsU(i,t);
    }

}

void dfsV(int v,int t)
{
    V[v]=t;
    t++;
    for(auto i:gph[v])
    {
        if(V[i]!=-1) continue;
        dfsV(i,t);
    }

}



int32_t main()
{
    int n,u,v,x,y;
    cin>>n>>u>>v;
    u--;
    v--;
    gph.resize(n);
    U.resize(n,-1);
    V.resize(n,-1);
    for(int i=0;i<n-1;i++)
    {
        cin>>x>>y;
        x--; y--;
        gph[x].pb(y);
        gph[y].pb(x);

    }
    //for(int i=0;i<n;i++)
    //{
    	//for(auto j:gph[i])
    	 //cout<<j+1;
   // cout<<"\n";
    //}
    dfsU(u,0);
    dfsV(v,0);
    int ans=0;
    //for(auto i:U) cout<<U[i]<<" ";
    //cout<<endl;
    //for(auto i:V) cout<<V[i]<<" ";
    //cout<<endl;
    for(int i=0;i<n;i++)
    {
        if(ans<V[i]&&U[i]<V[i])
         ans=V[i];
    }
    cout<<ans-1;
   return 0;
}

Measured memory_bytes: 9984
#include<iostream>
using namespace std;
typedef long long li;
#define rep(i,n) for(int i=0;i<(n);i++)
#define df 0
template<class T> void print(const T& t){ cout << t << "\n"; }
template<class T, class... Ts> void print(const T& t, const Ts&... ts) { cout << t; if (sizeof...(ts)) cout << " "; print(ts...); }

int main(){
  int n; cin >>n;
  double a=n/3.0;
  printf("%.10lf\n",a*a*a);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int w,h,x,y; cin >>w>>h>>x>>y;
  if(2*x==w && 2*y == h)
    cout<< 0.5000*w*h << " " <<1 << endl;
  else
    cout<< 0.5000*w*h << " " << 0 << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<functional>
using namespace std;
int main(){
 char s[50],t[50];
 vector<int>ques(50);
 scanf("%s",s);
 scanf(" %s",t);
 int slen,tlen;
 slen=strlen(s);
 tlen=strlen(t);
 int i,j;
 for(i=0;i<slen;i++){
  ques[i]=0;
  //printf("%d %c\n",i,s[i]);
 }
 for(i=slen;i>=0;i--){
  if(s[i]=='?'){
   if(i==49)ques[i]=1;
   else ques[i]+=1+ques[i+1];
   //printf("%d %c %d\n",i,s[i],ques[i]);
  }
 }
 int k=0;
 
 //何文字かが一致しているパターン
 bool flag2=0,flag3=0;k=0;
 int start=0;
 for(i=slen-1;i>=0;i--){
  flag2=0;
  if(s[i]=='?'||s[i]==t[0]){
   k=0;
   for(j=i;j<tlen+i;j++){
     //printf("i ga %d %c\n",i,s[j]);
    if(j>=slen||(s[j]!='?'&&s[j]!=t[k])){
     flag2=1;
    }
    k++;
    if(flag2){
     //puts("flag2 break");
     break;
    }
    if(j==tlen+i-1){
     //puts("ok flag3=1");
     start=i;flag3=1;
    }
   // printf("flag2 %d flag3 %d\n",flag2,flag3);
   if(flag3)break;
  }
  k=0;
  if(flag3){
   for(j=start;j<tlen+start;j++){
    s[j]=t[k];k++;
   // printf("j %d %c\n",j,s[j]);
    }
   }
  }
 if(flag3)break;
 }
 if(flag3){
  // puts("flag3");
  for(i=0;i<slen;i++){
   if(s[i]=='?')s[i]='a';
   printf("%c",s[i]);
   if(i==slen-1)return 0;
  }
 }
 puts("UNRESTORABLE");
return 0;}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
vector <int> have;
int main(){
    int N, K, d, a;
    int count = 0;
    cin >> N >> K;
    have = vector<int>(N,0);

    for (int i = 0;i < K;i++){
        cin >> d;
        for(int j = 0;j < d;j++){
            cin >> a;
            have[a-1]++;
        }
    }

    for (int i = 0; i < N; i++)
    {
        if(have[i] == 0)count++;
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 3624
#include "bits/stdc++.h"
#include <boost/range/irange.hpp>
//#include <boost/range/algorithm.hpp>
//#include <boost/multi_array.hpp>
//#include <boost/optional.hpp>

using namespace std;
using boost::irange;

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

#define ALL(x)              (x).begin(),(x).end()
#define REP(i, n)           for (ll i = 0 ; i < (ll)n ; ++i)
#define REPN(i, m, n)       for (ll i = m ; i < (ll)n ; ++i)
#define INF                 (ll)1e9
#define MOD                 (1000 * 1000 * 1000 + 7)
#define Ceil(x, n)          (((((x))+((n)-1))/n))
#define CeilN(x, n)         (((((x))+((n)-1))/n)*n)
#define FloorN(x, n)        ((x)-(x)%(n))
#define IsOdd(x)            (((x)&0x01UL) == 0x01UL)
#define IsEven(x)           (!IsOdd((x)))
#define M_PI                3.14159265358979323846

/*-----------------------------------------------------------------------------
　処理
 -----------------------------------------------------------------------------*/
static void solve()
{
	ll N;
	cin >> N;
	vector<ll> A(N);
	for (auto i : irange<ll>(0, N)) {
		cin >> A[i];
	}
	sort(ALL(A));
	vector<ll> B = A;
	reverse(ALL(B));

	auto calc = [N](vector<ll> &v) {
		ll ans = 0;
		for (auto i : irange<ll>(0, N - 1)) {
			ans += abs(v[i + 1] - v[i]);
		}
		return ans;
	};

	vector<ll> aft(N);
	ll idx = 0;
	for (auto i : irange<ll>(1, N, 2)) {
		aft[i] = B[idx++];
	}
	idx = 0;
	for (auto i : irange<ll>(2, N, 2)) {
		aft[i] = A[idx++];
	}
	aft[0] = A[Ceil(N, 2) - 1];
	ll ans = calc(aft);

	idx = 0;
	for (auto i : irange<ll>(1, N, 2)) {
		aft[i] = A[idx++];
	}
	idx = 0;
	for (auto i : irange<ll>(2, N, 2)) {
		aft[i] = B[idx++];
	}
	aft[0] = B[Ceil(N, 2) - 1];
	ans = max(ans, calc(aft));

	cout << ans << endl;
}

/*-----------------------------------------------------------------------------
　メイン
 -----------------------------------------------------------------------------*/
int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}


Measured memory_bytes: 2688
import itertools,bisect

num_list = []#753数となりえる数の生成
for i in range(3,10):
    num_list += list(itertools.product('753',repeat=i) )
    
num = []#753数の絞り込み
for nm in num_list:
    if '3' in nm and '5' in nm and '7' in nm:
        num.append(int(''.join(nm)))

num.sort()#にぶたん
print(bisect.bisect_right(num,int(input())))


Measured memory_bytes: 13700
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <math.h>
#include <iomanip>
#include <vector>
#include <queue>
#include <functional>
#include <random>
#include <time.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
int main() {
	string a, b, c;
	cin >> a >> b;
	c = a + b;
	ll A, B;
	A = B = 0;
	for (int i = 0; i < c.size(); i++) {
		A += (c[i] - '0')*pow(10, c.size()-1-i);
	}
	B = sqrt(A);
	B *= B;
	if (A == B)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}


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

long long dp[200001][3];
long long arr[200000];
int n;
const long long INF=1e16;

long long ans(int ind,int left) {
    if (left<0) {
        return -INF;
    }
    if (ind>=n) {
        return 0;
    }
    if (dp[ind][left]!=-1) {
        return dp[ind][left];
    }
    dp[ind][left]=arr[ind]+max({ans(ind+2,left),ans(ind+3,left-1),ans(ind+4,left-2)});
    return dp[ind][left];
}

int main(void) {
    memset(dp,-1,sizeof(dp));
    scanf("%d\n",&n);
    for(int i=0;i<n;i++) {
        scanf("%lld",&arr[i]);
    }
    if (n%2==0) {
        printf("%lld",max(ans(0,1),ans(1,0)));
    }
    else {
        printf("%lld",max({ans(0,2),ans(1,1),ans(2,0)}));
    }
}

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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a < b) ? (a = b, 1) : 0;}
template<class T>bool chmin(T &a, const T &b) { return (b < a) ? (a = b, 1) : 0;}

using ll = long long;
using R = long double;
const R EPS = 1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r) {return (r > EPS) - (r < -EPS);}
inline R sq(R x) {return sqrt(max(x, 0.0L));}

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

#define error(args...) { vector<string> _debug = split(#args, ',');err(begin(_debug), args);}


// Problem Specific Parameter:
char s[2010][2010];

int vertex[2010][2010];
int edge[4][2010][2010];


int main(void) {
	int n, m, q;
	scanf("%d %d %d", &n, &m, &q);

	rep(i, n) scanf("%s", s[i]);

	rep(i, 1, n + 1)rep(j, 1, m + 1) {
		if (s[i - 1][j - 1] != '1') continue;
		vertex[i][j]++;

		rep(d, 4) {
			const int ni = i + dy[d] , nj = j + dx[d] ;
			if (1 <= ni and ni <= n and  1 <= nj and nj <= m and s[ni - 1][nj - 1] == '1')
				edge[d][i][j]++;
		}
	}


	rep(i, 1 , n + 1)rep(j, 1 , m + 1) {
		vertex[i][j] += vertex[i - 1][j];
		vertex[i][j] += vertex[i][j - 1];
		vertex[i][j] -= vertex[i - 1][j - 1];

		rep(k, 4) {
			edge[k][i][j] += edge[k][i - 1][j];
			edge[k][i][j] += edge[k][i][j - 1];
			edge[k][i][j] -= edge[k][i - 1][j - 1];
		}
	}


	rep(loop, q) {
		int y[2], x[2];
		rep(i, 2) scanf("%d %d", &y[i], &x[i]);

		int v = 0, e = 0;

		{
			const int t = y[0] , b = y[1] ;
			const int l = x[0] , r = x[1] ;
			v +=  vertex[b][r] - vertex[t - 1][r] - vertex[b][l - 1] + vertex[t - 1][l - 1];
		}

		rep(d, 4) {
			const int t = y[0] + (d == 3);
			const int b = y[1] - (d == 1);
			const int l = x[0] + (d == 2);
			const int r = x[1] - (d == 0);
			if (t <= b and l <= r) e += edge[d][b][r] - edge[d][t - 1][r] - edge[d][b][l - 1] + edge[d][t - 1][l - 1];
		}

		e/=2;
		
		const int ans = v - e;
		printf("%d\n", ans);
	}

	return 0;
}

Measured memory_bytes: 84608
#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 1;
  }
  return 0;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int64_t abs(int64_t n) {
  if (n < 0) {
    n = -n;
  }
  return n;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}

int main() {
  int64_t n, m;
  cin >> n >> m;
  vector <pair <int64_t, int64_t>> v(n);
  rep(i, n) {
    int64_t a, b;
    cin >> a >> b;
    v.at(i) = make_pair(a, b);
  }
  sort(v.begin(), v.end());
  int64_t ans = 0;
  rep(i, n) {
    if (m > v.at(i).second) {
      ans += v.at(i).first*v.at(i).second;
      m -= v.at(i).second;
    } else {
      ans += m*v.at(i).first;
      break;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1792
#include <cstdio>

int main() {
    int a,b,c;
    std::scanf("%d %d %d" ,&a,&b,&c);

    if(a <= b && b <= c){
        std::printf("%d %d %d\n",a,b,c);
        }

    else if(a <= c && c <= b){
        std::printf("%d %d %d\n",a,c,b);
    }
    
    else if(b <= a && a <= c){
        std::printf("%d %d %d\n",b,a,c);
    }
   
    else if(b <= c && c <= a){
        std::printf("%d %d %d\n",b,c,a);
    }

    else if(b <= a && a <= c){
        std::printf("%d %d %d\n",b,a,c);
    }

    else if(c <= a && a <= b){
        std::printf("%d %d %d\n",c,a,b);
    }

    else if(c <= b && b <= a){
        std::printf("%d %d %d\n",c,b,a);
    }

return 0;
}


Measured memory_bytes: 2656
H,N = map(int,input().split())
AB = [list(map(int,input().split())) for _ in range(N)]
dp = [0]+[float("inf")]*H
for i in range(N):
    for h in range(H+1):
        t = h + AB[i][0] 
        if h + AB[i][0] > H:
            t = H
        dp[t] = min(dp[t],dp[h]+AB[i][1])
print(dp[H])


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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end())
#define vdelete(v) (v).erase(unique(all(v)), (v).end())
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1000000007
#define INF 9223372036854775807

int n,memo[10][10],dp[25000000];

signed main() {
    cin >> n;
    rep(i,2) rep(j,3) cin >> memo[j][i];
    rep(i,3) {
        rep(j,n-memo[i][0]+1) {
            dp[j+memo[i][0]] = max(dp[j+memo[i][0]],dp[j]+memo[i][1]);
        }
    }
    rep1(i,n) dp[i] = max(dp[i],dp[i-1]+1);
    n = dp[n];
    rep(i,6000) dp[i] = 0;
    rep(i,3) swap(memo[i][0],memo[i][1]);
    rep(i,3) {
        rep(j,n-memo[i][0]+1) {
            dp[j+memo[i][0]] = max(dp[j+memo[i][0]],dp[j]+memo[i][1]);
        }
    }
    rep1(i,n) dp[i] = max(dp[i],dp[i-1]+1);
    cout << dp[n] << endl;
}




Measured memory_bytes: 195584
from collections import deque

H, W = map(int, input().split())
maze = [input() for _ in range(H)]
visited = [[0] * W for _ in range(H)]

black = 0
for i in range(H):
    black += maze[i].count('#')

que = deque([[0, 0]])

flag = False
while len(que):
    px, py = que.popleft()
    dx = [1, 0, -1, 0]
    dy = [0, 1, 0, -1]
    for i, j in zip(dx, dy):
        nx = px + i
        ny = py + j
        if nx < 0 or ny < 0 or nx >= W or ny >= H:
            continue
        if maze[ny][nx] == '#':
            continue
        if visited[ny][nx]:
            continue
            
        visited[ny][nx] = visited[py][px] + 1
        que.append([nx, ny])
        
        if nx == W-1 and ny == H-1:
            cnt = visited[ny][nx] + 1
            flag = True
            break
    if flag:
        break

if flag:
    print(H*W - black - cnt)
else:
    print(-1)
    

Measured memory_bytes: 3316
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

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

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define INF 1000000000000
#define MOD 1000000007
#define MAXR 100000
#define _GLIBCXX_DEBUG

int threemax(int a, int b, int c) {
	if (a >= b && a >= c) {
		return a;
	}
	else if (b >= a && b >= c) {
		return b;
	}
	else {
		return c;
	}
}

int threemin(int a, int b, int c) {
	if (a <= b && a <= c) {
		return a;
	}
	else if (b <= a && b <= c) {
		return b;
	}
	else {
		return c;
	}
}

void chmaxl(ll &a,ll b){
	if(a<b){
		a=b;
	}
	return;
}

void chminl(ll &a,ll b){
	if(a>b){
		a=b;
	}
	return;
}

void chmaxi(int &a,int b){
	if(a<b){
		a=b;
	}
	return;
}

void chmini(int &a,int b){
	if(a>b){
		a = b;
	}
	return;
}



int main() {
  int N,K;
  cin >> N >> K;
  vector<int> vec(N);
  for(int i=0;i<N;i++){
    cin >> vec.at(i);
  }
  sort(ALL(vec));
  int ans=0;
  for(int i=0;i<K;i++){
    ans+=vec.at(i);
  }
  cout << ans;
}

Measured memory_bytes: 3608
#!/usr/bin/env pypy3
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
mod=10**9+7

def main():
    H,W=MI()
    c=[[] for _ in range(10)]
    A=[[] for _ in range(H)]
    
    for i in range(10):
        c[i]=LI()
    for i in range(H):
        A[i]=LI()
        
    def warshall_floyd(d):
        #d[i][j]: iからjへの最短距離
        n=10
        for k in range(n):
            for i in range(n):
                for j in range(n):
                    d[i][j] = min(d[i][j],d[i][k] + d[k][j])
        return d
    
    c=warshall_floyd(c)
    
    ans=0
    for i in range(H):
        for j in range(W):
            if A[i][j]==-1:
                continue
            else:
                ans+=c[A[i][j]][1]
                
    print(ans)
            
    
    

main()


Measured memory_bytes: 40172
import copy

def j(n):
    if n:print("yes")
    else:print("no")
    exit(0)
rem = 10 ** 9 + 7

"""
def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")
"""

def ip():
    return int(input())
def iprow():
    return [int(i) for i in input().split()]
def ips():
    return (int(i) for i in input().split())
def ipmultiplerow(n):
    a = []
    for i in range(n):
        a.append(ip())
    return a
def printrow(a):
    for i in a:
        print(i)

a = input()
b = input()
s = 0
for i in range(3):
    if a[i] == b[i]:
        s+=1
print(s)

Measured memory_bytes: 3700
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
    int n, x; cin >> n >> x;
    long long ans=0;
    int prev=0;
    for(int i=0; i<n; ++i){
        int a; cin >> a;
        int d=max(prev+a-x, 0);
        ans+=d;
        prev=a-d;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
#define forn(i,a,b)for(int i=(a),_b=(b);i<=_b;i++)
#define fore(i,b,a)for(int i=(b),_a=(a);i>=_a;i--)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ll long long
#define pii pair<int,int>
#define vi vector<int>
#define vpii vector<pii>
#define m_p make_pair
#define re return
#define pb push_back
#define si set<int>
#define ld long double
#define X first
#define Y second
#define st string
#define ull unsigned long long
#define mod 1000000007
#define INF 1000000007
#define x1 XZVJDFADSPFOE
#define y1 GASDIJSLDAEJF
#define x2 DFDAJKVOHKWIW
#define y2 PSFSAODSXVNMQ
#define LLINF 0x3f3f3f3f3f3f3f3fLL
using namespace std;
inline void read(int &x)
{
	short negative=1;
    x=0;
    char c=getchar();
    while(c<'0' || c>'9')
    {
		if(c=='-')
			negative=-1;
		c=getchar();
	}
    while(c>='0' && c<='9')
        x=(x<<3)+(x<<1)+(c^48),c=getchar();
    x*=negative;
}
ll quickpower(ll n,ll k){
	ll ans=1;
	while(k){
		if(k%2){
			ans*=n;
			ans%=mod;
		}
		n*=n;
		n%=mod;
		k/=2;
	}
	return ans;
}
ll doit[700];
/*======================================================================*/
int main()
{
  /*
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
  */
  /*====================================================================*/
  int x;
  cin>>x;
  for(ll i=(-300);i<=300;i++)
  {
  	doit[i+300]=(i*i*i*i*i);
  }
  rep(i,601)
  {
  	rep(j,601)
  	{
  	  if(doit[i]-doit[j]==x)
  	  {
  	  	cout<<i-300<<" "<<j-300<<endl;
  	  	return 0;
	  }	
	}
  }
  return 0;
}



Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define all(in) in.begin(), in.end()
#define INF (sizeof(int) == 4 ? (int)1e9:(int)1e18)
#define EPS 0.0000000001
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
signed main(){
    string s; cin >> s;
    int MOD = 1000000007;
    int mod = 13;
    auto memo = vectors(s.size() + 2,13,-1LL);
    vector<int>base(s.size() + 1,0LL);
    base[s.size() - 1] = 1;
    
    for(int i = (int)s.size() - 2; i >= 0; --i)
        base[i] = (9 * base[i + 1] + base[i + 1]) % mod;
    for(int i = 0; i < 13; ++i)
        memo[s.size() - 1][i] = (i <= 9 and (s.back() == '?' or s.back() - '0' == i) ? 1 : 0);
    
    function<int(int,int)>solver = [&](int digit,int cmod){
        if( memo[digit][cmod] != -1LL) return memo[digit][cmod];
        memo[digit][cmod] = 0;
        int idx = digit;
        if(s[idx] == '?'){
            for(int num = 0; num < 10; ++num){
                int temp =  ( base[digit] * num ) % mod;
                int nmod =  (cmod - temp <= 0 ? cmod - temp + 13 : cmod - temp) % mod;
                memo[digit][cmod] += solver(digit + 1,nmod);
                memo[digit][cmod] %= MOD;
            }
        } else {
            int num = s[idx] - '0';
            int temp =  ( base[digit] * num ) % mod;
            int nmod =  (cmod - temp <= 0 ? cmod - temp + 13 : cmod - temp) % mod;
            memo[digit][cmod] += solver(digit + 1, nmod);
            memo[digit][cmod] %= MOD;
        }
        return (memo[digit][cmod]) % MOD;
    };
    cout << (solver(0,5)) << endl;
}



Measured memory_bytes: 25344
import java.io.*;
import java.math.*;
public class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
		long n = Integer.valueOf(r.readLine());
		outer: for(long i = 0; i < n; i++) {
			int count = 0;
			BigInteger sum = BigInteger.ZERO;
			boolean flag = false;
			while(count++ < 2) {
				String in = r.readLine();
				if(in == null) break outer;
				if(in.length() > 80) {
					flag = true;
				}
				sum = sum.add(new BigInteger(in));
				if(sum.toString().length() > 80) {
					flag = true;
				}
			}
			if(flag) {
				System.out.println("overflow");
			} else {
				System.out.println(sum);
			}
		}
	}
}

Measured memory_bytes: 9732
import sys
import math
import collections
import heapq
import queue
import itertools
import functools
import operator
import time

readline = sys.stdin.readline
 
IPS = lambda: readline().rstrip()
IP = lambda: int(readline().rstrip())
MP = lambda: map(int, readline().split())
LS = lambda: list(map(int, readline().split()))

def solve():
    for _ in range(1):
        n = IP()
        d = int(n//1000)
        print( ((d+1)*1000 - n)%1000)
       
       
if __name__ == "__main__":
    solve()

Measured memory_bytes: 9684
N,K=map(int,input().split())
a=[]
for i in range(K):
    d=int(input())
    k=list(map(int,input().split()))
    a.append(k)
b=[]
for m in range(K):
    b+=a[m]
b=set(b)
ans=N-(len(b))
print(ans)

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

int i, m, n, h;
int main (){
	string v;
	
	while (cin >> v && v != "-"){
		cin >> m;
		n = v.size();
		for (i = 0; i < m; i++){
			cin >> h;
			
			rotate (v.begin(), v.begin() + h, v.begin() + n);
		}
		
		cout << v << endl;
		
	}
	return 0;
}



Measured memory_bytes: 3140
p Math.sqrt($<.to_a[1..-1].map{|x|
	x.split.map &:to_i
}.product([*0...5000]).select{|x|
	x[0][0]*Math.cos(2*Math::PI*x[1]/5000)+x[0][1]*Math.sin(2*Math::PI*x[1]/5000)>=0
}.group_by{|x|x[1]}.map{|x|
	x[1].inject([0,0]){|s,y|[s[0]+y[0][0],s[1]+y[0][1]]}.inject(0){|s,y|s+y*y}
}.max)

Measured memory_bytes: 56444
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <cmath>
#include <set>
#include <stack>
#include <queue>
#include <numeric>
#include <deque>
#include <cstring>
#include <iterator>
#include <map>
#include <cstdlib>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <complex>
#include <bitset>
#include <chrono>
#include <random>
using namespace std;

#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define eb emplace_back
#define el '\n'
typedef  long long  ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<pll> vpll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<bool> vb;


const int mod=1000000007;
//const int mod=998244353;









int main()
{   ios_base::sync_with_stdio(false);cin.tie(NULL);
    ll t,n,m,k,q,x,a,b,c,d,y,r;
    cin >> n;
    a=n%10;
    
    if(a==2||a==4||a==5||a==7||a==9){
        cout << "hon\n";
    }
    else if(a==0||a==1||a==6||a==8){
        cout << "pon\n";
    }
    else{
        cout << "bon\n";
    }
    return 0;
}





Measured memory_bytes: 3648
N, M = map(int, input().split())
*H, = map(int, input().split())
H = [-float('inf')]+H

top = [True]*(N+1)
for i in range(M):
    a, b = map(int, input().split())
    if H[a] > H[b]:
        top[b] = False
    elif H[a] < H[b]:
        top[a] = False
    else:
        top[a] = top[b] = False

ans = -1
for t in top:
    if t:
        ans += 1
print(ans)


Measured memory_bytes: 85096