akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
typedef unsigned int uint;
using namespace std;

int main(){
  int N,K;
  cin >> N >> K;
  int x[N];
  for(int i=0;i<N;i++) cin >> x[i];

  int ans = 0;
  for(int i=0;i<N;i++){
    int dist = min(x[i] , K-x[i]);
    ans += dist * 2;
  }

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

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

unordered_map<string, long long> m;

long long n, t;
string s;
int main(){
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> s;
        sort(s.begin(), s.end());
        t += m[s]; m[s]++;
    }
    cout << t;
}


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

int main() {
    int h, w; cin >> h >> w;
    vector< vector<int> > a(h, vector<int>(w));
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            cin >> a.at(i).at(j);
        }
    }
    int n = 0;
    vector< vector<int> > op(h * w, vector<int>(4));
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (i == h - 1 && j == w - 1) break;
            if (a.at(i).at(j) % 2 == 1) {
                if (i == h - 1) {
                    a.at(i).at(j + 1)++;
                    op.at(n) = {i, j, i, j + 1};
                } else {
                    a.at(i + 1).at(j)++;
                    op.at(n) = {i, j, i + 1, j};
                }
                n++;
            }
        }
    }
    cout << n << endl;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 4; j++) {
            cout << op.at(i).at(j) + 1;
            if (j < 3) cout << " ";
            else cout << endl;
        }
    }
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

set<pair<int,int>> S;
set<pair<int,int>> S2;
ll H,W,N;
ll A[10];
void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>H>>W>>N;
	FOR(i,N) {
		cin>>x>>y;
		S.insert({x,y});
		FOR(j,3) FOR(k,3) S2.insert({x-j,y-k});
	}
	
	A[0]=(H-2)*(W-2);
	FORR(r,S2) {
		x = r.first;
		y = r.second;
		if(x<=0 || x+2>H) continue;
		if(y<=0 || y+2>W) continue;
		int ret=0;
		FOR(j,3) FOR(k,3) ret += S.count({x+j,y+k});
		
		A[ret]++;
		A[0]--;
		
	}
	FOR(i,10) cout<<A[i]<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


Measured memory_bytes: 47104
#include<bits/stdc++.h>
#define EPS (1e-8)
using namespace std;
typedef complex<double> point;
typedef pair<point,point> line;

//??????
double dot(point a,point b){
  return real(conj(a)*b);
}

//??????
double cross(point a,point b){
  return imag(conj(a)*b);
}

point crosspoint_ll(line l1, line l2){
  double a=cross(l1.second-l1.first,l2.second-l2.first);
  double b=cross(l1.second-l1.first,l1.second-l2.first);
  if(fabs(a)<EPS&&fabs(b)<EPS)return l2.first;
  else if(fabs(a)>=EPS) return l2.first+b/a*(l2.second-l2.first);
} 

int ccw(point a,point b,point c){
  point d=b-a;
  point e=c-a;
  if(cross(d,e)>0)return 1;//?????´
  if(cross(d,e)<0)return -1;//?????´
  if(dot(d,e)<0)return 2;//onlineback
  if(abs(d)<abs(e))return -2;//onlinefront
  return 0;//onsegment
}

vector<point> Convex_Cut(vector<point> polygon,line l){
  vector<point> res;
  for(int i=0;i<polygon.size();i++){
    point a=polygon[i],b=polygon[(i+1)%polygon.size()];
    if(ccw(l.first,l.second,a)!=-1)res.push_back(a);
    if(ccw(l.first,l.second,a)*ccw(l.first,l.second,b)<0)
      res.push_back(crosspoint_ll(line(a,b),l));
  }
  return res;
}

double get_area(vector<point> polygon){
  double res=0;
  for(int i=0;i<polygon.size();i++)
    res+=cross(polygon[i],polygon[(i+1)%polygon.size()]);
  return res/2;
}

int main(){
  int n,q,x,y;
  vector<point> v;
  cin>>n;
  for(int i=0;i<n;i++)
    cin>>x>>y,v.push_back(point(x,y));
  cin>>q;
  for(int i=0;i<q;i++){
    point p1,p2;
    cin>>x>>y;
    p1=point(x,y);
    cin>>x>>y;
    p2=point(x,y);
    printf("%.8f\n",get_area(Convex_Cut(v,line(p1,p2))));
  }
  return 0;
}

Measured memory_bytes: 1248
// 2011/02/15 Tazoe

#include <iostream>
using namespace std;

struct bridge{
	int a;
	int b;
	int c;
	bool chk;
};

