akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

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

        int x = n%10;
        int y = n/10%10;
        int z = n/100%10;
        int w = n/1000;

        if((x==y&&y==z) || (y==z&&z==w)){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 23764
N=int(input())
ta= list(map(int,input().split()))
ans=1
check=0
a=N-2
for i in range(N):
    if(i==0): continue
    for j in range(N-a):
        if(ta[j]<=ta[i]):
            if(j==N-a-1):
                ans+=1
        else:
            check+=1
        if(check==1):
            break
    check=0
    a-=1
print(ans)

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

using namespace std;
using ll = long long;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V)) //小さい方からソート
#define REV(V) reverse(ALL(V)) //リバース
#define RSORT(V) SORT(V);REV(V) //大きい方からソート
#define NPN(V) next_permutation(ALL(V)) //順列
#define pb(n) push_back(n)
#define endl '\n'
#define Endl '\n'
#define DUMP(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define Yay(n) cout << ((n) ? "Yay!": ":(") << endl
#define RAPID cin.tie(0);ios::sync_with_stdio(false)
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c 
#define IN4(a,b,c,d) cin >> a >> b >> c >> d
#define VIN(V) for(int i = 0; i < (V).size(); i++) {cin >> (V).at(i);}
#define OUT(n) cout << n << endl
#define VOUT(V) REP(i, (V).size()) {cout << (V)[i] << endl;}
#define VOUT2(V) REP(i, (V).size()) {cout << (V)[i] << " ";} cout<<endl;

// 型マクロ定義
#define int long long
#define P pair<ll,ll>
#define Vi vector<ll>
#define Vd vector<double>
#define Vs vector<string>
#define Vc vector<char>
#define M map<ll,ll>
#define S set<ll>
#define PQ priority_queue<ll>
#define PQG priority_queue<ll,V,greater<ll>
//

const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int gcd(int a,int b){return b?gcd(b,a%b):a;} //最小公倍数

// デフォルト変数定義
string n,m,a,b,c,d,x,y,z;
string s,t;
//

signed main() {
  RAPID;
  IN2(x,y);
  if(x<y) OUT("<");
  else if(x>y) OUT(">");
  else OUT("=");
}

Measured memory_bytes: 384
#include <stdio.h>

int main(int argc, char const *argv[])
{
	int i, j, mm, dd;
	int days = 0, weekidx;

	while(1) {
		int a = 0, b = 0, c = 0;
		scanf("%d %d", &mm, &dd);
		if(mm == 0) break;

		if(mm >= 1 && mm <= 12) {
			// mmの前月までループを回す
			for(i = 1; i < mm; i++) {
				switch (i) {
					case 1:
					case 3:
					case 5:
					case 7:
					case 8:
					case 10:
					case 12:
						a++;
						break;
					case 4:
					case 6:
					case 9:
					case 11:
						b++;
						break;
					case 2:
						c = 1;
						break;
					default:
						break;
				}
			}

			// デバッグ
			// printf("dd = %d a = %d b = %d c = %d\n", dd,a,b,c);

			days = 31 * a + 30 * b + 29 * c + dd;
			weekidx = days % 7;
			switch (weekidx) {
				case 0: printf("Wednesday\n");
					break;
				case 1: printf("Thursday\n");
					break;
				case 2: printf("Friday\n");
					break;
				case 3: printf("Saturday\n");
					break;
				case 4: printf("Sunday\n");
					break;
				case 5: printf("Monday\n");
					break;
				case 6: printf("Tuesday\n");
					break;
			}
		}
	}
	return 0;
}

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

using namespace std;

struct Node {
    vector<int> to;
    bool b_done, w_done;
    int b_dist, w_dist;
};

void b_dfs(int pos, vector<Node> &node) {
    node[pos].b_done = true;
    for (int i = 0; i < node[pos].to.size(); i++) {
        int next = node[pos].to[i];
        if (node[next].b_done == false) {
            node[next].b_dist = node[pos].b_dist + 1;
            b_dfs(next, node);
        }
    }
}

void w_dfs(int pos, vector<Node> &node) {
    node[pos].w_done = true;
    for (int i = 0; i < node[pos].to.size(); i++) {
        int next = node[pos].to[i];
        if (node[next].w_done == false) {
            node[next].w_dist = node[pos].w_dist + 1;
            w_dfs(next, node);
        }
    }
}

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

    vector<Node> node(N);
    for (int i = 0; i < N; i++) {
        node[i].b_done = false;
        node[i].w_done = false;
    }
    for (int i = 0; i < N - 1; i++) {
        int a, b; cin >> a >> b; a--; b--;
        node[a].to.push_back(b);
        node[b].to.push_back(a);
    }

    node[0].b_dist = 0;
    node[N - 1].w_dist = 0;
    b_dfs(0, node);
    w_dfs(N - 1, node);

    int fennec = 0, snuke = 0;
    for (int i = 0; i < N; i++) {
        if (node[i].b_dist <= node[i].w_dist) fennec++;
        else snuke++;
    }

    if (fennec > snuke) cout << "Fennec" << endl;
    else cout << "Snuke" << endl;

    return 0;
}

