akhauriyash/Code-Regression huggingface dataset:
class Dice():
    def __init__(self,rot,Face):
        self.rot= rot
        self.Face = Face
    def Rotate(rot,Face):
        r=len(rot)
        intFace=[int(Face[i]) for i in range(6)]

        for i in range(r):
            Temp=[intFace[i] for i in range(6)]

            if rot[i]== "E":
                intFace[0]=Temp[3]
                intFace[1]=Temp[1]
                intFace[2]=Temp[0]
                intFace[3]=Temp[5]
                intFace[4]=Temp[4]
                intFace[5]=Temp[2]

            elif rot[i]== "W":
                intFace[0]=Temp[2]
                intFace[1]=Temp[1]
                intFace[2]=Temp[5]
                intFace[3]=Temp[0]
                intFace[4]=Temp[4]
                intFace[5]=Temp[3]

            elif rot[i]== "N":
                intFace[0]=Temp[1]
                intFace[1]=Temp[5]
                intFace[2]=Temp[2]
                intFace[3]=Temp[3]
                intFace[4]=Temp[0]
                intFace[5]=Temp[4]

            elif rot[i]== "S":
                intFace[0]=Temp[4]
                intFace[1]=Temp[0]
                intFace[2]=Temp[2]
                intFace[3]=Temp[3]
                intFace[4]=Temp[5]
                intFace[5]=Temp[1]

        return intFace
#returnしてなかったわ インデント幅も注意

Face1 = input().split()
Face2 = input().split()
rot=""

###################
#同じ整数があるので前のは使えず。ごっそり修正
####################3
D1=["","N","W","E","S","NN"]
D2= ["","NWS","NWSNWS","NWSNWSNWS",]
same=False
for k in range(6):
    for i in range(4):
        rot = D1[k]+D2[i]

        dice=Dice(rot,Face2)
        tempFace= Dice.Rotate(rot,Face2)
        j=0
        while j<6:
            if tempFace[j]!=int(Face1[j]):
                break
            else:
                if j==5:
                    same=True
                j+=1
if same:
    print("Yes")
else:
    print("No")



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

int main(int argc, const char *argv[])
{
    string s;
    cin >> s;
    for (int i = 1; i < s.length(); i++)
    {
        if (s[i] == s[i - 1])
        {
            cout << "Bad" << endl;
            return 0;
        }
    }
    cout << "Good" << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<math.h>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
#define REP(i, N) for(ll i = 0; i < N; ++i)
#define FOR(i, a, b) for(ll i = a; i < b; ++i)
#define ALL(a) (a).begin(),(a).end()
#define pb push_back
#define INF (long long)1000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

vector<string> res;
string s;

void dfs(int n) {
	if(n == 0) {
		res.pb(s);
		return;
	}
	bool ex = false;
	REP(i, s.size()) {
		if(s[i] == 'a' + n) {
			ex = true;
			break;
		}
		if(s[i] == 'a' + (n - 1)) {
			s[i] = 'a' + n;
			dfs(n - 1);
			s[i] = 'a' + (n - 1);
		}
	}
	if(!ex) {
		dfs(n - 1);
	}
}

int main(void) {
	while(true) {
		cin>>s;
		if(s == "#") break;
		res.resize(0);
		dfs(25);
		sort(ALL(res));
		cout<<res.size()<<endl;
		if(res.size() <= 10) {
			REP(i, res.size()) {
				cout<<res[i]<<endl;
			}
		} else {
			REP(i, 5) {
				cout<<res[i]<<endl;
			}
			REP(i, 5) {
				cout<<res[res.size() - 5 + i]<<endl;
			}
		}
	}
}

Measured memory_bytes: 4216
#include <cstdio>

char map[20][20];
int C,R;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
bool vst[20][20][16][4];

bool dfs(int x,int y,int m,int d) {
	if(x==-1) x=C-1;
	if(x==C) x=0;
	if(y==-1) y=R-1;
	if(y==R) y=0;
	if(vst[x][y][m][d]) return false;
	vst[x][y][m][d]=true;
	if(map[x][y]=='<') {
		return d=2,dfs(x+dx[d],y,m,d);
	}else if(map[x][y]=='>') {
		return d=0,dfs(x+dx[d],y,m,d);
	}else if(map[x][y]=='^') {
		return d=3,dfs(x,y+dy[d],m,d);
	}else if(map[x][y]=='v') {
		return d=1,dfs(x,y+dy[d],m,d);
	}else if(map[x][y]=='_') {
		return d=!m?0:2,dfs(x+dx[d],y,m,d);
	}else if(map[x][y]=='|') {
		return d=!m?1:3,dfs(x,y+dy[d],m,d);
	}else if(map[x][y]=='?') {
		for(int i=0;i<4;i++) {
			if(dfs(x+dx[i],y+dy[i],m,i)) return true;
		}
		return false;
	}else if(map[x][y]=='.') {
		return dfs(x+dx[d],y+dy[d],m,d);
	}else if(map[x][y]=='@') {
		return true;
	}else if('0'<=map[x][y]&&map[x][y]<='9') {
		return m=map[x][y]-'0',dfs(x+dx[d],y+dy[d],m,d);
	}else if(map[x][y]=='+') {
		return m=m<15?m+1:0,dfs(x+dx[d],y+dy[d],m,d);
	}else if(map[x][y]=='-') {
		return m=m>0?m-1:15,dfs(x+dx[d],y+dy[d],m,d);
	}
}

int main() {
	scanf("%d %d",&R,&C);
	getchar();
	for(int j=0;j<R;j++) {
		for(int i=0;i<C;i++) {
			map[i][j]=getchar();
		}
		getchar();
	}
	printf("%s\n",dfs(0,0,0,0)?"YES":"NO");
}

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

int main(){
  int x;
  int i;
  int k, f;
  int uresisa;
  cin >> x;
  k = x / 500;
  f = (x - (k * 500)) / 5;
  uresisa = k * 1000 + f * 5;
  cout << uresisa << endl;
}

Measured memory_bytes: 3552
//Utkarsh.25dec
#include <bits/stdc++.h>
#define ll long long int 
#define ull unsigned long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define rep(i,n) for(ll i=0;i<n;i++)
#define loop(i,a,b) for(ll i=a;i<=b;i++)
#define vi vector <int>
#define vs vector <string>
#define vc vector <char>
#define vl vector <ll>
#define all(c) (c).begin(),(c).end()
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
using namespace std;
const int N=500023;
bool vis[N];
vector <int> adj[N];
void solve()
{
    ll s;
    cin>>s;
    ll a=sqrt(s);
    ll x1=0,y1=0,x2=0,y2=0;
    if((a*a)==s)
    {
        x1=a;
        y2=a;
        x2=0;
        y1=3;
    }
    else
    {
        a++;
        x1=a;
        y2=a;
        ll rem=a*a-s;
        ll fact1=0,fact2=0;
        for(int i=1;i<=100000;i++)
        {
            if(rem%i!=0)
                continue;
            fact1=i;
            fact2=rem/i;
            if(fact2<=1000000000)
            {
                x2=i;
                y1=fact2;
                break;
            }
        }
    }
    cout<<0<<' '<<0<<' '<<x1<<' '<<y1<<' '<<x2<<' '<<y2;
}
int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    int T=1;
    //cin>>T;
    int t=0;
    while(t++<T)
    {
        //cout<<"Case #"<<t<<":"<<' ';
        solve();
        //cout<<'\n';
    }
}

