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

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

void cin_Ignore(){cin.ignore(numeric_limits<streamsize>::max(), '\n');}

int main(){
    
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    string input;
    
    /*

入力例 1
3 3
dxx
axx
cxx

出力例 1
axxcxxdxx
    */
    
    int N, L;
    cin >> N >> L; cin_Ignore;
    vector<string> Area(N);
    
    for(int i = 0; i< N; i++){
        cin >> Area[i]; cin_Ignore;
    }
    sort(Area.begin(), Area.end());
    FOR(i,N){
        cout << Area[i];
    }
    
}

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

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


Measured memory_bytes: 3624
#include "bits/stdc++.h"
#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##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

int main() {
    ll H;
    cin >> H;
    int bit = 0;
    for (; H; H /= 2) bit++;

    ll ans = 0;
    ll n = 1;
    rep(i, bit) {
        ans += n;
        n *= 2;
    }
    write(ans);
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;

struct Graph {
    static constexpr int INF = 1 << 30;
    struct Edge {
        int i, r, f;
    };
    Graph(int n) : v(n), e(n) {}
    void add_edge(int i, int j, int f) {
        int r0 = e[j].size();
        int r1 = e[i].size();
        e[i].push_back({ j, r0, max(+f, 0) });
        e[j].push_back({ i, r1, max(-f, 0) });
    }
    void bfs(int i0, int i1) {
        fill(v.begin(), v.end(), -1);
        v[i0] = 0;
        queue<int> q;
        q.push(i0);
        while (!q.empty()) {
            int i = q.front(); q.pop();
            for (Edge& o : e[i]) {
                if (v[o.i] >= 0 || o.f == 0) continue;

                v[o.i] = v[i] + 1;
                if (o.i == i1) return;
                q.push(o.i);
            }
        }
    }
    int dfs(int i, int i1, int f0) {
        for (Edge& o : e[i]) {
            if (v[o.i] <= v[i] || o.f == 0) continue;

            int f = min(f0, o.f);
            if (o.i != i1) f = dfs(o.i, i1, f);
            if (f == 0) continue;

            o.f -= f;
            e[o.i][o.r].f += f;
            return f;
        }
        return 0;
    }
    int64_t max_flow(int i0, int i1) { // i0 != i1
        for (int64_t f = 0;;) {
            bfs(i0, i1);
            if (v[i1] < 0) return f;
            while (1) {
                int t = dfs(i0, i1, INF);
                if (t == 0) break;
                f += t;
            }
        }
    }
    vector<int> v;
    vector<vector<Edge>> e;
};

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

    Graph g(n);
    for (int i = 0; i < m; i++) {
        int a, b, c;
        cin >> a >> b >> c;

        g.add_edge(a, b, c);
    }

    cout << g.max_flow(0, n - 1) << endl;

    return 0;
}


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

int main() {
    int n, a, b, c, x;
    while (cin >> n >> a >> b >> c >> x and (n or a or b or c or x)) {

        vector<int> y(n);
        rep(i, n) cin >> y[i];

        int cnt=0, i=0;
        for (i=0; i<=10000 and cnt<n; ++i) {
            if (i) x = (a * x + b) % c;
            if (x == y[cnt] ) {
                cnt++;
            }
            if (cnt == n) {
                break;
            }
        }

        cout << (cnt == n ? i : -1) << endl;

    }
}

Measured memory_bytes: 3076
n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(m)]
edge = [[] for _ in range(n)]
for a, b in ab:
    edge[a-1].append(b-1)
    edge[b-1].append(a-1)
if n - 1 in edge[0]:
    print("POSSIBLE")
    exit()
else:
    for e in edge[0]:
        if n -1 in edge[e]:
            print("POSSIBLE")
            exit()
print("IMPOSSIBLE")


Measured memory_bytes: 79540
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define FOR(i,n,j) for(int i=(j);i<(n);++i)
#define ssort(n) sort((n).begin(),(n).end())
using ll=long long;
using ld=long double;
typedef pair<int,int> P;
#define INF 10101010

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

    
    int min=INF;
    int cost;
    ssort(a);
    FOR(i,a[N-1]+1,a[0]){
        cost=0;
        rep(j,N){
            cost+=(a[j]-i)*(a[j]-i);
        }
        if(cost<min){
            min=cost;
        }
    }
    cout << min << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
  int i,j,t,a[5];
  for(i=0;i<5;++i)scanf("%d",&a[i]);
  for(i=0;i<4;++i)for(j=4;j>i;--j)if(a[i]<a[j]){t=a[i];a[i]=a[j];a[j]=t;}
  for(i=0;i<5;++i)printf("%d%c",a[i],(i!=4)?' ':'\n');
  return 0;
}

Measured memory_bytes: 596
N = int(input())
p = [int(x) for x in input().split()]
diff = 0

for i in range(N):
    if (i + 1) != p[i]:
        diff += 1
    if diff >= 3:
        break

if diff == 0 or diff == 2:
    print('YES')
else:
    print('NO')


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long
#define lf long double
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef pair <ll,ll> ii;
typedef vector <ll> vi;
typedef vector <ii> vii;
typedef vector <bool> vb;
typedef vector <vector <ll> > vv;
typedef vector <vector <vector<ll> > > vvv;
typedef vector <string> vs;
typedef vector <lf> vf;
#define tr1(x) cerr << #x << ": " << x << endl
#define tr2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl
#define tr3(x,y,z) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trv(a) cerr<<#a<<": ";for(ll zz=0;zz<a.size();zz++) cerr<<a[zz]<<" ";cerr<<endl
#define mod 1000000007ll
#define inf 9999999999999999ll

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin>>n;
    vi volor(n,-1);
    vector <vii> e(n,vii());
    for(ll i=0;i<n-1;i++)
    {
        ll w,u,v;
        cin>>u>>v>>w;
        u--;
        v--;
        e[u].pb(mp(v,w));
        e[v].pb(mp(u,w));
    }
    vi dist(n,0);
    vb vis(n,false);
    queue <ll> q;
    q.push(0);
    vis[0]=true;
    while(!q.empty())
    {
        ll u=q.front();
        q.pop();
        for(ll i=0;i<e[u].size();i++)
        {
            ll v=e[u][i].F;
            ll w=e[u][i].S;
            if(!vis[v])
            {
                vis[v]=true;
                dist[v]=dist[u]+w;
                q.push(v);
            }
        }
    }
    for(ll i=0;i<n;i++)
    {
        if(dist[i]%2)
        {
            cout<<1<<"\n";
        }
        else
            cout<<0<<"\n";
    }
}


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

