akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Linq;

namespace AOJ {
    public class Probrem {
        public static void Main() {
            string str;
            while ((str = Console.ReadLine()) != "0 0") {
                var data = str.Split().Select(int.Parse).ToArray();
                Console.WriteLine(data[0] > data[1] ? data[1] + " " + data[0] : data[0] + " " + data[1]);
            }
        }
    }
}


Measured memory_bytes: 9704
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
using namespace std;
using ll = long long int;
template<typename T>
ostream& operator+(ostream& out, const vector<T> &vec){
    for(const auto &x : vec){
        out<<x<<" ";
    }
    out<<"\n";
    return out;
}
template<typename T>
ostream& operator*(ostream& out, const vector<T> &vec){
    for(const auto &x : vec){
        out+x;
    }
    return out;
}
template<typename T>
istream& operator>>(istream& in, vector<T> &vec){
    for(auto &x : vec){
        in>>x;
    }
    return in;
}
void solve(){
    string s;
    cin>>s;
    if(s.back()=='s'){
        s+="es";
    }
    else{
        s+='s';
    }
    cout<<s<<"\n";
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
}

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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

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

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

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

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

  ll N, K;
  cin >> N >> K;

  vector<ll> A(N), F(N);
  for(int i = 0; i < N; i++) cin >> A[i];
  for(int i = 0; i < N; i++) cin >> F[i];

  sort(A.begin(), A.end());
  sort(F.rbegin(), F.rend());

  ll left = -1;
  ll right = 1e12+1;

  while(right - left > 1){

    ll mid = left + (right - left) / 2;

    ll cost = K;
    for(int i = 0; i < N; i++){
      cost -= max(A[i] - mid / F[i], 0LL);
    }

    if(cost >= 0) right = mid;
    else left = mid;
  }

  cout << right << endl;

  return 0;
}


Measured memory_bytes: 3456
#???????????¢?????¢???(search0)
#??????????°???????????????????????°???????????????????????????????????????????????????±???????????¢?´¢???????????°??????

def search rest
	if rest == []
		return true
	end
	if rest.count(rest[0]) > 2
		if search(rest[3..-1])
			return true
		end
	end
	if rest.index(rest[0] + 1) && rest.index(rest[0] + 2)
		nex = rest.dup
		nex.slice!(nex.index(rest[0]))
		nex.slice!(nex.index(rest[0]+1))
		nex.slice!(nex.index(rest[0]+2))
		if search(nex)
			return true
		end
	end
	return false
end

def search0 rest
	1.upto(9){|i|
		if rest.count(i) > 1
			nex = rest.dup
			nex.slice!(nex.index(i))
			nex.slice!(nex.index(i))
			if search(nex)
				return true
			end
		end
	}
	return false
end

while gets
	s = $_.chomp.chars.map &:to_i
	ans = []
	1.upto(9){|i|
		unless s.count(i) == 4
			if search0((s+[i]).sort)
				ans << i
			end
		end
	}
	if ans == []
		puts 0
	else
		puts ans*" "
	end
end

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

int main() {
    int n; cin >> n;
    vector<int>a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = n - 1; i >= 0; i--) {
        cout << a[i];
        if (i != 0) {
            cout << ' ';
        } else if (i == 0) {
            cout << endl;
        }
    }
}


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

int main(){
    string s,t;
    bool flag=false;
    cin >> s >> t;
    int nagasa=t.size();
    int now=nagasa;
    for(int j=s.size();j>=nagasa-1;j--){
    for(int i=j;i>=0;i--){
        if(s[i]==t[now-1]||s[i]=='?'){
            now--;
        }
        else{
            now=nagasa;
            break;
        }
        if(now==0){
            s.replace(i,nagasa,t);
            flag=true;
            break;
        }
    }
    if(flag) break;
    }
    
    if(!flag){
        puts("UNRESTORABLE");
        return 0;
    }
    
    rep(i,s.size()){
        if(s[i]=='?') cout << 'a';
        else cout << s[i];
    }
    
    cout << endl;
    
    return 0;
}







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

#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef long double ld;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

int main() {

    int N; cin >> N;
    double res = 0;
    vector<double> A;
    forn(i, N) {
        int a; cin >> a; A.pb(a);
    }
    forn(i, N) {
        res += 1 / A.at(i);
    }
    cout << 1 / res << endl;
}


Measured memory_bytes: 256
n, u, v, m = map(int, input().split())
usa_mat = [list(map(int, input().split())) for _ in range(n)]
nek_mat = [list(map(int, input().split())) for _ in range(n)]
usa_dic = {}
nek_dic = {}
for y in range(n):
  for x in range(n):
    usa_dic[usa_mat[y][x]] = (x, y)
    nek_dic[nek_mat[y][x]] = (x, y)

usa_count = [0] * (2 * n + 2)
nek_count = [0] * (2 * n + 2)

flag = 0
usa_point = 0
nek_point = 0
for _ in range(m):
  a = int(input())
  if flag:
    continue
  
  if a in usa_dic:
    ux, uy = usa_dic[a]
    usa_count[ux] += 1
    if usa_count[ux] == n:
      usa_point += 1
    usa_count[uy + n] += 1
    if usa_count[uy + n] == n:
      usa_point += 1
    if ux + uy == n - 1:
      usa_count[-1] += 1
      if usa_count[-1] == n:
        usa_point += 1
    if ux == uy:
      usa_count[-2] += 1
      if usa_count[-2] == n:
        usa_point += 1
  
  if a in nek_dic:
    nx, ny = nek_dic[a]
    nek_count[nx] += 1
    if nek_count[nx] == n:
      nek_point += 1
    nek_count[ny + n] += 1
    if nek_count[ny + n] == n:
      nek_point += 1
    if nx + ny == n - 1:
      nek_count[-1] += 1
      if nek_count[-1] == n:
        nek_point += 1
    if nx == ny:
      nek_count[-2] += 1
      if nek_count[-2] == n:
        nek_point += 1
  
  if n == 1:
    usa_point = min(usa_point, 1)
    nek_point = min(nek_point, 1)

  if usa_point >= u and nek_point >= v:
    flag = 1
  elif usa_point >= u:
    flag = 2
  elif nek_point >= v:
    flag = 3