Measured memory_bytes: 12032
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

//Nature of Prime Numbers
public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true){
			int n = sc.nextInt();
			if(n==0)break;
			int[] c = new int[(n-1)/2+1];
			int[] a = new int[n];
			int id = 0;
			Set<Integer> set = new HashSet<Integer>();
			for(int i=1;i<n;i++){
				int x = i*i%n;
				if(!set.contains(x)){
					set.add(x);
					a[id++] = x;
				}
			}
			for(int i=0;i<id;i++){
				for(int j=0;j<id;j++){
					if(i==j)continue;
					int sub = a[i]-a[j];
					if(sub<0)sub+=n;
					if(sub > (n-1)/2)sub = n-sub;
					c[sub]++;
				}
			}
			for(int i=1;i<=(n-1)/2;i++)System.out.println(c[i]);
		}
	}
}

Measured memory_bytes: 13000
from itertools import permutations as per


def main():
    a1, a2, a3 = map(int, input().split())
    As = list(per([a1, a2, a3], 3))
    ans = float("inf")
    for A in As:
        ans = min(ans, abs(A[0] - A[1])+abs(A[1] - A[2]))

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
s=list(input())
n=len(s)
#print(s)
num=[]
def search(now,kigo): #自分より右に何回同じ記号が続くか
    global s,n
    count=0
    while s[now]==kigo:
        now+=1
        count+=1
        if now==n:
            break
    return count
where=0
left=0
if s[0]=="<":
    a=search(0,"<")
    nn=0
    for i in range(a):
        num.append(nn)
        if i==a-1:
            break
        nn+=1
    left=nn
else:
    a=search(0,">")
    nn=a
    for i in range(a):
        num.append(nn)
        nn-=1
    left=1
where=a #次調べる場所
while where<=n-1:
    if s[where]=="<":
        a=search(where,"<")
        nn=0
        for i in range(a):
            num.append(nn)
            if i==a-1:
                break
            nn+=1
        left=nn
    else:
        a=search(where,">")
        if left<a:
            nn=a
        else:
            nn=left+1
        num.append(nn)
        nnn=a-1
        for i in range(a-1):
            num.append(nnn)
            nnn-=1
        left=1
    where+=a
    #print(a)
if s[-1]=="<":
    num.append(left+1)
else:
    num.append(left-1)
#print(num)
print(sum(num))

Measured memory_bytes: 104524
#include <bits/stdc++.h>
#if ONLINE_JUDGE
#define DEBUG false
#else
#define DEBUG true
#endif
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, k, n) for (int i = (int)(k); i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define rREP(i, k, n) for (int i = (int)(n)-1; i >= k; i--)
#define foreach(i, vec) for(auto &&i : vec)
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort(all(x))
#define REV(x) reverse(all(x))
#define MAX(x) *max_element(all(x))
#define MIN(x) *min_element(all(x))
#define LOWitr(x, n) lower_bound(all(x), n)
#define UPRitr(x, n) upper_bound(all(x), n)
#define cii(x) int x;cin >> x
#define cill(x) LL x;cin >> x
#define cis(x) string x;cin >> x
#define co(x) cout << x << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define truecheck assert
#define dump(x) cerr << #x << ": " << (x) << endl
using namespace std;
typedef long long LL;
typedef long long int64;
typedef std::vector<int> VI;
typedef std::vector<VI> VVI;
typedef std::vector<LL> VL;
typedef std::vector<VL> VVL;
typedef std::vector<string> VS;
typedef std::pair<int, int> PII;
typedef std::pair<int64, int64> PLL;
typedef std::queue<int> QI;
typedef std::priority_queue<int> PQI;
template<class T,class U>inline bool chmax(T &a, const U &b){if (a<b){a=b;return true;}return false;}
template<class T,class U>inline bool chmin(T &a, const U &b){if (b<a){a=b;return true;}return false;}
template<class T,class U>inline void vcin(T &v, U n){rep(i, n){typename T::value_type a;cin >> a;v.pb(a);}}

const int INF = 1e9, MOD = 1e9 + 7;
const LL LLINF = 1e16;
// M_PI 3.1415...

int main() {
    fastcin();
    cout << fixed << setprecision(10);
    cill(n);
    cill(m);
    LL ans = 0;
    VVI vvi(11);
    VI p;
    rep(i, m){
        cii(k);
        vcin(vvi[i], k);
    }
    vcin(p, m);
    rep(bit, (1<<n)){
        bool flag = true;
        rep(i, m){
            int sum = 0;
            for(auto&& j : vvi[i]){
                if(bit & (1<<j-1)){
                    sum++;
                }
            }
            flag = flag && (p[i] == sum % 2);
        }
        if(flag) ans++;
    }
    co(ans);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
//const ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
const ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll divceil(ll A, ll B) {return (A + (B - 1)) / B;}
ll myctoi(char C) {return C - '0';}
char myitoc(ll N) {return '0' + N;}
#define FINALANS(A) do {cout << (A) << '\n'; exit(0);} while (false)

ll modpow(ll a, ll n, ll m)
{
  ll ret = 1;
  while (n > 0)
  {
    if (n % 2 == 1) ret = ret * a % m;
    a = a * a % m;
    n /= 2;
  }
  return ret;
}

ll modinv(ll a, ll m)
{
  ll b = m, x = 1, y = 0;
  while (b > 0)
  {
    ll q = a / b, r = a - q * b, s = x - q * y;
    a = b, b = r;
    x = y, y = s;
  }
  return mod(x, m);
}

int main()
{
  ll N, A, B;
  cin >> N >> A >> B;

  ll ans = modpow(2, N, MOD) - 1;
  ll c1 = 1;
  for (ll i = 0; i < A; i++)
  {
    c1 *= (N - i) * modinv(A - i, MOD) % MOD;
    c1 %= MOD;
  }
  ll c2 = 1;
  for (ll i = 0; i < B; i++)
  {
    c2 *= (N - i) * modinv(B - i, MOD) % MOD;
    c2 %= MOD;
  }

  cerr << ans << " " << c1 << " " << c2 << endl;

  ans += MOD - c1, ans %= MOD;
  ans += MOD - c2, ans %= MOD;
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int n, m, u[2019] = {}, v[2019] = {}, w[2019] = {};
    bool b[2019] = {}, c[2019] = {};
    ll d[1003] = {};
    cin >> n >> m;
    for (int i = 0; i < m; i++) cin >> u[i] >> v[i] >> w[i], w[i] = -w[i];
    queue<int> q;
    q.push(1);
    b[1] = 1;
    while (!q.empty()) {
        int x = q.front();
        q.pop();
        for (int i = 0; i < m; i++) if (u[i] == x && !b[v[i]]) {
            b[v[i]] = 1;
            q.push(v[i]);
        }
    }
    q.push(n);
    c[n] = 1;
    while (!q.empty()) {
        int x = q.front();
        q.pop();
        for (int i = 0; i < m; i++) if (v[i] == x && !c[u[i]]) {
            c[u[i]] = 1;
            q.push(u[i]);
        }
    }
    for (int i = 2; i <= n; i++) d[i] = (ll)mod * mod;
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j < m; j++) {
            if (d[u[j]] + w[j] < d[v[j]]) d[v[j]] = d[u[j]] + w[j];
        }
    }
    for (int i = 0; i < m; i++) if (b[u[i]] && c[v[i]] && d[u[i]] + w[i] < d[v[i]]) {
        cout << "inf";
        return 0;
    }
    cout << -d[n];
}


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

