akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include<string.h>

int main()
{
char S[100];
gets(S);
if(strcmp(S,"Sunny")==0 || strcmp(S,"sunny")==0)
 {printf("Cloudy");}

else if(strcmp(S,"Cloudy")==0 || strcmp(S,"cloudy")==0)
    {printf("Rainy");}

else if(strcmp(S,"Rainy")==0 || strcmp(S,"rainy")==0)
{printf("Sunny");}
else
{}
return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#include <string.h>

int main(void)
{
  char s[100], p[100];
  int i, j, lenS = 0, lenP = 0, count;

  scanf("%s", s);
  scanf("%s", p);

  lenS = strlen(s);
  lenP = strlen(p);

  for (i = 0; i < lenS; i++) {
    count = 0;
    if (s[i] == p[0])  {
      count++;
      for (j = 1; j < lenP; j++) {
        if (s[(i + j) % lenS] != p[j])  {
          break;
        }
        else {
          count++;
        }
      }
    }
    if (count == lenP) {
      puts("Yes");
      break;
    }
    if (i == lenS - 1)  {
      puts("No");
    }
  }
  return 0;
}

Measured memory_bytes: 524
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define dbg(x) cout<<#x<<":"<<x<<endl
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;

int main(){
  int n,m;
  cin>>n>>m;
  int cnt[111111];
  for(int i=0;i<m;i++){
    int a,b;
    cin>>a>>b;
    a--,b--;
    cnt[a]++;
    cnt[b]++;
  }

  int is_odd=0;;
  for(int i=0;i<n;i++){
    if(cnt[i]%2)is_odd=1;
  }

  if(is_odd)cout<<"NO"<<endl;
  else cout<<"YES"<<endl;
  
  return 0;
}


Measured memory_bytes: 768
#include <stdio.h>

int main()
{
  int n;
  scanf("%d",&n);
  int arr[n],sum=0;
  int max=arr[0];
  for(int i=0;i<n;i++)
  {
    scanf("%d",&arr[i]);
    sum=sum+arr[i];
    if(arr[i]>max)
    {max=arr[i];}
 
  }
  int x=sum-max;
  if(x>max)
  {printf("Yes");}
  else{printf("No");}
  return 0;
}

Measured memory_bytes: 1728
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
int main() {
  int n;
  cin >> n;
  vi p(n);
  rep(i,n) cin >> p[i];
  int sum=0;
  for(int i=1;i<n-1;i++){
    if(p[i] < p[i-1] && p[i+1] < p[i]){
      sum++;
    }
    if(p[i] < p[i+1] && p[i-1] < p[i]){
      sum++;
    }
  }
   cout << sum << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=1010010010010010000;
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;
}
//グリッド：（典型）dp,dfs,bfs,最短経路,その他
int main(){
    ll a;cin>>a;
    string s;cin>>s;
    if(a>=3200) cout<<s<<endl;
    else cout<<"red"<<endl;
    return 0;
}

Measured memory_bytes: 384
s = list(str(input()))


flag = True
for i in range(len(s)//2):
    if s[i] == s[-1-i]:
        pass
    else:
        flag = False

sub_s = s[:(len(s)-1) // 2]

for i in range(len(sub_s)//2):
    if sub_s[i] == sub_s[-1-i]:
        pass
    else:
        flag = False

sub_s2 = s[(len(s)+3) // 2 - 1:]

for i in range(len(sub_s2)//2):
    if sub_s2[i] == sub_s2[-1-i]:
        pass
    else:
        flag = False

if flag:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3064
#include "iostream"
#include "vector"
#include "array"
#include "string"
#include "algorithm"
#include "functional"
#include <math.h>


using namespace std;
#define rep(p,q) for(int i = p;i < q;i++)

//A
int main(void) {
	bool one = false, four = false, seven = false, nine = false;
	rep(0, 4) {
		int num;
		cin >> num;
		switch(num) {
			case 1:
				one = true;
				break;
			case 4:
				four = true;
				break;
			case 7:
				seven = true;
				break;
			case 9:
				nine = true;
				break;

		}
	}

	if (one && four && seven && nine) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
}

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

int lcs[3009][3009];
string a, b, ans;

int call(int i, int j)
{
    if(i == a.size() || j == b.size())
        return 0;
    if(lcs[i][j] != -1)
        return lcs[i][j];

    if(a[i] == b[j])
        return lcs[i][j] = 1 + call(i+1, j+1);
    else
        return lcs[i][j] = max(call(i+1, j), call(i, j+1));
}

int main()
{
    cin >> a >> b;
    memset(lcs, -1, sizeof lcs);
    call(0, 0);

    int i = 0, j = 0;
    string ans;
    while(i < a.size() && j < b.size())
    {
        if(a[i] == b[j])
        {
            ans = ans + a[i];
            i++;
            j++;
        }
        else if(lcs[i+1][j] >= lcs[i][j+1])
            i++;
        else
            j++;
    }

    cout << ans;
}


Measured memory_bytes: 35968
#include <vector>
#include <queue>
#include <iostream>
#include <set>
#include <algorithm>
#define ii pair<int, int>
#define iii pair<ii, int>
#define pq priority_queue

using namespace std;

vector<int> bfs(vector<vector<int>> adj_list, int start, int n) {
    queue<ii> possible;
    set<int> visited;
    vector<int> signposts(n - 1, -1);
    possible.push(make_pair(start, -1));
    while (!possible.empty()) {
        int island = possible.front().first;
        int parent = possible.front().second;
        possible.pop();
        if (visited.find(island) == visited.end()) {
            for (int adj_node : adj_list[island]) {
                possible.push(make_pair(adj_node, island));
            }
            if (island != start && signposts[island - 1] == -1) {
                signposts[island - 1] = parent;
            }
            visited.insert(island);
        }
    }
    if (visited.size() == n) {
        return signposts;
    }
    else {
        return vector<int>(1, -1);
    }
}

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

    int n, m;
    cin >> n >> m;
    vector<vector<int>> adj_list(n);
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        adj_list[a - 1].push_back(b - 1);
        adj_list[b - 1].push_back(a - 1);
    }
    vector<int> ans = bfs(adj_list, 0, n);
    if (ans[0] == -1) {
        cout << "No";
    }
    else {
        cout << "Yes\n";
        for (int i = 0; i < n - 1; i++) {
            cout << ans[i] + 1 << '\n';
        }
    }
}

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

int main() {
    int c[3][3];
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            cin >> c[i][j];
        }
    }
    int a[3],b[3];
    a[0]=0;
    for(int i=0;i<3;i++){
        b[i]=c[0][i];
    }
    for(int i=1;i<3;i++){
        a[i]=c[i][0]-b[0];
    }
    bool ans=true;
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            if(c[i][j]!=a[i]+b[j]) ans=false;
        }
    }
    if(ans) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#include <set>
#include <map>
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout << fixed << setprecision(20);
#define rep(i,n) for (int i=0; i<n;++i)
#define ALL(a)  (a).begin(),(a).end()
#define PI 3.14159265358979
typedef long long ll;
using namespace std;
const ll MOD = 1e9+7LL;
const int INF = 2e9;
int A,B,C,D;

int main() {
  INCANT;
  cin >> A >> B >> C >> D;
  int p = (A+D-1)/D;
  int q = (C+B-1)/B;
  string ans = p>=q?"Yes":"No";
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 3656
#include<bits/stdc++.h>
#define nl "\n"
using namespace std;
typedef unsigned long long ull;
typedef long double ld;
#define PI 3.1415926535897932384626433832795

void solve() {
	ld a, b, h, m;
	cin >> a >> b >> h >> m;
	ld angh = PI * (h + m/60) / 6;
	ld angm = PI * (m / 5) / 6;
	ld ang = abs(angh - angm);
	ld ans = sqrt(a*a + b*b - (2*a*b*cos(ang)));
	cout << fixed << setprecision(15) << ans << endl;
}

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


Measured memory_bytes: 4188
#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")

const ll mod = 1e9 + 7;
const ll inf = 1e18;

int t[200] = {};

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

    // input
    int a, b, c, d;
    cin >> a >> b >> c >> d;

    FOR(i, a, b+1){
        t[i]++;
    }
    FOR(i, c, d+1){
        t[i]++;
    }
    int count = 0;
    FOR(i, 0, 200){
        if(t[i]==2){
            count++;
        }
    }

    if(count>1){
        p(count-1);
    }else{
        p(0);
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <algorithm>
#include <tuple>
#include <list>
#include <deque>
#include <stack>
#include <complex>
#include <functional>
#include <regex>
#include <numeric>
#include <map>

using namespace std;

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

const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1};
const int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

using ll = long long;
using ld = long double;
using ull = unsigned long long;

const int PI = acos(-1);
const int INF = numeric_limits<int>::infinity() / 2;
const ll INFLL = numeric_limits<ll>::infinity() / 2;

ll calc(vector<ll> &A, ll b) {
  ll ret = 0;
  rep(i, A.size()) ret += abs(A[i] - b);
  return ret;
}

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

  vector<ll> A(N);
  rep(i, N) {
    cin >> A[i];
    A[i] -= (i + 1);
  }

  ll l = numeric_limits<ll>::min(), h = numeric_limits<ll>::max();
  while (l + 1 < h) {
    ll mid = (l + h) / 2;
    if (calc(A, mid) - calc(A, mid - 1) < 0) l = mid;
    else h = mid;
  }

  ll k = 0;
  rep(i, N) k += abs(A[i] - l);

  cout << k << endl;

  return 0;
}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

int r;
int main() {
    cin>>r;
    int ans = 3*pow(r,2);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

typedef tree<int, null_type, less<int>, rb_tree_tag,
        tree_order_statistics_node_update>
        new_data_set;


#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define PSET(x,y) fixed<<setprecision(y)<<x
#define pb push_back
#define pf push_front
#define mp make_pair
#define pii pair<int,int>
#define vi vector<int>
#define vip vector<pair<int,int> >
#define ff first
#define ss second
#define int long long
#define SIZE 200010
#define mod 1000000007
#define BIG 998244353
#define s(t) scanf("%d",&t)
#define p(t) printf("%d\n",t)
#define mii map<int,int>
#define MSET(table,i) memset(table, i, sizeof(table))
#define endl '\n'
#define tc int t;cin>>t;while(t--)
#define pi  3.1415926358
#define print(x) for(auto el: x) cout<<el<<" ";cout<<endl
#define bits(x) __builtin_popcount(x)
#define minimum(a,n) min_element(a,a+n)-a
#define maximum(a,n) max_element(a,a+n)-a
#define pqbig priority_queue<int>
#define pqsmall priority_queue<int,vector<int>,greater<int> >
#define all(v) v.begin(),v.end()
#define sitr set<int>:: iterator
#define mitr map<int,int>:: iterator


#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl

int solve(int a,int b,int c)
{
    int right=b/c;
    int left=(a-1)/c;
    return (right-left);
}

int32_t main()
{
    fast;
    int a,b,c,d;cin>>a>>b>>c>>d;
    int divi_by_c=solve(a,b,c);
    int divi_by_d=solve(a,b,d);
    int both=solve(a,b,(c*d)/__gcd(c,d));

    int only=divi_by_c+divi_by_d-both;
    int num=b-a+1;
    cout<<num-only;
}

Measured memory_bytes: 256
//#pragma once
#include <stdio.h>
#include <string>
#include <iostream>
#include <queue>
#include <algorithm>
#include <sstream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cctype>


using namespace std;
#define modd 1000000007


typedef pair<long long, long long> pl;


typedef string::const_iterator State;
class ParseError {};




#define ll long long




/*
class UnionFind {
public:
	vector <ll> par;
	vector <ll> siz;
	vector <ll> gr;

	// Constructor
	UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) ,gr(sz_){
		for (ll i = 0; i < sz_; ++i) par[i] = i;
	}
	void init(ll sz_) {
		par.resize(sz_);
		siz.assign(sz_, 1LL);  // resize だとなぜか初期化されなかった
		for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
	}

	// Member Function
	// Find
	ll root(ll x) { // 根の検索
		while (par[x] != x) {
			x = par[x] = par[par[x]]; // x の親の親を x の親とする
		}
		return x;
	}

	// Union(Unite, Merge)
	bool merge(ll x, ll y) {
		x = root(x);
		y = root(y);
		if (x == y) return false;

		// merge technique（データ構造をマージするテク．小を大にくっつける）
		if (siz[x] < siz[y]) swap(x, y);
		siz[x] += siz[y];
		par[y] = x;
		return true;
	}



	bool issame(ll x, ll y) { // 連結判定
		return root(x) == root(y);
	}

	ll size(ll x) { // 素集合のサイズ
		return siz[root(x)];
	}


};*/


long long N, M, K, a, b, c, d, e, H, W, L;
ll A[100005] = {};
ll B[300005] = {};
ll C[300005] = {};
bool f, ff;
string S,T;
set <long long>sll;
pl bufpl;
vector <long long>vl;
vector <pl>vpl;
vector <string> vs;
set<ll> llset;

/*struct ST
{
	long long Kati;
	int bangou;

	bool operator<(const ST& another) const
	{
		return Kati < another.Kati;//比較
	};

};



vector <ST> vst;
ST st[200005];
ST bufst;
bitset<5000> bits;*/


long long modinv(long long aa, long long mm) {
	long long bb = mm, uu = 1, vv = 0;
	while (bb) {
		long long tt = aa / bb;
		aa -= tt * bb; swap(aa, bb);
		uu -= tt * vv; swap(uu, vv);
	}
	uu %= mm;
	if (uu < 0) uu += mm;
	return uu;
}



ll minn, maxx;
double ansa;
bool fl[30] = {};

string ss, sss;

int main() {


	cin >> N>>S>>T;
	A[S[0] - 'a'] = 1;

	for (int i = 1; i < N-1; i++) {
		A[S[i] - 'a'] += A[T[i] - 'a'];
		A[S[i] - 'a'] %= modd;

	}

	cout << A[T[N-1] - 'a']%modd << endl;

	return 0;

}



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

long long mod = 998244353;

int main(){
    long long n, k;
    cin >> n >> k;

    vector<long long> l(k);
    vector<long long> r(k);
    for(long long i = 0; i < k; i++) cin >> l[i] >> r[i];

    vector<long long> dp(n, 0);
    dp[0] = 1;
    dp[1] = -1;

    for(long long i = 0; i < n; i++){
        if(i > 0) dp[i] += dp[i-1];
        dp[i] %= mod;
        for(long long j = 0; j < k; j++){
            if(i+l[j] < n){
                dp[i+l[j]] += dp[i];
                dp[i+l[j]] %= mod;
            }

            if(i+r[j] + 1 < n){
                dp[i+r[j]+1] -= dp[i];
                dp[i+r[j]+1] += mod;
                dp[i+r[j]+1] %= mod;
            }
        }
    }

    cout << dp[n-1] << endl;
    return 0;
}

Measured memory_bytes: 4792
#include <bits/stdc++.h>
using namespace std;
#define PI acos(-1) 
int main(){
	int a,b,x;
	while(cin >> a >> b >> x){
		double s, l, t;
		if(x > a * a * b / 2){
			x = (a * a * b - x) * 2;
			s = 1.0 * x / (a * a);
			l = sqrt(s * s + 1.0 * a * a);
			t = 1.0 * a / l;	
		}
		else{
			x *= 2;
			s = 1.0 * x / (a * b);
			l = sqrt(s * s + 1.0 * b * b);
			t = s / l;
//			printf("%.6lf  %.6lf\n",s,l);			
		}
		printf("%.10lf\n",acos(t) * 180.0 / PI);

	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using LL=long long;
int H,W;
string S[400];  
int c[400][400]={};
vector<pair<LL,LL>>s;
void f(int i,int j,int k=-1){
  if(c[i][j]!=-1){
    assert(k==-1||c[i][j]==k);
    return;
  }
  if(k==-1){
  	c[i][j]=s.size();
  	s.push_back({0,0});
  }else{
    c[i][j]=k;
  }
  
  if(S[i][j]=='#')
    s[c[i][j]].first++;
  else
    s[c[i][j]].second++;
  
  if(i>0  && S[i][j]!=S[i-1][j]) f(i-1,j,c[i][j]);
  if(i<H-1&& S[i][j]!=S[i+1][j]) f(i+1,j,c[i][j]);
  
  if(j>0  && S[i][j]!=S[i][j-1]) f(i,j-1,c[i][j]);
  if(j<W-1&& S[i][j]!=S[i][j+1]) f(i,j+1,c[i][j]);
}
int main(){
  cin>>H>>W;
  for(int i=0;i<H;i++)cin>>S[i];
  
  for(int i=0;i<H;i++)for(int j=0;j<W;j++)c[i][j]=-1;
  for(int i=0;i<H;i++)for(int j=0;j<W;j++)f(i,j);
  
  LL ans=0;
  for(pair<LL,LL> q:s){
    ans+=q.first*q.second;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 16128
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;


public class Main{
	
	static int[][] cost;
	static int[] d,sum;
	static boolean[] used;
	static int n,V;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true) {
			n = sc.nextInt();
			V = 0;
			ArrayList<Integer> arr = new ArrayList<Integer>();
			if(n==0) break;
			cost = new int[2<<9][];
			d = new int[2<<9];
			sum = new int[2<<9];
			used = new boolean[2<<9];
			Arrays.fill(sum, 0);
			for (int i = 0; i < cost.length; i++) {
				cost[i] = new int[2<<9];
				Arrays.fill(cost[i], 2<<9);
			}
			for (int i = 0; i < n; i++) {
				
				int y = sc.nextInt();
				int x = sc.nextInt();
				int c = sc.nextInt();
				if(!arr.contains(x)) {
					arr.add(x);
					V++;
				}
				if(!arr.contains(y)) {
					arr.add(y);
					V++;
				}
				cost[y][x] = c;
				cost[x][y] = c;
			}
			for (int i = 0; i < V; i++) {
				dijkstra(i);
			}
			int ans = Integer.MAX_VALUE;
			int index = 0;
			for (int i = 0; i < V; i++) {
				if(ans>sum[i]) {
					index = i;
					ans = sum[i];
				}
			}
			System.out.println((index)+" "+ans);
		}
		
	}
	
	
	public static void dijkstra(int s) {
		Arrays.fill(d, 2<<9);
		Arrays.fill(used, false);
		d[s] = 0;
		
		while(true) {
			int v = -1;
			for (int u = 0; u < V; u++) 
				if(!used[u]&&(v==-1||d[u]<d[v])) v=u; 
			
			if(v==-1) break;
			used[v] = true;
			for (int u = 0; u < V; u++) {
				d[u] = Math.min(d[u], d[v]+cost[v][u]);
			}
		}
		int temp = 0;
		for (int i = 0; i < V; i++) {
			temp+=d[i];
		}
		sum[s] = temp;
		
	}
	
}



Measured memory_bytes: 51384
let () = 
  Scanf.scanf " %s\n" @@ fun s1 ->
  Scanf.scanf " %s" @@ fun s2 ->
  let lst1 = Str.split (Str.regexp "") s1 in
  let lst2 = Str.split (Str.regexp "") s2 in
  let ans = List.fold_left2
    (fun a b c -> if b = c then a else a + 1) 0 lst1 lst2 in
  Printf.printf "%d" ans
  

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

const int INF = 1e9;
int N, A, B, C;
vector<int> l(8);

int dfs(int count, int sum_A, int sum_B, int sum_C){

  if(count == N){
    if(sum_A == 0 || sum_B == 0 || sum_C == 0)
      return INF;
    else
      return abs(A-sum_A)+abs(B-sum_B)+abs(C-sum_C);
  }
  
  int value_A = dfs(count+1, sum_A + l.at(count), sum_B, sum_C);
  int value_B = dfs(count+1, sum_A, sum_B + l.at(count), sum_C);
  int value_C = dfs(count+1, sum_A, sum_B, sum_C + l.at(count));
  int value_not = dfs(count+1, sum_A, sum_B, sum_C);
  
  if(sum_A != 0) value_A += 10;
  if(sum_B != 0) value_B += 10;
  if(sum_C != 0) value_C += 10;

  return min({value_A, value_B, value_C, value_not});
}

int main(){

  cin >> N >> A >> B >> C;
  for(int i=0; i<N; i++)
    cin >> l.at(i);
  
  cout << dfs(0, 0, 0, 0) << endl;
  
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
def inpl(): return tuple(map(int, input().split()))
from collections import Counter
from string import ascii_lowercase

S = input()
C = Counter(list(S))
D = {k:i for i, k in enumerate(ascii_lowercase)}

for a in list(ascii_lowercase):
    if C[a] == 0:
        S += a
        print(S)
        break
else:
    nokori = [D[S[-1]]]    
    for i in range(24, -1, -1):
        res = 30
        for n in nokori:
            if D[S[i]] < n:
                res = min(res, n)

        if res == 30:
            nokori.append(D[S[i]])            
        else:
            S = S[:i] + ascii_lowercase[res]
            print(S)
            break
    else:
        print(-1)


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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
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 gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a*b/gcd(a, b);
}

int main()
{
    cout << fixed << setprecision(15);
    ll S, W;
    cin >> S >> W;
    if(S<=W){
        cout << "unsafe" << endl;
    }
    else{
        cout << "safe" << endl;
    }
    return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <iomanip>

int main() {
	std::string s; std::cin >> s;
	int count0 = 0;
	int count1 = 0;
	for (int i = 0; i < s.size(); ++i) {
		if (s[i] == '0')++count0;
		else if (s[i] == '1') ++count1;
	}
	std::cout << s.size() - std::abs(count0 - count1) << std::endl;

	return 0;
}


Measured memory_bytes: 3704
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fr first
#define sc second
typedef vector<int> Vi;
typedef pair<int,int> Pii;
typedef pair<int,Pii> Pip; 
const int INF = (1<<30);
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

int main(){

  int n;
  int p[100] = {0};
  int rank[100] = {0};
  cin >> n;
  for(int i=0; i<n * (n - 1) / 2; i++) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    a--; b--;
    if( c > d ) p[a] += 3;
    if( c < d ) p[b] += 3;
    if( c == d ) { p[a]++; p[b]++; }
  }

  for(int i=0; i<n; i++) {
    for(int j=0; j<n; j++) {
      if( i != j ) {
	if( p[i] < p[j] ) rank[i]++;
      }
    }
  }

  for(int i=0; i<n; i++) {
    cout << rank[i]+1 << endl;
  }
}

Measured memory_bytes: 1160
let () =
  let n = read_int () in
  let a = Array.make_matrix n n 0 in
  for _ = 0 to n - 1 do
    let (id, k) = Scanf.scanf "%d %d " (fun id k -> (id, k)) in
    for _ = 0 to k - 1 do
      a.(id-1).(Scanf.scanf "%d " (fun i -> i) - 1) <- 1
    done
  done;
  for i = 0 to n - 1 do
    for j = 0 to n - 1 do
      Printf.printf (if j = 0 then "%d" else " %d") a.(i).(j)
    done;
    print_newline ()
  done

Measured memory_bytes: 4256
#include <string>
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
using namespace std;
using ll = long long int;

ll solve1(string s, int l, int r) {
    s += '+'; r++;
    vector<ll> vs;

    ll val = 1;
    for(int i=l; i<r; i++) {
        if(s[i] == '*') continue;
        if(s[i] == '+') vs.emplace_back(val), val = 1;
        if(isdigit(s[i])) val *= (s[i] - '0');
    }

    return accumulate(vs.begin(), vs.end(), 0LL);
}

ll solve2(string s, int l, int r) {
    ll res = s[0] - '0';

    char op = '?';
    for(int i=1; i<r; i++) {
        if(isdigit(s[i])) {
            if(op == '*') res = res * (s[i] - '0');
            if(op == '+') res = res + (s[i] - '0');
        }
        else op = s[i];
    }
    return res;
}

int main() {
    string s; cin >> s;
    int N = s.size();
    ll res; cin >> res;

    ll v1 = solve1(s, 0, N);
    ll v2 = solve2(s, 0, N);
    
    if(v1 == res and v2 != res) cout << "M" << endl;
    else if(v2 == res and v1 != res) cout << "L" << endl;
    else if(v1 == res and v2 == res) cout << "U" << endl;
    else cout << "I" << endl;
    return 0;
}



Measured memory_bytes: 3220
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <bitset>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define index(xs, x) (int)(lower_bound(all(xs), x) - xs.begin())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
inline void chmin(int &x, int v) { if (x > v) x = v; }

int N;
char C[4000];
int A[4000];
int dp[2001][2001];
int white[2000], black[2000];
vector<int> leftW[4000], leftB[4000];

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> N;
  rep(i, 2*N) cin >> C[i] >> A[i], A[i]--;
  rep(i, 2*N) {
    if (i > 0) {
      leftW[i] = vector<int>(leftW[i-1]);
      leftB[i] = vector<int>(leftB[i-1]);
    }
    if (C[i] == 'W') white[A[i]] = i, leftW[i].pb(A[i]);
    else black[A[i]] = i, leftB[i].pb(A[i]);
    sort(all(leftW[i]));
    sort(all(leftB[i]));
  }

  rep(l, N+1) rep(r, N+1) dp[l][r] = INF;
  dp[0][0] = 0;
  rep(l, N+1) rep(r, N+1) {
    if (l < N) { // o
      int pos = white[l];
      int cost = 0;
      cost += leftB[pos].end() - lower_bound(all(leftB[pos]), r);
      cost += leftW[pos].end() - lower_bound(all(leftW[pos]), l+1);
      chmin(dp[l+1][r], dp[l][r]+cost);
    }
    if (r < N) { // x
      int pos = black[r];
      int cost = 0;
      cost += leftB[pos].end() - lower_bound(all(leftB[pos]), r+1);
      cost += leftW[pos].end() - lower_bound(all(leftW[pos]), l);
      chmin(dp[l][r+1], dp[l][r]+cost);
    }
  }
  cout << dp[N][N] << "\n";
  return 0;
}


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

long long a, b, c, x;
int main() {
	cin >> a >> b >> c;
	x = c-a-b;
	cout << (x>0 && 4*a*b<x*x ? "Yes" : "No");
	return 0;
}


Measured memory_bytes: 3592
n,m = map(int,input().split())
AB = sorted([list(map(int,input().split())) for i in range(n)])
res = 0
for a,b in AB:
    m -= b
    if m >= 0:
        res += a*b
    else:
        m += b
        res += a*m
        break
print(res)

Measured memory_bytes: 28652
#include<bits/stdc++.h>
using namespace std;
int n,m,i,sum=0;
long long ans=0;
struct ab{
	long long a;
	long long b;
}ba[100000];
bool cmp(ab al,ab bl){
	return al.a<bl.a;
}
int main(){
	cin>>n>>m;
	sum=m;//你能买sum瓶水 
	for(i=0;i<n;i++)
		cin>>ba[i].a>>ba[i].b;//结构体，将价格与购买上限写在一起 
	sort(ba,ba+n,cmp);//按价格从小到大排序 
	for(i=0;i<n;i++){
		if(ba[i].b<=sum){//如果这瓶水的购买上限小于等于我可以购买的水量 
			sum-=ba[i].b;//那我就全买光 
			ans+=ba[i].a*ba[i].b;//价钱加购买上限*水的价钱 
		}
		else{//如果我不能买那么多水 
			ans+=ba[i].a*sum;//那我就把我剩下的次数用掉 
			break;//此时sum一定等于0，直接结束。 
		}
	}
	cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while(true) {
            int H = sc.nextInt();
            int W = sc.nextInt();
            if(H==0 && W==0) break;
            for(int i=0;i<H;i++){
                for(int j=0;j<W;j++){
                    if((i+j)%2 == 0) System.out.print('#');
                    else System.out.print('.');
                }
                System.out.println("");
            }
            System.out.println();
        }
        sc.close();
    }
}


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

#define CIN_ONLY if(1)
struct cww{cww(){
    CIN_ONLY{
        ios::sync_with_stdio(false);cin.tie(0);
    }
}}star;
#define fin "\n"
#define FOR(i,bg,ed) for(int i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
#define pb push_back
#define DEBUG if(0)
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l,T r)
{bool a=l>r;if(a)l=r;return a;}
template <typename T>inline bool chmax(T &l,T r)
{bool a=l<r;if(a)l=r;return a;}
template <typename T>
istream& operator>>(istream &is,vector<T> &v){
    for(auto &it:v)is>>it;
    return is;
}
int X[112];
int Y[112];
int C[112][112];
int getcost(int l,int r){
    if(C[l][r]>=0)return C[l][r];
    if(r==l)return 0;
    int x=max(0,X[r]-getcost(l,r-1));
    return C[l][r]=max(Y[r]-x,0);
}
typedef vector<int> V;
typedef vector<V> VV;
int main(){
    REP(i,112)REP(j,112)C[i][j]=-1;
    int N,P;
    cin>>N>>P;
    N++;
    FOR(i,1,N)cin>>X[i]>>Y[i];
    VV dp(N,V(N,-1));
    dp[0][0]=P;
    FOR(i,1,N){
        VV nxt(N,V(N,-1));
        REP(j,i)REP(k,i)
            chmax(nxt[j][i],dp[j][k]);
        REP(j,i)REP(k,i){
            int need=getcost(k,i);
            if(need<=dp[j][k])
                chmax(nxt[j+1][k],dp[j][k]-need);
        }
        swap(dp,nxt);
    }
    int res=0;
    REP(i,N)REP(j,N){
        if(dp[i][j]>=0)chmax(res,i);
    }
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 3312
import java.util.Scanner;

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

		int n = sc.nextInt();

		int sn = 0;
		int a = n;

		while (a != 0) {
			sn += a % 10;
			a /= 10;
		}

		if(n%sn == 0) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}

	}
}