if flag == 2:
  print("USAGI")
elif flag == 3:
  print("NEKO")
else:
  print("DRAW")


Measured memory_bytes: 47556
#include <bits/stdc++.h>
using namespace std;
struct node{
  long long int u, v;
    node(long long int _u, long long int _v)
    {
        u = _u;
        v = _v;
    }
};
map <long long int,long long int> parent;
map<long long int, long long int> members;
long long int t,n;
vector <long long> member;
long long int findingRoot(long long int a)
{

    if(parent[a]==a)
    return a;
    else
        return parent[a]= findingRoot(parent[a]);

}
long long lastPar;
void unionSet(long long int a, long long int b)
{
    long long int    A = findingRoot(a);
    long long int  B = findingRoot(b);
    if(A!=B)
    {
         parent[B]=A;

          if(findingRoot(lastPar)!=A )
          {
                 t-=(member[A]*(member[A]-1))/2;
                   t-=(member[B]*(member[B]-1))/2;
                 member[A]+=member[B];
                t+= (member[A]*(member[A]-1)/2);
                lastPar = A;
          }
          else
          {
                   t-=(member[A]*(member[A]-1))/2;
                   t-=(member[B]*(member[B]-1))/2;
                    member[A]+=member[B];
                    member[B]=member[A];
                    t += (member[A]*(member[A]-1)/2);

          }


    }

}
int main()
{
    long long int n, xx, m,x,y;
    cin>>n>>m;
    vector <node> adj;
    while(m--)
    {
        cin>>x>>y;
          parent[x]= x;
            parent[y]= y;
        adj.push_back(node(x,y));
    }
    reverse(adj.begin(),adj.end());
    vector<long long> ans;
    xx = n*(n-1)/2;
    ans.push_back(xx);
    m= adj.size();
    t =0;
    member.resize(n+1,1);
    for(int i=0; i<m; i++)
    {
        long long s1 = adj[i].u, s2 = adj[i].v;
        unionSet(s1,s2);
        ans.push_back(xx-t);
    }

    for(int i=ans.size()-2; i>=0; i--)
        cout<<ans[i]<<endl;
}


Measured memory_bytes: 11888
/*
 * じょえチャンネル
 * 高評価・チャンネル登録よろしくおねがいします！
 * https://www.youtube.com/channel/UCRXsI3FL_kvaVL9zoolBfbQ
 */
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define all(v) v.begin(),v.end()
#define inf (int)(3e18)
#define P pair<int,int>
#define mod (int)(1e9+7)
template<class T> inline void chmin(T &a, T b) {
	a = min(a, b);
}
template<class T> inline void chmax(T &a, T b) {
	a = max(a, b);
}

struct UnionFind {
	vector<int> par, size;
	UnionFind(int x) {
		par.resize(x);
		size.resize(x, 1);
		rep(i,x)
			par[i] = i;
	}
	int find(int x) {
		if (par[x] == x)
			return x;
		return par[x] = find(par[x]);
	}
	bool same(int x, int y) {
		return find(x) == find(y);
	}
	int consize(int x) {
		return size[find(x)];
	}
	void unite(int x, int y) {
		x = find(x), y = find(y);
		if (x == y)
			return;
		if (size[x] < size[y]) {
			par[x] = y;
			size[y] += size[x];
		} else {
			par[y] = x;
			size[x] += size[y];
		}
	}
};
int N,M,K;
vector<int>G[100005];
int fr[100005];
signed main(){
	cin>>N>>M>>K;
	UnionFind uf(N);
	rep(i,M){
		int a,b;cin>>a>>b;a--;b--;
		uf.unite(a,b);
		fr[a]++;fr[b]++;
	}
	rep(i,K){
		int a,b;cin>>a>>b;a--;b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	rep(i,N){
		int sz=uf.size[uf.find(i)];
		sz-=fr[i];
		for(int j:G[i]){
			if(uf.same(i,j))sz--;
		}
		cout<<sz-1<<" ";
	}
	cout<<endl;
}


Measured memory_bytes: 9088
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <limits>
#include <sstream>
#include <string>
#include <vector>

using namespace std;

#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, a, n) for (int i = a; i < n; i++)
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eps 1e-15

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef tuple<int, int, int> ti3;

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

    a = n / 100;
    b = (n - (n / 100 * 100)) / 10;
    c = (n - (n / 10 * 10));

    if (a == 1 || a == 9) {
        a = 10 - a;
    }
    if (b == 1 || b == 9) {
        b = 10 - b;
    }
    if (c == 1 || c == 9) {
        c = 10 - c;
    }

    printf("%d%d%d\n", a, b, c);

    return 0;
}


Measured memory_bytes: 256
import math


def run(X):
    ret = 1
    for i in range(2, X):
        for j in range(2, int(math.log2(X))):
            tmp = i**j
            if tmp > X:
                break
            ret = max(ret, tmp)
    return ret


def main():
    X = int(input())
    print(run(X))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
s = gets.strip
n = gets.strip.to_i

n.times do
	line = gets.strip.split(" ")
	op = line[0]
	case op
	when "replace"
		a, b, p = line[1].to_i, line[2].to_i, line[3]
		s[a..b] = p
	when "reverse"
		a, b = line[1].to_i, line[2].to_i
		s[a..b] = s[a..b].reverse
	when "print"
		a, b = line[1].to_i, line[2].to_i
		puts s[a..b]
	end