#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()
const int INF = 1<<29;

typedef pair<string, int> P;
P solve(string s, int x, int y) {
//  cout << s << endl;
  string name;
  REP(i,s.size()) {
    if (s[i]=='>') {
      name = s.substr(1,i-1);
      break;
    }
  }
  int x1,x2,y1,y2;
//  cout << name << endl;
  string tmp = s.substr(name.size()+2);
  sscanf(tmp.c_str(), "%d,%d,%d,%d", &x1,&y1,&x2,&y2);
//  cout << x1 << y1 << y1 << y2 << endl;
  if (!(x1<=x&&x<=x2&&y1<=y&&y<=y2))
    return P("OUT OF MAIN PANEL", 1);
  
  int aa = 0;
  int num = 0;
  int pos;
  REP(i,tmp.size()-1) {
    if (tmp.substr(i,2) == "</") {
      aa--;
    } else if (tmp[i] == '<') {
      aa++;
      if (aa==1)
        pos = i;
    }
    
    if (tmp[i] == '>'&&aa==0) {
      P p = solve(tmp.substr(pos, i-pos+1), x,y);
      if (p.first != "OUT OF MAIN PANEL")
        return p;
      num++;
    }
  }
  return P(name, num);
}

int main() {
  int n;
  while(cin>>n,n) {
    string s;
    cin >> s;
    REP(i,n) {
      int x,y;
      cin>>x>>y;
      P a = solve(s,x,y);
      cout << a.first << " " << a.second << endl;
    }
  }
}

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

int main(){
  int N; cin>>N;
  cout<<N/2+N%2<<endl;
  return 0;
}

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

using namespace std;

#define pb push_back
#define F first
#define S second
#define INF ll(1e18)
#define MOD 1000000007

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef long double ld;

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
    int a;string b;cin>>a>>b;
    if(a<3200){cout<<"red";}
    else{cout<<b;}
}


Measured memory_bytes: 256
/*Made by Shivam Solanki*/
#include<bits/stdc++.h>
#pragma GCC optimize ("Ofast")
using namespace std;
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define ll long long int
#define endl '\n'
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vll> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<pii> vp;
typedef vector<pll> vpll;
typedef map<int,int> mii;
typedef map<ll,ll> mll;
typedef set<int> sii;
typedef set<ll> sll;
typedef queue<int> qii;
typedef priority_queue<int> pq;
typedef unordered_map<int,int> umii;
typedef unordered_map<ll,ll> umll;
#define all(x) x.begin(),x.end()
#define rep(i,k,n) for (int i = k; i < n; ++i) 
#define repr(i,k,n) for (int i = n; i>=k; --i)
#define repll(i,k,n) for (ll i = k; i < n; ++i) 
#define pb push_back
#define mp make_pair
#define gcd __gcd
#define F first
#define S second
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const int INF = 1e9+5;
const int MOD = 1e9+7;

void solve(){
    int k;
    cin>>k;
    string s;
    cin>>s;
    if(k<s.size()){
        rep(i,0,k) cout<<s[i];
        cout<<"...";
    }
    else{
        cout<<s;
    }
}

int main(){ 
    // #ifndef ONLINE_JUDGE  
        // freopen("input.txt", "r", stdin); 
        // freopen("output.txt", "w", stdout); 
    // #endif 
    fastio;
    int t=1;
    // cin>>t;
    while(t--)
        solve();
    return 0;
}


Measured memory_bytes: 3644
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdlib.h>
#include <cmath>
#include <numeric>
#include <functional>
#include <stack>
#include <iomanip>
#include <map>
#include <cstdio>