Measured memory_bytes: 10368
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  int n, q;
  while (cin >> n >> q, n) {
    vector<tuple<string, int, int>> v;
    while (n--) {
      string s;
      int a, b;
      cin >> s >> a >> b;
      v.emplace_back(s, b - a, b);
    }
    while (q--) {
      int x;
      cin >> x;
      ([&]() {
        for (auto &t : v) {
          string s;
          int a, b;
          tie(s, a, b) = t;
          if (a < x && x <= b) {
            cout << s << ' ' << x - a << endl;
            return;
          }
        }
        cout << "Unknown" << endl;
      })();
    }
  }
}

Measured memory_bytes: 3200
# -*- coding: utf-8 -*-
import sys
import math
import collections
#sys.setrecursionlimit(100000)

n=int(input())

tmp = input().split()
t1 = tmp[0]
t2 = tmp[1]
t3=""

for i in range(n):
	t3=t3+t1[i]
	t3=t3+t2[i]
print(t3)




Measured memory_bytes: 3316
#include <iostream>
#include <cassert>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <unordered_map>

using namespace std;

#define all(v) v.begin(), v.end()
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) for (int i=0;i<(n);i++)
#define PB push_back
#define pb push_back
#define MP make_pair
#define mp make_pair
#define VS vector<string>
#define VI vector<int>
#define I_SCAN(n) cin >> n;
#define VI_SCAN(vi,n) REP(i,n) cin >> vi[i];
int main(void) {
  int H, W;
  I_SCAN(H);
  I_SCAN(W);

  REP(i,W+2) cout << "#";
  cout << endl;

  REP(h,H) {
    REP(w,W+2){
      if (w==0 || w==W+1) cout << "#";
      else {
        char c;
        cin >> c;
        cout << c;
      }
    }
    cout << endl;
  }
  REP(i,W+2) cout << "#";
  cout << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <map>
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define pb(a) push_back(a)
#define MAX(a, b) ((a < b)?b:a)
#define MIN(a, b) ((a > b)?b:a)
typedef long long int ll;
typedef unsigned long long int ull;
using namespace std;

template<typename T> void cinpb(vector<T>& x) { T n; cin >> n; x.push_back(n); }
ull gcd(ull a, ull b) { return b ? gcd(b, a%b) : a; }
ull lcm(ull m, ull n) {	return ((0 == m) || (0 == n)) ? 0 : ((m / gcd(m, n)) * n); }
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

void yesno(bool f) { cout << (f ? "Yes" : "No") << endl; }

//


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

	int a, b, c;

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

	if ( a == 1 ) a = 9; else if ( a == 9 ) a = 1;
	if ( b == 1 ) b = 9; else if ( b == 9 ) b = 1;
	if ( c == 1 ) c = 9; else if ( c == 9 ) c = 1;

	cout << a << b << c << endl;

	return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << endl;
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    int N;
    cin >> N;

    vll A(N);
    REP(i, N) {
        cin >> A[i];
        A[i] -= i + 1;
    }

    sort(ALL(A));

    ll ans = 0;

    REP(i, N) {
        ans += abs(A[i] - A[N/2]);
    }

    print(ans);

    
}


Measured memory_bytes: 4752
#include<iostream>
#include<string.h>
#include<queue>
#include<map>
using namespace std;

int visited[100][100];
pair<int,int> jumpto[100][100];

int main() {
  int N,x,y;
  while(cin>>N, N) {

    for(int i=0; i<N; ++i)
      for(int j=0; j<N; ++j) {
    cin>>x>>y;
    jumpto[i][j] = pair<int,int>(x,y);
    visited[i][j] = 0;
      }

    int ans = 0;
    for(int i=0; i<N; ++i) {
      for(int j=0; j<N; ++j) {
    if(visited[i][j] == 0) {
      ans++;
      queue< pair<int,int> > Q;
      Q.push(pair<int,int>(j,i));
      visited[i][j] = ans;
      while(!Q.empty()) {
        pair<int,int> pos = Q.front(); Q.pop();
        int nx = jumpto[pos.second][pos.first].first;
        int ny = jumpto[pos.second][pos.first].second;
        if(visited[ny][nx] == ans) break;
        if(visited[ny][nx] != 0) {
          for(int i=0; i<N; ++i)
        for(int j=0; j<N; ++j)
          if(visited[i][j] == ans) visited[i][j] = visited[ny][nx];
          ans--;
          break;
        }
        Q.push(pair<int,int>(nx,ny));
        visited[ny][nx] = ans;
      }
    }
      }
    }

    cout<<ans<<endl;
  }
}

Measured memory_bytes: 0
#include <iostream>

using namespace std;
typedef long long ll;
ll n, m;

void solve() {
  if (n * 2 > m) {
    cout << (m / 2) << endl;
  } else {
    m -= n * 2;
    cout << (n + m / 4) << endl;
  }
}

int main() {
  cin >> n >> m;
  solve();
}


Measured memory_bytes: 256
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>
 
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
 
using namespace std;
 
#define int long long
//typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;
 
const int INF=1e+9;
const double EPS=1e-9;
const int MOD=1000000007;
 
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
 
int s;
vector<int> G[100010],ans;
bool used[100010];
 
bool dfs(int v){
	used[v] = true;
	bool flag = true;
	for(int i = 0;i < G[s].size();i++) if(!used[G[s][i]]) flag = false;
	for(int i = 0;i < G[v].size();i++){
		if(!used[G[v][i]]){
			flag = false;
			if(dfs(G[v][i])) {
				ans.pb(v);
				used[v] = false;
				return true;
			}
		}
	}
	if(flag){
		ans.pb(v);
		used[v] = false;
		return true;
	}
	used[v] = false;
	return false;
}
 