end


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

int main() {
  int N;
  long long ans=0;
  cin >> N;
  vector<long long> V = {0,4999999950000000,19999999900000000,44999999850000000,
                         79999999800000000,124999999750000000,179999999700000000,
                         244999999650000000,319999999600000000,404999999550000000,499999999500000000};
  int x = N/100000000;
  ans = V[x];
  
  for(int i=100000000*x;i<N;i++) ans += i;
  
  cout << ans << endl;
  return 0;
}


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

int main() {
  int N;
  cin >> N;
  while(N--) {
    string s, t;
    cin >> s;
    sort(s.begin(), s.end());
    t = s;
    reverse(t.begin(), t.end());
    cout << atoi(t.c_str()) - atoi(s.c_str()) << endl;
  }
}

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

int main(){
    int n;
    cin >> n;
    int buka[n];
    rep(i,n) buka[i] = 0;
    rep(i,n-1){
        int tmp;
        cin >> tmp;
        buka[tmp-1]++;
    }
    rep(i,n) cout << buka[i] << endl;
}

Measured memory_bytes: 4372
N, K = map(int, input().split())
A = [int(i) for i in input().split()]

num = {}
for i in A:
	if not i in num.keys():
		num[i] = 1
	else:
		num[i] += 1

cnt = list(num.values())
cnt.sort()
print(sum(cnt[:len(cnt)-K]))


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


int main(){
    string s; cin>>s;
    for (int bit=0;bit<(1<<s.size());bit++){
        int sum = s[0]-'0';
        string ans = string() + s[0];
        for (int i=0;i<s.size()-1;i++){
            if (bit & (1<<i)) {
                sum+=s[i+1]-'0';
                ans += "+"+(string()+s[i+1]);
            }else{
                sum-=s[i+1]-'0';
                ans += "-"+(string()+s[i+1]);
            }
        }
        if (sum==7){
            cout << ans+"=7" << endl;
            break;
        }
    }
}

Measured memory_bytes: 256
q = int(input())
query = [list(map(int,input().split())) for _ in range(q)]

N = int(1e+5)
max_num = int(N**0.5)
is_prime = [True]*(N+1)
is_prime[0] = False
is_prime[1] = False
for i in range(2,max_num+1):
    if not is_prime[i]:
        continue
    for j in range(i*2,N+1,i):
        is_prime[j] = False

ans = [False] * (N+1)
for i in range(3,N+1,2):
    b = (i+1)//2
    if is_prime[i] and is_prime[b]:
        ans[i] = True

comurative_ans = [0] * (N+1)
sum_true = 0
for i in range(N+1):
    if ans[i] :
        sum_true += 1
    comurative_ans[i] = sum_true
for l,r in query:
    print(comurative_ans[r+1]-comurative_ans[l-1])

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define LL long long

string s[400];
bool v[400][400];
vector<vector<int>> ans;
vector<vector<int>> ans_sub;
int h,w,cur=0;

void dfs(int i,int j,char c){
  if(v[i][j])return;
  if(c=='.'){
    ans_sub[cur].push_back((i*w+j));
  }
  if(c=='#'){
    ans[cur].push_back(i*w+j);
  }
  v[i][j]=true;
  if(i-1>=0 && !v[i-1][j] && s[i-1][j]!=c)dfs(i-1,j,s[i-1][j]);
  if(i+1<h && !v[i+1][j] && s[i+1][j]!=c)dfs(i+1,j,s[i+1][j]);
  if(j-1>=0 && !v[i][j-1] && s[i][j-1]!=c)dfs(i,j-1,s[i][j-1]);
  if(j+1<w && !v[i][j+1] && s[i][j+1]!=c)dfs(i,j+1,s[i][j+1]);
}

int main(){
  cin>>h>>w;
  REP(i,h)
    cin>>s[i];

  REP(i,h){
    REP(j,w)
      v[i][j]=false;
  }

  REP(i,h){
    REP(j,w){
      if(v[i][j])continue;
      vector<int> p1;
      vector<int> p2;
      ans.push_back(p1);
      ans_sub.push_back(p2);
      cur=ans.size()-1;
      dfs(i,j,s[i][j]);
    }
  }
  
  LL ret=0;
  REP(i,ans.size()){
    ret+=(LL)(ans[i].size()*ans_sub[i].size());
  }
  cout<<ret<<endl;
  return 0;
}


Measured memory_bytes: 16324
#include <bits/stdc++.h>
#define reps(i,a,b) for(long long int i=a;i<b;i++)
#define rep(i,a) for(long long int i=0;i<a;i++)
typedef long long int ll;
using namespace std;
//http://kyopro.hateblo.jp/entry/2019/05/06/043431

class Tree {
public:
    int n;
    vector<vector<pair<int, int>>> adj;

    Tree(int nn) { n = nn;
    adj.resize(n);
    }

    void add_edge(const int v1, const int v2, const int w) {
        adj[v1].push_back(make_pair(v2, w));//v1→v2 重みがw
        adj[v2].push_back(make_pair(v1, w));//adj[v1]にはv1から行けるところが入ってる。これは無向グラフの奴
    }

    pair<int, int> Dfs(const int prev, const int cur) { //深さ優先探索　previous昔　current　今
        pair<int, int> res(cur, 0); //result。右側が距離？
        for (const auto &e : adj[cur]) {//adj[cur]というベクトルの初めから最後までやります　参照auto& eを書くと、コンテナ内の要素を変更できる。＆がないと変更できない//次に行ける場所へと！
            if (prev == e.first) continue;//後戻りはしない
            auto nxt = Dfs(cur, e.first);//そこから先の距離を返せ//再帰のキモ
            nxt.second += e.second;//そこから先の距離＋今回の移動分
            if (res.second < nxt.second) res = nxt;//最大値を求める
        }
        return res;
    }




    