Measured memory_bytes: 23892
unittest
{
	assert( [ "RRLRL" ].parse.expand.solve == "0 1 2 1 1" );
	assert( [ "RRLLLLRLRRLL" ].parse.expand.solve == "0 3 3 0 0 0 1 1 0 2 2 0" );
	assert( [ "RRRLLRLLRRRLLLLL" ].parse.expand.solve == "0 0 3 2 0 2 1 0 0 0 4 4 0 0 0 0" );
}



import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto s = input.front.to!( dchar[] );
	return tuple( s );
}

auto solve( dchar[] s )
{
	auto anss = new long[ s.length ];
	anss[] = 1;
	
	// RRをまとめる
	for( auto i = 0L; i + 1 < s.length; i++ )
	{
		if( s[ i ] == 'R' && s[ i + 1 ] == 'R' )
		{
			anss[ i + 1 ] += anss[ i ];
			anss[ i ] = 0L;
		}
	}
	
	// LLをまとめる
	for( auto i = s.length.signed - 1; 0 < i; i-- )
	{
		if( s[ i ] == 'L' && s[ i - 1 ] == 'L' )
		{
			anss[ i - 1 ] += anss[ i ];
			anss[ i ] = 0L;
		}
	}
	
	// RLを計算
	for( auto i = 0L; i + 1 < s.length; i++ )
	{
		if( s[ i ] == 'R' && s[ i + 1 ] == 'L' )
		{
			auto l = cast( long )( ceil(  anss[ i ] / 2.0 ) + floor( anss[ i + 1 ] / 2.0 ) );
			auto r = cast( long )( floor( anss[ i ] / 2.0 ) + ceil(  anss[ i + 1 ] / 2.0 ) );
			anss[ i     ] = l;
			anss[ i + 1 ] = r;
		}
	}
	
	return anss.to!( string[] ).join( " " );
}