int main()
{
	while(true){
		int n, m;
		cin >> n >> m;
		if(n==0&&m==0)
			break;

		struct bridge brd[4950];
		for(int i=0; i<m; i++){
			cin >> brd[i].a >> brd[i].b >> brd[i].c;
			brd[i].chk = false;
		}

		int ttl = 0;
		int num = m;
		while(num>0){
			int i_min = -1;
			int c_min = 200;
			for(int i=0; i<m; i++){
				if(brd[i].chk)
					continue;
				if(brd[i].c<c_min){
					i_min = i;
					c_min = brd[i].c;
				}
			}

			ttl += brd[i_min].c;
			int n_fr = brd[i_min].a;
			int n_to = brd[i_min].b;
			brd[i_min].chk = true;
			num--;

			for(int i=0; i<m; i++){
				if(brd[i].chk)
					continue;
				if(brd[i].a==n_fr)
					brd[i].a = n_to;
				else if(brd[i].b==n_fr)
					brd[i].b = n_to;
				else
					continue;
				if(brd[i].a==brd[i].b){
					brd[i].chk = true;
					num--;
				}
			}
		}

		cout << ttl << endl;
	}

	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
typedef pair<int,int> p;
const int inf=(1<<30);
#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--)
	
int main(){
	ll a,b,c;
	cin>>a>>b>>c;
	ll x=min(c,b);
	ll y=a-b-c;
	if(y<0)cout<<x<<' '<<abs(y)<<endl;
	else cout<<x<<' '<<0<<endl;
}

Measured memory_bytes: 256
from math import floor
A = [int(input()) for _ in range(5)]

ans = 0
tmp = 10
for a in A:
    q, mod = divmod(a, 10)
    if mod == 0:
        ans += q
    else:
        ans += q+1
        tmp = min(tmp, mod)
        
print(ans*10 - (10 - tmp))

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#define INF 10000000000000000
#define ll long long

using namespace std;

int main(){
  ll V, E, r;
  cin >> V >> E >> r;
  vector< vector< pair<ll,ll> > > edges(V);
  for(ll i = 0; i < E; i++){
    ll s,t,d;
    cin >> s >> t >> d;
    edges[s].push_back(make_pair(t,d));
  }
  vector<ll> dist(V, INF);
  dist[r] = 0;
  for(ll i = 0; i < E; i++){
    for(ll k = 0; k < V; k++){
      for(pair<ll,ll> edge: edges[k]){
	if(dist[k] != INF && dist[edge.first] > dist[k] + edge.second){
	  if(i == E-1){
	    cout << "NEGATIVE CYCLE" << endl;
	    return 0;
	  }
	  dist[edge.first] = dist[k] + edge.second;
	}
      }
    }
  }

  for(ll i = 0; i < V; i++){
    if(dist[i] == INF){
      cout << "INF" << endl;
    }else{
      cout << dist[i] << endl;
    }
  }
}

Measured memory_bytes: 3168
import Foundation


func readStr() -> String {
  return readLine()!
}

func readInt() -> Int {
    return Int(readLine()!)!
}

func readInts() -> [Int] {
    return readLine()!.split(separator: " ").map { Int($0)! }
}

func readTwoInts() -> (a: Int, b: Int) {
    let ints = readLine()!.split(separator: " ").map { Int($0)! }
    return (a: ints[0], b: ints[1])
}

var (N, X) = readTwoInts()
var mn = 10000000087
for _ in 0..<N {
    let m = readInt()
    X -= m
    mn = min(mn, m)
}

if X >= mn {
    N += X / mn
    print(N)
} else {
    print(N)
}




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

int main() {
    string s;
    cin >> s;
    string ans = "No";
    if (s[2] == s[3] && s[4] == s[5]) ans = "Yes";
    cout << ans << endl;
}

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

int main() {
    int n, W;
    cin >> n >> W;
    
    rep(i, n) cin >> v[i] >> w[i];
    
    int dp[n+1][W+1];
    rep(i, W+1) dp[0][i] = 0;
    
    rep(i, n){
        rep(j, W+1){
            if(j >= w[i]){
                dp[i+1][j] = max(dp[i][j-w[i]] + v[i], dp[i][j]);
            }else{
                dp[i+1][j] = dp[i][j];
            }
        }
    }
    
    cout << dp[n][W] << endl;
    return 0;
}


Measured memory_bytes: 7040
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(c) begin(c), end(c)
#define dump(x) cerr << __LINE__ << ":\t" #x " = " << (x) << endl

vector<vector<int>> g, rg;
int E;

vector<int> vis;
vector<int> arr;
vector<int> ord;

vector<int> par;

void tsort(int v) {
    vis[v] = true;
    for (auto &c : g[v]) {
        if (!vis[c]) tsort(c);
    }
    arr.push_back(v);
}

int main() {
    int n, m;
    while (cin >> n >> m) {
        E = n + m - 1;
        g.assign(n, {});
        rg.assign(n, {});
        rep(i, E) {
            int a, b;
            cin >> a >> b;
            --a; --b;
            g[a].push_back(b);
            rg[b].push_back(a);
        }

        vis.assign(n, false);
        par.assign(n, -1);
        arr.clear();
        rep(i, n) {
            if (!vis[i]) tsort(i);
        }
        reverse(all(arr));

        ord.resize(n);
        rep(i, n) {
            ord[arr[i]] = i;
        }
        rep(v, n) {
            int par = -1;
            for (auto &src : rg[v]) {
                if (par == -1 || ord[par] < ord[src]) {
                    par = src;
                }
            }
            cout << par + 1 << '\n';
        }
        // puts("aaa");
    }
}


Measured memory_bytes: 16636
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		String s=scan.next();
		String t=scan.next();
		int count=0;
		
		char[] c = s.toCharArray();
		char[] d = t.toCharArray();
		
        for(int i=0; i<s.length();i++) {
            if(c[i]!=d[i])	count++;
        }
        
        System.out.println(count);
	}

}


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