    pair<int, int> farthest_pair;
    int Diameter() {
        const auto v1 = Dfs(-1, 0), v2 = Dfs(-1, v1.first);//初期状態で初めの場所とかないから-1
        farthest_pair = make_pair(v1.first, v2.first);
        return v2.second;
    }
};

bool Solve() {
    int n;
    cin >> n;

    Tree tree(n);
    for (int i = 0, a, b; i + 1 < n; ++i) {
        cin >> a >> b;
        tree.add_edge(a - 1, b - 1, 1);
    }

    return tree.Diameter() % 3 != 1;
}

int main() {
    cin.tie(0); ios::sync_with_stdio(false);
    // cout << setprecision(8) << setiosflags(ios::fixed);

    if (Solve()) cout << "First" << endl;
    else cout << "Second" << endl;

    return 0;
}

Measured memory_bytes: 18176
#include <bits/stdc++.h>
#include <random>
#include <ctime>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//#pragma GCC optimize("-O3")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("avx2")
#define ll long long
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define pll pair<ll,ll>
#define ld double
#define pld pair<ld,ld>
#define pii pair<int,int>
#define sqr(a) ((a)*(a))
#define all(v) v.begin(),v.end()

using namespace std;
//using namespace __gnu_pbds;

const ll MOD = 1e9+7;
const ll INF = 1e18;
const ld E = 1e-12;
const ld PI=acos(-1);
mt19937_64 rnd(time(0));
ll p1 = 31, p2 = 37, p3 = 7, p4 = rnd() % 100 + 1, md1 = MOD, md2 = 998244353, md3 = 998244357, md4 = rnd() % 1000000000;

//using ord_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

ll n, m, infact[1000001], fact[1000001], pr[1000001], sf[1000001];

ll binpow(ll h, ll r, ll md = MOD)
{
    ll l = 1;
    while (r)
    {
        if (r & 1) l *= h, l %= md;
        h *= h;
        h %= md;
        r /= 2;
    }
    return l;
}

ll gcd(ll x, ll y)
{
    if (x < y) swap(x, y);
    while (x && y)
    {
        x %= y;
        swap(x, y);
    }
    return x + y;
}

#define dies_from_cringe exit(0)

void solve()
{
    cin >> n >> m;
    fact[0]=1;
    infact[0]=1;
    for (ll i = 1; i <= n; i++)
    {
        fact[i]=fact[i-1]*i%MOD;
        infact[i]=binpow(fact[i],MOD-2);
    }
    pr[0]=1;
    sf[0]=1;
    pr[1]=m-n+1;
    sf[1]=m;
    for (ll i = 2; i <= n; i++)
    {
        pr[i]=pr[i-1]*(m-n+i)%MOD;
    }
    for (ll i = 2; i <= m; i++)
    {
        sf[i]=sf[i-1]*(m-i+1)%MOD;
    }
    ll ans=pr[n]*pr[n]%MOD;
    //cout << ans << "\n";
    for (ll i = 1; i <= n; i++)
    {
        ll C=fact[n]*infact[i]%MOD*infact[n-i]%MOD, u=1;
        if (i%2) u=-1;
        ll o=C*pr[n-i]%MOD*pr[n-i]%MOD*sf[i]%MOD;
        ans=ans+u*o;
        //cout << C << " "<< u << " " << o << " " << fact[n] << " " << infact[i] << " " << infact[n-i] << "\n";
        if (ans<0) ans+=MOD;
        ans%=MOD;
    }
    cout << ans << "\n";
    //cout << (881613484*2)%MOD << "\n";
}

int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    //freopen("capitals.in","r",stdin);
    //freopen("capitals.out","w",stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll t=1;
    //cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}

/*
1
3 3
10 1 2
5 1 1
*/


Measured memory_bytes: 19164
#include <stdio.h>

int main(void) {
	int i,s,w,n,a,b,d[32];
	for(i = 1;i <= 30;i++){
		d[i] = i;
	}
	scanf("%d",&w);
	scanf("%d",&n);
	for(i = 1;i <= n;i++){
		scanf("%d,%d",&a,&b);
		s = d[a];
		d[a] = d[b];
		d[b] = s;
	}
	for(i = 1;i <= w;i++){
		printf("%d\n",d[i]);
	}
	return 0;
}

Measured memory_bytes: 592
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	//	"strings"
)

func main() {
	sc := NewScanner()

	n := sc.NextInt()
	prev := sc.NextLine()
	mp := map[string]int{}
	mp[prev]++
	for i := 1; i < n; i++ {
		tmp := sc.NextLine()
		if mp[tmp] > 0 {
			fmt.Printf("No\n") // output for debug
			return
		}
		if string(tmp[0]) != string(prev[len(prev)-1]) {
			fmt.Printf("No\n") // output for debug
			return
		}
		mp[tmp]++
		prev = tmp
	}
	fmt.Printf("Yes\n")
}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			result = append(result, v)
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	result = append(result, v)

	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 640
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <set>
#include <list>
#include <fstream>
#include <map>
#include <queue>
#include <iomanip>
#include <algorithm>
#include <cmath>
using namespace std;

#define ll long long
#define mod 1000000007
#define infinity (ll)1e9+1
#define pdd pair<double,double>
#define pll pair<ll, ll>
#define pii pair<int,int>
#define MP make_pair
#define vi vector<ll>

#define FOR(i,a,b) for(ll i = (a); i < (b); ++i)
#define RFOR(i,b,a) for(ll i = (b) - 1; i >= (a); --i)
#define REPEAT(i) FOR(counter1234,0,i)
#define ALL(a) a.begin(), a.end()