Measured memory_bytes: 7704
N = int(input())
X = list(map(int, input().split()))

b = [0] * N
res = 0
for i in range(N):
    res += X[i] * (-1) ** i
b[0] = res // 2

for i in range(1, N):
    b[i] = X[i - 1] - b[i - 1]

print(*[v * 2 for v in b])


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

int main()
{
	int n;
	double x[10],sum=0;
	string u[10];
	
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>x[i]>>u[i];
		if(u[i]=="JPY") sum+=x[i];
		else sum+=x[i]*380000;
	}
	
	cout<<sum<<endl;
	
	return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int t = sc.nextInt();
        int cost = 9999;

        for(int i = 0;i<n;i++){
            int c = sc.nextInt();
            int t2 = sc.nextInt();
            if(t>=t2){
                if(cost>c){
                    cost=c;
                }
            }
        }

        if(cost==9999){
            System.out.println("TLE");
        }else{
            System.out.println(cost);
        }


        
    }
}


Measured memory_bytes: 21844
while(s=?/+gets.gsub(/\d+/){|k|?1*k.to_i})!~/#/
n=s.reverse.index(?/)
a,b,c,d=gets.split.map &:to_i
s[n*a-n+b]=?1
s[n*c-n+d]=?b
$><<s[1..-1].gsub(/1+/,&:size)
end