signed main(){
	int n,m;
	int cnt[100000] = {};
	cin >> n >> m;
	for(int i = 0;i < m;i++){
		int a,b;
		cin >> a >> b; a--;b--;
		G[a].pb(b);
		G[b].pb(a);
		cnt[a]++;
		cnt[b]++;
	}
	vector<P> vec;
	for(int i = 0;i < n;i++) vec.pb(P(cnt[i],i));
	sort(vec.begin(),vec.end());
	for(int i = 0;;i++){
		s = vec[i].second;
		if(dfs(s)) break;
	}
	cout << ans.size() << endl;
	for(int i = 0;i < ans.size();i++) cout << (i ? " " : "") << ans[i] + 1;
	cout << endl;
	return 0;
}

Measured memory_bytes: 13680
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < (n);i++)
using ll = long long;
const ll MOD=1000000007;
const double pi=acos(-1);





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


Measured memory_bytes: 256
S=str(input())
T=str(input())
if T in S:
    print(0)

else:
    S=list(S)
    T=list(T)
    nums=len(T)
    for i in range(len(S)-len(T)+1):
        ans=0
        for j in range(len(T)):
            if S[i+j]!=T[j]:
                ans+=1
        nums=min(nums,ans)
    print(nums)

Measured memory_bytes: 9136
# C
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors

N = int(input())
divisors = make_divisors(N)
memo = 0
maX = divisors[0] + divisors[len(divisors) - 1]
for (i, r) in zip(divisors, reversed(divisors)):
    maX = min(i + r, maX)
    memo = i
    if memo == r:
        break
print(maX - 2)


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