int main() {
  
  int a, flag=0;
  cin >> a;
  
  for( int b=1; b<=9; b++ ){
    for( int c=1; c<=9; c++ ){
      if( a == b*c ){
        flag++;
      }
    }
  }
  
  if( flag>0 ){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
////////////////////////////////////////////////////////////////////
// This source code is for Visual Studio
////////////////////////////////////////////////////////////////////
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <stack>
#include <functional>
#include <iomanip>
#include <string>
#include <cstring>
#include <deque>
#include <math.h>
#include <assert.h>

#define	numberof(a)	(sizeof(a) / sizeof(a[0]))
#define	INF32		INT32_MAX
#define	INF64		INT64_MAX
#define Rep(i,n) for(int i = 0; i < (n); ++i )

using namespace std;

typedef vector< vector<int> > MAT;
typedef pair<int, int> PINT;
typedef long long ll;
typedef uint32_t u32;
typedef uint64_t u64;
typedef int32_t s32;
typedef int64_t s64;

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

// main function
int main()
{
	ll A = 0;
	ll B = 0;
	ll C = 0;
	ll K = 0;
	ll ans = 0;

	cin >> A >> B >> C >> K;
	if (K % 2 == 0) {
		ans = A - B;
	}
	else {
		ans = B - A;
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <utility>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;

#define INF_LL (ll)1e18
#define INF (int)1e9
#define REP(i, n) for(int i = 0;i < (n);i++)
#define FOR(i, a, b) for(int i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
using ll = long long;
using PII = pair<int, int>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

int main(void){
	int d[10][10] = {};
	int H, W;
	cin >> H >> W;
	REP(i, 10){
		REP(j, 10){
			int c;
			cin >> d[i][j];
		}
	}
	REP(k, 10){
		REP(i, 10){
			REP(j, 10){
				d[i][j] = min(d[i][j], d[i][k]+d[k][j]);
			}
		}
	}
	int res = 0;
	REP(i, H){
		REP(j, W){
			int A;
			cin >> A;
			if(A == -1) continue;
			res += d[A][1];
		}
	}
	cout << res << endl;
}


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

using namespace std;

typedef long long ll;

const ll MOD = 1000000007;

ll n, x;

// i から k 戻る
ll circle(int i, int k){
    if(i - k >= 0) return i - k;
    return n - (k - i);
}

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cin >> n >> x;
    ll a[n];
    for(int i=0;i<n;i++) cin >> a[i];

    // {a_i, a_{i-1}, ..., a_{i-k}} のうち最小の a 
    ll mina[n];

    // 魔法なし
    ll ans = 0;
    for(int i=0;i<n;i++){
        mina[i] = a[i];
        // cout << mina[i] << " ";
        ans += a[i];
    }
    // cout << endl;

    // 魔法を唱える回数
    for(int k=1;k<n;k++){
        ll sec = 0;
        for(int i=0;i<n;i++){
            mina[i] = min(mina[i], a[circle(i, k)]);
            // cout << mina[i] << " ";
            sec += mina[i];
        }
        // cout << endl;
        sec += k * x;
        ans = min(ans, sec);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)   for(signed i=0; i<n; i++)
#define yn(b)   cout << ((b)?"Yes":"No") << endl
#define YN(b)   cout << ((b)?"YES":"No") << endl
#define pr(r)   cout << r << endl
#define str string
int main(void){
    str s;
    cin >> s;
    if(s.at(5)=='1') pr("TBD");
    else{
        switch (s.at(6)){
            case '1':
                pr("Heisei");
                break;
            case '2':
                pr("Heisei");
                break;
            case '3':
                pr("Heisei");
                break;
            case '4':
                pr("Heisei");
                break;
            default:
                pr("TBD");
        }
    }
}

Measured memory_bytes: 256
n = int(input())
A = list(map(int, input().split()))

ans = []
for i in range(n):
  ind = -1
  for j in range(len(A)):
    if A[j] == j + 1:
      ind = j
  if ind == -1:
    break
  else:
    A.pop(ind)
    ans.append(ind+1)

if ind == -1:
  print(-1)
else:
  ans.reverse()
  for a in ans:
    print(a)

Measured memory_bytes: 64108
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<queue>
#include<map>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int MAXN = 50 + 5;
const ll linf = 0x3f3f3f3f3f3f3f3f;

bool check(const string &s)
{
	for(int i=0; i<(int)s.size()-i-1; ++i)
		if(s[i] != s[(int)s.size()-i-1]) return 0;
	return 1;
}

string s[MAXN];
int c[MAXN];

typedef pair<ll, pair<bool,string> > State;

ll ans = linf;
map<pair<bool,string>, ll> dis;
priority_queue<State,vector<State>,greater<State> > q;

inline void push(const bool x, const string &s, ll d)
{
	if(d >= ans) return;
	pair<bool, string> u = make_pair(x,s); 
	
	map<pair<bool, string>,ll>::iterator it = dis.find(u);
	if(it!=dis.end() && it -> second <= d) return;
	
	dis[u] = d;
	q.push(make_pair(d,u));
}

inline void gao(const string &s,const string &t, ll d)
{
	if(d>=ans) return;
	for(int i=0; i<(int)s.size() && i<(int)t.size(); ++i)
		if(s[i] != t[(int)t.size()-i-1]) return;
	if((int)s.size() == (int)t.size()){ ans = min(ans, d); return;}
	
	string now = s.size() > t.size()? s.substr(t.size()): t.substr(0,t.size()-s.size());
	if(check(now)){ ans = min(ans, d); return;}
	
	push(!(s.size() > t.size()), now, d);
}

int main(void)
{
	int n;
	scanf("%d",&n);
	for(int i=1; i<=n; ++i)
		cin>>s[i]>>c[i];
	
	for(int i=1; i<=n; ++i)
	{
		if(check(s[i])) ans = min(ans, (ll)c[i]);
		else push(0, s[i], c[i]);
	}
	
	while(!q.empty())
	{
		State uu = q.top(); q.pop();
		if(dis[uu.second] != uu.first) continue;
		pair<bool,string> &u = uu.second;
		
		for(int i=1; i<=n; ++i)
		{
			if(u.first == 0)
				gao(u.second, s[i], uu.first + c[i]);
			else
				gao(s[i], u.second, uu.first + c[i]);
		}
	}
	
	if(ans == linf) printf("-1");
	else printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 3828
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <string>
#include <cctype>
#include <map>
#include <queue>

using namespace std;

const int mod = 1000000007;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
#define ll long long

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

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

        sum += to - from + 1;
    }
    
    cout << sum << endl;
}

Measured memory_bytes: 256
/* ex6_2
   moka223711 */

#include <stdio.h>
#include <string.h>

int main(void){
    char str[101];
    int len;
    scanf("%s", str);
    len = strlen(str);
    
    printf("%c%d%c", str[0], len-2, str[len-1]);
    return 0;
}



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

using namespace std;

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

int main(){
    int n;
    cin >> n;
    vector<P> t;
    for(int i = 0; i < n; i++){
        ll a, b;
        cin >> a >> b;
        t.push_back(P(b, a));
    }
    sort(t.begin(), t.end());
    ll pre=0;
    for(int i = 0; i < n; i++){
        if(pre+t[i].second > t[i].first){
            cout << "No" << endl;
            return 0;
        }
        pre+=t[i].second;
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 6580
#include <bits/stdc++.h>
#include <stdio.h>
#define ll long long
#define fr(i,p,n) for(ll i=p;i<n;i++)
#define fr1(i,p,n) for(ll i=p;i>=n;i--)
#define FAST ios::sync_with_stdio(0);
#define sz(v) (ll)v.size()
#define pb push_back
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define PI 3.14159265358979323846
#define mod 1000000007
#define mod1 998244353
#define precise cout << std::setprecision(12) << std::fixed;
#define endl "\n"
using namespace std;

int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    FAST
    int t=1;
    //cin>>t;
    while(t--)
    {
        int r,g,b;
        cin>>r>>g>>b;
        int k;
        cin>>k;
        int cnt=0;
        while(g<=r)
        {
            g*=2;
            cnt++;
        }
        while(b<=g)
        {
            b*=2;
            cnt++;
        }
        if(cnt<=k) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 3648
#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
#define LC(x) (x<<1)
#define RC(x) ((x<<1)+1)
#define MID(x,y) ((x+y)>>1)
#define CLR(arr,val) memset(arr,val,sizeof(arr))
#define FAST_IO ios::sync_with_stdio(false);cin.tie(0);
typedef pair<int, int> pii;
typedef long long LL;
const double PI = acos(-1.0);
const int N = 810;
char pos[N][N];
int step[N][N];
struct info
{
    int x, y, step;
    info operator+(info b)
    {
        b.x += x;
        b.y += y;
        b.step += step;
        return b;
    }
};
info S, dir[4] = {{1, 0, 1}, { -1, 0, 1}, {0, 1, 1}, {0, -1, 1}};
int n, m, k;

void init()
{
    CLR(step, -1);
}
inline bool check(const info &t)
{
    return t.x >= 0 && t.x < n && t.y >= 0 && t.y < m && step[t.x][t.y] == -1 && pos[t.x][t.y] == '.';
}
void bfs()
{
    queue<info>Q;
    Q.push(S);
    step[S.x][S.y] = 1;
    while (!Q.empty())
    {
        info u = Q.front();
        Q.pop();
        for (int i = 0; i < 4; ++i)
        {
            info v = u + dir[i];
            if (check(v))
            {
                step[v.x][v.y] = v.step;
                Q.push(v);
            }
        }
    }
    return ;
}
int main(void)
{
    int i, j;
    while (~scanf("%d%d%d", &n, &m, &k))
    {
        init();
        for (i = 0; i < n; ++i)
        {
            scanf("%s", pos[i]);
            for (j = 0; j < m; ++j)
            {
                if (pos[i][j] == 'S')
                {
                    S.x = i;
                    S.y = j;
                    S.step = 0;
                }
            }
        }
        bfs();
        int ans = INF;
        for (i = 0; i < n; ++i)
        {
            for (j = 0; j < m; ++j)
            {
                if (~step[i][j])
                {
                    int L=j;
                    int R=m-1-j;
                    int U=i;
                    int D=n-1-i;
                    int base=ceil(step[i][j]*1.0/k);
                    ans=min(ans,base+(int)ceil(L*1.0/k));
                    ans=min(ans,base+(int)ceil(R*1.0/k));
                    ans=min(ans,base+(int)ceil(U*1.0/k));
                    ans=min(ans,base+(int)ceil(D*1.0/k));
                }
            }
        }
        printf("%d\n", ans);
    }
    return 0;
}


Measured memory_bytes: 3456
# W分の配列を用意、全Wに対してVが最大になるものを見つける
N,W=map(int,input().split())
WV=[list(map(int,input().split())) for _ in range(N)]

dp=[-1]*(W+1)
dp[0]=0
for i in range(N):
  w,v=WV[i]
  for j in range(W-w,-1,-1): # 逆順じゃないと同じものを二つ選べる
    if dp[j]!=-1:
      dp[j+w]=max(dp[j+w],dp[j]+v)
print(max(dp))

Measured memory_bytes: 41708
#include<stdio.h>

int main(void){
	int in[100],out[100],data[100];
	int i=0,j=-1,n=-1;
	
	while(scanf("%d",&in[i])==1){
		if(in[i]>0){
			n++;
			data[n]=in[i];
		}
		if(in[i]==0){
			j++;
			out[j]=data[n];
			n--;
		}
		i++;
	}
	for(i=0;i<=j;i++)
		printf("%d\n",out[i]);
		
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << min(a, b) + min(c, d) << endl;
}

Measured memory_bytes: 256
from collections import Counter

N = int(input())

A = list(map(int,input().split()))

back = -1
same = 1
ans = 0
for a in A:
    if a==back:
        same+=1
    else:
        ans += same//2
        same=1
    back = a
    
ans += same//2
    
print(ans)

Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
int main(){
	long n,k;
	cin>>n>>k;
	long sum=0;
	if(k==0){
	    cout<<n*n;
	    return 0;
	}
	for(int i=k+1; i<=n; i++)
	    sum+=(n/i)*(i-k)+max(n%i-k+1,(long)0);	
	cout<<sum;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <string>

using namespace std;

int main(){

	string S;
	int K;

	cin >> S;
	cin >> K;

	// Sの最初に1が何個あるか
	int ones = 0;
	for (int i = 0; i < S.length(); i++){
		if (S[i] == '1') ones++;
		else break;
	}

	if (S.length() == 1)
		cout << S[0] << endl;
	else
		if (S[0] == '1'){
			if (ones >= K)
				cout << "1" << endl;
			else
				cout << S[ones] << endl;
		}
		else
			cout << S[0] << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
  using namespace std;
#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) int ab;cin>>ab;(p).push_back(ab);
#define vecpl2(p) long long ab;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
 		
 		
int main() {

int N,K;
vec(A)
  cin>>N>>K;
fx(N){
	vecp(A)
}
if((N-1)%(K-1)==0){
ce((N-1)/(K-1))
}else{
  ce((N-1)/(K-1)+1)
}
}


Measured memory_bytes: 892
using System;
using System.Linq;
using System.Collections.Generic;

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine();
            var t = Console .ReadLine();
            var dict = new Dictionary<char, List<int>>();
            for (var i = 0; i < s.Length; i++) {
               if (dict.ContainsKey(s[i]))
                   dict[s[i]].Add(i+1);
               else
               {
                  dict[s[i]] = new List<int>();
                  dict[s[i]].Add(i+1);
               }
            }

            var ans = 0L;
            var bef = 0;
            for (var i = 0; i < t.Length; i++) {
                if (!dict.ContainsKey(t[i])) {
                   Console.WriteLine(-1);
                   return;
                } else {
                   var list = dict[t[i]];
                   var cur = UpperBound(list, bef);
                   if (cur < list.Count) {
                      ans += list[cur] - bef;
                      bef = list[cur];
                   } else {
                      ans += s.Length - bef + list[0];
                      bef = list[0];
                   }
                   //Console.WriteLine(ans);
                }
            }
            
            Console.WriteLine(ans);
        }

        public static int UpperBound(List<int> arr, int start, int end, int value, IComparer<int> comparer)
        {
            int low = start;
            int high = end;
            int mid;
            while (low < high)
            {
                mid = ((high - low) >> 1) + low;
                if (comparer.Compare(arr[mid], value) <= 0)
                    low = mid + 1;
                else
                    high = mid;
            }
            return low;
        }

        public static int UpperBound(List<int> arr, int value)
        {
            return UpperBound(arr, 0, arr.Count, value, Comparer<int>.Default);
        }
    }
}


Measured memory_bytes: 15200
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>
#include "math.h"
#include <set>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define VI vector<int>
#define debug(x) cout<<#x<<": "<<x<<endl
#define DEBUG(x) cout<<#x<<": "<<x<<endl
double A,B,X;
string s;
vector <int > H;
int main()
{

	cin >> s;
	int ans =0;
	REP(i,s.length()/2){
		if(s[i] != s[s.length()-i-1]){
			ans++;
		}
	}

	cout << ans;

}




Measured memory_bytes: 256
#!/usr/bin/env python3

n = int(input())

data = {}
for i in range(n):
    s, p = list(map(str, input().split()))
    p = int(p)
    if s in data:
        data[s].append([p, i+1])
    else:
        data[s] = [[p, i+1]]

# print(data)
name_list = list(data.keys())
name_list.sort()


for i in name_list:
    data_tmp = data[i]
    data_tmp = sorted(data_tmp, key=lambda x: x[0], reverse=True)
    for j in data_tmp:
        print(j[1])


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

using namespace std;

int main(){
  int N;
  cin >> N;
  long long int ans = 0;
  int mod = 1000000007;
  long long int sum = 0;
  for(int i = 0; i < N; i++){
    long long int a;
    cin >> a;
    ans += (a * sum) % mod;
    sum += a;
    sum %= mod;
  }
  cout << ans % mod << endl;
  return 0;
}

Measured memory_bytes: 3636
#python3
INF = 10**9
def dist(tuple_a, tuple_b):
    return abs(tuple_a[0] - tuple_b[0]) + abs(tuple_a[1] - tuple_b[1])

def main():
    n, m = map(int, input().split())
    p = []
    for _ in range(n):
        a, b = map(int, input().split())
        p.append((a, b))
    chp = []
    for _ in range(m):
        c, d = map(int, input().split())
        chp.append((c, d))
    ans = []
    for i in range(n):
        tmp = INF
        v = 0
        point = p[i]
        for j in range(m):
            di = dist(point, chp[j])
            if  di < tmp: 
                tmp = di
                v = j
        ans.append(v)
    for i in range(n):
        print(ans[i]+1)
main()


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

using namespace std;

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

typedef long long ll;

const int Inf = 1e9;
const double EPS = 1e-9;

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

int lcm(int a, int b) {
    return a * b / gcd(a, b);
}

int bitCount(long bits) {
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, k;  cin >> n >> k;
    ll ans = 1;
    ans *= k;
    rep (i, n - 1) {
      ans *= k - 1;
    }
    cout << ans << '\n';

    return 0;
}


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

int h, n;
vector<int> a(100000);
int main(){
  cin >> h >> n;
  for(int i=0;i<n;i++){
    cin >> a.at(i);
  }
  int point=0;
  for(int i=0;i<n;i++){
    point += a.at(i);
    if(point >= h){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;

  cin >> N;
 
  if ((N >= 1110) && (9 >= N % 1110)) {
    cout << "Yes" << endl;
  } else if (0 == N % 1000 % 111) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define SORT(x) sort(x.begin(),x.end())
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
#define No cout<<"No"<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define YES cout<<"YES"<<endl;
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main(){
    ll a,b;
    cin>>a>>b;
    if((a+b)%2==1){
        cout<<"IMPOSSIBLE"<<endl;
    }
    else{
        cout<<(a+b)/2<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <deque>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define print(x) cout<<(x)<<endl
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define INF10 1001001001 
#define INF5 100000
#define EPS 1e-10


int main() {
	int N, M, C; cin >> N >> M >> C;
	vector<int>B(M);
	REP(i, M)cin >> B[i];
	vector<int>A(M);
	int cnt = 0;
	REP(i, N) {
		REP(i, M)cin >> A[i];
		int ans = C;
		REP(i, M)ans += A[i] * B[i];
		if (ans > 0)cnt++;
	}
	print(cnt);

	return 0;
}


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

const int N = 100005;

int n, v[N];
long long c, x[N], y[N], l[N], ml[N], r[N], mr[N];

int main()
{
    scanf("%d%lld", &n, &c);
    for (int i = 1; i <= n; i++)
    {
        scanf("%lld%d", x + i, v + i);
        y[n + 1 - i] = c - x[i];
    }
    for (int i = 1; i <= n; i++)
    {
        l[i] = l[i - 1] + x[i - 1] - x[i] + v[i];
        ml[i] = max(ml[i - 1], l[i]);
        r[i] = r[i - 1] + y[i - 1] - y[i] + v[n + 1 - i];
        mr[i] = max(mr[i - 1], r[i]);
    }
    long long ans = max(ml[n], mr[n]);
    for (int i = 1; i <= n; i++)
    {
        ans = max(ans, l[i] - x[i] + mr[n - i]);
        ans = max(ans, r[i] - y[i] + ml[n - i]);
    }
    printf("%lld", ans);
}

Measured memory_bytes: 5376
def main():
    sea = 1
    n = int(input())
    h = list(map(int, input().split()))
    mountain = h[0]
    for i in range(1, n):
        if mountain <= h[i]:
            sea += 1
            mountain = h[i]
    print(sea)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9040
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define INF 1000000000 //1e9

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

    int N, K;
    cin>>N>>K;

    /*if (K == 0) {
        cout << N * N << endl;
        return 0;
    }*/

    ll ans = 0;
    FOR(b, K+1, N+1) {
        int p = N / b;
        int r = N % b;
        ans += (b - K) * p;
        ans += max(0, r - K + 1 - !K);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;

ll a, b, q;
vector<P> v;

bool flag(P a,P b){
	if (a.first == b.first){
		return a.second < b.second;
	}
	return a.first > b.first;
}

int main(){
	while (scanf("%d,%d", &a, &b) && a + b){
		v.push_back(P(b, a));
	}
	sort(ALL(v), flag);
	while (cin >> q){
		ll co = 0, k = -1;
		REP(i, v.size()){
			if (v[i].first != k){
				co++;
				k = v[i].first;
			}
			if (v[i].second == q){
				cout << co << endl;
				break;
			}
		}
	}
}

Measured memory_bytes: 1244
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(){
  int i,m,r=1e9,n;
  char s[11];
  scanf("%s",s);
  m=strlen(s);
  for(i=0;i<m-2;i++){
    n=100*(s[i]-'0')+10*(s[i+1]-'0')+s[i+2]-'0';
    if(abs(753-n)<r)r=abs(753-n);
  }
  printf("%d",r);
  return 0;
}

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

int main(){
  long long a,b;
  cin >> a >> b;
  if (a == b-1) cout << "Brown" << endl;
  else if (b == a-1) cout << "Brown" << endl;
  else if (b == a) cout << "Brown" << endl;
  else cout << "Alice" << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip>//setprecision
#include<math.h>
#include <functional>
#include<climits>
using namespace std;
#define rep(i, n)        for(int i=0; i<(int)(n); ++i)
#define ll  long long 
  vector<ll>to[1000005];
int main(){
  ll n,m;cin>>n>>m;
  rep(i,m){
    ll a,b;cin>>a>>b;a--;b--;
    to[a].push_back(b);
    to[b].push_back(a);
  } 
  queue <ll>q;
  vector<ll>dist(n,INT_MAX);
  vector<ll>pre(n,-1);
  dist[0]=0;
  q.push(0);
  while(!q.empty()){
    ll v=q.front();q.pop();
    for(ll u:to[v]){
      if(dist[u]!=INT_MAX)continue;
      dist[u]=dist[v]+1;
      pre[u]=v;
      q.push(u);
    }
  }
  cout<<"Yes"<<endl;
  rep(i,n){
    if(i==0)continue;
    cout<<pre[i]+1<<endl;
  }
  }


Measured memory_bytes: 34564
#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for(long long i=0;i<(n);i++)
#define REP1(i,n) for(long long i=1;i<=(n);i++)
#define REP2D(i,j,h,w) for(long long i=0;i<(h);i++) for(long long j=0;j<(w);j++)
#define REP2D1(i,j,h,w) for(long long i=1;i<=(h);i++) for(long long j=1;j<=(w);j++)
#define PER(i,n) for(long long i=((n)-1);i>=0;i--)
#define PER1(i,n) for(long long i=(n);i>0;i--)
#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define FORE(i,a,b) for(long long i=(a);i<=(b);i++)
#define ITE(arr) for(auto ite=(arr).begin();ite!=(arr).end();++ite)
#define ALL(a) ((a).begin()),((a).end())
#define RANGE(a) (a),((a)+sizeof(a))
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define YNPRT(b) cout<<((b)?"Yes":"No")<<endl
#define ENTER printf("\n")
#define REV(arr) reverse(ALL(arr))
#define PRT(a) cout<<(a)<<endl

#ifdef DEBUG
#define DBPRT(a) cout << "[Debug] - " << #a << " : " << (a) << endl
#define DBSTART if(1){
#define DBEND }
#define PRTLST(arr,num) REP(_i,num) cout<<_i<<" - "<<arr[_i]<<endl;
#define PRTLST2(arr2,d1,d2) REP(_i,d1) REP(_j,d2) cout<<_i<<","<<_j<<" : "<<arr2[_i][_j]<<endl;
#define PRTLST2D(arr2,d1,d2) do{cout<<"L\t";REP(_i,d2) cout<<_i<<"\t"; cout<<endl; REP(_i,d1){cout<<_i<<"\t";REP(_j,d2){cout<<arr2[_i][_j]<<"\t";}cout<<endl;}}while(0);
#else
#define DBPRT(a) if(0){}
#define DBSTART if(0){
#define DBEND }
#define PRTLST(arr,num) if(0){}
#define PRTLST2(arr2,d1,d2) if(0){}
#define PRTLST2D(arr2,d1,d2) if(0){}
#endif

#define TOSUM(arr,sum,n) {sum[0]=arr[0];REP1(i,n-1) sum[i]=sum[i-1]+arr[i];}

#define MIN(target,v1) (target)=min(target,v1)
#define MAX(target,v1) (target)=max(target,v1) 
#define P1 first
#define P2 second
#define PB push_back
#define UB upper_bound
#define LB lower_bound
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int INF_INT = 2147483647;
const ll INF_LL = 9223372036854775807LL;
const ull INF_ULL = 18446744073709551615Ull;
const ll P = 92540646808111039LL;
const int Move[4][2] = {-1,0,0,1,1,0,0,-1};
const int Move_[8][2] = {-1,0,-1,-1,0,1,1,1,1,0,1,-1,0,-1,-1,-1};
template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p) {os<<"( "<<p.P1<<" , "<<p.P2<<" )";return os;}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& v) {ITE(v) os << (ite-v.begin()) << " : " << *ite <<endl;return os;}
template<typename T>
ostream& operator<<(ostream& os,const set<T>& v) {os<<" { ";ITE(v) {os<<*ite;if(ite!=--v.end()){os<<" , ";}} os<<" } ";return os;}
template<typename T1,typename T2>
ostream& operator<<(ostream& os,const map<T1,T2>& m) {ITE(m) {os<<ite->P1<<"\t\t|->\t\t"<<ite->P2<<endl;} return os;}

//---------------------
#define MAXN 100000
//---------------------

ll n;
int main(){
	cin >> n ;
	PRT((n+1)/2);
	return 0;
}









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

#define int long long
#define rep(i,l,r) for(int i=(int)(l);i<(int)(r);i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)x.size())
template<class T>bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,T b){if(a>b){a=b;return 1;}return 0;}

/*
 *  *  */

using vi = vector<int>;
using vvi = vector<vi>;
using P = pair<int,int>;

int n, m;
vi es[55];
int u[22], v[22];
int node[22];
int num[55][55];

bool dfs(int vv, int p, int mm){
  if(vv == v[mm]){
    return true;
  }

  for(int to : es[vv]) if(to != p){
    if(dfs(to, vv, mm)){
      node[mm] |= 1LL<<num[vv][to];
      return true;
    }
  }

  return false;
}

signed main() {
  cin >> n;
  rep(i, 0, n-1){
    int a, b;
    cin >> a >> b;
    es[a-1].emplace_back(b-1);
    es[b-1].emplace_back(a-1);
    num[a-1][b-1] = num[b-1][a-1] = i;
  }

  cin >> m;
  rep(i, 0, m){
    cin >> u[i] >> v[i];
    u[i]--; v[i]--;
  }

  rep(i, 0, m){
    dfs(u[i], -1, i);
//    rep(j, 0, n-1) if(node[i]>>j & 1) cout << j+1 << " ";
    //    cout << endl;
  }

  int ans = 1LL<<(n-1);
  rep(i, 1, 1<<m){
    int st = 0;
    rep(j, 0, m){
      if(i & 1LL<<j) st |= node[j];
    }

    int pop = __builtin_popcount(i);
    int cnt = __builtin_popcountll(st);
    int tmp = 1LL<<(n-1-cnt);
    //    cout << i << " " << tmp << endl;
    //    cout << i << " - " << cnt << endl;
    if(pop%2){
      ans -= tmp;
    }else{
      ans += tmp;
    }
  }

  cout << ans << endl;

  return 0;
}





Measured memory_bytes: 384
i,v,s[5000],m,*p;main(n){for(;~scanf("%d",&n);n&&printf("%d\n",m))for(n&&memset(s,i=0,n*4),m=-1e5;i++<n;)for(scanf("%d",&v),p=s+i;p---s;m=*p>m?*p:m)*p+=v;}

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

const int MAXK = 1e5 + 10;
const int MOD = 1e9 + 7;

int pref[MAXK],dp[MAXK],N,K;

int calc(int a,int b){
	if(a < 0) a = 0;
	int ans = pref[b];
	if(a != 0) ans -= pref[a-1];
	return ans % MOD;
}

int main(){

	cin >> N >> K;

	dp[0] = 1;

	for(int kid = 1;kid<=N;kid++){

		int c;
		cin >> c;

		pref[0] = dp[0];
		dp[0] = 0;
		for(int i = 1;i<=K;i++){
			pref[i] = (pref[i-1] + dp[i]) % MOD;
		}

		for(int i = 0;i<=K;i++){
			dp[i] = calc(i-c,i);
		}

	}

	int ans = dp[K];
	if(ans < 0) ans += MOD; 
	printf("%d\n",ans);

	return 0;

}

Measured memory_bytes: 4488
import java.util.Scanner;

public class Main {
 static int Search(long low, long high, long b) {
 
  long mid = 0;
  while (low < high) {
   mid = (low + high) / 2;
   long ans = mid * mid + mid;
   if (ans == b)
    return (int) mid;
   else if (ans < b)
    low = mid + 1;
   else
    high = mid;
  }
  return (int) mid;
 }

 public static void main(String[] args) {
  Scanner sc = new Scanner(System.in);

  while (true) {
   long b = sc.nextLong();
   if (b == 0)
    break;
   b *= 2;
   int max = Search(1, (long) Math.sqrt(b) + 2, b);
   int size = 1;
   int a = 0;
   for (size = max; size > 0; size--) {
    if (b % size != 0)
     continue;
    else if ((b / size - size + 1) % 2 != 0)
     continue;
    a = (int) (b / size - size + 1) / 2;
    break;
   }
   System.out.println(a + " " + size);
  }
  sc.close();
 }
}


Measured memory_bytes: 30644
#include <iostream>
#include<vector>
#include<algorithm>
#include <queue>
#include <string>
#include <set>
using namespace std;
#define ff(i,n,m) for(int i=n;i<m;i++)
#define i64 int64_t

int main() {
	int n;
	cin >> n;
	int t[101];
	int ts = 0;
	ff(i, 1, n + 1) {
		cin >> t[i];
		ts += t[i];

	}
	int m;
	cin >> m;
	ff(i, 0, m) {
		int p;
		cin >> p;
		int t1;
		cin >> t1;
		cout << ts - t[p] + t1 << endl;
	}
	return 0;
}

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

public class Main {
  public static void main(String args[] ) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    int w = Integer.parseInt(br.readLine());
    int n = Integer.parseInt(br.readLine());

    int list[] = new int[w];

    for (int i = 0; i < w; i++) {
      list[i] = i + 1;
    }

    for (int i = 0; i < n; i++) {
      String s = br.readLine();
      int a = (Integer.parseInt(s.split(",")[0])-1);
      int b = (Integer.parseInt(s.split(",")[1])-1);

      int t = list[a];
      list[a] = list[b];
      list[b] = t;
    }

    for (int i = 0; i < w; i++) {
      System.out.println(list[i]);
    }
  }
}

Measured memory_bytes: 24212
sx,sy,tx,ty=map(int,raw_input().split())
x=tx-sx
y=ty-sy
print "U"*y + "R"*x + "D"*y + "L"*x + "L" + "U"*(y+1) + "R"*(x+1) + "DR" + "D"*(y+1) + "L"*(x+1) + "U"

Measured memory_bytes: 2692
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

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

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}


int main(int argc, char const *argv[]) {
    int n,m; cin>>n>>m;
    vector<ll> h(n);
    rep(i,n) cin>>h[i];
    vector<vector<int>> g(n);
    rep(i,m) {
        int a,b; cin>>a>>b;
        --a,--b;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    auto check = [&](int x) {
        bool ret = true;
        ll t = h[x];
        for (auto &&e: g[x]) {
            if (h[e] >= t) ret = false;
        }
        return ret;
    };

    int ans = 0;
    rep(i,n) {
        if (check(i)) ans++;
    }

    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 9068
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i,n)  for(ll i=0;i<n;i++)
#define fb(i,n) for(ll i=n-1;i>=0;i--)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef pair<int,int> pii;
int main()
{
	IOS;
	//int t; cin>>t;
	//ll M=pow(10,9)+7;
	int t=1;
	while(t)
	{
		int l,r,d; cin>>l>>r>>d;
		int L,R;
		if(l%d==0) L=l/d;
		else L=l/d+1;
		R=r/d;
		int count=R-L+1;
		cout<<count;
		t--;
	}
	return 0;
}

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

nx = 0
ny = 0#現在地
nt = 0
ans = "Yes"
for i in range(n):
  t,x,y = map(int, input().split())
  if ans == "Yes":
    if ((t - nt) % 2 == ((x-nx) + (y-ny)) % 2 and  ((x-nx) + (y-ny)) <= (t - nt)):
      nt = t
      nx = x
      ny = y
    else:
      ans = "No" 
  

print(ans)
      


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i,m,n) for(ll i = (m); i < (n); i++)
#define all(v) v.begin(), v.end()
#define print(x) cout << (x) << endl

int main() {
    ll A,B,N;
    cin >> A >> B >> N;
    if(N >= B){
        cout << A*(B-1)/B << endl;
    }else {
        cout << A*N/B << endl;
    }
    return 0;
}


Measured memory_bytes: 3632