Measured memory_bytes: 8696
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int N;
  cin >> N;
  vector<int> d(N);
  for (int i = 0; i < N; i++) cin >> d.at(i);

  int ans = 0;

  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      ans += d.at(i) * d.at(j);
    }
  }

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


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
#AGC029A https://atcoder.jp/contests/agc029/tasks/agc029_a
import sys
#import collections

#n= int(input())
#s= input()
#tmp = input().split()
#n,m = list(map(lambda a: int(a), tmp))
s= input()

n=len(s)

cnt=0
total=0
for i in range(0,n):
	if(s[i]=="B"):
		cnt+=1
	else:
		total+=cnt
print(total)


Measured memory_bytes: 3500
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,i,j,l,maxmns,totpls,total=0,bn=0,cn=0;
  string s;
  cin>>n;
  vector<vector<int>> a(n,vector<int>(2));
  for(i=0;i<n;i++){
    cin>>s;
    maxmns=0;
    totpls=0;
    l=s.length();
    for(j=0;j<l;j++){
      if(s.at(j)=='(') totpls++;
      else if(s.at(j)==')'){
        totpls--;
        if(maxmns<-totpls) maxmns=-totpls;
      }
    }
    a.at(i).at(0)=maxmns;
    a.at(i).at(1)=totpls;
    if(maxmns==0) total+=totpls;
    else if(maxmns>0 && totpls>0) bn++;
    else if(maxmns>0 && totpls<=0) cn++;
  }
  vector<vector<int>> b(bn,vector<int>(2));
  vector<vector<int>> c(cn,vector<int>(3));
  bn=0; cn=0;
  for(i=0;i<n;i++){
    if(a.at(i).at(0)>0 && a.at(i).at(1)>0){
      b.at(bn).at(0)=a.at(i).at(0);
      b.at(bn).at(1)=a.at(i).at(1);
      bn++;
    }
    else if(a.at(i).at(0)>0 && a.at(i).at(1)<=0){
      c.at(cn).at(0)=a.at(i).at(0)+a.at(i).at(1);
      c.at(cn).at(1)=a.at(i).at(0);
      c.at(cn).at(2)=-a.at(i).at(1);
      cn++;
    }
  }
  sort(b.begin(),b.end());
  for(i=0;i<bn;i++){
    if(total>=b.at(i).at(0)) total+=b.at(i).at(1);
    else{
      cout<<"No"<<endl;
      return 0;
    }
  }
  sort(c.begin(),c.end());
  reverse(c.begin(),c.end());
  for(i=0;i<cn;i++){
    if(total>=c.at(i).at(1)) total-=c.at(i).at(2);
    else{
      cout<<"No"<<endl;
      return 0;
    }
  }
  if(total==0) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 85372