int main()
{
	int n; cin >> n;
	vector<string> s(n);
	FOR(i, 0, n)
		cin >> s[i];

	vector<map<char, int>> m(n);
	FOR(i, 0, n)
	{
		FOR(j, 0, s[i].length())
			m[i][s[i][j]]++;
	}

	map<char, int> acc;
	FOR(i, 'a', 'z' + 1)
	{
		acc[i] = m[0][i];
		FOR(j, 1, n)
			acc[i] = min(acc[i], m[j][i]);
	}


	FOR(i, 'a', 'z' + 1)
	{
		FOR(j, 0, acc[i])
			cout << (char)i;
	}
	

	return 0;
}

Measured memory_bytes: 256
#dt = {} for i in x: dt[i] = dt.get(i,0)+1
#dt = {k:v for k,v in sorted(x.items(), key=lambda i: i[1])}
ipnl = lambda n: [int(input()) for _ in range(n)]
inp = lambda :int(input())
ip = lambda :[int(w) for w in input().split()]
mp = lambda :map(int,input().split())

dt = {}
x = []
for i in range(300):
    dt[i**5] = i
    x.append(i**5)
num = inp()
if num in dt:
    print(dt[num],0)
    exit()
n = len(x)
for i in range(n-1):
    for j in range(i+1,n):
        if x[i] + x[j] == num:
            print(dt[x[i]],-dt[x[j]])
            exit()
        elif x[j] - x[i] == num:
            print(dt[x[j]],dt[x[i]])



Measured memory_bytes: 80324
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
n=int(input())
l = []
for i in range(0,n):
  l.append(int(input()))
  

def gcd(x, y):
  while y:
    x, y = y, x % y
  return x
def lcm(x, y):
  return (x * y) // gcd(x, y)

res=l[0]
for i in range(1,n):
  res=lcm(res,l[i])
print(res)



Measured memory_bytes: 3060
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

H,W,N=map(int,input().split())

sr,sc=map(int,input().split())
S=input()[:-1]
T=input()[:-1]

left=0
right=W+1
up=0
down=H+1

ans="YES"
for i,(s,t) in enumerate(zip(reversed(S),reversed(T))):
    if i!=0 or True:
        if t=='R':
            left=max(0,left-1)
        elif t=="L":
            right=min(W+1,right+1)
        elif t=="D":
            up = max(0,up-1)
        else:
            down=min(H+1,down+1)


    if s=="R":
        right-=1
    elif s=="L":
        left+=1
    elif s=="D":
        down-=1
    else:
        up+=1

    if right-left==1 or down-up==1:
        ans="NO"
        break

if not left<sc<right or not up<sr<down:
    ans="NO"
print(ans)


Measured memory_bytes: 3888
#include <bits/stdc++.h>
using namespace std;
typedef complex<double> P;
#define x real()
#define y imag()

string ccw(P a, P b, P c) {
    P ab = b - a, ac = c - a;
    P k = ac * conj(ab);
    if (k.y > 0) return "COUNTER_CLOCKWISE";
    if (k.y < 0) return "CLOCKWISE";
    if (k.x < 0) return "ONLINE_BACK";
    if (abs(ab) < abs(ac)) return "ONLINE_FRONT";
    return "ON_SEGMENT";
}

int main() {
    double x0, y0, x1, y1, x2, y2;
    cin >> x0 >> y0 >> x1 >> y1;
    P   a(x0, y0);
    P   b(x1, y1);
    int n;
    cin >> n;
    while (n--) {
        cin >> x2 >> y2;
        P c(x2, y2);
        cout << ccw(a, b, c) << endl;
    }
    return 0;
}



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

using namespace std;
//vector<long long> factors;
#define ll long long

#define pii pair<int,int>
#define pll pair<ll,ll>
#define _ <<'\n'
#define __ << ' '
#define all(x) (x).begin(), (x).end()
#define gcd __gcd
int IT_MAX = 1 << 17;
int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x0f3f3f3f3f3f3f3f;
const double PI = acos(-1);
const double ERR = 1e-10;
#define szz(x) (int)(x).size()
#define IOS ios_base::sync_with_stdio(false); cout.tie(0);cin.tie(0);
#define flush fflush(stdout)

ll mod(ll a, ll m) { return (a + (abs(a) / m) * m + m) % m; }