int main() {

	std::string s;

	std::cin >> s;

	long long black = 0;
	long long ans = 0;

	for (long long i = 0; i < s.length(); i++)
	{
		if (s[i] == 'B') {
			black++;
		}
		else {
			ans += black;
		}
	}

	std::cout << ans << std::endl;

	return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<deque>
#include<tuple>
#include<queue>
#include<map>
#include<cstdint>
#include<unordered_map>
#include<boost/multiprecision/cpp_int.hpp>


#define rep(i, n) for(int i = 0; i < ( int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define F first
#define S second

namespace mp = boost::multiprecision;

using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

bool dfs(vector<vector<char>>&cam, int s, int t) {
	int size = cam.size();
	int size1 = cam[s].size();
	int count = 0;
	for (int i = max(0, s - 1); 
		i< min(s + 2, size); i++) {
		if (cam[i][t] == '#') {
			count++;
		}
	}
	for (int i = max(t - 1, 0);
		i< min(t + 2,size); i++) {
		if (cam[s][i] == '#'&&i!=t) {
			count++;
		}
	}
	if (count >= 2) {
		return true;
	}
	else {
		return false;
	}
}
int main() {
	string s;
	cin >> s;
	int k;
	cin >> k;
	deque<string>str;
	FOR(i,1, k+1) {
		rep(j, s.size()+1-i) {
			str.push_back(s.substr(j, i));
		}
	}
	sort(all(str));
	string tmp = "";
	
	int count = 0;

	rep(i, str.size()) {
		if (tmp < str[i]) {
			count++;
			tmp = str[i];
		}
		if (count == k) {
			break;
		}
	}
	cout << tmp << endl;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
    long N,A[5]={0};
    char S[15];
 
    scanf("%ld",&N);
    for(int i=0; i<N; i++){
        scanf("%s",S);
        if(S[0] == 'M'){
            A[0]++;
        }else if(S[0] == 'A'){
            A[1]++;
        }else if(S[0] == 'R'){
            A[2]++;
        }else if(S[0] == 'C'){
            A[3]++;
        }else if(S[0] == 'H'){
            A[4]++;
        }
    }
long ans=0;
    for(int i=0; i<5; i++){
        for(int j=i+1; j<5; j++){
            for(int k=j+1; k<5; k++){
                ans += A[i] * A[j] * A[k];
            }
        }
    }
   printf("%ld",ans);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pr;
priority_queue <pr,vector<pr>,greater<pr> > v;
#define maxn 100010
struct edge
{
	int to,nxt;
}e[maxn];
int head[maxn],d[maxn],w[maxn],n,c[maxn],a[maxn],i,j,x,y,ans=0,sz=0;
pr p;
void addedge(int x,int y)
{
	e[++sz].to=y;
	e[sz].nxt=head[x];
	head[x]=sz;
}
int main()
{
	scanf("%d",&n);
	for (i=1;i<n;i++)
	{
		scanf("%d%d",&x,&y);
		addedge(x,y);
		addedge(y,x);
		d[x]++;
		d[y]++;
	}
	for (i=1;i<=n;i++)
		scanf("%d",&c[i]);
	sort(c+1,c+n+1);
	for (i=1;i<=n;i++)
		v.push(make_pair(d[i],i));
	for (i=1;i<=n;)
	{
		p=v.top();
		v.pop();
		if (d[p.second]!=p.first) continue;
			else
			{
				ans+=d[p.second]*c[i];
				a[p.second]=c[i];
				for (j=head[p.second];j;j=e[j].nxt)
					if (!a[e[j].to])
					{
						d[e[j].to]--;
						v.push(make_pair(d[e[j].to],e[j].to));
					}
				i++;
			}
	}
	printf("%d\n",ans);
	for (i=1;i<=n;i++)	
		printf("%d ",a[i]);
	return 0;
}

Measured memory_bytes: 896
a,b,k =  input().split()
a = int(a)
b = int(b)
k = int(k)

if a + b < k:
    i = 0
    m = 0
elif a <= k:
    i = 0
    m = b - (k-a)
else:
    i = a-k
    m=b
print(i,m)

Measured memory_bytes: 3060
n = int(input())
la = list(map(int, input().split()))
lb = list(map(int, input().split()))
lc = list(map(int, input().split()))

res = sum(lb)
for a0, a1 in zip(la, la[1:]):
    if a1 == a0 + 1:
        res += lc[a0 - 1]
print(res)

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

cur = [i ** 5 for i in range(1000)]
for i in range(1000):
    for j in range(i + 1, 1000):
        if cur[j] - cur[i] == n:
            print(j, i)
            exit()
        if cur[j] + cur[i] == n:
            print(j, -i)
            exit()

Measured memory_bytes: 9084
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mk make_pair
#define rint register int
using namespace std;
const int mod = 1e9+7;
inline int read(){int w=1,s=0;char ch=getchar();while(!isdigit(ch)){if(ch=='-')w=-1;ch=getchar();}while(isdigit(ch)){s=s*10+ch-'0';ch=getchar();}return w*s;}
int f[200010],n,C[200010],Sum[200100],Seq[200010],cnt,Pre[200010],hd[200010];
//inline int add(int a,int b){a+=b;return a>=mod?a-mod:a;}
int S[200010];
inline int lowbit(int x){return x&(-x);}
inline void add(int pos,int dd){while(pos<=(n+1)) S[pos]+=dd,S[pos]%=mod,pos+=lowbit(pos);}
inline int Qry(int pos){if(pos<0) return 0;int res=0;while(pos) res+=S[pos],pos-=lowbit(pos),res%=mod; return res;}
inline int Add(int a,int b){a+=b;return a>=mod?a-mod:a;}
int main()
{
	n=read();
	for(rint i=1;i<=n;++i)
		C[i]=read();
	for(rint i=1;i<=n;++i) if(C[i]!=Seq[cnt]) Seq[++cnt]=C[i];
	n=cnt; 
	for(rint i=1;i<=n;++i) Pre[i]=hd[Seq[i]],hd[Seq[i]]=i;//	cout<<1<<"\n";
	f[0]=1;
	add(1,1);
	for(rint i=1;i<=n;++i)
	{	
//		cout<<Pre[i]<<"\n";
//		f[i]=Add(f[i],f[i-1]);
//		if(Pre[i]==0) Pre[i]++;
		if(Pre[i]==0) continue;
		f[i]=Add(f[i],Qry(Pre[i]+1));
//		if(Pre[i]>1)
		add(i+1,f[i]);
//		cout<<Pre[i]<<"\n";
//		cout<<f[i]<<"   f\n";
	}int res=0;
	for(rint i=0;i<=n;++i)
	{
		res+=f[i];res%=mod;
	}cout<<res%mod;
	return 0;
}


Measured memory_bytes: 5760
#include <bits/stdc++.h>
#define f(i,q,a) for(long long i=q; i<a; i++)
#define ll long long
#define pb push_back
#define mod 1000000007
using namespace std;
int main()
{
    ll n;
    cin>>n;
    ll A[n]={};
    ll c=0;
    map<array<ll,3>,ll>mp={};
    f(i,0,n)cin>>A[i];
    f(i,0,n)
    f(k,i+1,n)
    f(j,k+1,n)
    {
        if((A[i]+A[j]>A[k]&&A[i]+A[k]>A[j])&&(((A[k]+A[j]>A[i]&&i!=k)&&(k!=j&&i!=j)))&&(A[i]!=A[k]&&(A[k]!=A[j]&&A[i]!=A[j])))c++;
    }
    cout<<c<<endl;
}


Measured memory_bytes: 3608
#include<iostream>
#include<algorithm>
#include<math.h>
#include<cstring>
#include<vector>

using namespace std;

#define long long long
#define ft(i, a, b) for (int i = (long)a ; i <= (long)b ; i++)
#define fd(i, a, b) for (int i = (long)a ; i >= (long)b ; i--)

const int MAXN = 1e5 + 5;
const long oo = 1e15;

long n , k;
long a[MAXN] , dp[MAXN];

long choose(int i , int j) {
    return abs(a[i] - a[j]);
}

void Solve() {
    ft(i , 2 , n) {
        dp[i] = oo;
        fd(j , i - 1 , max(i - k , 1LL)) {
            dp[i] = min(dp[j] + choose(i , j) , dp[i]);
            //if (i == n) cout << "THIS IS DEBUG " << j << " " << dp[j] << " " << i << " " << dp[i] << "\n";
        }
    }    
    cout << dp[n];
}

void FastInput() {
    ios_base::sync_with_stdio(NULL);
    cin.tie(NULL);
    cout.tie(NULL);
    //freopen(".inp", "r", stdin);
    //freopen(".out", "w", stdout);
}

void Input() {
    cin >> n >> k;
    ft(i , 1 , n) cin >> a[i];
}

int main() {
    FastInput();
    Input();
    Solve();
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/tag_and_trait.hpp>
using namespace __gnu_pbds;

using namespace std;
using ll = long long;

pair<pair<int, int>, pair<int, int>> split(pair<int, int> p, int s){
    //s++;
    s %= (p.first + p.second);
    if(s < p.second){
        return make_pair(make_pair(p.first, p.second - s), make_pair(p.first, s));
        return make_pair(make_pair(p.first - s, p.second), make_pair(s, p.second));
    }else{
        s -= p.second;
        return make_pair(make_pair(p.first - s, p.second), make_pair(s, p.second));
    }
}

int main(){
    int n, w, d;
    while(cin >> n >> w >> d){
        if(n == 0 && w == 0 && d == 0)return 0;
        tree<pair<int, pair<int, int>>,null_type,less<pair<int, pair<int, int>>>,rb_tree_tag,tree_order_statistics_node_update> var_name;
        var_name.insert(make_pair(0, make_pair(d, w)));
        int idx = 1;
        while(n--){
            int p, s;cin >> p >> s;
            p--;
            pair<int, pair<int, int>> square = *var_name.find_by_order(p);
            var_name.erase(var_name.find_by_order(p));
            pair<pair<int, int>, pair<int, int>> po = split(square.second, s);
            if(po.first.first * po.first.second < po.second.first * po.second.second){
                var_name.insert(make_pair(idx, po.first));
                idx++;
                var_name.insert(make_pair(idx, po.second));
                idx++;
            }else{
                var_name.insert(make_pair(idx, po.second));
                idx++;
                var_name.insert(make_pair(idx, po.first));
                idx++;
            }
            /*
            for(auto a : var_name){
                cout<<a.second.second * a.second.first<<" ";
            }
            cout<<endl;
            */
            
        }
        vector<int> ans;
        for(auto a : var_name){
            ans.push_back(a.second.first * a.second.second);
        }
        sort(ans.begin(), ans.end());
        for(int i = 0;i < ans.size();i++){
            cout<<ans[i]<<(i != ans.size() - 1 ? " " : "");
        }
        cout<<endl;
    }
}


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

#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define fi first
#define se second
#define ff first
#define ss second
#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 long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pii;
typedef long double ld;
typedef string st;
const double PI=3.14159265358979323846264338327950288419716939937510582097494459230;
const ll MOD = 1e9 + 7 ;
const ll INF=1e14;
ll mpow(ll a,ll b,ll p=MOD){a=a%p;ll res=1;while(b>0){if(b&1)res=(res*a)%p;a=(a*a)%p;b=b>>1;}return res%p;}
const ll N=200002;

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  ll a,b,c;
  cin>>a>>b>>c;
  ll ans=0;
  ll d=min(b,c);
  ans+=2*d;
  b-=d;
  c-=d;
  d=min(a,c);
  ans+=d;
  a-=d;
  c-=d;
  if(c) ans++;
  ans+=b;
  cout<<ans;
} 
//nothing is impossible

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) throws IOException {
		FastScanner in = new FastScanner(System.in);
		String s= in.next();
		boolean [] a= new boolean[10000];
		for(int i=0; i<s.length();i++){
			if(a[s.charAt(i)]){
				System.out.println("no");
				return;
			}
			a[s.charAt(i)]=true;
		}
		System.out.println("yes");
	}
	static class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner(InputStream in) {
			br = new BufferedReader(new InputStreamReader(in));
			st = new StringTokenizer("");
		}

		public double nextDouble() throws NumberFormatException, IOException {
			return Double.parseDouble(next());
		}

		public String next() throws IOException {
			if (!st.hasMoreTokens()) {
				st = new StringTokenizer(br.readLine());
				return next();
			}
			return st.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
	}
}


