akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;

int n;
int a[300];
int cnt[4];
double dp[301][301][301];

double dfs(int i, int j, int k) {
	if (i == 0 && j == 0 && k == 0) return 0;
	if (dp[i][j][k] != -1) return dp[i][j][k];
	
	double kitai = 0;
	if (i > 0) {
		kitai += (double)i / n * dfs(i - 1, j, k);
	}
	if (j > 0) {
		kitai += (double)j / n * dfs(i + 1, j - 1, k);
	}
	if (k > 0) {
		kitai += (double)k / n * dfs(i, j + 1, k - 1);
	}
	kitai += 1;
	return dp[i][j][k] = (double)n / (i + j + k) * kitai;
}

signed main() {
	int i, j, k;
	
	cin >> n;
	rep(i, n) cin >> a[i];
	rep(i, n) cnt[a[i]]++;
	rep(i, 301) rep(j, 301) rep(k, 301) dp[i][j][k] = -1;
	
	printf("%.14f\n", dfs(cnt[1], cnt[2], cnt[3]));
	return 0;
}

Measured memory_bytes: 213376
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define ANS cout << ans << endl
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define REVERSE(a) reverse(all(a))
#define int long long
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define VIin(a) for(int i=0; i<a.size(); i++) cin >> a[i]
#define OUT(a) cout << a << endl
typedef vector<int> VI;
typedef vector<VI> VVI;
const int MOD=1e9+7;
const long long INF = 1LL << 60;
/*最大公約数*/int gcd(int x, int y) { return y ? gcd(y,x%y) : x;}
/*最小公倍数*/int lcm(int a, int b) { int g = gcd(a, b); return a / g * b; }
/*素数判定*/int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*約数列挙*/vector<int> getDivisor(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);}}}sort(v.begin(),v.end()); return v;}
//----------------------------------------------
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int a,b; cin >> a >> b;
    int ans = 0;
    int g = gcd(a,b);
    VI y = getDivisor(g);
    int x = y.size();
    rep(i,x){
        if(isPrime(y[i]) == 1) ans++;
    }
    cout << ans + 1 << endl;

    return 0;
}

Measured memory_bytes: 384
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

import numpy as np

h, w, k = map(int, readline().split())
s = np.array([list(map(int, readline().rstrip().decode())) for _ in range(h)], np.int64)
ans = h + w
for i in range(2 ** (h - 1)):
    wp = np.zeros((h, w), np.int64)
    wq = np.zeros((h, ), np.int64)
    wp[0] = s[0]
    cnt = 0
    for j in range(h - 1):
        if i >> j & 1:
            cnt += 1
        wp[cnt] += s[j + 1]
    if cnt >= ans or np.count_nonzero(wp > k):
        continue
    for j in range(w):
        wq += wp[:, j]
        if np.count_nonzero(wq > k):
            cnt += 1
            wq = wp[:, j]
    if ans > cnt:
        ans = cnt
print(ans)


Measured memory_bytes: 12672
/*
***************************************************************************
 name  : ITP1_03_D.cpp
 title : How Many Divisors?
 make  : 2018/08/08 tanabe
***************************************************************************
*/

// Library
#include <iostream> // standard input output object

main(void){
  int a,b,c; // integers
  int d;     // divisor
  int i;     // index

  std::cin >> a >> b >> c; // input "a b c"

  // initialized i = a and d = 0
  // continue i <= b
  // increment i at loop update
  for(i = a,d = 0;i <= b;i++){
    if(c%i == 0){
      d++; // increment d
    }
  }

  std::cout << d << std::endl; // output "d"

}



Measured memory_bytes: 3112
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include <cstring>
#define MAX_N 1000 + 16

using namespace std;

int N, H, W;
int X1[MAX_N], X2[MAX_N], Y1[MAX_N], Y2[MAX_N];
int fld[2 * MAX_N][2 * MAX_N], // 填充遍历用，代表坐标(i, j)处是否空白（压缩后）
dx[4] = { 1, -1, 0, 0 }, dy[4] = { 0, 0, 1, -1 };

// 压缩坐标，将坐标的值变成“这是第几种值”，返回一共有几种坐标
int compress(int *x1, int *x2, int w)
{
	vector<int>xs;

	for (int i = 0; i < N; ++i)
	{
		int tx1 = x1[i], tx2 = x2[i];
		if (1 <= tx1 && tx1 < w) xs.push_back(tx1);
		if (1 <= tx2 && tx2 < w) xs.push_back(tx2);
	}
	xs.push_back(0);
	xs.push_back(w);
	sort(xs.begin(), xs.end());
	xs.erase(unique(xs.begin(), xs.end()), xs.end());
	for (int i = 0; i < N; ++i)
	{
		x1[i] = find(xs.begin(), xs.end(), x1[i]) - xs.begin();
		x2[i] = find(xs.begin(), xs.end(), x2[i]) - xs.begin();
	}
	return xs.size() - 1;
}

int bfs()
{
	int ans = 0;
	for (int i = 0; i < H; ++i)
	{
		for (int j = 0; j < W; ++j)
		{
			if (fld[i][j]) continue;
			++ans;
			queue<pair<int, int> >que;
			que.push(make_pair(j, i));
			while (!que.empty())
			{
				int nx = que.front().first, ny = que.front().second;
				que.pop();

				for (int i = 0; i < 4; ++i)
				{
					int tx = nx + dx[i], ty = ny + dy[i];
					if (tx < 0 || W < tx || ty < 0 || H< ty || fld[ty][tx] > 0) continue;
					que.push(make_pair(tx, ty));
					fld[ty][tx] = 1;
				}
			}
		}
	}
	return ans;
}

///////////////////////////SubMain//////////////////////////////////
int main(int argc, char *argv[])
{
	while (cin >> W >> H, W | H)
	{
		cin >> N;
		for (int i = 0; i < N; ++i)
		{
			cin >> X1[i] >> Y1[i] >> X2[i] >> Y2[i];
		}

		memset(fld, 0, sizeof(fld));

		W = compress(X1, X2, W);
		H = compress(Y1, Y2, H);

		// imos-法
		for (int i = 0; i < N; i++)
		{
			fld[Y1[i]][X1[i]]++;
			fld[Y1[i]][X2[i]]--;
			fld[Y2[i]][X1[i]]--;
			fld[Y2[i]][X2[i]]++;
		}
		// 横向累积
		for (int i = 0; i < H; i++)
		{
			for (int j = 1; j < W; j++)
			{
				fld[i][j] += fld[i][j - 1];
			}
		}
		// 纵向累积
		for (int i = 1; i < H; i++)
		{
			for (int j = 0; j < W; j++)
			{
				fld[i][j] += fld[i - 1][j];
			}
		}// 累积完后，fld中非0部分表示有挡板
		cout << bfs() << endl;
	}
	return 0;
}