int main() {
    IOS

    ll n;
    cin >> n;
    string st;
    cin >> st;
    for (int i = 0; i < st.size(); ++i) {
        st[i] = 'A' + int(st[i] - 'A' + n) % 26;
    }
    cout << st;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <cassert>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
typedef pair<int,int> PI;
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define MP make_pair
#define PB push_back

typedef struct{
  int to,cost;
}edge;


vector<edge> E[100];

int n,m;

int kruskal(){
  int ret=0;
  set<int> V;
  V.insert(0);
  
  while(V.size()<n){
    int minc=10000,to,from;
    FOR(siter,V){
      rep(i,E[*siter].size()){
        if(V.count(E[*siter][i].to))continue;
        if(E[*siter][i].cost<minc){
          to=E[*siter][i].to;
          minc=E[*siter][i].cost;
        }
      }
    }
    ret+=minc;
    V.insert(to);
  }
  return ret;
}
  
    


main(){
  while(cin>>n>>m,n){
    
    rep(i,n)E[i].clear();
    
    rep(i,m){
      int a,b,c;
      cin>>a>>b>>c;
      E[a].PB((edge){b,c});
      E[b].PB((edge){a,c});
    }
    
    cout<<kruskal()<<endl;
  }
}

Measured memory_bytes: 0
class Problem
  attr_accessor :a, :b, :n, :h, :ans

  def initialize
    @n, @h = gets.to_s.split.map { |v| v.to_i }
    @a, @b = Array.new(@n) { gets.to_s.split.map { |v| v.to_i } }.transpose
    @ans = 10 ** 10
  end

  def solve
    throws.each_with_index do |hit, i|
      cnt = swing_num_to_kill(h - hit, swing) + i
      chmin(cnt)
    end
    puts @ans
  end
  
  def throws
    @throws ||= b.sort.reverse.each_with_object([0]) { |v, h| h << h[-1] + v }
  end

  def swing
    @swing ||= a.max
  end

  def swing_num_to_kill(hp, d)
    return 0 if hp <= 0
    (hp + d - 1) / d
  end

  def chmin(cnt)
    @ans = cnt if cnt < @ans
  end
end

pr = Problem.new
pr.solve


Measured memory_bytes: 25520
def solve():
    N = list(input().split())[0]
    a,b,c,d = int(N[0]),int(N[1]),int(N[2]),int(N[3])

    if a+b+c+d == 7:
        print('{0}+{1}+{2}+{3}=7'.format(a,b,c,d))
        return 

    if a+b+c-d == 7:
        print('{0}+{1}+{2}-{3}=7'.format(a,b,c,d))
        return 

    if a+b-c+d == 7:
        print('{0}+{1}-{2}+{3}=7'.format(a,b,c,d))
        return 

    if a-b+c+d == 7:
        print('{0}-{1}+{2}+{3}=7'.format(a,b,c,d))
        return 

    if a+b-c-d == 7:
        print('{0}+{1}-{2}-{3}=7'.format(a,b,c,d))
        return 

    if a-b+c-d == 7:
        print('{0}-{1}+{2}-{3}=7'.format(a,b,c,d))
        return 

    if a-b-c+d == 7:
        print('{0}-{1}-{2}+{3}=7'.format(a,b,c,d))
        return 

    if a-b-c-d == 7:
        print('{0}-{1}-{2}-{3}=7'.format(a,b,c,d))
        return 

# print(solve())

# テスト用

solve()



Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int main(){
  char *s = (char *)malloc(sizeof(char)*5);
  s[4] = 0;
  cin >> s;
  int count = 0;
  int elc = 0;
  char tmp1, tmp2;
  tmp1 = *s;
  tmp2 = *s;
  s++;
  count++;
  for(int i=0; i<3; i++){
    if(*s != tmp1 && elc == 0){
      tmp2 = *s;
      elc = 1;
    }
    if(*s == tmp1) count++;
    if(*s != tmp1 && *s != tmp2) elc = -1;
    s++;
  }
  if(count == 2 && elc == 1) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
//#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
#define vec vector<ll>
#define mat vector<vector<ll> >
#define fi first
#define se second
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pll;
typedef long double ld;
typedef complex<double> comp;
const ll INF=1e9+7;
const ll MOD=998244353;
const int MAX=200010;

struct UnionFind {
    vector< int > data;

    UnionFind() = default;

    explicit UnionFind(size_t sz) : data(sz, -1) {}

    bool unite(int x, int y) {
        x = find(x), y = find(y);
        if(x == y) return false;
        if(data[x] > data[y]) swap(x, y);
        data[x] += data[y];
        data[y] = x;
        return true;
    }

    int find(int k) {
        if(data[k] < 0) return (k);
        return data[k] = find(data[k]);
    }

    int size(int k) {
        return -data[find(k)];
    }

    bool same(int x, int y) {
        return find(x) == find(y);
    }
};

signed main(){
    ll n,q;cin>>n>>q;
    UnionFind uf(n);
    rep(tmp,q){
        ll i,u,v;cin>>i>>u>>v;
        if(i){
            ll ans=uf.same(u,v);
            cout<<ans<<endl;
        }else{
            uf.unite(u,v);
        }
    }
}

Measured memory_bytes: 4004
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
  ll n,k;
  cin >> n >> k;
  ll ans=k;
  for(ll i=0;i<n-1;i++){
    ans*=(k-1);
  }
  cout << ans;
}
    
  

Measured memory_bytes: 3584
#include<bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
typedef long long ll;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

int main(int argc, char const *argv[]) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,a[100],minj,cnt=0;
  cin>>n;
  REP(i,n){
    cin>>a[i];
  }
  REP(i,n){
    minj=i;
    FOR(j,i,n){
      if(a[j]<a[minj]){
         minj=j;
       }
     }
    if(i!=minj) cnt++;
    swap(a[i],a[minj]);
  }
  REP(i,n){
    if(i==n-1) cout<<a[i]<<endl;
    else  cout<<a[i]<<" ";

  }

  cout <<cnt<<endl;



  return 0;
}



Measured memory_bytes: 3112
#include <bits/stdc++.h>
#define fim '\n'
using namespace std;

double vet[3000], dp[3000][3000];

int main() {
    
    int n;
    cin >> n;
    
	
	for(int i = 1; i <= n; i++)
		cin >> vet[i];
		
	dp[0][0] = 1.0;
	
	for(int i = 1; i <= n; i++)
		for(int heads = 0; heads <= i; heads++) {
			dp[i][heads] = dp[i-1][heads] * (1 - vet[i]); 
			if(heads) dp[i][heads] += dp[i-1][heads-1] * vet[i];
		}
	
	double ans = 0.0;
	for(int i = 1; i <= n; i++)
		if(i > n-i) ans += dp[n][i];
		
	cout << fixed << setprecision(15) << ans << endl;
}