int main(){
    //入力
    int H,W;

    cin >> H >> W;

    vector<string> S(H);
    for(int i=0;i<H;i++){
        cin >> S.at(i);
    }

    //出力
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            if(S.at(i).at(j)=='.'){
                int count=0;
                for(int k=-1;k<=1;k++){
                    for(int l=-1;l<=1;l++){
                        if(i+k>=0&&i+k<H&&j+l>=0&&j+l<W){
                            if(S.at(i+k).at(j+l)=='#'){
                                count++;
                            }
                        }
                                     
                    }
                }
                cout << count;
            }else{
                cout << '#';
            }
            
        }
        cout << endl;
    }

}

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

using namespace std;

int main()

{
	int a, i;
	
	vector<int> takasa;
	
	for(i = 0; i < 10; i++)
	{
		cin >> a;
		takasa.push_back(a);
	}
	
	
	sort(takasa.begin(), takasa.end());
	
	
	cout << takasa[9] << endl;
	cout << takasa[8] << endl;
	cout << takasa[7] << endl;
	
	
	return 0;
	
}

Measured memory_bytes: 1216
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
typedef pair<int, int>P;
const int INF = 1e8;

signed main() {
	int N, num;
	cin >> N;
	map<int, int>m;
	rep(i, N) {
		cin >> num;
		m[num]++;
	}
	int cnt = 0;
	for (auto i : m) {
		if (i.first > i.second)cnt += i.second;
		else cnt += i.second - i.first;
	}
	cout << cnt;
}

Measured memory_bytes: 6272
import java.util.ArrayList;
import java.util.Scanner;
class Main{

	
	static char[][] map;
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);			//文字の入力



		int x = sc.nextInt();
		int a = sc.nextInt();
		if(x < a){
			System.out.println(0);
		}else{
			System.out.println(10);
		}
	}
	
	static int rsearch(int y,int x){
		
		int count = 0;
		while(x < map[0].length && map[y][x] != '#'){
			count++;
			x++;
		}
		return count;	
		
	}

	static int csearch(int y,int x){
		
		int count = 0;
		while(y < map.length && map[y][x] != '#'){
			count++;
			y++;
		}
		return count;	
	}


	static boolean checkswitch(int bit,int[] k,ArrayList<ArrayList<Integer>> list,int[] p,int m){

		//		System.out.println("bit " + bit);

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

			ArrayList<Integer> sub = list.get(i);
			int onnum = 0;						//onの数
			for(int j = 0;j < sub.size();j++){
				//				System.out.println("sub "+ sub.get(j));
				if((bit & (1 << sub.get(j))) != 0){				//目的のスイッチがついているか
					onnum++;
					//					System.out.println("on  ");
				}

			}
			if(onnum % 2 != p[i]){				//一個でも電球がつかなかったらout
				return false;
			}

		}


		return true;

	}

	static int gcd(int a,int b){				//最大公約数を返す
		if(b == 0){
			return a;
		}else{
			return gcd(b, a%b);
		}
	}





}



class Pair implements Comparable{
	int from;
	int end;
	@Override
	public int compareTo(Object other) {
		Pair otherpair = (Pair)other;

		return  otherpair.end - end;
	}
}




Measured memory_bytes: 21844
#include<cstdio>
using namespace std;
int main()
{
	int n,i,a[200][3],flg,j,k,sum;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		for(j=0;j<3;j++){
			scanf("%d",&a[i][j]);
		}
	}
	for(i=0;i<3;i++){
		for(j=0;j<n;j++){
			flg=0;
			for(k=0;k<n;k++){
				if(j!=k){
					if(a[j][i]!=0){
						if(a[j][i]==a[k][i]){
							a[k][i]=0;
							flg=1;
						}
					}
				}
			}
			if(flg==1){
				a[j][i]=0;
			}
		}
	}
	for(i=0;i<n;i++){
		sum=0;
		for(j=0;j<3;j++){
			sum+=a[i][j];
		}
		printf("%d\n",sum);
	}
	return 0;
}


Measured memory_bytes: 2748
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#include<cmath>
#include<deque>
#include<set>
#include<iostream>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x.begin(), _x.end(), std::greater<int>())
#define INF 1LL << 60
#define MAX 1000000000