int main()
{
  int num = 0;
  cin >> num;
  if(num & 0x1)
  {
    cout << (num / 2 + 1) * (num / 2);
  }
  else
  {
    cout << (num / 2) * (num / 2);
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <limits>
#include <cmath>
#include <iomanip>
#include <functional>
#include <random>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using ll = long long;

int main()
{
    // 整数の入力
    string S;
    cin >> S;
    if( S == "ABC" ){
        cout << "ARC" << endl;
    }else{
        cout << "ABC" << endl;
    }
   return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <cctype>
#include <string>

using namespace std;

int main() {

	string str;

	getline(cin, str);

	for (int i = 0; i < str.length(); i++) {
		if (islower(str[i])) str[i] = toupper(str[i]);
		else if (isupper(str[i])) str[i] = tolower(str[i]);
	}

	cout << str << "\n";

	return 0;
}

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

struct Fast {Fast(){cin.tie(0);ios::sync_with_stdio(0);}} fast;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define ceiv(a, b) (1 + (int)((a) - 1)/(int)(b))
//#define int long long

int main() {
    char c;
    rep(i,9){
        cin >> c;
        if(i % 4 == 0) cout << c;
    }
    cout << endl;
}

Measured memory_bytes: 256
as = gets.chomp.split.map(&:to_i)
ans = 1000000000000000000
(0...3).to_a.permutation(3) do |ps|
  x = (as[ps[1]] - as[ps[0]]).abs + (as[ps[2]] - as[ps[1]]).abs
  ans = [ans, x].min
end
p ans


Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll n, x;
ll all[51] ={}, pat[51] = {};
void init(){
  all[0] = 1;
  pat[0] = 1;
  for(int i=1;i<=50;i++){
    all[i] = all[i-1] * 2 + 3;
    pat[i] = pat[i-1] * 2 + 1;
  }
}

ll solve(ll n, ll x){
  if (x <= 1) return (n == 0?1:0);
  else if (x <= all[n-1] + 1) return solve(n-1, x-1);
  else if (x == all[n-1] + 2) return pat[n-1] + 1;
  else if (x <= 2 * all[n-1] + 2) return pat[n-1] + 1 + solve(n - 1, x - all[n-1] - 2);
  else return pat[n];
}

int main(){
  cin >> n >> x;
  init();
  cout << solve(n, x) << endl;
}


Measured memory_bytes: 256
S = input()
T = input()
alp = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
ans = 'No'
for i in range(len(alp)):
    if S + alp[i] == T:
        ans = 'Yes'
        break
print(ans)

Measured memory_bytes: 9072
#include<bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
//long long int countt[200003];
#include<ext/pb_ds/assoc_container.hpp> // include the associative containers or group of templates such as set, multimap, map etc.
#include<ext/pb_ds/tree_policy.hpp> // include the tree_order_statistics_node update
using namespace __gnu_pbds; //necessary for the GNU based Policy based data structures.
typedef tree<pair<int,int> ,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

#define int long long
#define f first
#define s second
signed main()
{
    FAST;
    
    int i=0,j=0,k=0,n=0,m=0,count=0,temp=0,z;
    int temp1=0,temp2=0,temp3=0,x=0,l=0,y=0,sum=0;
    int left=0,up=0,anss=0,start=0,end=0,r=0,q=0,total=0;
    int maxx=0,minn=0,curr=0,ans=0,places=0,zeroes=0,low=0,high=0;
    int prev=0,mid=0,zz=0,d=0,val=0;
    
    cin>>n;
    double ii;
    ii = (double)n/3;
    
    cout<<setprecision(15)<<ii*ii*ii<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <fstream>
#include <stdlib.h>
#include <time.h>
#include<cstring>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include <limits.h>
#include<cmath>
#include<map>
#include<queue>
#include<set>
using namespace std;


#define LL long long

const long long  mod =1000000009;  //霑吩クェ蠢?。サ譏ッ雍ィ謨ー
int q[1010],w[1010];
int main()
{
    int n,m;
    while (~scanf("%d%d",&n,&m) && n && m){
        for (int j=0;j<n;j++) scanf("%d",&q[j]);
        sort(q,q+n);
        for (int j=0;j<m;j++) scanf("%d",&w[j]);
        sort(w,w+m);
        int l=n-1;
        int ans=0;
        for (int j=m-1;j>=0;j--){
            while (l>=0 && q[l]>w[j]) ans+=q[l--];
            if (q[l]==w[j]){
                ans+=q[l--];
                continue;
            }else {
                ans+=w[j];
                continue;
            }
        }
        while (l>=0) ans+=q[l--];
        printf("%d\n",ans);
    }
    return 0;
}

Measured memory_bytes: 1208
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, j, n) for (ll i = j; i < n; i++)
#define all(x) (x).begin(),(x).end()
#define INF (1000000000)
#define MOD (1000000007)
#define MAX (100000)
#define pii pair<int, int>

/////////////////////////////////////////////////////////

class XY{
public:
  ll x, y;
  XY() {x = y = 0;}
  XY(ll u, ll v) {x = u; y = v;}
};

template<typename T1, typename T2>
void chmin(T1 &a, T2 b) {if(a > b) a = b;}
template<typename T1, typename T2>
void chmax(T1 &a, T2 b) {if(a < b) a = b;}

template<typename T1, typename T2>
ll mypow(T1 a, T2 n){
  if(n == 0) return 1;
  if(n == 1) return a;
  if(n % 2) return a * mypow(a, n - 1);
  ll tmp = mypow(a, n / 2);
  return tmp * tmp;
}

template<typename T>
int BS(vector<T> V, int left, int right, T key){
  int mid = (left + right) / 2;
  if(V[mid] <= key) left = mid;
  else right = mid;
  if(right - mid == 1) return left;
  else return BS(V, left, right, key);
}

ll comb(ll n, ll r){
	ll res = 1;
  rep(i, 0, r){
    res *= n - i;
    res /= i + 1;
  }
  return res;
}

template<typename T>
T euclid(T a, T b){
  if(b == 0) return a;
  else return euclid(b, a % b);
}

/////////////////////////////////////////////////////////

void Main() {
  const int num = 26;
  string S; cin >> S;
  vector<int> c(num, 0);
  rep(i, 0, S.size()){
    c[S[i] - 'a']++;
  }
  if(S.size() < num){
    rep(i, 0, num){
      if(c[i] == 0){
        char C = 'a' + i ;
        S.push_back(C);
        break;
      }
    }
  }else{
    bool ok = false;
    while(!ok){
      int n = S.size() - 1;
      for(int i = (S[n] - 'a') + 1; i < num; i++){
        if(c[i] == 0){
          S[n] = 'a' + i;
          ok = true;
          break;
        }
      }
      if(ok) break;
      else{
        c[S[n] - 'a'] = 0;
        S = S.substr(0, n);
      }
      if(S == ""){
        S = "-1";
        break;
      }
    }
  }
  cout << S << endl;
}

/////////////////////////////////////////////////////////

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << std::fixed << std::setprecision(15);

  Main();
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int n;
    cin>>n;
    vector<int> dp(3);

    for(int day=0 ; day<n ; day++)
    {
        vector<int> c(3);
        vector<int> new_dp(3);
        for(auto &k:c)  cin>>k;

        for(int i=0 ; i<3 ; i++)
            for(int j=0 ; j<3 ; ++j)
                if(i!=j)
                    new_dp[j] = max(new_dp[j] , dp[i] + c[j]);

        dp = new_dp;
    }
    cout<<max({dp[0],dp[1],dp[2]});
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using Map = map<string,ll>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
ll INF=1LL<<60;
ll MOD=1000000007;

int main(){
    ll S;
    cin >> S;
    ll W;
    cin >> W;
    for(ll i=0;i<1000000000;i++){
        swap(S,W)
    ;}
    if(S<=W)cout<<"unsafe"<<endl;
    else cout<<"safe"<<endl;
    return 0;
}


Measured memory_bytes: 3636
#include<iostream>
#include<vector>
#include<cstdlib>
#include<algorithm>
#include<climits>
#include<queue>
#include<stack>
#include<cmath>
#include<iterator>
typedef long long ll;
using namespace std;
#define rep(x, y)   for (ll i = x; i <= y; i ++)
#define repi(x, y)  for (ll i = x; i >= y; i --)
priority_queue< ll > cancel;
ll arr[200005];
ll brr[200005];
ll dp[3005][3005];
ll maximise(ll start,ll end)
{
    if(start==end)
    {
        dp[start][end]=arr[end];
        return dp[start][end];
    }
    else  if(dp[start][end]!=-1)
    {
        return dp[start][end];
    }
    else
    {
        dp[start][end]=max(arr[start]-maximise(start+1,end),arr[end]-maximise(start,end-1));
        return dp[start][end];
    }
}
int main()
{
    ll test=1;
    // cin>>test;
    for(ll z=0;z<test;z++)
    {
        ll n,k;
        cin>>n;
        for(ll i=0;i<n;i++)
        {
            for(ll j=0;j<n;j++)
            {
                dp[i][j]=-1;
            }
        }
        for(ll i=0;i<n;i++)
        {
            cin>>arr[i];
        } 
        cout<<maximise(0,n-1)<<endl;
    }
}

Measured memory_bytes: 74220
#include<stdio.h>
int main(void){
  long long n,k;
  unsigned long long c=1000000007;;
  scanf("%lld%lld",&n,&k);
  int a[n];
  for(int i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  
  long long bb[n][2];   //[0]:右の自分より小さい要素
				  //[1]:左の自分より小さい要素	
  for(int i=0;i<n;i++){
	for(int j=0;j<2;j++){
      bb[i][j]=0;
    }
  }
  
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      if(i==j)continue;
      if(i>j&&a[i]>a[j])bb[i][1]++;
      if(i<j&&a[i]>a[j])bb[i][0]++;
    }
  }
  if(k==1){int sum=0;
for(int i=0;i<n;i++){
  sum+=bb[i][0];
}
    printf("%d",sum);
  return 0;
  }
  for(int i=0;i<n;i++){
  //printf("%d %d %d\n",i+1,bb[i][0],bb[i][1]);
    
  }
  long long r=k*(k+1)/2;
  long long l=k*(k-1)/2;
  if(r>c)r%=c;
  if(l>c)l%=c;
  //printf("%lld\n%lld\n",r,l);
  unsigned long long sum=0,buf;
  //sum+=bb[0][0]*k+bb[n-1][1]*(k-1);
  for(int i=0;i<n;i++){
    //printf("%d %d %d\n",i+1,bb[i][0],bb[i][1]);
    buf=bb[i][0]*r+bb[i][1]*l;
    if(buf>c)buf%=c;
    //printf("%llu\n",buf);
    sum+=buf;
    //printf("%llu\n",sum);
    if(sum>c)sum%=c;
  }
  
  
  printf("%llu",sum);
  return 0;
}

Measured memory_bytes: 256
fun main(arg: Array<String>) {
    val (n, x) = listOfLong()
    val ans = 3 * (n - gcd(n, x))
    println(ans)
}
tailrec fun gcd(a: Long, b: Long): Long = if (a % b == 0L) b else gcd(b, a % b)
fun next() = readLine()!!
fun listOfString() = next().split(" ")
fun listOfLong() = listOfString().map { it.toLong() }


Measured memory_bytes: 37820
s = input()
ym = False
my = False

f = int(s[:2])
l = int(s[2:])

if 1 <= f <= 12:my =True
if 1 <= l <= 12 : ym = True
  
if ym and my : print('AMBIGUOUS')
elif ym : print('YYMM')
elif my : print('MMYY')
else:print('NA')



Measured memory_bytes: 3060
N, K = map(int, input().split())

if K == 1:
    print(N**3)
    exit()

ans = 0
for k in range(K):
    if (k * 2) % K != 0:
        continue
    M = (N // K) - (1 if k == 0 else 0)
    if N % K >= k:
        M += 1
    ans += M**3
print(ans)


Measured memory_bytes: 3060
// finish date: 2019/3/17

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<double> vd;
typedef vector<vector<double>> vvd;
typedef vector<vector<vector<double>>> vvvd;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, pair<int, int>> plii;
const int bigmod = 1000000007;
const int INF = 1050000000;
const long long INFll = 100000000000000000;


int main() {
    int N;
    cin >> N;
    string S;
    cin >> S;
    int wc = 0;
    int bc = 0;
    rep(i, N) {
        if (S[i] == '.') wc++;
        else bc++;
    }
    int mi = wc;
    int cnt = 0;
    rep(i, N) {
        if (S[i] == '.') wc--;
        else {
            bc--;
            cnt++;
        }
        mi = min(mi, cnt + wc);
    }
    cout << mi << endl;

    return 0;
}


Measured memory_bytes: 640
//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
using namespace std;
const int INF= 1e9+5;
typedef long long ll;

int main(){
  string s;
  cin>>s;
  int count=0;
  for(int i=0;i<4;i++){
    if(s[i]=='+')count++;
    else count--;
  }
  cout<<count<<endl;
}

Measured memory_bytes: 256
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
#define INF 100000000000
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(10);
}
signed main(){
  init_io();
  ll h,w,d,q;
  cin >> h >> w >> d;
  ll a[h][w],di[110000]={};
  map<ll,P> mp;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin >> a[i][j];
      mp[a[i][j]] =P(i,j);
    }
  }
  for(int i=d+1;i<=h*w;i++){
    di[i] = di[i-d]+abs(mp[i].first-mp[i-d].first)
      +abs(mp[i].second-mp[i-d].second);
  }
  cin >> q;
  vector<ll> l(q),r(q);
  for(int i=0;i<q;i++){
    cin >> l[i] >> r[i];
    cout << di[r[i]]-di[l[i]]<<endl;
  }
}