Measured memory_bytes: 68864
#include <iomanip>
#include <string>
#include <iostream>
#include <algorithm>
#include <math.h>
using namespace std;
int main() {
	string s[52] = {}, yojo[52];
	int a, b, cnt = 0, yan;
	cin >> a >> b;
	for (int i = 1; i <= a; i++) {
		yojo[i] = "b";
		cin >> s[i];
		yojo[i] += s[i];
		yojo[i] += "b";
	}
	for (int i = 1; i <= a; i++) {
		for (int j = 1; j <= b; j++) {
			if (yojo[i][j] == '#') {
				cout << yojo[i][j];
			}
			else {
				if (yojo[i - 1][j - 1] == '#') {
					cnt++;
				}
				if (yojo[i - 1][j] == '#') {
					cnt++;
				}
				if (yojo[i - 1][j + 1] == '#') {
					cnt++;
				}
				if (yojo[i][j - 1] == '#') {
					cnt++;
				}
				if (yojo[i][j + 1] == '#') {
					cnt++;
				}
				if (yojo[i + 1][j - 1] == '#') {
					cnt++;
				}
				if (yojo[i + 1][j + 1] == '#') {
					cnt++;
				}
				if (yojo[i + 1][j] == '#') {
					cnt++;
				}
				cout << cnt;
			}
			cnt = 0;
		}
		cout << endl;
	}
	return 0;
}

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

#define rep(i,n) for(long long i = 0; i < (long long)(n); i++)
#define repi(i,a,b) for(long long i = (long long)(a); i < (long long)(b); i++)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define mt make_tuple
#define mp make_pair
template<class T1, class T2> bool chmin(T1 &a, T2 b) { return b < a && (a = b, true); }
template<class T1, class T2> bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

using ll = long long; using vll = vector<ll>; using vvll = vector<vll>; using P = pair<ll, ll>;
using ld = long double;  using vld = vector<ld>; 

int main(void) {
	ll a,b,c; cin >>a>>b>>c;

	if(a==b) cout <<c <<endl;
	if(b==c) cout <<a <<endl;
	if(a==c) cout <<b <<endl;


	
   return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,n) for(int i=1;i<=n;i++)
int main()
{
    int n,m,l;

    cin >> n >> m >> l;

    long long A[n][m];
    long long B[m][l];
    long long c;

    rep(i,n){
        rep(j,m){
            cin >> A[i][j];
        }
    }

    rep(i,m){
        rep(j,l){
            cin >> B[i][j];
        }
    }

    rep(i,n){
        rep(j,l){
            c=0;
            rep(k,m){
                c += A[i][k]*B[k][j];
            }
            cout << c;
            if(j!=l-1) cout << " ";
        }
        cout << endl;
    }

    return 0;

}


Measured memory_bytes: 3200
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _20191029
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] i = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

            if (i[0] < 1 || i[0] > 9 || i[1] < 1 || i[1] > 9)
                Console.WriteLine(-1);

            else
                Console.WriteLine(i[0] * i[1]);

        }
    }
}


Measured memory_bytes: 13268
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int number = scan.nextInt();
        int[] array = new int[number];
        for(int i = 0; i < number; i++){
            array[i] = scan.nextInt();
        }
        for(int t = number-1; t >= 0; t--){
            System.out.print(array[t]);
            if(t > 0){
                System.out.print(' ');
            }
        }
        
        System.out.print("\n");
    }
}




Measured memory_bytes: 26260
#include <iostream> 
#include <string>
#include <string.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <stdlib.h>
#include <deque>  
#include <iomanip>

using namespace std;

using ll = long long;
#define INF 1e9
#define MOD 1e9 + 7
#define rep(i, n) for(int i = 0; i < n; i++)
#define loop(i, a, n) for(int i = a; i < n; i++)
#define all(in) in.begin(), in.end()
struct place{
    int x;
    int y;
    int num;
};