Measured memory_bytes: 21204
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const ll mod = 1000000007;
const ll INF = 1001001001;
const ll LINF = 1001001001001001001;

void prvec(vector<ll> vec){
    ll n = vec.size();
    rep(i,n) cout << "i" << " " << vec.at(i) << "\n";
}

void pr2d(vector<vector<ll>> vvec){
    ll h = vvec.size();
    ll w = vvec.at(0).size();
    rep(i,h){
        rep(j,w){
            cout << vvec.at(i).at(j) << " ";
        }
        cout << "\n";
    }
}

int main(){
    ll a,b; cin >> a >> b;
    if(a<=0 && b>=0){
        cout << "Zero" << endl;
    }else if(a>0){
        cout << "Positive" << endl;
    }else{
        if((b-a)%2){
            cout << "Positive" << endl;
        }else{
            cout << "Negative" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <math.h>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
using namespace std;
using ll = long long;
using graph = std::vector<std::vector<long long>>;
int main(){
    ll N;
    cin >> N;
    vector<ll> A(N);
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
    }
    sort(A.begin(),A.end());
    bool path[N-1];
    ll currentSum = A[0];
    for (int i = 0; i < N-1; ++i) {
        path[i] = currentSum * 2 >= A[i + 1];
        currentSum += A[i + 1];

    }
    ll count = 0;
    bool judge = false;
    for(int i = N - 2; i >= 0; i--){
        if(path[i]){
            count++;
        }else{
            cout << count + 1 << endl;
            return 0;
        }
    }
    cout << N << endl;
}

Measured memory_bytes: 1152
from collections import defaultdict
n=int(input())
s=[input() for i in range(n)]
cnt=defaultdict(lambda:0)
for i in s:
    cnt[i]+=1

cnt=list(cnt.items())
cnt=sorted(cnt,reverse=True,key=lambda x: x[1])
maxim=cnt[0][1]
ans=[]
for i in range(len(cnt)):
    if cnt[i][1]==maxim:
        ans+=[cnt[i][0]]
ans=sorted(ans)
print(*ans,sep='\n')

Measured memory_bytes: 43496
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
		String str = sc.nextLine();
		int jcnt = 0;
		int icnt = 0;
		for(int i = 0 ; i < str.length() -2 ; i++){
			if("JOI".equals(str.substring(i,i+3))){
				jcnt++;
			}else if("IOI".equals(str.substring(i,i+3))){
				icnt++;
			}
		}
		System.out.println(jcnt);
		System.out.println(icnt);
		}
	}

}