Measured memory_bytes: 9856
n=int(input())
x=list(map(int,input().split()))

""" ans=100000000000000000

for i in range(n):
    tmp=0
    for j in x:
        tmp+=(j-i-1)**2
    ans=min(ans,tmp)

print(ans)
print(range(n)) """

a=int(sum(x)/n)
b=a+1
ans1=0
ans2=0
for i in range(n):
    ans1+=(x[i]-a)**2
    ans2+=(x[i]-b)**2
print(min(ans1,ans2))

Measured memory_bytes: 9100
#include<iostream>
#include<math.h>
#include<complex>
#include<cstdlib>
#include<algorithm>
#include<functional>
#include <cstdint>
#include<string.h>

typedef unsigned long long ll;

using namespace std;

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


	if (a <= c && c <= b) {
		printf("Yes");
	}

	else if (a >= c && c >= b) {
		printf("Yes");
	}
	else {
		printf("No");
	}
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	int x,y,a,b,c;
	cin>>x>>y>>a>>b>>c;
	vector<ll> p(a),q(b),r(c);
//	set<ll> r;
	vector<ll> g;
	rep(i,a){
		cin>>p[i];
	}
	rep(i,b){
		cin>>q[i];
	}
	rep(i,c){
		cin>>r[i];
	}
	sort(begin(p),end(p),greater<ll>());
	sort(begin(q),end(q),greater<ll>());
	rep(i,x){
		g.push_back(p[i]);
	}
	rep(i,y){
		g.push_back(q[i]);
	}
	sort(begin(g),end(g));
	ll ans=0;
	rep(i,g.size()){
		ans+=g[i];
	}
	sort(begin(r),end(r),greater<ll>());
	ll now=ans;
	rep(i,min(c,x+y)){
		now-=g[i];
		now+=r[i];
		chmax(ans,now);
	}
	cout<<ans<<endl;
}

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