Measured memory_bytes: 19052
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <stack>
#include <list>
#include <utility>
#include <vector>
#include <set>
#include <algorithm>
#include <cmath>
#include <climits>
#include <map>
#include <unordered_map>
#include <string.h>
#include<iomanip>
#include <iterator>
#include <locale>

#define all(a) a.begin(),a.end()
#define VV(T) vector<vector< T > >
#define rep(i,N) for(int i = 0; i <N; i++)
#define repsg(i,s,g) for(int i = s; i <g; i++)
#define name(x) #x


using namespace std;

const int INF = INT_MAX;
const long long INFL = 1LL<<40;
const double PI = atan(1)*4;
const long long MOD = pow(10,9)+7;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

typedef long long ll,LL;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
typedef pair<int,int> pii;
typedef pair<LL, LL> pLL;


// vector入力
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
    for(T& x: vec) is >> x;
    return is;
}
// vector出力
template<typename T>
ostream& operator << (ostream& os, vector<T>& vec){
    for(int i=0; i<vec.size(); i++){
        os << vec[i] << ( i+1 == vec.size() ? "" : " " );
    }
    return os;
}

int main() {
    int n;cin>>n;
    vector<pii> c(n);
    rep(i,n){
        int a,b;cin>>a>>b;
        c[i].first = a;
        c[i].second = b;
    }
    sort(all(c));
    cout<<c[n-1].first+c[n-1].second<<endl;
    return 0;
}




Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
 int main(){
	ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int cnt=0;
    string s;
    cin>>s;
    for(int i=0;i<s.size();++i){
        if(i%2==0 && (s[i]=='R' || s[i]=='U' || s[i]=='D'))
            cnt++;
        if(i%2!=0 && (s[i]=='L' || s[i]=='U' || s[i]=='D'))
            cnt++;
    }
    if(s.size()==cnt)
        cout<<"Yes\n";
    else cout<<"No\n";    
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#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 irep(i, a, n) for(int i=a;i<(int)(n);++i)
#define rrep(i, n) for(int i=(int)(n)-1;i>=0;--i)
#define rrep1(i, n) for(int i=(int)(n);i>=1;--i)
#define allrep(V, v) for(auto&& V:v)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
const int INF=1<<29;
const double EPS=1e-9;
using namespace std;


int main (void)
{
  int a,b; cin>>a>>b;
  cout << (a-1)*(b-1) << endl;
  return 0;
}


Measured memory_bytes: 256
/**
 * Created by hiramekun at 20:55 on 2019-09-07.
 */
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

int main() {

    ll n, k;
    cin >> n >> k;
    string s;
    cin >> s;

    ll ans = 0;
    rep(i, n - 1) {
        if (s[i] == s[i + 1]) ans++;
    }
    ans += 2 * k;
    cout << min(n - 1, ans) << '\n';
    return 0;
}

Measured memory_bytes: 512
#include <cstdio>

using namespace std;

int main() {
  int n;
  scanf("%d", &n);
  int xr = 0;
  for (int i = 0; i < n; ++i) {
    int a, b;
    scanf("%d %d", &a, &b);
    while (a > b && a % b != 0) {
      int q = a / b;
      int x = (a - b * q) / (q + 1);
      if ((a - (q + 1) * x) % b != 0) {
        ++x;
      }
      a -= (q + 1) * x;
    }
    xr ^= a / b;
  }
  puts(xr != 0 ? "Takahashi" : "Aoki");
}


Measured memory_bytes: 128
/********************************************************
  **░██████╗██╗░░░░░░█████╗░██╗░░░██╗██╗░█████╗░░██████╗░**
  **██╔════╝██║░░░░░██╔══██╗██║░░░██║██║██╔══██╗██╔════╝░**
  **╚█████╗░██║░░░░░███████║╚██╗░██╔╝██║██║░░╚═╝██║░░██╗░**
  **░╚═══██╗██║░░░░░██╔══██║░╚████╔╝░██║██║░░██╗██║░░╚██╗**
  **██████╔╝███████╗██║░░██║░░╚██╔╝░░██║╚█████╔╝╚██████╔╝**
  **╚═════╝░╚══════╝╚═╝░░╚═╝░░░╚═╝░░░╚═╝░╚════╝░░╚═════╝░**
  *********************************************************/
 
#include <bits/stdc++.h>
using namespace std;
 
 
#define ll                          long long
#define ld                          long double
 
#define forn(i,n)                   for(int i=0;i<n;++i)
#define all(v)                      v.begin(), v.end()
#define rall(v)                     v.rbegin(),v.rend()
#define isSubstring(s1,s2)          s1.find(s2) != std::string::npos
	
#define pb                          push_back
#define pf                          push_front
#define mp                          make_pair
#define fr                          first
#define sc                          second
 
#define vpi                         vector<pair<int,int>>
#define vi                          vector<int>
#define sz(a)                       (int)a.size()
 
#define   endl                       "\n"
#define     nl                       cout<<"\n";
#define fastio                       ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
 
#define  MN                           INT_MIN
#define  MX                           INT_MAX
 
bool isPrime(ll n){if(n<2)return false;for(ll x = 2;x*x <=n;x++){if(n%x == 0)return false;}return true;}
bool isPerfectSquare(long double x){long double sr=sqrt(x);return((sr-floor(sr))==0);}
int gcd(int a, int b){if(a==0)return b;if(b==0) return a;if(a==b)return a;if(a>b)return gcd(a-b,b);return gcd(a,b-a);}

int32_t main()
{
	int n,d;
	cin >> n >> d;
	int ret =  n / (2 * d + 1);
	if(n % (2 * d + 1))++ret;
	cout << ret << endl;
}

Measured memory_bytes: 3616
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(a) (a).begin(), (a).end()

bool dp[100001];

int main() {
    int N, ans = 0;
    cin >> N;
    dp[N] = true;

    while (!dp[0]) {
        FOR(i, 1, N + 1) {
            if (!dp[i]) continue;

            int pow9 = 9, pow6 = 6;
            while (i >= pow9) {
                dp[i - pow9] = true;
                pow9 *= 9;
            }
            while (i >= pow6) {
                dp[i - pow6] = true;
                pow6 *= 6;
            }
            dp[i - 1] = true;
        }
        ans++;
    }

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

Measured memory_bytes: 384
import java.util.*;
public class Main {
  private static final int MOD = 1_000_000_007;
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    
    // A(0), C(1), G(2), T(3)
    int[][][][] dp = new int[N+1][4][4][4];
    dp[0][3][3][3] = 1;
    for (int len = 0; len < N; len++) {
      for (int c1 = 0; c1 < 4; c1++) {
        for (int c2 = 0; c2 < 4; c2++) {
          for (int c3 = 0; c3 < 4; c3++) {
            if (dp[len][c1][c2][c3] == 0) {
              continue;
            }
            for (int a = 0; a < 4; a++) {
              if ((a == 1 && c1 == 2 && c2 == 0)
                 || (a == 1 && c1 == 0 && c2 == 2)
                 || (a == 2 && c1 == 1 && c2 == 0)
                 || (a == 1 && c1 == 2 && c3 == 0)
                 || (a == 1 && c2 == 2 && c3 == 0)
                 ) {
                continue;
              }
              dp[len+1][a][c1][c2] += dp[len][c1][c2][c3];
              dp[len+1][a][c1][c2] %= MOD;
            }
          }
        }
      }
    }
    
    int ans = 0;
    for (int c1 = 0; c1 < 4; c1++) {
      for (int c2 = 0; c2 < 4; c2++) {
        for (int c3 = 0; c3 < 4; c3++) {
          ans += dp[N][c1][c2][c3];
          ans %= MOD;
        }
      }
    }
    
    System.out.println(ans);
  }
}

Measured memory_bytes: 21716
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main
{

  public static void main(String[] args) throws IOException
  {
    BufferedReader r = new BufferedReader(new InputStreamReader(System.in), 1);
    String s = r.readLine();
    int i = Integer.parseInt(s);

    System.out.println(i / 3);
  }

}


Measured memory_bytes: 21460
# coding: utf-8
# Your code here!

import itertools
import math

import sys

X = []
for _ in range(5):
    X.append(int(input()))

min_time = int(1e10)
for A in itertools.permutations(X, 5):
    time = 0
    for i, a in enumerate(A):
        if i == 4:
            time += a
        else:
            time += math.ceil(a / 10) * 10
        
    min_time = min(min_time, time)
    
print(min_time)

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <queue>
#define LL long long
#define inf 0x3f3f3f3f
#define lson rt<<1
#define rson rt<<1|1
#define PII pair<int,int>
#define test freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
using namespace std;
const int maxn=1e5+5;
struct nod
{
    int u,v,id;
    bool operator <(const nod& rhs) const 
    {
        if(u==rhs.u) return v<rhs.v;
        return u<rhs.u;
    }
};
vector<nod>lik;
int in[maxn];
int n,ff;
int to[maxn],ans[maxn];
int main()
{
    //test
    scanf("%d",&n);
    int u,v;
    for(int i=1;i<n;++i)
    {
        scanf("%d%d",&u,&v);
        lik.push_back(nod{u,v,i});
        in[u]++,in[v]++;
    }
    sort(lik.begin(),lik.end());
    ff=*max_element(in+1,in+1+n);
    printf("%d\n",ff);
    int p=0;
    for(int i=1;i<=n;++i)
    {
        int cnt=1;
        while(p<n&&lik[p].u==i)
        {
            if(cnt!=to[lik[p].u]) 
            {
                to[lik[p].v]=ans[lik[p].id]=cnt;
                ++p;
            }
            ++cnt;
        }
    }   
    for(int i=1;i<n;++i) printf("%d\n",ans[i]);
    return 0;
}


Measured memory_bytes: 2932
#include <bits/stdc++.h>
using namespace std;
 
int gcd(int x,int y){
    if(y==0)return x;

    return gcd(y,x%y);
}
int lcm(int x,int y){
    return x*y/gcd(x,y);
}

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main(){

    int N,MAX=0,MIN=2000,a;
    cin>>N;

    for(int i=1;i<=N;i++){
        cin>>a;
        MAX=max(MAX,a);
        MIN=min(MIN,a);
    }

    cout<<MAX-MIN<<endl;


    return 0;
}

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

void printV(vector<int> &v);
void printVV(vector<vector<int>> &vv);

string toBinary(int decimal);

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

  vector<vector<int>> vv(M);
  for(int i = 0; i < M; i++) {
    int k;
    cin >> k;
    vv.at(i).push_back(0);
    for(int j = 0; j < k; j++) {
      int s;
      cin >> s;
      vv.at(i).push_back(s);
    }
  }

  // 偶数奇数入力
  for(int i = 0; i < M; i++) {
    cin >> vv.at(i).at(0);
  }

  int ans = 0;
  int s = 10 - 1;
  int limit = (int)pow(2, N);
  for(int i = 0; i < limit; i++) { // スイッチの組合わせ
    string S = toBinary(i);

    for(int j = 0; j < M; j++) { // 電球
      int sum = 0;
      for(int n = 1; n < (int)vv.at(j).size(); n++) {
        int p = vv.at(j).at(n);
        sum += S.at(s-(p-1));
      }
      if(sum % 2 != vv.at(j).at(0)) break;
      if(j == M-1) ans++;
    }
  }

  cout << ans << endl;
}