Measured memory_bytes: 25192
#include <iostream>
using namespace std;
int main(){
  int n,mw;
  int v[1005],w[1005];
  cin >> n >> mw;
  for(int i=0;i<n;i++){
    cin >> v[i] >> w[i];
  }
  int dp[mw+2][n];
  fill(&dp[0][0],&dp[mw+1][n-1],0);
  for(int i=1;i<=mw;i++){
    for(int j=0;j<n;j++){
      dp[i][j] = i-w[j]>=0?max(dp[i][j-1],dp[i-w[j]][j]+v[j]):dp[i][j-1];
    }
  }
  cout << dp[mw][n-1] << endl;
}

Measured memory_bytes: 7000
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n,a,b = LI()
    s = input()
    su = sb = 0
    c = a+b
    for i in range(n):
        if su >= c:
            print("No")
            continue
        if s[i] == "a":
            su += 1
            print("Yes")
        elif s[i] == "b":
            if sb < b:
                su += 1
                sb += 1
                print("Yes")
            else:
                print("No")
        else:
            print("No")
    return

#Solve
if __name__ == "__main__":
    solve()


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

int main() {
  int N; cin >> N;
  double T, A; cin >> T >> A;
  double num = 1000000000;
  int t_ans;
  rep(i, N) {
    int h; cin >> h;
    double ans = abs((T - h * 0.006) - A);
    if (ans < num) {
      num = ans;
      t_ans = i+1;
    }
  }
  cout << t_ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")

using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
typedef long long ll;
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(int i=num, i##_len=(n); i<i##_len; ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define print(x) (cout << (x) << endl)
#define pb push_back
#define mp make_pair
#define sz(x) int(x.size())
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
#define fs first
#define sc second
// 多倍長
#include <boost/rational.hpp>
#include <boost/multiprecision/cpp_int.hpp>
using boost::rational;
using boost::multiprecision::cpp_int;

const int INF = 1e9;
const ll LLINF = 1e16;
const ll MOD = 1e9+7;
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}
 
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
 

// 指定した文字cが文字列に何文字入ってるか
ll stringcount(string s, char c) {
    return count(s.cbegin(), s.cend(), c);
}


// 割り算の切り上げ処理
template<typename T>
T rp(T a, T b) {
  return (a + b - 1) / b;
}

// 桁和
template<typename T>
T digsum(T n) {
    T res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

// 回文判定
bool kai (string s) {
    string t{s};
    reverse(begin(t), end(t));
    return s == t;
}

using pint = pair<int, int>;
using pll = pair<ll, ll>;


vector<string> split(const string &s, char delim) {
    vector<string> elems;
    string item;
    for (char ch: s) {
        if (ch == delim) {
            if (!item.empty())
                elems.push_back(item);
            item.clear();
        }
        else {
            item += ch;
        }
    }
    if (!item.empty())
        elems.push_back(item);
    return elems;
}


int ng[500];
int dp[500];

int main(void)
{
    cout.tie(0);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int a,b,c,k;
    cin >> a >> b >> c >> k;
    int count = 0;
    while(a >= b){
        b *= 2;
        count++;
    }
    if(count > k){
        print("No");
        return 0;
    }
    k -= count;
    count = 0;
    while(b >= c){
        c *= 2;
        count++;
    }
    if(count > k){
        print("No");
        return 0;
    }
    print("Yes");



    

}



Measured memory_bytes: 3636
#include <stdio.h>
int main(){
  int r,c,i,j,k[101][101],a[101],b[101],d=0;

  for(i = 0;i  < 101;i++){
    a[i] = 0;
    b[i] = 0;
    for(j = 0;j < 101;j++){
      k[i][j] = 0;
    }
  }
  
  scanf("%d %d",&r,&c);
  
  for(i = 0;i < r;i++){
    for(j = 0;j < c;j++){
      scanf("%d",&k[i][j]);
      a[i] = a[i] +k[i][j];
    }
  }
  for(j = 0;j < c;j++){
    for(i = 0;i < r;i++){
      b[j] = b[j] + k[i][j];
    }
    d = d + b[j];
  }
  for(i = 0;i < r;i++){
    for(j = 0;j < c;j++){
      printf("%d ",k[i][j]);
    }
    printf("%d\n",a[i]);
  }
  for(i = 0;i < c;i++){
    printf("%d ",b[i]);
  }
  printf("%d\n",d);
  
  return 0; 
}

Measured memory_bytes: 640
require 'pp'
$DEBUG ? define_method(:dpp){|e|pp e} : define_method(:dpp){|e|}

# 空白区切の入力値を数値の配列で返却する
def gets_i_list()
  gets.chomp.split(" ").map(&:to_i)
end
d, n = gets_i_list

if d == 0
  if n == 100
    puts n + 1
  else
    puts n
  end
elsif d == 1
  if n == 100
    puts n * 100 + 100
  else
    puts n * 100
  end
else
  if n == 100
    puts n * 100 * 100 + 100 * 100
  else
    puts n * 100 * 100
  end
end

Measured memory_bytes: 14628
#include <bits/stdc++.h>
#define int long long
using namespace std;
//string sort (s.begin(),s.end());

main() {
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);


       int n,k,x,y;
       cin>>n>>k>>x>>y;
       int sum=0;
       if(k>n)
       {
           cout<<n*x<<endl;

       }
       else
       {
            sum+=(k*x);
       sum+=(n-k)*y;
       cout<<sum<<endl;


       }



}



Measured memory_bytes: 3636
s=str(input())
s1=str(input())
l=[]
for i in range(0,len(s)-len(s1)+1):
    e=s[i:i+len(s1)]
    f=0
    for j in range(0,len(e)):
        if(e[j]!=s1[j]):
            f=f+1
    l.append(f)
print(min(l))

Measured memory_bytes: 73464
using System;
using System.IO;
using System.Linq;
using System.Text;
using System.Collections.Generic;
using System.Diagnostics;
using Enu = System.Linq.Enumerable;

public class Program
{
    public void Solve()
    {
        int N = Reader.Int(), M = Reader.Int();
        var Path = Reader.IntTable(M);
        var deg = new int[N];
        foreach (var p in Path) { deg[p[0] - 1]++; deg[p[1] - 1]++; }
        Console.WriteLine(deg.All(d => d % 2 == 0) ? "YES" : "NO");
    }
}


class Entry { static void Main() { new Program().Solve(); } }
class Reader
{
    static TextReader reader = Console.In;
    static readonly char[] separator = { ' ' };
    static readonly StringSplitOptions op = StringSplitOptions.RemoveEmptyEntries;
    static string[] A = new string[0];
    static int i;
    static void Init() { A = new string[0]; }
    public static void Set(TextReader r) { reader = r; Init(); }
    public static void Set(string file) { reader = new StreamReader(file); Init(); }
    public static bool HasNext() { return CheckNext(); }
    public static string String() { return Next(); }
    public static int Int() { return int.Parse(Next()); }
    public static long Long() { return long.Parse(Next()); }
    public static double Double() { return double.Parse(Next()); }
    public static int[] IntLine() { return Array.ConvertAll(Split(Line()), int.Parse); }
    public static int[] IntArray(int N) { return Range(N, Int); }
    public static int[][] IntTable(int H) { return Range(H, IntLine); }
    public static string[] StringArray(int N) { return Range(N, Next); }
    public static string[][] StringTable(int N) { return Range(N, () => Split(Line())); }
    public static string Line() { return reader.ReadLine().Trim(); }
    public static T[] Range<T>(int N, Func<T> f) { var r = new T[N]; for (int i = 0; i < N; r[i++] = f()) ; return r; }
    static string[] Split(string s) { return s.Split(separator, op); }
    static string Next() { CheckNext(); return A[i++]; }
    static bool CheckNext()
    {
        if (i < A.Length) return true;
        string line = reader.ReadLine();
        if (line == null) return false;
        if (line == "") return CheckNext();
        A = Split(line);
        i = 0;
        return true;
    }
}

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

const int inf = int (1e9) + 7;
const long long INF = 1e18;
const double eps = 1e-9;

using namespace std;

int main(){
	#ifdef nurik
	freopen ("in", "r", stdin);
	#endif

	ios_base::sync_with_stdio(0);

	int n, h, w;

	cin >> h >> w >> n;

	if(h < w)
		swap(h, w);

	int sum = 0, res = 0;
	for(int i=1; n > 0 && i <= w; ++i){
		sum += h;
		res++;
		n -= h;
	}

	cout << res;

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
const int  N = 100005;
int output[N << 1];
int main(){
    int n;      cin >> n;
    for(int i = 1;i < n;i++){
        int a;    cin >> a;
        output[a]++;
    }
    for(int i = 1;i <= n;i++)
        cout << output[i] << "\n";
    return 0;
}

Measured memory_bytes: 3940
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1E9
#define EPS 1E-9
#define MOD 1000000007
#define PI 3.1415926535897932384

template <class T>ostream &operator<<(std::ostream &o, const vector<T> &v)
{
	rep(i, v.size()) {
		o << (i > 0 ? " " : "") << v[i];
	}
	return o;
}

int main() {
	int n, t;
	ll in, high = 0;
	vi a, b, c;
	cin >> n;
	rep(i, n) {
		cin >> in;
		a.push_back(i*(n + 1) + 1);
		b.push_back((n - i - 1)*(n + 1) + 1);
		c.push_back(in);
	}
	rep(i, n) {
		t = c[i] - 1;
		b[t] += i;
	}
	cout << a << endl << b << endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h> 
using namespace std;
int main(){
	int a[33]={0,1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	int k;
	cin>>k;
	cout<<a[k]<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iomanip>

using namespace std;

int main()
{
    int n;
    cin >> n;
    int a = 0, b = 0, sum_a = 0, sum_b = 0, temp_a = 0, temp_b = 0;
    int max_sum = 1000;

    for (int i = 0; i < n-1; ++i) {
        ++a;
        b = n - a;
        temp_a = a;
        temp_b = b;
        sum_a = 0;
        sum_b = 0;

        while (temp_a > 0) {
            sum_a += temp_a % 10;
            temp_a /= 10;
        }

        while (temp_b > 0) {
            sum_b += temp_b % 10;
            temp_b /= 10;
        }

        if (sum_a + sum_b < max_sum) {
            max_sum = sum_a + sum_b;
        }
    }

    cout << max_sum << endl;
}


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

int main(){
    int N,M;
    cin >> N >> M;
    int H[N];
    int max[N];
    for (int i=0;i<N;i++) cin >> H[i];
    for (int i=0;i<N;i++) max[i]=H[i];
    int A[M],B[M];
    int ans[N];
    for(int i=0;i<N;i++) ans[i]=1;
    for(int i=0;i<M;i++){
        cin >> A[i] >> B[i];
        if (H[B[i]-1]>=H[A[i]-1]){
            ans[A[i]-1]=0;
        }
        if (H[A[i]-1]>=H[B[i]-1]){
            ans[B[i]-1]=0;
        }
    }
    int sum=0;
    for (int i=0;i<N;i++){
        sum+=ans[i];
    }
    cout << sum;
}

Measured memory_bytes: 5588
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
using namespace std;
typedef long long ll;
#define rep(i,a,n)	for(int i=a;i<n;i++)
#define rrep(i,a,n) for(int i=(a-1);i>=n;i--)
 
ll gcd(ll a,ll b){
	if(b==0)return a;
	return gcd(b,a%b);
}
ll lcm(ll a,ll b){
	ll g=gcd(a,b);
	return a/g*b;
}
int main(){
	int n;
	cin>>n;
	ll a[100010];
	rep(i,0,n){
		cin>>a[i];
	}
	sort(a,a+n);
	ll ans=0;
	ll cnt=1;
	rep(i,1,n){
		if(a[i]==a[i-1])cnt++;
		else{
			ans+=(cnt%2);
			cnt=1;
		}
	}
	ans+=(cnt%2);
	cout<<ans<<endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main()
{
  long long int n,x=1000,s=0,i,j;
  cin>>n;
  long long int a[n];
  for(i=0;i<n;i++)
    cin>>a[i];
  for(i=0;i<n-1;i++)
  {
    j=i;
    while(a[j]<=a[j+1]&&j<n-1)
    {
      j++;
    }
    s=x/a[i];
    x=x%a[i];
    x=x+s*a[j];
    i=j;
  } 
  cout<<x<<endl;
  return 0;
}

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

using namespace std;

typedef pair<int, pair<int, int>> pi;

class Solver {
public:
	static void solve() {
		int n;
		cin >> n;

		char x[1005];
		cin >> x;

		char xx[1005];
		for (int i = 0; i < 1005; i++)xx[i] = x[i];

		int d;
		cin >> d;

		for (int i = 0; i < n; i++) {
			if (d == 0)break;

			if (x[i] == '0') {
				xx[i] = '1';
				d--;
			}
		}

		for (int i = n - 1; i >= 0; i--) {
			if (d == 0)break;

			if (x[i] == '1') {
				xx[i] = '0';
				d--;
			}
		}

		cout << xx << endl;
	}
};

int main() {
	Solver::solve();
	return 0;
}


Measured memory_bytes: 3104
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <functional>
#include <limits.h>
#include <set>
#include <map>
#include <tuple>
using namespace std;

#define ll long long
#define ull unsigned long long
#define rep(i,N) for (ll i=0;i<N;i++)
#define loop(i,N,M) for(ll i=N;i<M;i++)
#define MAX(v) *max_element(v.begin(),v.end())
#define MIN(v) *min_element(v.begin(),v.end())
#define SORTL2S(type,v) sort(v.begin(),v.end(),greater<type>())
#define SORTS2L(type,v) sort(v.begin(),v.end())
#define SORTMF(v,func) sort(v.begin(),v.end(),func)

template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*)array, (T*)(array + N), val);
}

ll N;
vector<ll> vec;

void solve() {
	cin >> N;
	vec.resize(N);
	bool po = false, ne = false;
	rep(i, N) {
		cin >> vec[i];
		if (vec[i] >= 0) po = true;
		if (vec[i] < 0) ne = true;
	}
	SORTS2L(ll, vec);
	vector<pair<ll, ll>> ans;

	if (po == true && ne == false) {
		ll mm = vec[0];
		rep(i, N - 2) {
			ans.emplace_back(make_pair(mm, vec[i + 1]));
			mm -= vec[i+1];
		}
		ans.emplace_back(make_pair(vec[N - 1], mm));
		mm = vec[N - 1] - mm;

		cout << mm << endl;
		rep(i, N - 1) {
			cout << ans[i].first << " " << ans[i].second << endl;
		}

	}

	if (po == false && ne == true) {
		ll mx = vec[N - 1];
		rep(i, N - 2) {
			ans.emplace_back(make_pair(mx, vec[N-i-2]));
			mx -= vec[N - i - 2];
		}
		ans.emplace_back(make_pair(mx, vec[0]));
		mx = mx - vec[0];

		cout << mx << endl;
		rep(i, N - 1) {
			cout << ans[i].first << " " << ans[i].second << endl;
		}
	}

	if (po == true && ne == true) {
		ll mx = vec[N - 1];
		rep(i, N - 2) {
			if (vec[i + 1] > 0) break;
			ans.emplace_back(make_pair(mx, vec[i+1]));
			mx -= vec[i + 1];
		}
		ll mm = vec[0];
		rep(i, N - 2) {
			if (vec[N-i-2] <= 0) break;
			ans.emplace_back(make_pair(mm, vec[N-i-2]));
			mm -= vec[N-i-2];
		}

		ans.emplace_back(make_pair(mx, mm));
		mx = mx - mm;

		cout << mx << endl;
		rep(i, N - 1) {
			cout << ans[i].first << " " << ans[i].second << endl;
		}

	}

}

int main() {
	solve();
	cout << endl;
	return 0;
}

Measured memory_bytes: 4336
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
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; }
typedef long long ll;
const long long INF = 1LL << 60;
const long long MOD = 1e9 + 7;
const int MAX_V = 200000;
typedef pair<int, int> P;
int N, K;
ll ans = 0;
vector<vector<int>> G(MAX_V);
vector<bool> check(MAX_V);

void dfs(int v, int d) {
    ll c = K - 1;
    check[v] = true;
    if (d >= 1) c--;
    for (int to : G[v]) {
        if (check[to]) continue;
        ans *= c;
        ans %= MOD;
        c--;
        dfs(to, d + 1);
    }
}

int main()
{
    cin >> N >> K;
    rep(i, N - 1) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    
    ans = K;
    dfs(0, 0);

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

Measured memory_bytes: 14528
using System;
class p
{
  static void Main()
  {
    string S = Console.ReadLine();
    int n = S.Length / 2, count = 0;
    for (int i = 0; i < n; i++) {
      if (S[i] != S[(S.Length - 1) - i]) { count++; }
    }
    Console.WriteLine(count);
  }
}

Measured memory_bytes: 11092