struct Road{
    int d, p;
    bool operator<(const Road &obj)const{
        return p < obj.p;
    }
};

int main(){
    int n, m;
    while(cin >> n >> m, n != 0){
        vector<Road> v;
        for(int i=0;i<n;++i){
            int d, p;
            cin >> d >> p;
            v.push_back((Road){d, p});
        }
        sort(v.rbegin(), v.rend());
        for(auto& e : v){
            int tmp = e.d;
            e.d = max(0, e.d-m);
            m = max(0, m-tmp);
        }
        long long int sum = 0;
        for(auto e : v){
            sum += e.d * e.p;
        }
        cout << sum << endl;
    }

    return 0;
}



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

using namespace std;

#define REP(i,m) for(ll i=0; i<m; i++)
#define FOR(i,n,m) for(ll i=n; i<m; i++)
#define INF 1000000007
#define INFL (1LL << 60)
#define MOD 998244353
#define ALL(v) v.begin(),v.end()
#define pb push_back
#define ll long long int
#define P pair<ll, ll>

ll POW(ll a, ll b){
	if(b==0) return 1LL;
	if(b==1) return a;
	if(b%2==0) return POW(a*a%INF, b/2);
	return a*POW(a, b-1)%INF;
}

int main(){
	string l;
	cin >> l;
	int n = l.length();
	ll ans = 0, cur = -1;
	REP(i, n){
		if(l[i] == '1'){
			cur++;
			ans += (POW(2LL, cur) * POW(3LL, n-1-i));
			ans %= INF;
		}
	}
	ans += POW(2, cur+1);
	ans %= INF;
	cout << ans << endl;
	return 0;
} 


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define ll long long
#define pr pair<ll,ll>
using namespace std;
const ll INF = 1000000000000;
ll mat[302][302], n, m, l;
ll fil[302][302];
inline ll read()
{
	static char ch;
	bool sgn = false;
	while ((ch = getchar()) < '0' || ch > '9')
		if (ch == '-')
			sgn = true;
	ll res = ch - 48;
	while ((ch = getchar()) >= '0' && ch <= '9')
		res = res * 10 + ch - 48;
	return sgn ? -res : res;
}
void getmin() {
	for (int i = 1; i <= n; i++)mat[i][i] = 0;
	for (int k = 1; k <= n; k++) {
		for (int i = 1; i <= n; i++) {
			for (int j = 1; j <= n; j++) {
				mat[i][j] = min(mat[i][j], mat[i][k] + mat[k][j]);
			}
		}
	}
}
void init() {
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			mat[i][j] = INF;
		}
	}
}
void solve() {
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			if (mat[i][j] <= l) {
				fil[i][j] = 0;
			}
			else fil[i][j] = INF;
		}
	}
	for (int k = 1; k <= n; k++) {
		for (int i = 1; i <= n; i++) {
			for (int j = 1; j <= n; j++) {
				fil[i][j] = min(fil[i][j], fil[i][k] + fil[k][j] + 1);
			}
		}
	}
}
int main() {
	n = read(), m = read(), l = read();
	init();
	for (int i = 0; i < m; i++) {
		ll f = read(), t = read(), c = read();
		mat[f][t] = mat[t][f] = min(mat[f][t], c);
	}
	getmin();
	solve();
	ll q = read();
	while (q--) {
		ll s = read(), t = read();
		if (fil[s][t] >100000)cout << -1<<'\n';
		else cout << fil[s][t] << '\n';
	}
	return 0;
}


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

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

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

score_taro, score_hanako = 0, 0
for _ in range(n):
    card_taro, card_hanako = input().split()

    point_taro = 0
    point_hanako = 0
    if card_taro == card_hanako:
        score_taro += 1
        score_hanako += 1
        continue
    for i in range(min(len(card_taro), len(card_hanako))):
        if len(card_taro) > len(card_hanako):
            point_taro = 3
        elif len(card_taro) < len(card_hanako):
            point_hanako = 3
        if ord(card_taro[i:i+1]) > ord(card_hanako[i:i+1]):
            point_taro = 3
            point_hanako = 0
            break
        if ord(card_taro[i:i+1]) < ord(card_hanako[i:i+1]):
            point_taro = 0
            point_hanako = 3
            break
    score_taro += point_taro
    score_hanako += point_hanako