// ベクターの中身を全部出力
void printV(vector<int> &v) {
  cout << "  [ ";
  for(int i = 0; i < (int)v.size(); i++) {
    cout << v.at(i) << " ";
  }
  cout << "]" << endl;
}

void printVV(vector<vector<int>> &vv) {
  cout << "{" << endl;
  for(int i = 0; i < (int)vv.size(); i++) {
    cout << "  [ ";
    for(int j = 0; j < (int)vv.at(i).size(); j++) {
      cout << vv.at(i).at(j) << " ";
    }
    cout << "]," << endl;
  }
  cout << "}" << endl;
}

// １０進数を２進数に変換する関数
string toBinary(int decimal) {
  stringstream ss;
  ss << bitset<10>(decimal);

  return ss.str();
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
	int k,s,ans=0;
	cin>>k>>s;
	for(int i=0;i<=k;i++){
	    for(int j=0;j<=k;j++){
	    	if(s-(i+j)<=k && s-(i+j)>=0)
	    		ans++;
	    	}
	    }
	   
	cout<<ans;
	return 0;
}	



Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
	int i,j,r,c,x[100][100],sumr[100],sumc[100],sum;
	sum=0;
	scanf("%d %d",&r,&c);
	for(i=0;i<r;i++){
		sumr[i]=0;
		for(j=0;j<c;j++){
			scanf("%d",&x[i][j]);
			printf("%d ",x[i][j]);
			sumr[i]=sumr[i]+x[i][j];
		}
		printf("%d\n",sumr[i]);
	}
	for(j=0;j<c;j++){
		sumc[j]=0;
		for(i=0;i<r;i++)
			sumc[j]=sumc[j]+x[i][j];
		printf("%d ",sumc[j]);
		sum=sum+sumc[j];
	}
	printf("%d\n",sum);
	return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<math.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