int main() {
	int N, C, K, c = 0, ans = 0;
	scanf("%d%d%d", &N,  &C, &K);
	vector<int> A(N);
	rep(i, 0, N)scanf("%d", &A[i]);
	sort(all(A));
	while (1) {
		int i;
		for (i = c; i < min(C + c, N) && A[i] <= A[c] + K; i++);
		//printf("%d\n", c);
		if (i == N) { ans++; break; }
		c = i--;
		ans++;
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 640
#include<iostream> 
#include<iomanip> 
#include<vector> 
#include<map> 
#include<set> 
#include<algorithm> 
#include<numeric> 
#include<limits> 
#include<bitset> 
#include<functional> 
#include<type_traits> 
#include<queue> 
#include<stack> 
#include<array> 
#include<random> 
#include<utility> 
#include<cstdlib> 
#include<ctime>
#define INT_MAX 2147483647
#define _LIBCPP_DEBUG 0
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (n); ++i)	
using namespace std;

int max(int a,int b) {
	int max;
	if (a > b) max = a;
	else max = b;
	return max;
}
int min(int a, int b) {
	int min;
	if (a < b) min = a;
	else min = b;
	return min;
}

int main() {
	int n;
	int d[110];
	cin >> n;
	rep(i, n) {
		cin >> d[i];
	}
	sort(d, d + n);
	int count = 1;
	rep(i, n) {
		if (d[i] != d[i + 1]) {
			count++;
		}
	}
	cout << count-1 << endl;

}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int Time=0,d[101],f[101],v[101][101];
void Init()
{
    int i;
    for(i=1;i<=100;i++)
        d[i]=0;
}
void dfs(int cur,int n)
{
    int i;
    Time += 1;
    d[cur]=Time;
    for(i=1;i<=n;i++)
    {
        if(v[cur][i]==1 && d[i]==0)
            dfs(i,n);
    }
    Time += 1;
    f[cur] = Time;
}
int Find(int n,int d[])
{
    int flag=0,i;
    for(i=1;i<=n;i++)
        if(d[i]==0)
        {
            flag=i;
            break;
        }
    return flag;
}
int main()
{
    int n,m,k,i,j,flag;
    cin >> n;
    for(i=1;i<=n;i++)
        for(j=1;j<=n;j++)
            v[i][j]=0;
    for(i=1;i<=n;i++)
    {
        cin >> i >> k;
        for(j=1;j<=k;j++)
        {
            cin >> m;
            v[i][m]=1;
        }
    }
    Init();
    dfs(1,n);
    while(1)
    {
        flag = Find(n,d);
        if(flag == 0)
            break;
        else    dfs(flag,n);
    }
    for(i=1;i<=n;i++)
    {
        cout << i << ' ' << d[i] << ' ' << f[i] << endl;
    }
    return 0;
}



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

#define ll long long 
#define MAXN 1010
#define mod 1000000007

using namespace std;

int ans, n, base, last;
int c[MAXN][MAXN];
int h, t;

int main(){
	scanf("%d", &n);
	
	int tmp = 0, tp;
	for (int i = 0; i <= 9; i++) {
		for (int j = 0; j <= 9; j++) {
			tmp = 0;
			for (int k = 1; k <= n; k++) {
				tp = k;
				while (tp > 9) {
					tp /= 10;
				}
//				cout << k << " " << tp << endl;
				if (tp == i && k % 10 == j) tmp++;
			}
			c[i][j] = tmp;
		}
	}
	for (int i = 0; i <= 9; i++) {
		for (int j = 0; j <= 9; j++) {
			ans += c[i][j] * c[j][i];
		}
	}
//	cout << ans << endl;
	cout << ans << endl;
	
	return 0;
} 
//25

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define C 0.5772156649
#define pi acos(-1.0)
#define ll long long
#define mod 1000000007
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1

using namespace std;

const double g=10.0,eps=1e-12;
const int N=2000+10,maxn=90000+10,inf=0x3f3f3f3f;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin>>s;
    for(int i=0;i<s.size();i++)
    {
        if(s.substr(i,2)=="AC")
        {
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
    return 0;
}
/********************

********************/

Measured memory_bytes: 256
import itertools

N,M = map(int,input().split())

sw = [[] for _ in range(M)]
for i in range(M):
    sw[i] = list(map(int,input().split()[1:]))

P = list(map(int,input().split()))
ans = 0
for tpl in itertools.product([0,1], repeat=N):
    bl = True
    for i in range(M):
        s = sum([tpl[j-1] for j in sw[i]])
        if (s-P[i])%2 == 1:
            bl = False
            break
    if bl:
        ans += 1

print(ans)

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

int main(){
    int A,B,C;
    cin >> A >> B >> C;
    int fives=0, sevens=0;
    if(A == 5)fives++;
    if(A == 7)sevens++;
    if(B == 5)fives++;
    if(B == 7)sevens++;
    if(C == 5)fives++;
    if(C == 7)sevens++;
    if(fives == 2 && sevens == 1)cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
} 

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

int main()
{
  int n;
  int kazu=0,sum=0;
  int max,min;

  while(1)
    {
      cin >> n;

      if(n == 0)break;

      sum = 0;

      for(int i = 0;i < n;i++)
	{
	  cin >> kazu;
	  sum += kazu;

	  if(i == 0)
	    {
	      max = kazu;
	      min = kazu;
	    }

	  if(max < kazu) max = kazu;

	  if(kazu < min) min = kazu;
	}
      sum = sum - max - min;

      cout << sum/(n-2) << endl;
    }
}



Measured memory_bytes: 3088
#include<iostream>
#include<string>
#include<sstream>
using namespace std;
int main(){
string a,b,c;
cin>>a>>b;
c=a+a;
if(c.find(b)!=string::npos){
cout<<"Yes"<<endl;
}
else{
cout<<"No"<<endl;}
return 0;
}

Measured memory_bytes: 3168
a,b,c,d=map(int,input().split())

def calc_div_num(a,b,x):
  return b//x - (a-1)//x

num_c = calc_div_num(a, b, c)
num_d = calc_div_num(a, b, d)

import numpy as np
import math
#lcd = np.lcm(c, d)
lcd = c*d/math.gcd(c,d)
num_lcd = calc_div_num(a, b, int(lcd))

result = b-a+1 - (num_c+num_d-num_lcd)
print(result)

Measured memory_bytes: 27204
def resolve():
    N = int(input())
    X = list(map(int, input().split()))
    av = sum(X)/N
    def _round(x, d=0):
        import math
        p = 10 ** d
        return math.floor(x*p)/p if (x*p)%1 < 0.5 else math.ceil(x*p)/p
    P = round(av)
    ans = 0
    for x in X:
        ans += (x-P)**2
    print(ans)

if '__main__' == __name__:
    resolve()

Measured memory_bytes: 62080
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <fstream>
#include <iomanip>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toStr(T x) { ostringstream sout; sout << x; return sout.str(); }
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = INT_MAX / 2;
const int MOD = 1000000007;
typedef vector<ll> vl;
typedef vector<vl> vvl;

int main() {
	int N;
	cin >> N;
	vl T(N), A(N);
	REP(i, N) {
		cin >> T[i] >> A[i];
	}

	ll ansT = 1, ansA = 1;
	REP(i, N) {
		ll x = ansT / T[i];
		ll y = ansA / A[i];
		if (ansT%T[i] != 0) x++;
		if (ansA%A[i] != 0) y++;
		ll n = max(x, y);
		ansT = n * T[i];
		ansA = n * A[i];
	}

	cout << ansT + ansA << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
using namespace std;
int n,m;  int map[13][100003];  int book[13]; int ans; int newmap[13][100003]; int max0,max1; int preans;
void answer();
void dfs(int x)
{
	if(x==n+1) answer();
	else 
	{
		for(int i=0;i<2;i++)
		{
			book[x]=i;
			dfs(x+1);
		}
	}
}

void answer()
{
	 preans=0;
    
	for(int i=1;i<=n;i++)
	{
		if(book[i])
		for(int j=1;j<=m;j++)
		{
			newmap[i][j]=(map[i][j]+1)%2;
		}
		else 
		for(int j=1;j<=m;j++)
		{
			newmap[i][j]=map[i][j];
		}
	}

	for(int i=1;i<=m;i++)
	{
		for(int j=1;j<=n;j++)
		{
			if(newmap[j][i]==0)  max0++;
			else max1++;
		}
		 preans+=max(max0,max1);
		 max1=0; max0=0;
	}
	ans=max(ans,preans);
}


int main()
{
   	while(~scanf("%d%d",&n,&m)&&n!=0)
   	{
   		   ans=0; preans=0;
			 for(int i=1;i<=n;i++)
   		  {
   		     for(int j=1;j<=m;j++)
			 scanf("%d",&map[i][j]);	
		  }
       for(int i=0;i<2;i++)
       {
       	  book[1]=i;
       	  dfs(2);
	   }
	   cout<<ans<<endl;
	}
	return 0;
}


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

long solve(long x, long y) {
    long ans = LONG_MAX;
    for (long i=1; i<x; i++) {
        long d1 = floor(y / 2), d2 = floor((x-i)/2);
        long sa = y * i,
             sb1 = d1 * (x - i), sc1 = (y - d1) * (x - i),
             sb2 = d2 * y, sc2 = (x - i - d2) * y;
        long ans1 = abs(max({sa, sb1, sc1}) - min({sa, sb1, sc1})),
             ans2 = abs(max({sa, sb2, sc2}) - min({sa, sb2, sc2}));
        ans = min({ans, ans1, ans2});
    }
    return ans;
}

int main(){
    long h, w;
    cin >> h >> w;
    cout << min(solve(h, w), solve(w, h)) << endl;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){
    int H,N,answer = 0;
    cin >> H >> N;
    int A[N];
    for(int i = 0;i < N;i++){
        cin >> A[i];
    }
    for(int i : A){
        answer += i;
    }
    if(answer < H){
        cout << "No";
    }else{
        cout << "Yes";
    }
    return 0;
}

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

int main()
{
	int N;
	ll K;
	cin >> N >> K;
	vector<ll> A(N);
	ll S(0);
	for(int i(0);i<N;++i){
		cin >> A[i];
		S += A[i];
	}
	vector<ll> d;
	for(int i(1);i*i<=S;++i){
		if(S % i == 0){
			d.push_back(i);
			d.push_back(S/i);
		}
	}
	int M = d.size();
	vector<ll> a(N);
	ll a_sum,sum_left,sum_right,target_d,d_max(0);
	for(int i(0);i<M;++i){
		target_d = d[i];
		a_sum = 0;
		for(int j(0);j<N;++j){
			a[j] = A[j] % target_d;
			a_sum += a[j];
		}
		sort(a.begin(),a.end());
		sum_left = a_sum;
		sum_right = 0;
		ll swap_num = 1e18;
		for(int j(N-1);j>=0;--j){
			sum_left -= a[j];
			sum_right += target_d-a[j];
			if(abs(sum_left - sum_right) % target_d == 0) swap_num = min(swap_num, max(sum_left, sum_right));
		}
		if(swap_num <= K) d_max = max(d_max, target_d);
	}
	cout << d_max << endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
ac, wa, tle, re = 0, 0, 0, 0
for i in range(n):
    s = input()
    if s == "AC":
        ac += 1
    elif s == "WA":
        wa += 1
    elif s == "TLE":
        tle += 1
    elif s == "RE":
        re += 1
print("AC x " + str(ac))
print("WA x " + str(wa))
print("TLE x " + str(tle))
print("RE x " + str(re))

Measured memory_bytes: 9152
S = input()
T = input()

ans = 9999
for i in range(len(S)-len(T)+1):
    s = S[i:i+len(T)]
    cnt = 0
    for a,b in zip(s,T):
        if a!=b:
            cnt += 1
    ans = min(ans,cnt)
print(ans)

Measured memory_bytes: 9052
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,b,n) for(int i=b;i<n;i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
int n,m;
const int MAX_N =120;
const int MAX_M =120;
double dp[MAX_N][MAX_M];//dp[i][j]:=直前にjを与え、i回目に肥料を与えたときの最大の成長
double memo[MAX_N][MAX_N];
int main(){
	while(1){
		cin>>n>>m;
		if(n==0&&m==0){
			break;
		}
		for(int i =0;i <MAX_N;i++){
			for(int j =0;j <MAX_N;j++){
				dp[i][j] =0;
				memo[i][j]=0;
			}
		}
		rep(i,n){
			rep(j,n){
				cin>>memo[i][j];
			}
		}
		rep(i,n)dp[1][i] =1.00;

		double ans =0;
		for(int i =1;i <m;i++){
			for(int k =0;k <n;k++){//直前
				for(int j =0;j <n;j++){//直後
					dp[i+1][j] =max(dp[i+1][j],dp[i][k]*memo[k][j]);
				}
			}
		}
		rep(i,n)ans=max(ans,dp[m][i]);
		/*
		ans +=0.005;
		ans =ans*100;
		ans =(int)ans;
		ans =(double)ans/100;
		*/
		printf("%.2lf\n",ans);
	}
	return 0;
}

Measured memory_bytes: 1468
#include<stdio.h>
int main()
{
	int n,a,b,i,p,q,r,s,t, sum, temp, num;
	while(~scanf("%d %d %d", &n, &a, &b))
	{
		p=q=r=s=t=sum=0;
		for(i=1; i<=n; i++)
		{
			temp=0;
			for(num=i; num!=0; num/=10)
				temp+=num%10;
			if(temp>=a && temp<=b)
				sum+=i;
		}
		printf("%d\n", sum);
	}
	return 0;
}

Measured memory_bytes: 760
s = input()
t = input()

a = "abcdefghijklmnopqrstuvwxyz"
b = [0]*26
flag = 0

for i in range(len(s)):
    tmp = a.index(s[i])
    if b[tmp] == 0:
        b[tmp] = t[i]
        if b.count(t[i]) > 1:
            flag = 1
            break
    elif b[tmp] != t[i] :
        flag = 1
        break

        
print("Yes" if flag == 0 else "No")

Measured memory_bytes: 3632
// https://atcoder.jp/contests/abc175/tasks/abc175_d
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define CEIL(a, b) ((a - 1) / b + 1)

void solve() {
    int N, K;
    cin >> N >> K;
    vector<int> P(N), C(N);
    REP(i, N) cin >> P[i], P[i]--;
    REP(i, N) cin >> C[i];

    int ans = -1e12;
    // スタート位置
    REP(i, N) {
        // 循環する要素を求める（Pi != i なので自分自身へループしない）
        vector<int64_t> v;
        for (int j = i;; j = P[j]) {
            v.push_back(C[j]);
            // 開始時点に戻ったら終了
            if (P[j] == i)
                break;
        }
        // 循環する要素の長さ
        int m = v.size();
        // 循環する要素の合計
        auto sum = accumulate(begin(v), end(v), 0LL);
        int64_t cur = 0;
        for (int r = 1; r <= m; ++r) {
            if (r > K)
                break;
            cur += v[r - 1];
            // 先頭からスコアを加算し、残りの長さに対して何回循環するか数える
            ans = max(ans, cur + (K - r) / m * max(sum, 0LL));
        }
    }
    cout << ans << endl;
}

signed main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    solve();
}


Measured memory_bytes: 3792
N, M = map(int, input().split())

B = [list(map(int, input().split())) for _ in range(M)]

class Group:
    id = 0
    def __init__(self):
        self.id = Group.id
        Group.id += 1
        self.count = 1
        self.root = None

    def top(self):
        w = self
        c = []
        while not w.root is None:
            c.append(w)
            w = w.root
        for ci in c:
            ci.root = w
        return w

    def union(self, g):
        ss, gg = self.top(), g.top()
        ss.count += gg.count
        gg.root = ss

pt = []
G = [Group() for x in range(N+1)]
idx = 0
cnt = 0
while len(B):
    x, y = B.pop()
    wx = G[x].top()
    wy = G[y].top()
    if wx is wy:
        pt.append(0)
    else:
        pt.append(wx.count * wy.count)
        wx.union(wy)

    #print(G)

cnt = 0
while len(pt):
    cnt += pt.pop()
    print(cnt)


Measured memory_bytes: 84312
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define endl "\n"
using ll=long long;
using ld=long double;
using namespace std;
ll mod= 1e9+7;
ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }

ll a[210000];
ll b[210000];
main(){
    ll n,ans=0;
    cin>>n;
    if(n%2==1)cout<<0;
    else{
      n/=2;
      ll a5=5;
      while(n>=a5){
       ans+=n/a5;
       a5*=5;
      }
      cout<<ans;
    }
}

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

int main()
{
	int h, w;

	while(1) {
		cin >> h >> w;
		if (h == 0 & w == 0) break;

		int i, j;
		for (i = 0; i < h; i++) {
			for (j = 0; j < w; j++) {
				cout << "#";
			}
			cout << "\n";
		}
		cout << "\n";
	}

	return 0;
}

Measured memory_bytes: 1120
n = int(input())
apexes = [i + 1 for i in range(n)]
pairs = []

if n % 2 == 0:
    offset = 0
else:
    offset = 1
for i in range(n // 2):
    pairs.append((apexes[i], apexes[n - 1 - i - offset]))


# print(pairs)

edges = []
for i in range(len(pairs)):
    for j in range(i + 1, len(pairs)):
        edges.append((pairs[i][0], pairs[j][0]))
        edges.append((pairs[i][0], pairs[j][1]))
        edges.append((pairs[i][1], pairs[j][0]))
        edges.append((pairs[i][1], pairs[j][1]))

if n % 2 == 1:
    for i in range(1, n):
        edges.append((n, i))

print(len(edges))
for edge in edges:
    print("{0} {1}".format(edge[0], edge[1]))


Measured memory_bytes: 3700
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
using namespace std; using ll = long long; using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
//**デバッグ準備**//
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail>
void debug_out(Head h, Tail... t) {
	cerr << " " << h;
	if (sizeof...(t) > 0) cerr << " :";
	debug_out(t...);
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> vec) {
	for (size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	return os;
}
ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.first > secondElof.first;
}
//**Snippetリスト**//
//rep, vin, all, iteLoop//
//bitSearch, bitList, nod, gcdlcm, isPrime, primeFactorize, Npow, divisor, modinv, dfs, bfs, eratos//
//dijkstra, WarshallFloyd, BellmanFord, UnionFind, COM, digitDP ,RMQ//
ll i, j, k, l; ll N, M, K, H, W, L, X, Y, Z, R;
ll MOD = 1000000007; ll INF = 1LL << 62; ll ans = 1; ll z = 0, o = 1;
vl flag, color, D; vll path;
int main() {
	ll T;
	cin >> N >> T;
	vl A(N);
	for (i = 0; i < N; i++) cin >> A[i];
	vl B(N);
	B[N - 1] = A[N - 1];
	for (i = N-2; i >=0; i--) {
		B[i] = max(B[i + 1], A[i]);
	}
	ll big = 0;
	ll count = 1;
	for (i = 0; i < N-1; i++) {
		if (big == B[i + 1] - A[i]) count++;
		else if (big < B[i + 1] - A[i]) {
			big = B[i + 1] - A[i];
			count = 1;
		}
	}
	cout << count;
}

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

 using namespace std;

 int main() {
   int N;

   cin >> N;

   vector<int> L(N);
   int max_L = 1;
   int sum_L = 0;

   for (int i = 0;i < N; i++) {
     cin >> L.at(i);
     max_L = max(max_L, L.at(i));
     sum_L += L.at(i);
   }
   if (sum_L > 2 * max_L) cout << "Yes" << endl;
   else cout << "No" << endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

    /* チェックリスト
     * intの範囲を超えていないか
     * TLEしそうな処理の有無
     */
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int in = Integer.parseInt(sc.nextLine());
        float max = in;
        float oddness = 0;
        for(int i = 1;i <= in;i++){
            if(i % 2 != 0){
                oddness++;
            }
        }
        System.out.println(oddness / max);
    }
}

Measured memory_bytes: 21844
#define rep(i, n) for (int i = 0; i < (n); i++)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MOD = 1000000007;
// MAX int 2,147,483,647
// MAX O(n) 10^18

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> h(N);
    rep(i, N) cin >> h.at(i);

    int count = 0;
    rep(i, N) {
        if (h.at(i) >= K) count++;
    }

    cout << count << endl;
    
    return 0;
}


Measured memory_bytes: 3668
#include <stdio.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <cmath>
#include <map>
#include <unordered_map>
//#include <unordered_set>
//#include <boost/container/static_vector.hpp>
//#include <boost/unordered_set.hpp>
//#include <boost/unordered_map.hpp>
//#include <unistd.h>

const int MAX_N = 2050;
long long r, D, x[MAX_N];

int main(int argc, char **argv) {
    std::cin >> r >> D >> x[2000];

    for (int i = 2001; i <= 2010; i++) {
        x[i] = r * x[i-1] - D; 
    }

    for (int i = 2001; i <= 2010; i++) {
        std::cout << x[i] << std::endl;
    }

    return 0;
}

Measured memory_bytes: 256
import java.util.LinkedList;
import java.util.Scanner;
import java.util.Iterator;

class Graph {
	private int totalVertex;
	//adjMatrix[u][v] = 1 if there is an edge from u to v, otherwise 0
	private int[][] adjMatrix;
	//adjWeight[u][v] -- the weight of the edge from u to v if there is one
	private int[][] adjWeight;
	//if a node is settled (e.g., processed in the Dijkstra's algorithm)
	private Boolean[] ifSettled;
	public Graph() { totalVertex = 0; }
	public int getTotalVertex() { return totalVertex; }
	//load graph from standard input
	public void loadAdjMatrix() {
		Scanner in = new Scanner(System.in);
		totalVertex = in.nextInt();
		adjMatrix = new int[totalVertex][totalVertex];
		adjWeight = new int[totalVertex][totalVertex];
		ifSettled = new Boolean[totalVertex];
		int i, j;
		for(i = 0; i < totalVertex; i ++) {
			ifSettled[i] = false;
			for(j = 0; j < totalVertex; j ++) {
				adjMatrix[i][j] = adjWeight[i][j] = 0;
			}
		}
		int u, v;
		for(i = 0; i < totalVertex; i ++) {
			u = in.nextInt();
			int degree = in.nextInt();
			for(j = 0; j < degree; j ++) {
				v = in.nextInt(); 
				adjMatrix[u][v] = 1;
				adjWeight[u][v] = in.nextInt();
			}	
		}
		in.close();
	}
	//return weight of the edge from u to v if there is one
	public int getWeight(int u, int v) {
		return adjWeight[u][v];
	}
	//return neighbors of u as a LinkedList
	public LinkedList<Integer> getNeighbors(int u) {
		LinkedList<Integer> tmp = new LinkedList<Integer>();
		for(int v = 0; v < totalVertex; v ++) {
			if(adjMatrix[u][v] == 1) tmp.add(v);
		}
		return tmp;
	}
	//return unsettled neighbors of u as a LinkedList
	public LinkedList<Integer> getUnsettledNeighbors(int u) {
		LinkedList<Integer> tmp = new LinkedList<Integer>();
		for(int v = 0; v < totalVertex; v ++) {
			if((adjMatrix[u][v] == 1) && (ifSettled[v] == false)) tmp.add(v);
		}
		return tmp;
	}
	//return the unsettled node that has the smallest dist
	public int getUnsettledNearest(int[] dist) {
		int md = Integer.MAX_VALUE;
		int mv = -1;
		int v;
		for(v = 0; v < totalVertex; v ++) {
			if((ifSettled[v] == false) && (dist[v] < md)) {
				md = dist[v];
				mv = v;
			}
		}
		return mv;
	}
	//implement the following	
	public int[] Dijkstra(int s) {
		
		LinkedList<Integer> unsettled = new LinkedList<>();
		int[] d = new int[totalVertex];
		
		for(int i = 0; i < totalVertex; i++) {
			unsettled.add(i);
			d[i] = Integer.MAX_VALUE;
		}
		
		d[s] = 0;
		
		while(!unsettled.isEmpty()) {
			int nearest = getUnsettledNearest(d);
			ifSettled[nearest] = true;

			LinkedList<Integer> n = getUnsettledNeighbors(nearest);
			Iterator<Integer> it = n.iterator();
			// nearest has been settled so remove it
			unsettled.remove((Integer) nearest);
			
			while(it.hasNext()) {
				int j = it.next();
				int newWeight = getWeight(nearest, j) + d[nearest];
				if(d[j] > newWeight) {
					d[j] = newWeight;
				}
			}
		}
		return d;
	}
}

public class Main {
	public static void main(String[] argv) {
		Graph g = new Graph();
		g.loadAdjMatrix();
		int[] dist = g.Dijkstra(0);
		for(int i = 0; i < g.getTotalVertex(); i ++) {
			System.out.println(i + " " + dist[i]);
		}
	}
}


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

int sum(int y, int m, int d) {
	int t = 0;
	t += (y - 1) * 195 + (y - 1) / 3 * 5;
	t += (m - 1) * 19 + m / 2;
	if (y % 3 == 0) t += (m - 1) / 2;
	t += d - 1;
	return t;
}

int main() {
	int n;
	cin >> n;
	while (n--) {
		int y, m, d;
		cin >> y >> m >> d;
		
		cout << sum(1000, 1, 1) - sum(y, m, d) << endl;
	}
	return 0;
}

Measured memory_bytes: 3100
n = int(input())

for i in range(1, n+1):
    if i % 3 == 0:
        print(" " + str(i), end="")
    else:
        x = i
        while(x):
            if x % 10 == 3:
                print(" " + str(i), end="")
                break
            x //= 10

print()



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

int main() {
  int a,b;
  cin >> a >> b;
  vector<bool>data(4,true);
  data[0] = false;
  data[a] = false;
  data[b] = false;
  rep(i,4){
    if(data[i]) cout << i << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define sz(a)  int((a).size())
#define pb  push_back
#define eb  emplace_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define repC3(vari,varj,vark,n)  for(int vari=0;vari<(n)-2;++vari)for(int varj=vari+1;varj<(n)-1;++varj)for(int vark=varj+1;vark<(n);++vark)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))
using namespace std;
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }


int main() {
    int N,K;
    int ans=0;
    cin>>N>>K;
    char S[N];
    char prev='N';
    int count=0;
    rep(i,N){
        cin>>S[i];
        if(prev!=S[i]){
            ans+=count;
            count=0;
        }else{
            count++;
        }
        prev=S[i];
    }
    ans+=count;
    ans=min(N-1,K*2+ans);
    Out(ans);
    return 0;
}


Measured memory_bytes: 384
N,P=map(int, input().split())
*A,=map(int, input().split())
p = [0,0]
for a in A: p[a&1] += 1
even,odd=p[0],p[1]

def comb(n, r):
    p, q = 1, 1
    for i in range(r):
        p = p * (n-i)
        q = q * (i+1)
    return p // q

ans = 2**even
tmp = 0
if P:
    for i in range(1,odd+1,2):
        tmp += comb(odd, i)
else:
    for i in range(0,odd+1,2):
        tmp += comb(odd, i)
print(ans*tmp)

Measured memory_bytes: 38256
#include "bits/stdc++.h"

#define sai(j,n) for(sei j=0;j<sei(n);++j)
#define gsai(j,n) for(sei j=sei(n)-1;j>=0;--j)
#define kan(j,m,n) for(sei j=m;j<sei(n);++j)
#define gkan(j,m,n) for(sei j=sei(n)-1;j>=sei(m);--j)
#define zen(h) (h).begin(),(h).end()
#define yu(h) v.erase(unique(zen(h)), h.end());
#define mugen 10000000111
#define yo 10000000711
#define kyo 1e-9
#define datu break
#define saiki(a) while(a)
#define seiri(h) sort(zen(h))
#define sin() main()
#define hen return
#define nyu(a) cin >> a
#define syutu(a) cout << a << endl
#define ru(a) if(a)
#define ta else
#define ruguo(a) else if(a)

using namespace std;
typedef int seisu;
typedef void mu;
typedef long long sei;
typedef long double xyo;
typedef vector<sei> hs;
typedef vector<xyo> hx;
typedef vector<hs> hhs;
typedef vector<hx> hhx;
typedef pair<sei, sei> so;
typedef vector<so> hso;
typedef bool singi;

const seisu h1[8] = {1,1,0,-1,-1,-1,0,1};
const seisu h2[8] = {0,1,1,1,0,-1,-1,-1};

sei dai(sei a, sei b){return max(a,b);}
sei syo(sei a, sei b){return min(a,b);}

hs a(3);

seisu sin(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    nyu(a[0]);
    nyu(a[1]);
    nyu(a[2]);
    seiri(a);
    syutu(a[2]-a[0]);
    hen 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 110 , mz = 1e9+7;
int a[5];

int main(){

    for(int i = 0 ; i < 3 ; i++)    cin>>a[i];
    sort(a,a+3);
    int k;
    cin>>k;
    while( k-- )    a[2]*=2;
    cout<<a[2]+a[1]+a[0]<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;

int main(){
	long n = 0;
	cin >> n;
	vector< pair<long, long> > a(n);
	string b = "";
	long c = 0;
	long d = 0;

	for (long i = 0; i < n; i++){
		cin >> b >> c;
		if (b == "S"){
			d = 0;
		}
		else if (b == "H"){
			d = 1;
		}
		else if (b == "C"){
			d = 2;
		}
		else if (b == "D"){
			d = 3;
		}
		else {
			cout << "something error occurred";
		}
		a[i] = make_pair(d, c);
	}

	sort(a.begin(), a.end());
	
	vector< pair <long, long> > f(52);
	for (long i = 0; i < 4; i++){
		for (long j = 0; j < 13; j++){
			f[i * 13 + j] = make_pair(i, j + 1);
		}
	}

	vector<long> o(52, 0);
	for (long i = 0; i < 52; i++){
		for (long j = 0; j < n; j++){
			if (a[j] == f[i]){
				o[i] = 1;
				break;
			}
		}
	}

	string e;
	for (long i = 0; i < 52; i++){
		if (o[i] != 1){
			switch (f[i].first){
				case 0:
					e = "S";
					break;
				case 1:
					e = "H";
					break;
				case 2:
					e = "C";
					break;
				case 3:
					e = "D";
					break;
				default:
					e = "NULL";
					break;
			}
			cout << e << " " << f[i].second << endl;
		}
	}

	return 0;
}

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

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	vector<int> triangle(449);
	triangle[1] = 1;
	for (int q = 2; q <= 448; q++)
	{
		triangle[q] = triangle[q-1]+q;
	}
	int n;
	cin >> n;
	int num = -1;
	for (int q = 1; q <= 448; q++)
	{
		if (n == triangle[q])
		{
			num = q;
			break;
		}
	}
	if (num == -1)
	{
		cout << "No\n";
		return 0;
	}
	vector<vector<int>> ans(num+1, vector<int>(num));
	int cur = 0;
	int used = 0;
	while (cur < num)
	{
		for (int q = cur; q < num; q++)
		{
			ans[cur][q] = used+(q-cur+1);
		}
		for (int q = cur+1; q < num+1; q++)
		{
			ans[q][cur] = used + q- cur;
		}
		used += num-cur;
		cur++;
	}
	cout << "Yes\n";
	cout << (num+1) << "\n";
	for (int q = 0; q < num+1; q++)
	{
		cout << num << " ";
		for (int w = 0; w < num; w++)
		{
			cout << ans[q][w] << " ";
		}
		cout << "\n";
	}
	return 0;
}


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

#include <iostream>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <stdint.h>
#include <string.h>

#define _USE_MATH_DEFINES
#include <math.h>

#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <deque>
#include <string>

#include <algorithm>
#include <functional>
#include <bitset>
#include <functional>
#include <chrono>
#include <random>

#define sqr(x) (x) * (x)

typedef unsigned int u32;
typedef int i32;
typedef unsigned long long int u64;
typedef long long int i64;
typedef uint16_t u16;
typedef int16_t i16;
typedef uint8_t u8;
typedef int8_t i8;

using namespace std;
using namespace std::chrono;

const i64 mod = 1'000'000'000ll + 7;
//const i64 smod = 998244353ll;
//const i64 inf = 1'000'000'000'000'000'000ll + 7;
//const i64 inf = 1'000'000'007;

const double inf = 1e9;

const long double eps = 1e-8;



int main(int argc, char* argv[]) {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.precision(15); cout.setf(ios::fixed); cerr.precision(15); cerr.setf(ios::fixed);

    i64 n;
    cin >> n;
    vector<i64> a(n);

    for (i64 i = 0; i < n; i++) {
        cin >> a[i];
    }

    i64 s = 0;
    for (i64 i = 0; i < n; i++) {
        s += a[i];
        s %= mod;
    }

    i64 R = 0;
    for (i64 i = 0; i < n; i++) {
        s = (s - a[i] + mod) % mod;
        R += (s * a[i]) % mod;
        R %= mod;
    }

    cout << R << endl;

    return 0;
}

Measured memory_bytes: 4776
s,t = raw_input(), raw_input()
def f(s,t):
	cc = {}
	cr = {}
	for u,v in zip(s,t):
		if u in cc:
			if cc[u] != v: return False
		if v in cr:
			if cr[v] != u: return False
		
		cc[u] = v
		cr[v] = u
	return True
print 'Yes' if f(s,t) else 'No'

Measured memory_bytes: 90708
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
typedef pair<int,int> P;
struct edge{int to,cost;};
#define REP(i,n) for(int i=0;i<(n);i++)
const int INF=100000000000000000;
const int MOD=1000000007;



signed main(){
	int A[10]={};
	int sum=0;
	int Min=INF;
	vector<int> v;
	REP(i,5){
		cin>>A[i];
		v.push_back(A[i]);
	}
	sort(v.begin(),v.end());
	do{
		sum=0;
		REP(i,5){
			sum+=v[i];
			if(i!=4)while(sum%10!=0){
				sum++;
			}
		}
		Min=min(Min,sum);
	}while(next_permutation(v.begin(),v.end()));
	cout<<Min<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> VI;
typedef pair <int,int> ii;
typedef long long LL;
#define pb push_back
const int INF = 2147483647;
 
int n, a, np, i;

int main() {
scanf("%d", &n);
np = 0;
for (i=0;i<n;i++) {
	scanf("%d", &a);
	if (a % 2 == 1) np = 1;
}
if (np) cout << "first" << endl; else cout << "second" << endl;
return 0;
}



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

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

#define frep(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i, n) frep(i, 0, (n))
#define rrep(i, n) for(int i = (n - 1); i >= 0; i--)
#define all(i, x) for(typeof(x.begin()) i = x.begin(); i != x.end(); i++)
#define pb push_back

const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const int MAX = 100010;
const int INF = 1e9;
const int MOD = 1000000007;
const string END = "\n";

void solve(){
	ll n; cin >> n;
	ll a[n];
	rep(i, n) cin >> a[i];
	sort(a, a + n, greater<ll>());
	ll ans = 1;
	ll cnt = 0;
	bool flag = false;
	frep(i, 1, n){
		if(a[i] == a[i-1]){
			ans *= a[i];
			a[i] = 0;
			a[i-1] = 0;
			cnt += 1;
			if(cnt >= 2){
				flag = true;
				break;
			}
		}
	}
	if(flag) cout << ans << END;
	else cout << 0 << END;
}

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


Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<set>
#include<map>
using namespace std;
using ll = long long;

int main(){
    string str[]={
        "AKIHBR","KIHBR",
        "AKIHBRA","KIHBRA",
        "AKIHBAR","KIHBAR",
        "AKIHBARA","KIHBARA",
        "AKIHABR","KIHABR",
        "AKIHABRA","KIHABRA",
        "AKIHABAR","KIHABAR",
        "AKIHABARA","KIHABARA"
    };
    string str2;
    cin >> str2;
    for(int i=0;i<16;i++){
        if(str[i]==str2){
            cout << "YES";
            return 0;
        }
    }
    cout << "NO";
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String s = scanner.nextLine();
        long res = 0;
        long sofar = 0;
        for (int i = 0; i < s.length(); ++i) {
            if (s.charAt(i) == 'W') {
                res += sofar;
            } else {
                sofar += 1;
            }
        }
        System.out.println(res);
    }
}


Measured memory_bytes: 26444
#include<stdio.h>

int main(void){
	int n,a,b;
	char s[100000];
	scanf("%d %d %d",&n,&a,&b);
	scanf("%s",s);
	int i,cnt=0,cntb=0;

	for(i=0;i<n;i++){
		if(s[i]=='c'){
			printf("No\n");
			continue;
		}

		else if(s[i]=='a'){
			if(cnt<a+b){
				printf("Yes\n");
				cnt++;
				continue;
			}
			else{			
				printf("No\n");
				continue;
			}
		}

		else{
			if(cnt<a+b&&(cntb+1)<=b){
				printf("Yes\n");
				cnt++;
				cntb++;
				continue;
			}
			else{			
				printf("No\n");
				continue;
			}
		}
	}
	return 0;

}

Measured memory_bytes: 640