int move(char direction, int value){
    if(direction == 'N') return value;
    if(direction == 'S') return -value;
    if(direction == 'W') return -value;
    if(direction == 'E') return value;
    return 0;
}
int main(){
    int N;
    while(true){
        cin >> N;
        if(N == 0) break;
        pair<int, int> juel[N];
        rep(i, N) cin >> juel[i].first >> juel[i].second;
        int M; cin >> M;
        pair<char, int> order[M];
        rep(i, M) cin >> order[i].first >> order[i].second;
        place state = {10, 10, 0};
        rep(i, M){
            const char direction = order[i].first;
            const int value = order[i].second;
            if(direction == 'N'){
                for(int y = 1; y <= value; y++){
                    rep(k, N){
                        if(state.x == juel[k].first && state.y + y == juel[k].second){
                            state.num++;
                            juel[k].first = -2, juel[k].second = -2;
                        }
                    }
                }
                state.y +=  move(direction, value);
            }
            if(direction == 'S'){
                for(int y = 1; y <= value; y++){
                    rep(k, N){
                        if(state.x == juel[k].first && state.y - y == juel[k].second){
                            state.num++;
                            juel[k].first = -2, juel[k].second = -2;
                        }
                    }
                }
                state.y += move(direction, value);
            }
            if(direction == 'E'){
                for(int x = 1; x <= value; x++){
                    rep(k, N){
                        if(state.x + x == juel[k].first && state.y == juel[k].second){
                            state.num++;
                            juel[k].first = -2, juel[k].second = -2;
                        }
                    }
                }
                state.x += move(direction, value);
            }
            if(direction == 'W'){
                for(int x = 1; x <= value; x++){
                    rep(k, N){
                        if(state.x - x == juel[k].first && state.y == juel[k].second){
                            state.num++;
                            juel[k].first = -2, juel[k].second = -2;
                        }
                    }
                }
                state.x += move(direction, value);
            }
        }
        if(state.num == N) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 3068
#include<bits/stdc++.h>
using namespace std;
/*
int slicedigit(int num,int[] d){
  
  while(){
    ans=num%10;
    num/=10;
    digit--;
  }
}*/

int main(){
  int N,M;
  cin>>N>>M;
  
  int s[M],c[M];
  
  for(int i=0;i<M;i++){
    cin>>s[i]>>c[i];
    //cout<<A[i]<<endl;
  }
  int start;
  int goal;
  if(N==1){
    start=0;goal=9;
  }else if(N==2){
    start=10;goal=99;
  }else if(N==3){
    start=100;goal=999;
  }
  
  int ans=-1;
  
  for(int i=start;i<=goal;i++){
    
    bool flag=true;
    
    int digit[N];
    
    int index=0;
    int mod=0;
    int num=i;
    for(int index=N-1; index>-1;index--){
      mod=num%10;
      num/=10;
      digit[index]=mod;
    }
    
    for(int j=0;j<M;j++){
      if((digit[s[j]-1])!=c[j]){
        flag=false;
        break;
      }
    }
    if(flag==true){
      ans=i;
      break;
    }
  }
  
  
  cout<<ans<<endl;

}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        
        Set<Integer> set = new HashSet<>();
    
        for(int i = 1; i <= 9; i++){
            for(int j = 1; j <= 9; j++){
                set.add(i * j);
            }
        }
        
        if(set.contains(N)){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 24276
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;


public class Main {

	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		String[] tmpArray = br.readLine().split(" ");
		
		int n = Integer.parseInt(tmpArray[0]);
		int k = Integer.parseInt(tmpArray[1]);
		
		int balls[] = new int[n + 1];
//		ArrayList<Integer> list = new ArrayList<Integer>();
		
		tmpArray = br.readLine().split(" ");
		for(int i = 0; i < n; i++){
			int tmp = Integer.parseInt(tmpArray[i]);
			
			balls[tmp]++;
		}
		
		Arrays.sort(balls);
		
		//debug
//		for(int i = 0; i <= n; i++){
//			System.out.print(balls[i]+" ");
//		}
//		System.out.println();
//		
		//0じゃないインデックスを探す
		int nonZero = -1;
		for(int i = 0; i <= n; i++){
			if(balls[i] != 0){
				nonZero = i;
				break;
			}
		}
		
		int kinds = n - nonZero;
		
		int sum = 0;
		
		for(int i = nonZero; i <= n - k; i++){
			sum += balls[i];
		}
		
		System.out.println(sum);
	}

}


Measured memory_bytes: 49748
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
typedef pair<ll, ll>P;
#define PI 3.14159265359
#define MOD 1000000007
const int MAX = 510000;

int main(){
  int N,K;cin>>N>>K;
  vector<ll>h(N);
  rep(i,N){cin>>h[i];}
  sort(h.begin(),h.end());
  ll dif=1000000000;
  for(int i=0;i<=N-K;i++){
  	ll g=h[i+K-1]-h[i];
    dif=min(dif,g);
  }
  cout<<dif;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include <map>
#include <fstream>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <assert.h>
#include <complex>
using namespace std;
#define eps 0.000001
#define LONG_INF 10000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 998244353
#define seg_size 65536*16
#define REP(i,n) for(long long i = 0;i < n;++i)
int main(){
	int n, k;
	cin >> n >> k;
	if ((n + 1) / 2 >= k) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
	return 0;
}

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

#define ll long long
#define vi vector<int>
#define si set<int>
#define stk stack<int>
#define que queue<int>
#define pb push_back
#define ff first
#define ss second
#define pii pair<int,int>

using namespace std;

int main() {
	int n,s=0;
	cin>>n;

	vi a(n);

	for(int i=0;i<n;i++){
		cin>>a[i];
		s+=a[i];
	}
	int ans=0;
	for(int i=0;i<n;i++){
		if(a[i]!=0)
			ans+=a[i]*(s-a[i]);
		s-=a[i];
	}
	cout<<ans<<endl;
}

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

using namespace std;
 
#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

typedef int64_t ll; typedef vector<int> VI; typedef pair<ll,ll> pii;
const ll mod = 1e9+7;

void dbg(){ cerr << "\n"; }  
template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }

const int dr[] = { 0, -1, 0, 1, 0 };
int main()
{
 	
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int h,w;
	cin >>h >>w;
	vector<string> ba(h);
	rep(i, h) cin >>ba[i];

	vector<VI> dd(h, VI(w, mod));
	queue<int> q;
	rep(i, h) rep(j,w){
		if(ba[i][j]=='#'){
			dd[i][j] =0;
			q.push(i*w + j);
		}
	}
	while(!q.empty()){
		int cy,cx; cy = q.front();
		q.pop(); 
		cx=cy%w; cy/=w;
		rep(i,4){
			int ny=cy+dr[i], nx=cx+dr[i+1];
			if(ny<0 || ny>=h || nx<0 || nx>=w) continue;
			if(ba[ny][nx]=='.' && dd[ny][nx] == mod){
				q.push( ny*w+nx );
				dd[ny][nx] = dd[cy][cx] + 1;
			}
		}
	}

	//for(auto xl: dd){for(auto x :xl) printf("%d, ",x); puts("");}
	int ans =0;
	rep(i,h) rep(j,w) ans = max(ans, dd[i][j]);
	
	cout << ans <<"\n";
	return 0;
}


Measured memory_bytes: 9344
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7

N, M = MAP()
a = [INT() for _ in range(M)]

dp = [0]*(N+1)
dp[0] = 1
dp[1] = 1

check = [0]*(N+1)
for i in a:
	check[i] = 1

if check[1] == 1:
	dp[1] = 0

for i in range(2, N+1):
	if not check[i]:
		dp[i] = (dp[i-1] + dp[i-2])%mod

print(dp[N])


Measured memory_bytes: 10768
#include <bits/stdc++.h>
#define rep(i,n,m) for(int i=n;i<(int)(m);i++)
#define rrep(i,n,m) for(int i=((int)(n)-1);i>=m;i--)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;
int main(){
    string s;
    rep(i,0,4){
        char c;
        cin>>c;
        s+=c;
    }
    sort(all(s));
    cout<<(s=="1479" ? "YES" : "NO")<<endl;
}


Measured memory_bytes: 256