print("{0} {1}".format(score_taro, score_hanako))

Measured memory_bytes: 7708
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: u32,
        d: [u32; n],
    }
    let mut d = d;
    d.sort_by_key(|&x| x);

    let mut ans = 1;
    let mut v = d[0];
    for val in d {
        if v != val {
            ans += 1;
        }
        v = val;
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
#include <cmath>

using namespace std;

int main(){
  int n,x;
  cin >> n;
  long sum = 0;
  vector<int> vec;
  for(int i=0; i<n; i++){
    cin >> x;
    sum += (long)x;
    vec.push_back(x);
  }
  sort(vec.begin(),vec.end());
  cout << vec[0] << " " << vec[n-1] << " " << sum << endl;
  return 0;
}



Measured memory_bytes: 3272
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn gcd(a: i64, b: i64) -> i64 {
    if b == 0 {
        return a;
    }
    gcd(b, a % b)
}

fn main() {
    let mut v: Vec<i64> = read_vec();
    let (n, k) = (v[0], v[1]);
    let n = n as usize;
    let a = read_vec::<i64>();
    let max_a = a.iter().cloned().max().unwrap();
    if max_a < k {
        println!("IMPOSSIBLE");
        return;
    }

    let mut gcd_num = a[0];
    for i in 1..n {
        gcd_num = gcd(gcd_num, a[i]);
    }
    if (max_a - k) % gcd_num == 0 {
        println!("POSSIBLE");
    } else {
        println!("IMPOSSIBLE");
    }
}


Measured memory_bytes: 8444
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using Console = System.Console;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var r1 = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var r2 = Console.ReadLine().Split().Select(int.Parse).ToArray();
            long ret = 0;
            for (int i = 0; i < N; i++)
            {
                if (r1[i] > r2[i])
                {
                    ret += r2[i];
                }
                else
                {
                    ret += r1[i];
                    var remain = r2[i] - r1[i];
                    if (r1[i + 1] <= remain)
                    {
                        ret += r1[i + 1];
                        r1[i + 1] = 0;
                    }
                    else
                    {
                        ret += remain;
                        r1[i + 1] = r1[i + 1] - remain;
                    }
                }
            }
            Console.WriteLine(ret);
        }

    }
}

Measured memory_bytes: 34332
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n;
    cin>>n;
    ll a[n];
    for(ll i=0;i<n;i++)
        cin>>a[i];
    ll cur=0;
    ll i;
    vector<ll>v;
    for(i=1;i<=n;i++)
    {
        if(cur==n)
            break;
        while(cur<n && a[cur]!=i)
            cur++;
        if(cur<n && a[cur]==i)
            v.push_back(i);
    }
    if(v.size()==0)
    {
        cout<<"-1";
        return 0;
    }
    cout<<n-v[v.size()-1];
}


Measured memory_bytes: 3956
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
const ll INF=1e9+7;
const ll N = 9;
char c,ans=0;

int main(){
	FOR(i,0,3){
		cin>>c;
		if(c=='1')ans++;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n);i++)
#define ll long long
using namespace std;
int main(){
	int n;
	int f[100][14];
	int p[100][15];
	cin>>n;
	rep(i,n){
		rep(j,10){
			cin>>f[i][j];
		}
	}
	rep(i,n){
		rep(j,11){
			cin>>p[i][j];
		}
	}
  	int ans = -1e9;
  	rep(bit,(1<<10)){
  		if(bit==0){
  			continue;
  		}
  		int sum=0;
  		rep(i,n){
  			int c=0;
  			rep(j,10){
  				if(bit&(1<<j)){
  					if(f[i][j]){
  						c++;
  					}
  				}
  			}
  			sum+=p[i][c];
  		}
  		ans=max(ans,sum);
  	}
  	cout<<ans<<endl;
}

Measured memory_bytes: 256
def mycounter(d,i):
    if i in d:
        d[i]+=1
    else:
        d[i]=1
    return d
s=input()
d=dict()
for i in s:
    d=mycounter(d,i)
l=-(-len(s)//3)
for i in d.values():
    if l<i:
        print('NO')
        exit()
print('YES')

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

int main(){
  int n,m,X,Y;
  int amax,amin;
  cin >> n >> m >> X >> Y;
  vector<int> x(n),y(m);
  for(int i=0;i<n;i++){
    cin >> x[i];
  }
  for(int i=0;i<m;i++){
    cin >> y[i];
  }
  amax=-101;
  for(int i=0;i<n;i++){
    amax=max(amax,x[i]);
  }
  amin=101;
  for(int i=0;i<m;i++){
    amin=min(amin,y[i]);
  }
  if(max(amax,X)<min(amin,Y)){
    cout << "No War" << endl;
  }else{
    cout << "War" << endl;
  }
  
}

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

using ll = long long;
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) < (b)) ? (b) : (a))
int const nmax = 1000000;
int const modulo = 1000000007;