#pragma GCC optimize ("O3")
#include<bits/stdc++.h>
#include <queue>
#include <cstring>

#define pb push_back
#define p push

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define ll long long

#define getI(a) scanf("%d",&a)
#define getII(a, b) scanf("%d%d",&a,&b)
#define getIII(a, b, c) scanf("%d%d%d",&a,&b,&c)
#define getL(a) scanf("%lld",&a)
#define getLL(a, b) scanf("%lld%lld",&a,&b)
#define getLLL(a, b, c) scanf("%lld%lld%lld",&a,&b,&c)
#define BEND(c) (c).begin(),(c).end()
#define BEND2(c) (c).rbegin(),(c).rend()
#define fi first
#define se second
#define pi 3.1415926535897932384626
#define getS(a) scanf("%s",a)
#define pfb(a) printf("%.10lf\n",a);
#define pfi(a) printf("%d",a);
#define pfii(a, b) printf("%d%d",a,b);
#define pfl(a) printf("%lld",a);
#define pfll(a, b) printf("%lld%lld",a,b);
#define pfd(a) printf("%.12lf\n",a);
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);
#define endl "\n"

#define SIZE  ( int)(1e9 + 7)
#define MAXN (ll) ((1e6+5))
#define K 25
#define  ALPHABET_SIZE  26
//#define N (int)(1e5+10)
#define sag (sol|1)
#define sol (root<<1)
#define ort (bas+son)/2
#define INF (ll )1e18
#define int ll
using namespace std;

typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<vector<pair<int,int>>> vvpi;
typedef vector<long long> vl;
typedef vector<pair<int, int>> vpi;
typedef vector<pair<long long, long long>> vpl;
typedef pair<int, int> pii;
typedef pair <ll, ll> pll;
typedef vector<vi> graph ;



signed main ( ) {
 string s ;
 cin >> s ;
 ll n  = 0 ;
    for (int i = 0; i <s.size() ; ++i) {
        if( s[i] == '+')n++;
        else n--;
    }
    cout << n;
}



















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

int main(){
  long long N;
  cin >> N;
  vector<long> d(N);
  for(long long i=0; i<N; i++){
    cin >> d[i];
  }
  sort(d.begin(), d.end());
  long long x = d[N/2-1];
  long long y = d[N/2];
  cout << y-x << endl;
  return 0;
}


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

int main()
{
    int berapa, n, prev_n, max_counter=0, temp_counter=0;
    cin >> berapa;
    for(int i=0; i<berapa; ++i)
    {
        //if not first, do function
        if(i!=0)
        {
            prev_n = n;
        }
        cin >> n;


        if((i!=0) && (n<=prev_n))
            ++temp_counter;
        else
            temp_counter=0;

        if(temp_counter > max_counter)
            max_counter = temp_counter;
    }
    cout << max_counter;
    return 0;
}


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