using namespace std;
using ll = long long int;

int main(void) {
    int n; cin >> n;
    string s, t; cin >> s >> t;
    REP(i, n) cout << s[i] << t[i];
    cout << endl;
}

Measured memory_bytes: 256
s = input() + "R"
v = [0 for i in range(len(s)-1)]

even = 0
odd = 0
lrpos = 0
lr = "R"

for i in range(len(s)):
    if lr != s[i]:
        if lr == "R":
            if even == odd:
                v[i-1] += even
                v[i] += odd
            else:
                v[i] += even
                v[i-1] += odd
        else:
            if even == odd:
                v[lrpos] += even
                v[lrpos-1] += odd
            else:
                v[lrpos-1] += even
                v[lrpos] += odd
        
        odd = 0
        even = 0
        lr = s[i]
        lrpos = i

    if even < odd:
        even += 1
    else:
        odd += 1
    
for i in v:
    print(str(i) + " ",end="")


Measured memory_bytes: 4984
def my_match s,t
  
  sl = s.length
  sl.times do |i|
    return false if s[i] != ?? and s[i] != t[i]
  end
  return true
end

def solve sp,t
  
  s = sp
  sl = s.length
  tl = t.length
  
  no = "UNRESTORABLE"
  return no if sl < tl
  
  if sp.include?(t)
    k = sp.index(t)
    s[k, tl] = t
    return s.gsub(??, ?a)
  end
  
  k = sl - tl
  anss = []
  0.upto(k) do |i|
    if my_match(sp[i,tl],t)
      tmp = String.new(sp)
      tmp[i,tl] = t
      anss << tmp.gsub(??, ?a)
    end
  end
  
  return anss.sort[0] if anss.size != 0 
  
  return no
end

sp = gets.chomp
t = gets.chomp