struct Mint{
private:
  void gcd(int a, int b, int &x, int &y) {
    if(b == 0) {
      x = 1;
      y = 0;
    } else {
      gcd(b, a % b, x, y);
      int aux = x;
      x = y;
      y = aux - a / b * y;
    }
  }
public:
  int number;
  Mint(ll number_ = 0) {
    number = number_ % modulo;
  }
  Mint operator + (Mint a) {
    return (number + a.number);
  }
  Mint operator - (Mint a) {
    return (modulo + number - a.number);
  }
  Mint operator * (Mint a) {
    return 1LL * number * a.number;
  }
  Mint operator / (Mint a) {
    int x, y;
    gcd(a.number, modulo, x, y);
    x %= modulo;
    if(x < 0)
      x += modulo;
    return 1LL * number * x;
  }
  friend std::ostream &operator <<(std::ostream &output, Mint a) {
    output << a.number;
    return output;
  }
};

Mint fact[1 + nmax];
void precompute() {
  fact[0] = 1;
  for(int i = 1;i <= nmax; i++)
    fact[i] = fact[i - 1] * i;
}
Mint comb(int n, int k) {
  if(0 <= k && k <= n)
    return fact[n] / fact[k] / fact[n - k];
  return 0;
}

int main() {
  precompute();
  int n;
  std::cin >> n;
  if(n == 2) {
    std::cout << 1;
    return 0;
  }
  Mint result;
  result = fact[n - 1] * (n);
  for(int i = (n + 1) / 2; i < n; i++) {
    result = result - comb(i - 1, n - 1 - i) * fact[i] * fact[n - 1 - i];
  }
  std::cout << result;
  return 0;
}


Measured memory_bytes: 7480
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int A = sc.nextInt();
    int B = sc.nextInt();
    int[] X = new int[N];
    for (int i = 0; i < N; i++) {
      X[i] = sc.nextInt();
    }
    long ans = 0;
    for (int i = 1; i < N; i++) {
      int d = X[i]-X[i-1];
      ans += Math.min((long)d*A, B);
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 50112
#include <iostream>
#include <string.h>
using namespace std;
int main(void){
    // Your code here!
    char s[200001],t[200001];
    scanf("%s",s);
    scanf("%s",t);
    int count = 0;
    int N = strlen(s);
    for(int i = 0; i < N; i++)
    {
        if(s[i]!=t[i]) count++;
    }
    printf("%d\n", count);
}

Measured memory_bytes: 4212
#include<stdio.h>
#include<stdlib.h>
void swap(char **p, char **q){
	char *a;
	a = *p;
	*p = *q;
	*q = a;
}

int length(char *p){
	int i = 0, L = 0;
	while(p[i] != '\0'){
		L++;
		i++;
	}
	return 0;
}

int comp(int L,char *p, char *q){
	/*if p < q, then return 1, else return 0*/
	int i = 0;
	while(i < L){
		if(p[i] > q[i])return 1;
		if(p[i] < q[i])break;
		i++;
	}
	return 0;
}
		
int main(){
	int i = 0, j = 0, n, L;
	char *buf;
	char **s;
	s = (char **)malloc(sizeof(char *)*100);
	*s = (char *)malloc(sizeof(char)*100);
	scanf("%d %d", &n, &L);
	
	for(i = 0; i < n; i++){
		buf = (char *)malloc(sizeof(char) * 100);
		scanf("%s", buf);
		s[i] = buf;
	}
	for(i = 0; i < n; i++){
		for(j = 0; j+i < n; j++){	
			if(comp(L, s[i], s[i+j] ) )swap(&(s[i]), &(s[i+j]));
		}
	}
	
	for(i = 0; i < n; i++){
		printf("%s", s[i]);
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int a,b,c,ans=0;
  cin>>a>>b>>c;
  int d=a+b,e=a+c,f=c+b;
  ans=min(d,e);
  ans=min(ans,f);
  cout<<ans<<endl;
}

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

// 
int main() {
    int N, K;
    cin >> N >> K;

    long long A[N];

    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }

    long long firstA = A[0];
    for (int i = K; i < N; i++) {
        // cout << firstA << ":" << A[i] << endl;  // debug
        if (firstA < A[i]) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
        firstA = A[i - K + 1];
    }
}


Measured memory_bytes: 5176
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define rep(i,j,k) for(int i=j;i<k;i++)
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
int main(){
  int k,x;
  cin >> k >> x;
  for(int i= max(-1000000,x-k+1);i <min(1000001,x+k) ;i++){
    cout << i << " " << endl;
  }
	return 0;
}


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


void solve() {
    int n;
    cin >> n;
    unordered_map<int, int> mp;
    while(n--) {
        int x;
        cin >> x;
        mp[x]++;

    }
    int ans = 0;
    for (auto p : mp) {
        int sum = p.second - p.first;
        if(sum < 0) {
            sum = p.second;
        }
        ans += sum;
    }
    cout << ans;

}


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


Measured memory_bytes: 7176
n, k = map(int, input().split())
ww = [int(input()) for _ in range(n)]
def chk(p):
    c = 1
    s = 0
    for w in ww:
        if w > p:
            return False
        if s + w <= p:
            s += w
        else:
            c += 1
            s = w
        if c > k:
            return False
    return True
def search(l, r):
    if r - l < 10:
        for i in range(l, r):
            if chk(i):
                return i
    m = (l + r) // 2
    if chk(m):
        return search(l, m + 1)
    else:
        return search(m + 1, r)
print(search(0, 2 ** 30))

Measured memory_bytes: 11580