int main()
{
	int n;
	cin >> n;
	vector<vector<pair<int, int>>> as(n);
	for (auto &&a : as)
	{
		int x;
		cin >> x;
		a.resize(x);
		for (auto &&p : a)
		{
			cin >> p.first >> p.second;
			p.first--;
		}
	}

	int ans = 0;
	for (int i = 0; i < (1 << n); i++)
	{
		bool flag = true;
		for (int j = 0; j < n; j++)
		{
			if ((i >> j) & 1)
			{
				for (auto &&p : as[j])
				{
					flag &= ((i >> p.first) & 1) == p.second;
				}
			}
		}
		if (flag)
		{
			ans = max(ans, __builtin_popcount(i));
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        // 年齢
        int old = sc.nextInt();
        // 料金
        int price = sc.nextInt();
        price = old>12? price: 5<old && old<=12? price/2: 0;
        // 出力
        System.out.println(price);
    }
}

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

const int N = 200054;

int n;
int p[N], q[N];

int main() {
	int i, j, ans;
	scanf("%d", &n);
	for (i = 1; i <= n; ++i) scanf("%d", p + i), q[p[i]] = i;
	for (i = n - 1; i > 0 && q[i] < q[i + 1]; --i);
	if (!i) return putchar(48), putchar(10), 0;
	for (ans = 1, j = i-- + 1; i > 0; --i)
		if (q[i] > q[i + 1] ^ q[i + 1] > q[j] ^ q[i] > q[j])
			++ans, j = i + 1;
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 1792
import itertools
url = "https://atcoder.jp//contests/abc057/tasks/abc057_a"

def main():
    n, m = list(map(int, input().split()))
    ab = [list(map(int, input().split())) for _ in range(n)]
    cd = [list(map(int, input().split())) for _ in range(m)]
    for i in range(len(ab)):
        dist = []
        for k in range(len(cd)):
            tmp = abs(ab[i][0] - cd[k][0]) + abs(ab[i][1] - cd[k][1])
            dist.append(tmp)
        print(dist.index(min(dist)) + 1)


if __name__ == '__main__':
    main()

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

const ll MOD = 1e9 + 7;

struct Mod {
  vector<ll> fact;
  Mod() {}
  Mod(ll n, ll p) {
    fact.resize(n + 1);
    for (ll i = 0; i < n + 1; i++) fact[i] = (i == 0) ? 1 : fact[i - 1] * i % p;
  }
  ll extgcd(ll a, ll b, ll& x, ll& y) {
    ll d = a;
    if (b != 0) {
      d = extgcd(b, a % b, y, x);
      y -= (a / b) * x;
    } else {
      x = 1, y = 0;
    }
    return d;
  }
  ll mod_inverse(ll a, ll m) {
    ll x, y;
    extgcd(a, m, x, y);
    return (m + x % m) % m;
  }
  ll mod_fact(ll n, ll p, ll& e) {
    e = 0;
    if (n == 0) return 1;
    ll res = mod_fact(n / p, p, e);
    e += n / p;
    ll s = (n / p % 2 != 0) ? p - fact[n % p] : fact[n % p];
    return res * s % p;
  }
  ll mod_comb(ll n, ll k, ll p) {
    if (n < 0 || k < 0 || n < k) return 0;
    ll e1, e2, e3;
    ll a1, a2, a3;
    a1 = mod_fact(n, p, e1);
    a2 = mod_fact(k, p, e2);
    a3 = mod_fact(n - k, p, e3);
    if (e1 > e2 + e3) return 0;
    return a1 * mod_inverse(a2 * a3 % p, p) % p;
  }
};

main() {
  int N, M; cin >> N >> M;
  if (N > M) swap(N, M);
  Mod m(M + 1, MOD);
  ll e;
  ll ans = (M - N > 1) ? 0 : (M - N == 1) ? 1 : 2;
  ans = (ans * m.mod_fact(N, MOD, e)) % MOD;
  ans = (ans * m.mod_fact(M, MOD, e)) % MOD;
  cout << ans << endl;
}


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner stdIn = new Scanner(System.in);
		long A = stdIn.nextLong();
		long B = stdIn.nextLong();

		if(((A + B) % 2) == 0){
			System.out.println((A + B) / 2);
		}
		else{
			System.out.println("IMPOSSIBLE");
		}
		stdIn.close();
	}
}