puts solve sp,t


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

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

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

    if(b%a ==0) cout << a+b << endl;
    else cout << b-a << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(int argc, char const *argv[])
{
    int a, b, k; cin >> a >> b >> k;
    for(int i=100;i>=1;--i){
        if (a%i==0 && b%i==0) {
            --k;
        }
        if (k==0) {
            cout << i << endl;
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

int main() {
  int n;
  cin >> n;
  cout << 800 * n - n / 15 * 200 << endl;
}

Measured memory_bytes: 256
// B.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>
#include <cmath>

using namespace std;

typedef long long LL;

int main() {
	LL a, b, v, w, t;
	cin >> a >> v >> b >> w >> t;
	LL dist = abs(a - b);
	LL diff = v - w;
	bool ans = diff > 0;
	if (ans) {
		LL mx = t * diff;
		if (mx < dist) {
			ans = false;
		}
	}
	cout << (ans ? "YES" : "NO") << endl;
	return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define ll long long
using namespace std;

int n,k;
int arr[200005];
int dp[200005];

int main() {
    cin >> n >> k;
    for (int i=1;i<=n;i++) {
        cin >> arr[i];
    }

    for (int i=2;i<=n;i++) {
        dp[i]=INT_MAX;
        for (int j=1;j<=k;j++) {
            if (i>j) {dp[i]=min(dp[i],dp[i-j]+abs(arr[i]-arr[i-j]));}
        }
    }
    cout << dp[n] << endl;
}




Measured memory_bytes: 4272
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
 
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#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__)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
const int mod=1e9+7;

int main(){
    int n,k;cin>>n>>k;
    if(k>(n-1)*(n-2)/2){
        cout<<-1<<endl;exit(0);
    }
    cout<<n-1+(n-1)*(n-2)/2-k<<endl;
    rep(i,n-1){
        cout<<i+1<<" "<<n<<endl;
    }
    int ctr=0;
    rep(i,n-1){
        if(ctr==(n-1)*(n-2)/2-k)break;
        rep(j,i+1,n-1){
            if(ctr==(n-1)*(n-2)/2-k)break;
            cout<<i+1<<" "<<j+1<<endl;
            ctr++;
        }
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
#include <set>
#include <math.h>
#include <tuple>
#include <map>
#include <iomanip>
using namespace std;
typedef long long ll;

int main() {
    int h, w, k;
    char s[500][500];
    cin >> h >> w >> k;
    for (int i = 0; i < h; i++) cin >> s[i];

    bool fh = false;
    int ans[500][500], cnt = 1;
    for (int i = 0; i < h; i++) {
        int ichigo = 0;
        for (int j = 0; j < w; j++) ichigo += (s[i][j] == '#');
        if (ichigo == 0) {
            if (fh) {
                for (int j = 0; j < w; j++) ans[i][j] = ans[i - 1][j];
            }
        }
        else {
            int j = 0;
            while (j < w) {
                int sub = 0;
                while (j + sub < w && s[i][j + sub] == '.') {
                    sub++;
                }
                if (s[i][j + sub] == '#') {
                    for (int p = 0; p <= sub; p++) ans[i][j + p] = cnt;
                    cnt++;
                }
                else {
                    for (int p = j; p < w; p++) ans[i][p] = cnt - 1;
                }
                j += sub + 1;

            }
            if (!fh) {
                for (int p = 0; p < i; p++) {
                    for (int q = 0; q < w; q++) ans[p][q] = ans[i][q];
                }
            }
            fh = true;
        }
    }

    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (j != 0) cout << " ";
            cout << ans[i][j];
        }
        cout << endl;
    }

}


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

using namespace std;

#define SZ(v) ((int)(v).size())
#define ALL(v) (v).begin(),(v).end()
#define one first
#define two second
typedef long long ll;
typedef pair<int, int> pi;
const int INF = 0x3f2f1f0f;
const ll LINF = 1ll * INF * INF;

const int MAX_N = 2e3 + 10;

int N, K, M;
int Ix[MAX_N], Cnt[MAX_N], Nr[MAX_N];
bool Vis[MAX_N];
vector<pi> Co;
int main() {
	cin >> N >> K >> M;
	for(int i=0; i<N; i++) {
		int x; scanf("%d", &x);
		Nr[i] = x;
		Co.emplace_back(x, i);
	}
	sort(ALL(Co));
	int ans = INF;
	for(int s=0, e=0; s<N; s=e) {
		int ix = 0;
		int now = -1;
		priority_queue<int, vector<int>, greater<int>> Q;
		for(int a=0, b=0; a<N; a=b) {
			if(Vis[a]) {b = a+1; continue;}
			ix++;
			int cnt = 0;
			while(b < N && !Vis[b]) {
				Ix[b] = ix;
				cnt++;
				b++;
			}
			if(cnt - K + 1 >= 1) {
				priority_queue<int, vector<int>, greater<int>> q;
				for(int i=a; i<b; i++) q.push(Nr[i]);
				for(int i=0; i<cnt-K+1; i++) Q.push(q.top()), q.pop();
			}
			Cnt[ix] = max(0, cnt - K + 1);
		}
		if(SZ(Q) >= M) {
			for(int i=0; i+1<M; i++) Q.pop();
			ans = min(ans, Q.top() - Co[s].one);
		}
		/*
		int now = 0;
		for(int i=s; i<N; i++) {
			if(Cnt[Ix[i]] > 0) {
				now++;
				Cnt[Ix[i]]--;
			}
			if(now == Q) {
				ans = min(ans, Co[i].one - Co[s].one); 
				break;
			}
		}
		*/
		while(e < N && Co[s].one == Co[e].one) {
			int x, ix; tie(x, ix) = Co[e];
			Vis[ix] = true;
			e++;
		}
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 256
package main

import "fmt"

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

	sl := make([]int, n)
	for i := 1; i <= m; i++ {
		var a, b int
		fmt.Scan(&a, &b)
		sl[a-1]++
		sl[b-1]++
	}

	for i := 0; i < n; i++ {
		fmt.Println(sl[i])
	}
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define fi first
#define se second
/*typedef pair<int,int> P;
typedef pair<int, P> PP;*/
const int inf = 1e9+7;
const int INF = 1e18+7;
int mod = 1e9+7;

typedef pair<double,int> P;
struct input{int x, y, r;};
double d[1002];
input in[1002];
vector<P> G[1002];
priority_queue<P, vector<P>, greater<P> > q;

signed main(){
	int n, sx, sy, tx, ty;
	fill(d, d+1002, (double)INF);
	scanf("%lld%lld%lld%lld%lld", &sx, &sy, &tx, &ty, &n);
	rep(i,n){
		int x, y, r;
		scanf("%lld%lld%lld", &x, &y, &r);
		in[i] = (input){x, y, r};
	}
	in[n] = (input){sx, sy, 0};
	in[n+1] = (input){tx, ty, 0};
	
	rep(i,n+2)rep(j,n+2){
		if(i == j)continue;
		double dx = (in[i].x-in[j].x)*(in[i].x-in[j].x);
		double dy = (in[i].y-in[j].y)*(in[i].y-in[j].y);
		double cost = max((double)0, sqrt(dx+dy)-(in[i].r+in[j].r));
		//printf("%lf\n", cost);
		G[i].pb(P(cost, j));
		G[j].pb(P(cost, i));
	}
	
	q.push(P((double)0, n));
	d[n] = 0;
	while(!q.empty()){
		P p = q.top();q.pop();
		int from = p.se, m = G[from].size();
		if(d[from] < p.fi)continue;
		rep(i,m){
			int to = G[from][i].se;
			double cost = G[from][i].fi;
			if(p.fi+cost < d[to]){
				d[to] = p.fi+cost;
				q.push(P(d[to], to));
			}
		}
	}
	
	//rep(i,n+2)printf("%lf ", d[i]);
	printf("%.10lf\n", d[n+1]);
	return 0;
}


Measured memory_bytes: 38512
#include "bits/stdc++.h"
using namespace std;
#ifdef LOCAL
#define imie(...) __debug_print(#__VA_ARGS__, __VA_ARGS__)
#else
#define imie(...)
#define endl '\n'
#pragma GCC optimize("O2")
#endif

int main(){
    int n;
    cin >> n;
    vector<int> arr(n);
    for(int& i : arr) cin >> i;
    int64_t sum = 0, cnt1 = 0, cnt2 = 0;
    for(int i = 0; i < n; ++i){
        int64_t tsum = sum + arr[i];
        if((i&1) && tsum >= 0) {
            cnt1 += abs(arr[i] + 1 + sum);
            //cerr << "CHANGE " << arr[i] << " TO " << -1-sum << endl;
            sum = -1;
        }
        else if(!(i&1) && tsum <= 0){
            // arr[i]* = 1 - sum;
            cnt1 += abs(arr[i] - 1 + sum);
            //cerr << "CHANGE " << arr[i] << " TO " << 1-sum << endl;
            sum = 1;
        }
        else sum = tsum;
    }
    sum = 0;
    for(int i = 0; i < n; ++i){
        int64_t tsum = sum + arr[i];
        if((i&1) && tsum <= 0){
            cnt2 += abs(arr[i] - 1 + sum);
            //cerr << "CHANGE " << arr[i] << " TO " << 1-sum << endl;
            sum = 1;
        }
        else if(!(i&1) && tsum >= 0){
            cnt2 += abs(arr[i] + 1  + sum);
            //cerr << "CHANGE " << arr[i] << " TO " << -1-sum << endl;
            sum = -1;
        }
        else sum = tsum;
    }
    cout << min(cnt1, cnt2) << endl;
}

Measured memory_bytes: 3800
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#define N 100002
using namespace std;
typedef long long ll;
const ll mod = 1000000007LL;
int n, a, b;
int x[N];
int main() {
	cin>>n>>a>>b;
	for (int i =1; i <= n; ++i) {
		cin>>x[i];
	}
	ll ans = 0LL;
	for (int i = 2; i <= n; ++i) {
		ll det = x[i]-x[i-1];
		ans += min(det * (ll)a, (ll)b);
	}
	cout<<ans<<endl;
	return 0;
}

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

using namespace std;
using ll=long long;
struct Node {
    int x, y;
    Node() {}
    Node(int _x, int _y) : x(_x), y(_y) {}
    bool operator<(const Node& _oth) const {
        return x < _oth.x;
    }
};

void solve() {
    int n; cin >> n;
    vector<Node> a(n);
    for (int i = 0; i < n; i++) {
        int x,y;
        cin >> x >> y;
        if(x>y) swap(x,y);
        a[i] = {x,y};
    }
    sort(a.begin(), a.end());
    int lmi = a[0].x, lmx = a[n-1].x;
    int rmi = 0x3f3f3f3f, rmx = -1;
    for (int i = 0; i < n; i++) {
        rmi = min(rmi, a[i].y);
        rmx = max(rmx, a[i].y);
    }
    ll res = 1ll*(lmx-lmi) * (rmx-rmi);

    int coeff = (rmx-lmi);
    int ans = 0x3f3f3f3f;
    rmx = rmi = a[0].y;
    for (int i = 1; i < n-1; i++) {
        ans = min(ans, max(rmx, a[n-1].x) - min(rmi, a[i].x));
        rmx = max(rmx, a[i].y);
        rmi = min(rmi, a[i].y);
    }
    res = min(res, 1ll*ans*coeff);
    cout << res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


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

int main() {
	long long int x;
	cin >> x;

	for (int i = 119; i >= -118; i--) {
		for (int j = i - 1; j >= -119; j--) {
			if (pow(i, 5) - pow(j, 5) == x) {
				cout << i << " " << j << endl;
				return 0;
			}
		}
	}
}

Measured memory_bytes: 4008
# coding: utf-8

import itertools
import collections


def main():
    n = int(input())
    c = collections.Counter(map(int, input().split()))
    if c[0] > 0:
        return 0
    if c.most_common(1)[0][1] >= 3:
        return 0
    l1 = []
    l2 = []
    for i, cnt in c.most_common():
        if cnt == 2:
            l2.append(i)
        elif cnt == 1:
            l1.append(i)
    s = 0
    for i in range(len(l1) + 1):
        for invs in itertools.combinations(l1, i):
            l = [0]
            for k in l1:
                l.append(-k if k in invs else k)
            for k in l2:
                l.append(k)
                l.append(-k)
            l.sort()
            ss = 24
            for j in range(len(l)-1):
                ss = min(l[j + 1] - l[j], ss)
            d = l[-1] - l[0]
            ss = min(min(d, 24-d), ss)
            s = max(s, ss)

    return s

print(main())


Measured memory_bytes: 3444
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

typedef long long ll;

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

  ll q, h, s, d;
  cin >> q >> h >> s >> d;
  ll n;
  cin >> n;

  ll one = min(q * 4, min(h * 2, s));
  ll two = min(one * 2, d);

  ll ans;
  if(n % 2 == 0){
    ans = (n / 2) * two;
  }
  else{
    ans = (n / 2) * two + one;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define MAX 500009
#define MOD 1000000007
#define INF 1000000000

int main(){
  int N;
  cin>>N;
  vector<vector<int>> a(N,vector<int>(N));
  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      cin>>a.at(i).at(j);
    }
  }

  vector<vector<ll>> dp(N+1,vector<ll>(1<<N,0));
  dp.at(0).at(0)=1;
  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      if(a.at(i).at(j)==1){
        int bit=1<<j;
        vector<int> p(N,0);
        for(int k=N-i;k<N;k++){
          p.at(k)=1;
        }
        do{
          int k=0;
          for(int kk=0;kk<N;kk++){
            k+=p.at(kk)*(1<<kk);
          }
          if((k&bit)==0){
            dp[i+1][k|bit]+=dp[i][k];
            dp[i+1][k|bit]%=MOD;
          }
        }while(next_permutation(p.begin(),p.end()));
      }
    }
  }
  cout<<dp.at(N).at((1<<N)-1)<<endl;
}


Measured memory_bytes: 377216
N,C=map(int,input().split())
D=[[]for i in range(C)]
for i in range(C):
    D[i]=list(map(int,input().split()))
c=[[] for i in range(N)]
for i in range(N):
    c[i]=list(map(int,input().split()))
data0=[0 for i in range(0,C+1)]
data1=[0 for i in range(0,C+1)]
data2=[0 for i in range(0,C+1)]

for i in range(0,N):
    for j in range(0,N):
        if (i+j)%3==0:
            data0[c[i][j]]+=1
        elif (i+j)%3==1:
            data1[c[i][j]]+=1
        else:
            data2[c[i][j]]+=1

ans=10**100
for i in range(1,C+1):
    for j in range(1,C+1):
        for k in range(1,C+1):
            if i!=j and j!=k and k!=i:
                test=sum(data0[l]*D[l-1][i-1] for l in range(1,C+1))+sum(data1[l]*D[l-1][j-1] for l in range(1,C+1))+sum(data2[l]*D[l-1][k-1] for l in range(1,C+1))
                if test<ans:
                    ans=test
print(ans)

Measured memory_bytes: 49372
import sys

if sys.platform =='ios':
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

N = INT()
A = MAP()

norm = []
genius = []
for a in A:
	if a >= 3200: genius.append(a//400)
	else: norm.append(a//400)

#print(norm)
#print(genius)

print(len(set(norm)) if norm else 1, len(set(norm))+len(genius))

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

const int INF = 1001001001;

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

  int n;
  n = s.length();

  for(int i = 0; i < n/2; i++){
    if(s[i] != s[n-1-i]){
      cout<<"No"<<endl;
      exit(0);
    }
  }

  n = n/2;
  if(n > 1){
    for(int i = 0; i < n/2; i++){
      if(s[i] != s[n-1-i]){
        cout<<"No"<<endl;
        exit(0);
      }
    }
  }
  cout<<"Yes"<<endl;

  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long int lli;
typedef pair<int, int> mp;
#define fir first
#define sec second
#define IINF INT_MAX
#define LINF LLONG_MAX
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define pque(type) priority_queue<type,vector<type>,greater<type> >
#define memst(a,b) memset(a,b,sizeof(a))
 
int main(void){
	string a, b;
	cin >> a >> b;
	
	if(a.size()!= b.size()){
		cout << (a.size()>b.size()?"GREATER":"LESS") << endl;
		return 0;
	}else{
		rep(i, a.size()){
			if(a[i] != b[i]){
				cout << (a[i]>b[i]?"GREATER":"LESS") << endl;
				return 0;
			}
		}
		cout << "EQUAL" << endl;
		return 0;
	}
}

Measured memory_bytes: 256
#include<stdio.h>
 
int main(){
    int game,n;
    int a,b;
    int A,B;
    int Anoten[100],Bnoten[100];
 
    while(1){
    scanf("%d",&game);
    if(game==0)break;
    A=0,B=0;
    for(n=0;n<game;n++){
        scanf("%d %d",&a,&b);
        if(a<b){
            Bnoten[n]=a+b;
            Anoten[n]=0;
        }
        else if(b<a){
            Anoten[n]=a+b;
            Bnoten[n]=0;
        }
        else{
            Anoten[n]=a;
            Bnoten[n]=b;
        }
		 A+=Anoten[n];
		 B+=Bnoten[n];
    }
	printf("%d %d\n",A,B);
    A=0,B=0;
	}
    return 0;
    }

Measured memory_bytes: 600
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	/**
	 * ????§???¢??????????????\???????????¨???????§???¢????????\??????????????¨??????????±???????
	 *
	 * @param args
	 *            ?????¨?????????
	 * @throws IOException
	 */
	public static void main(String[] args) throws IOException {
		try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
			int lineNum = Integer.parseInt(br.readLine());
			for (int i = 0; i < lineNum; i++) {
				String line = br.readLine();
				String[] sCoordinates = line.split(" ");
				float[] fCoordinates = new float[6];
				for (int j = 0; j < 6; j++) {
					fCoordinates[j] = Float.parseFloat(sCoordinates[j]);
				}
				Circle circle = new Circle(fCoordinates[0], fCoordinates[1], fCoordinates[2], fCoordinates[3],
						fCoordinates[4], fCoordinates[5]);
				System.out.printf("%.3f %.3f %.3f\n", circle.getCenterX(), circle.getCenterY(), circle.getRadius());
			}
		}
	}

	public static class Circle {
		private float centerX;
		private float centerY;
		private float radius;

		public Circle(float x1, float y1, float x2, float y2, float x3, float y3) {

			/**
			 * ?¨???????????????????????????????(x1, y1)???????????¨????????§?¨???????????????????
			 */
			x2 = x2 - x1;
			y2 = y2 - y1;

			x3 = x3 - x1;
			y3 = y3 - y1;

			/**
			 * X^2 + Y^2 - 2mX - 2nY + l = 0 ????§£?????????????????¨??????????±???????
			 */
			centerY = ((x3 * x3 + y3 * y3) * x2 - (x2 * x2 + y2 * y2) * x3) / (2.0f * (y3 * x2 - y2 * x3));
			centerX = ((x3 * x3 + y3 * y3) * y2 - (x2 * x2 + y2 * y2) * y3) / (2.0f * (x3 * y2 - x2 * y3));

			radius = (float) Math.sqrt(centerX * centerX + centerY * centerY);

			/**
			 * ????????§?¨???????????????????
			 */
			centerX += x1;
			centerY += y1;
		}

		public float getCenterX() {
			return centerX;
		}

		public float getCenterY() {
			return centerY;
		}

		public float getRadius() {
			return radius;
		}
	}

}

Measured memory_bytes: 24880
n=int(input())
s=[int(input()) for _ in range(n)]
p=sum(s)
if p%10!=0:
  print(p)
else:
  s.sort()
  d=0
  for i in s:
    if i%10!=0:
      d=i
      break
  if d==0:
    print(0)
  else:
    print(p-d)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int PREP = (cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(9), 0);
//int SEGV = getenv("D") || (exit(system("D= SEGFAULT_SIGNALS=all catchsegv ./prog.exe") >> 8), 0);
int main() {
    string S; cin >> S;
    vector<int> A(S.size() + 1);
    int one = 1;
    A[0] = 0;
    reverse(begin(S), end(S));
    for (int i = 0; i < S.size(); i++) {
        A[i + 1] = (A[i] + (S[i] - '0') * one) % 2019;
        one = (one * 10) % 2019;
    }
    map<int, int> M;
    for (int a : A) M[a]++;
    Int ans = 0;
    for (auto &p : M) {
        ans += p.second * (p.second - 1) / 2;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4368
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
const int mod = 1e9 + 7;
//const int mod = 998244353;

ll get(ll n, ll dig, bool mn){
	string s = to_string(n);
	ll t = dig - s.size();
	rep(i,t) s.push_back('0');
	if(mn) sort(all(s));
	else sort(rall(s));
	return stoi(s);
}

int main(){
	while(1){
		ll n,l; cin >> n >> l;
		if(!n && !l) break;
		map<ll,ll> mp;
		mp[n] = 0;
		ll cnt = 1;
		while(1){
			ll mx = get(n,l,0);
			ll mn = get(n,l,1);
			if(mp.find(mx-mn) != mp.end()){
				print3(mp[mx-mn],mx-mn,cnt-mp[mx-mn]);
				break;
			}
			mp[mx-mn] = cnt;
			n = mx-mn;
			cnt++;
		}
	}
}


Measured memory_bytes: 3224
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <bitset>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef tuple<ll, ll, ll> tl3;



const int BIG_NUM = 1e9;
const ll INF = 1000000000000000000;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;



int main() {
	string s;
	cin >> s;
	string t;
	cin >> t;
	int cnt = 0;
	for (int i = 0; i < 3; i++) {
		if (s[i] == t[i]) {
			cnt++;
		}
	}

	cout << cnt << endl;
}


Measured memory_bytes: 3612
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int kunt[] = new int[200009];
        int n = in.nextInt();
        int k = in.nextInt();
        for(int i = 1; i <= n; i++){
            int x = in.nextInt();
            kunt[x]++;
        }
        Vector <Integer> inp = new Vector <Integer>();
        for(int i = 1; i <= 200000; i++){
            if(kunt[i] > 0){
                inp.addElement(kunt[i]);
            }
        }
        Collections.sort(inp);
        int SZ = inp.size();
        int ans = 0;
        if(SZ <= k) System.out.println(0);
        else {
            for(int i = 0; i < SZ - k; i++){
                ans += inp.get(i);
            }
            System.out.println(ans);
        }
        //System.out.println(ans);
    }
}

Measured memory_bytes: 64632
n,m = map(int,input().split())
h = list(map(int,input().split()))
li = []
for _ in range(m):
    li.append(list(map(int,input().split())))
counted_list = [0] * n #0ならオッケー、1ならアウト
for i in range(m):
    if h[li[i][0]-1] > h[li[i][1]-1]:
        counted_list[li[i][1]-1] = 1
    elif h[li[i][0]-1] == h[li[i][1]-1]:
        counted_list[li[i][1]-1] = 1
        counted_list[li[i][0]-1] = 1
    else:
        counted_list[li[i][0]-1] = 1
print(counted_list.count(0))

Measured memory_bytes: 32016
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
#define maz(a,b) a=max(a,b);
typedef long long ll;

using namespace std;
#define N 310
ll d[N][N][N],n,x;
string s;
int main(){
    cin>>s>>x; n=s.size();
    lol(k,x+1)lol(i,n)d[0][i][k]=0,d[1][i][k]=1;
    for(ll t=2;t<=n;t++){
	for(ll i=0;i+t-1<n;i++)lol(k,x+1){
	    ll l=i,r=i+t-1;
	    ll res=max(d[t-1][i][k],d[t-1][i+1][k]);
	    if(s[l]==s[r]){
		maz(res,d[t-2][i+1][k]+2);
	    }
	    else if(k){
		maz(res,d[t-2][i+1][k-1]+2);
	    }
	    d[t][i][k]=res;
	}
    }
    cout<<d[n][0][x]<<endl;
    return 0;
}


Measured memory_bytes: 225536
#include<bits/stdc++.h>
#define inf 0x3f3f3f3f
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef double dd;
const int N = 2e6+5;
const dd eps = 1e-8;
const int mod = 1e9+7;

int k,n,ss;
ll fac[N];
string s;

inline ll qpow(ll a,ll b){
  ll ans = 1;
  a = (a%mod + mod)%mod;
  for(;b;b >>= 1){
    if(b&1) ans = (ans*a)%mod;
    a = (a*a)%mod;
  }
  return ans;
}

ll comb(int n,int m){
  ll up = fac[n],down = (fac[m]*fac[n-m])%mod;
  ll ans = (up*qpow(down,mod-2))%mod;
  return ans;
}

int main(){
  ios::sync_with_stdio(false);
  // freopen("input.txt","r",stdin);
  cin>>k>>s;
  n = k + s.size();
  ss = s.size();
  fac[0] = 1;
  for(int i = 1;i <= 2e6;i++){
    fac[i] = (fac[i-1]*i)%mod;
  }
  ll ans = qpow(26,n);
  ll neg = 0;
  for(int i = 0;i < ss;i++){
    neg = (neg + (comb(n,i)*qpow(25,n-i))%mod)%mod;
  }
  ans = (ans - neg + mod)%mod;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 19904
#include<iostream>

using namespace std;

int main()
{
    long N; cin >> N;
    long Z;
    int count, ans;
    ans = 0;
    if(N == 1){
        cout << 0;
    }else{
        Z = N;
        for(int i=2; i<1000010; i++){
            if(Z%i == 0){
                count = 0;
                while(Z%i==0){
                    count++;
                    Z = Z/i;
                }
                for(int j=1; j<=16; j++){
                    if(count < j*(j+1)/2){
                        ans += j-1;
                        break;
                    }
                }
            }else if(i == 1000004 and Z>1){
                ans++;
                break;
            }
        }
        cout << ans;
    }
}

Measured memory_bytes: 3644
#include <stdio.h>
#define MAX 100

int main () {
  int i, j, a, u[MAX], k, v[MAX], r[MAX][MAX] = {0};

  scanf("%d", &a);
  for(i = 0 ; i < a ; i++) {
    scanf("%d%d", &u[i], &k);
    for(j = 0 ; j < k ; j++) {
      scanf("%d", &v[j]);
      r[i][v[j]-1] = 1;
    }
  }

  for(i = 0 ; i < a ; i++) {
    for(j = 0 ; j < a ; j++) {
      printf("%d", r[i][j]);
      if(j != a-1) printf(" ");
    }
    printf("\n");
  }

  return 0;
}

Measured memory_bytes: 648
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000000;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

///////////////////////////

ll beki(ll n) {
	if (n == 0) { return 1; }
	else { return 2 * beki(n - 1); }
}



int main() {

	ll N;
	cin >> N;

	ll A[100];
	ll sho[100][100] = {};

	repn(i, N) {
		cin >> A[i];
		repn(j, A[i]) {
			ll x, y;
			cin >> x >> y;
			sho[i][x] = y + 1;//2ならhonest 1ならunkind
		}
	}

	ll ans = -1;

	rep(i, beki(N)) {
		ll v = 1;

		ll nin = 0;
		ll hon[100];
		rep(j, N) {
			hon[j + 1] = i / beki(j) % 2;
			if (hon[j + 1] == 1) { nin++; }
			
		}

		repn(j, N) {

			if (hon[j] == 1) {
				repn(k, N) {
					if (hon[k]==1&& sho[j][k]==1) { v = 0; }
					if (hon[k] == 0 && sho[j][k] == 2) { v = 0; }
				}
			}
		}

		

		if (v == 1) { ans = max(ans, nin); }

	}

	cout << ans;

	system("PAUSE");
}

Measured memory_bytes: 512