Measured memory_bytes: 35528
#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;

map<pair<int, pair<int, int>>, int> mp;
int n, nx, ny, newh;
vector<pair<int, int>> zero;

int main() {
  cin >> n;
  for(int i = 0; i < n; ++i) {
    int x, y, h;
    cin >> x >> y >> h;
    if(h == 0) {
      zero.push_back(make_pair(x, y));
      --i;
      --n;
      continue;
    }
    nx = x;
    ny = y;
    newh = h;
    for(int j = 0; j <= 100; ++j)
      for(int k = 0; k <= 100; ++k) {
        int nh = h + abs(x - j) + abs(y - k);
        ++mp[(make_pair(nh, make_pair(j, k)))];
      }
  }
  for(int i = 0; i <= 100; ++i)
    for(int j = 0; j <= 100; ++j) {
      int nh = abs(nx - i) + abs(j - ny) + newh;
      if(mp[make_pair(nh, make_pair(i, j))] == n) {
        for(int k = 0; k <= zero.size(); ++k) {
          if(k < zero.size()) {
            int p =
                abs(i - zero[k].fi) + abs(j - zero[k].se);
            if(nh - p > 0) break;
          }
          if(k == zero.size()) {
            cout << i << " " << j << " " << nh << endl;
            return 0;
          }
        }
      }
    }
  return 0;
}

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

int main()
{
    int arr[32] = {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 << arr[K - 1];

    return 0;
}

Measured memory_bytes: 256
# coding: utf-8
# Your code here!
import queue

H, W = map(int, input().rstrip().split())
m = [input() for _ in range(H)]

def bfs(h, w):
    q = queue.Queue()
    q.put((h, w, 0))
    f = [[False] * W for _ in range(H)]
    f[h][w] = True
    max_d = 0
    while q.qsize() > 0:
        h, w, d = q.get()
        max_d = max(max_d, d)
        for dh, dw in [[-1, 0], [1, 0], [0, 1], [0, -1]]:
            if h + dh >= 0 and h + dh < H and w + dw >= 0 and w + dw < W:
                if f[h+dh][w+dw] == False and m[h+dh][w+dw] == '.':
                    q.put((h+dh, w+dw, d+1))
                    f[h+dh][w+dw] = True
    return max_d    

max_d = 0
for h in range(H):
    for w in range(W):
        if m[h][w] == '.':
            max_d = max(max_d, bfs(h, w))
        
print(max_d)
        

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

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

const ll INF = 1LL << 60;
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

#define int long long

inline void my_io() {

	std::ios::sync_with_stdio(false);

	std::cin.tie(0);

	cout << fixed << setprecision(16);

}

signed main() {
	ll n, w;

	cin >> n >> w;

	vector<ll> wei(n + 1, 0);
	vector<ll> val(n + 1, 0);
	vector<vector<ll>> dp(n + 1, vector<ll>(100001, INF / 2));

	REP(i, n) {
		cin >> wei[i + 1] >> val[i + 1];
	}

	dp[0][0] = 0;

	FOR(i, 1, n + 1) {
		FOR(j, val[i], 100001) {
			dp[i][j] = min(dp[i][j], dp[i - 1][j - val[i]] + wei[i]);
		}
		REP(j, 100001) {
			dp[i][j] = min(dp[i][j], dp[i - 1][j]);
		}
	}

	ll ans = 0;

	RREP(i, 100001) {
		if (dp[n][i] < w + 1) {
			ans = i;
			break;
		}
	}
	
	cout << ans << endl;
}

Measured memory_bytes: 80256
import java.util.*;
import java.math.BigDecimal;
import java.math.MathContext;

public class Main {
  public static void main(String[] args) {
    Scanner sc=new Scanner(System.in);
    long n=sc.nextLong();
    BigDecimal n1=BigDecimal.valueOf(n);
    BigDecimal nn=sqrt(n1,1);
    nn=nn.setScale(0,BigDecimal.ROUND_UP);
    int a=nn.intValue();
    long x=1;
    long y=1;
    for(int i=a;i>0;i--){
      if(n%i==0){
        x=i;
        y=n/i;
        break;
      }
    }
    System.out.println(x+y-2);
  }

  public static BigDecimal sqrt(BigDecimal a, int scale){
    BigDecimal x = new BigDecimal(Math.sqrt(a.doubleValue()), MathContext.DECIMAL64);
    if(scale < 17) return x;
    BigDecimal b2 = new BigDecimal(2);
    for(int tempScale = 16; tempScale < scale; tempScale *= 2){
      x = x.subtract(x.multiply(x).subtract(a).divide(x.multiply(b2), scale, BigDecimal.ROUND_HALF_EVEN));
    }
    return x;
  }
}

Measured memory_bytes: 27552
#include<bits/stdc++.h>
#include <array>
using namespace std;
using ULL = unsigned long long;
using UL = unsigned;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

struct Problem {

	UL S[1001][1001] = {};

	void Solve() {
		UL N; cin >> N;
		UL K; cin >> K;
		rep(i, N) {
			UL x, y; cin >> x >> y;
			char c; cin >> c;
			if (c == 'B') x += K;
			y %= K * 2;
			if (y >= K) { x += K; y -= K; }
			x %= K * 2;
			if (x < K) {
				S[0][0]++;
				S[x][0]--;
				S[0][y]--;
				S[x][y] += 2;
			}
			else {
				x -= K;
				S[x][0]++;
				S[0][y]++;
				S[x][y] -= 2;
			}
		}
		rep(x, K) rep(y, K + 1) {
			S[x + 1][y] += S[x][y];
		}
		rep(x, K + 1) rep(y, K) {
			S[x][y + 1] += S[x][y];
		}
		UL ans = 0;
		rep(y, K) {
			rep(x, K) {
				UL tmp = S[x][y];
				ans = max(ans, tmp);
				ans = max(ans, N - tmp);
			}
		}
		cout << ans << endl;
	}

	Problem();
};
int main() {
	unique_ptr<Problem> p(new Problem());
	p->Solve();
	return 0;
}
Problem::Problem() {
	cout << fixed << setprecision(10);
}


Measured memory_bytes: 4224