akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define all(c) (c).begin(),(c).end()
 
using namespace std;
 
const double R=6378.10;
const double PI=3.1415926535;
const double EPS=1e-10;
const double toRad=180.0/PI;
 
int main(void){
  double a,b,c,d;
  while(cin >> a >> b >> c >> d){
    if(a<0 && b<0 && c<0 && d<0)break;
    a/=toRad,b/=toRad,c/=toRad,d/=toRad;
    double ax=cos(b)*cos(a),ay=sin(b)*cos(a),az=sin(a);
    double bx=cos(d)*cos(c),by=sin(d)*cos(c),bz=sin(c);
    double D=sqrt(pow(ax-bx,2)+pow(ay-by,2)+pow(az-bz,2));
    double rad=acos(1-D*D/2);
    printf("%.0f",round(R*rad));
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 3576
#include <iostream>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const long long INF = 1LL<<60;

const int MAX_N = 110;
const int MAX_V = 100100;

// 入力
int N;
long long W, weight[MAX_N], value[MAX_N]; // 品物の個数は 100 個なので少し余裕持たせてサイズ 110 に

// DPテーブル
long long dp[MAX_N][MAX_V];

int main() {
    cin >> N >> W;
    for (int i = 0; i < N; ++i) cin >> weight[i] >> value[i];

    // 初期化
    for (int i = 0; i < MAX_N; ++i) for (int j = 0; j < MAX_V; ++j) dp[i][j] = INF;

    // 初期条件
    dp[0][0] = 0;

    // DPループ
    for (int i = 0; i < N; ++i) {
        for (int sum_v = 0; sum_v < MAX_V; ++sum_v) {

            // i 番目の品物を選ぶ場合
            if (sum_v - value[i] >= 0) chmin(dp[i+1][sum_v], dp[i][sum_v - value[i]] + weight[i]);

            // i 番目の品物を選ばない場合
            chmin(dp[i+1][sum_v], dp[i][sum_v]);
        }
    }

    // 最適値の出力
    long long res = 0;
    for (int sum_v = 0; sum_v < MAX_V; ++sum_v) {
        if (dp[N][sum_v] <= W) res = sum_v;
    }
    cout << res << endl;
}

Measured memory_bytes: 86400
#include<bits/stdc++.h>
using namespace std;
int d[100009];
int main()
{
	int n,q,l,r,an;
	string s;
	cin>>n>>q>>s;
	n=(int)s.size()-1;
	for(int i=0;i<n;i++)if(s[i]=='A'&&s[i+1]=='C')d[i]++;
	n++;
	for(int i=1;i<n;i++)d[i]+=d[i-1];

	while(q--)
	{
	cin>>l>>r;
	l--;r--;
	an=d[r]-(l==0?0:d[l-1]);
	if(s[r]=='A'&&r<n-1&&s[r+1]=='C')an--;
	cout<<an<<endl;
		
	}

}



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


void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}

#define fo(i, n) for(int i=0; i<n; i++)
#define Fo(i, k, n) for(int i=k; i<n; i++)
#define w(x)  int x; cin>>x; while(x--)
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define watch2(x,y) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<"\n"
#define watch3(x,y,z) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<" and "<<(#z)<<" is "<<(z)<<"\n"
#define watch4(x,y,z,q) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<" and "<<(#z)<<" is "<<(z)<<" and "<<(#q)<<" is "<<(q)<<"\n"
#define MOD 1000000007
#define INF 1000000007;
#define F first
#define S second
#define pb(x) push_back(x);


#define ll  long long
#define all(c) (c).begin(),(c).end()
#define endl "\n"

typedef vector<int> vl;
typedef vector< vl > vvl;
typedef pair< int, int> pll;
typedef map< int, int> mll;


#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif





void c_p_c()
{
#ifndef ONLINE_JUDGE
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}
void parray(int a[],int n){
    for(int i=0;i<n;i++){
    cout<<a[i]<<" ";
    }
    cout<<endl;
}

int main() {
    int i,n,m,k,c=0;
    c_p_c();
    cin>>n>>m>>k;
    ll sum;
    ll a[m];
    fo(i,m) cin>>a[i];

    // for (int i = 0; i < m; ++i)
    // {
    // 	/* code */
    // 	cout<<a[i]<<" ";

    	
    // }
    // cout<<endl;
    for (int i = 0; i < n; ++i)
    {
    	/* code */
    	sum=k;
    	ll b[m];
    	fo(pp,m) cin>>b[pp];


    	// debug(b);

    	// for (int rr = 0; rr < m; ++rr)
    	// {
    	// 	 code 
    	// 	cout<<b[rr]<<" ";
    	// }
    	// cout<<endl;

    	for (int j = 0; j < m; ++j)
    	{
    		
    		sum+=(a[j]*b[j]);
    	}
    	// watch(sum);
// 
    // cout<<sum<<endl;
    	if(sum<=0)
    		c++;
    }
    cout<<n-c<<endl;

    return 0;
}



Measured memory_bytes: 3604
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;
#define int long long int
const int INF = 1001001001001001LL;
const int MOD = 1000000007;

signed main(){
    double n;
    int k; cin >> n >> k;
    vector<double> p(n + 1, 1.0/n);

    for(int i = 1; i <= n; i++){
        int val = i;
        while(val < k){
            val *= 2;
            p[i] = p[i] / 2.0;
        }
    }

    double ans = 0.0;
    for(int i = 1; i <= n; i++) ans += p[i];
    printf("%.10f\n", ans);
    return 0;
}



Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
struct node{
	int i,j;
	node(int _i=0,int _j=0){
		i = _i;
		j = _j;
	}
};
int nn[510][510];
vector<node> ans;
int op=0;
int main()
{
	int n,m;
	int i,j;
	scanf("%d%d",&n,&m);
	for(i=1;i<=n;i++)
		for(j=1;j<=m;j++)
			scanf("%d",&nn[i][j]);
		
	for(i=1;i<=n;i++)
	{
		if(i%2 == 1)
		{
			for(j=1;j<m;j++)
			{
				if(nn[i][j]%2 == 1)
				{
					nn[i][j] -= 1;
					nn[i][j+1] += 1;
					op++;
					ans.push_back(node(i,j));
					ans.push_back(node(i,j+1));
				}
			}
			if(nn[i][m]%2 == 1 && i+1<=n)
			{
				nn[i][m] -= 1;
				nn[i+1][m] += 1;
				op++;
				ans.push_back(node(i,m));
				ans.push_back(node(i+1,m));
			}
		}
		else
		{
			for(j=m;j>1;j--)
			{
				if(nn[i][j]%2 == 1)
				{
					nn[i][j] -= 1;
					nn[i][j-1] += 1;
					op++;
					ans.push_back(node(i,j));
					ans.push_back(node(i,j-1));
				}
			}
			if(nn[i][1]%2 == 1 && i+1<=n)
			{
				nn[i][1] -= 1;
				nn[i+1][1] += 1;
				op++;
				ans.push_back(node(i,1));
				ans.push_back(node(i+1,1));
			}
		}
	}
	printf("%d\n",op);
	for(i=0;i<op;i++)
		printf("%d %d %d %d\n",ans[i*2].i,ans[i*2].j,ans[i*2+1].i,ans[i*2+1].j);
	return 0;
}

Measured memory_bytes: 5232
#!/usr/bin/env python3
import sys
from queue import PriorityQueue
try:
    from typing import List, Tuple, Dict
except ImportError:
    pass
def debug(*args): print(*args, file=sys.stderr)
def exit(): sys.exit(0)


N = int(input())
a = list(map(int, input().split()))


left_queue = PriorityQueue()  # type: PriorityQueue[Tuple[int, None]]

for i in range(N):
    item = (a[i], None)
    left_queue.put(item)


score = sum(a[:N])
left_scores = [score]

for i in range(N, 2*N):
    b, none = left_queue.get()
    if a[i] < b:
        item = (b, None)
        dscore = 0
    else:
        item = (a[i], None)
        dscore = a[i] - b
    left_queue.put(item)
    score += dscore
    left_scores.append(score)


right_queue = PriorityQueue()  # type: PriorityQueue[Tuple[int, None]]

for i in range(2*N, 3*N):
    item = (-a[i], None)
    right_queue.put(item)


score = - sum(a[2*N:])
right_scores = [score]

for i in range(2*N-1, N-1, -1):
    b, none = right_queue.get()
    if -a[i] < b:
        item = (b, None)
        dscore = 0
    else:
        item = (-a[i], None)
        dscore = -a[i] - b
        # debug(a[i], b, i)
    right_queue.put(item)
    # debug(item, score, dscore)
    score += dscore
    right_scores.append(score)


scores = []
for i in range(N+1):
    scores.append(left_scores[i] + right_scores[N-i])

debug(scores)
print(max(scores))


Measured memory_bytes: 125732
import scala.math._

object Main extends App {
  val sc = new java.util.Scanner(System.in)
//  val list = List.fill(3)(sc.nextInt)
  val n = sc.nextInt
  val a = sc.nextInt

  val ans = n * n - a

  println(ans)

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

  def bigIterator(start: BigInt, end: BigInt, step: BigInt = 1) =
    Iterator.iterate(start)(_ + step).takeWhile(_ <= end)

  def lcm(a :Int, b :Int): Int =
    a / gcd(a, b) * b

  def lcm(a :Long, b :Long): Long =
    a / gcd(a, b) * b

  def gcd(a: Int, b: Int): Int =
    if (b == 0) a else gcd(b, a % b)

  def gcd(a: Long, b: Long): Long =
    if (b == 0) a else gcd(b, a % b)

  def setOrUpdated[A, B](a: Map[A, B], key: A, value: B, f: (B, B) => B) =
    a.get(key) match {
      case Some(v) => a.updated(key, f(value, v))
      case _ => a + (key -> value)
    }
}

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

using namespace std;

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

    int sum = 0, minn=1000000;
    int temp;
    for(int i=1; i<=n; i++)
    {
        temp=l+i-1;
        sum+=temp;

        if(abs(temp)<abs(minn))
        {
            minn=temp;
        }
    }
    cout<<sum-minn;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>

#include <bits/stdc++.h>
#include <cmath>
#include <limits>

using namespace std;

int main(int argc, char* argv[]){
	cin.tie(0);
	ios::sync_with_stdio(false);

	string s, t;
	cin >> s;
	cin >> t;

	sort(s.begin(), s.end());
	sort(t.begin(), t.end());
	std::reverse(t.begin(), t.end());
	int ret = strcmp(s.c_str(), t.c_str());
	if(ret < 0){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 3664
import sys

m, k = map(int, raw_input().split(" "))

if k >= 2 ** m:
    print(-1)
    sys.exit(0)

if m == 0:
    if k == 0:
        print("0 0")
        sys.exit(0)

    else:
        print(-1)
        sys.exit(0)

if m == 1:
    if k == 0:
        print("0 1 1 0")
        sys.exit(0)

    else:
        print(-1)
        sys.exit(0)


for i in range(0, 2 ** m):
    if i != k:
        sys.stdout.write("%d " % i)

sys.stdout.write("%d " % k)

for i in range((2 ** m) -1, 0 - 1, -1):
    if i != k:
        sys.stdout.write("%d " % i)

print(k)


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

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<29;

vector<string> str[21];
vector<string> seq;
vector<char> mp(26);
int n;
char ans[26];
int ok;

map<pair<int, vector<char> >, bool> memo;

void dfs(int num) {
  // cout << num << endl;
  // if (memo[make_pair(num,mp)]) return;
  // memo[make_pair(num,mp)] = 1;
  
  if (num == seq.size()) {
    ok++;
    REP(i, 26)
      ans[i] = mp[i];
    return;
  }
  bool change[26];
  string s = seq[num];
  if (ok > 1) return;
  FOR(it, str[s.size()]) {
    string t = *it;
    bool dame = 0;
    memset(change,0,sizeof(change));
    REP(i, s.size()) {
      if (mp[s[i]-'A'] == 0) {
        if (mp[t[i]-'A']) {
          dame = 1;
          break;
        }
        mp[s[i]-'A'] = t[i];
        mp[t[i]-'A'] = s[i];
        change[s[i]-'A'] = 1;
        change[t[i]-'A'] = 1;
      } else if (mp[s[i]-'A'] != t[i]) {
        dame = 1;
        break;
      }
    }
    // REP(i, 26) if (mp[i]) printf("(%c,%c)",i+'A', mp[i]);
    // cout << endl;
    if (!dame)
      dfs(num+1);
    REP(i, 26)
      if (change[i])
        mp[i] = 0;
  }
}


int main() {
  while(cin>>n,n) {
    REP(i,21) str[i].clear();
    REP(i, n) {
      string tmp;
      cin >> tmp;
      str[tmp.size()].push_back(tmp);
    }
    seq.clear();
    string line;
    cin.ignore();
    getline(cin,line);
//    cout << "line : " << line << endl;
    stringstream sin(line);
    string tmp;
    while(sin>>tmp, tmp[tmp.size()-1] != '.') seq.push_back(tmp);
    seq.push_back(tmp.substr(0, tmp.size()-1));

    vector<pair<int, string> > v;
    vector<int> num(21);
    FOR(it, seq)
      num[it->size()]++;
    FOR(it, seq) v.push_back(make_pair(num[it->size()], *it));
    sort(ALL(v));
    seq.clear();
    FOR(it, v) {
      seq.push_back(it->second);
//      cout << it->second << endl;
    }

    mp = vector<char>(26);
    memo.clear();
    //cout << line << endl;
    ok = 0;
    dfs(0);
    if (ok == 1) {
      REP(i, line.size()) {
        if (line[i] == ' ' || line[i] == '.') cout << line[i];
        else cout << ans[line[i]-'A'];
      }
      cout << endl;
    } else {
      cout << "-." << endl;
    }
  }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define ios ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
using namespace std;
// bitset<8>set1(p);
// __builtin_popcountll(x);
// bitset<100> b("1010");
long long power(long long a, long long b) {
    //a %= m;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
    }
  ll int binomial(ll int n, ll int k) 
{ 
    ll int C[k+1]; 
    memset(C, 0, sizeof(C)); 
  
    C[0] = 1;  // nC0 is 1 
  
    for (ll int i = 1; i <= n; i++) 
    { 
        // Compute next row of pascal triangle using 
        // the previous row 
        for (int j = min(i, k); j > 0; j--) 
            C[j] = C[j] + C[j-1]; 
    } 
    return C[k]; 
} 
  vector<int> pr;
void Sieve(ll int n) 
{ 
    bool prime[10000000];
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        if (prime[p] == true) 
        { 
            pr.push_back(p);
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
}
 

int gcd(int a, int b) 
{ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
} 
  
// Function to find gcd of array of 
// numbers 
int find(int arr[], int n) 
{ 
    int result = arr[0]; 
    for (int i = 1; i < n; i++) 
    { 
        result = gcd(arr[i], result); 
  
        if(result == 1) 
        { 
           return 1; 
        } 
    } 
    return result; 
} 


//It reurns Fn,Fn+1
pair<int, int> fib (int n) {
    if (n == 0)
        return {0, 1};

    auto p = fib(n >> 1);
    int c = p.first * (2 * p.second - p.first);
    int d = p.first * p.first + p.second * p.second;
    if (n & 1)
        return {d, c + d};
    else
        return {c, d};
}
void reverse(string& str) 
{ 
    int n = str.length(); 
  
    // Swap character starting from two 
    // corners 
    for (int i = 0; i < n / 2; i++) 
        swap(str[i], str[n - i - 1]); 
} 

  
int main() {
    ll int n;
    cin>>n;
    int l=n/1000;
    if(n%1000!=0)
    {
        l++;
    }
    int k=l*1000;
    cout<<k-n<<endl;
}   



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

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;
}

int v[100100][3];
vector<vector<int>> dp(100100, vector<int>(3, 0));

int rec(int i, int j){
    if(dp[i][j]>0) return dp[i][j];
    if(i==0) return 0;
    
    int r = 0;
    rep(k, 3){
        if(i==1 || j!=k)chmax(r, rec(i-1, k) + v[i-1][k]);
    }

    return dp[i][j] = r;
}

int main(){
    int N;
    cin >> N;
    
    rep(i, N) rep(j, 3) cin >> v[i][j];

    cout << max({rec(N, 0), rec(N, 1), rec(N, 2)}) << endl;
    return 0;
}


Measured memory_bytes: 28520
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define cerr cout
#define F first
#define S second
#define fori(i,a,b) for (i = a; i < b; ++i)
#define ford(i,a,b) for(i = a; i>=b;--i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) int(x.size())
typedef long long ll;
typedef pair <int, int> pii;
typedef vector <int> vi;
typedef vector <ll> vl;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fill(a, x) memset(a, x, sizeof(a))
#define INF 1000000000
#define MOD 1000000007
#define SMOD 998244353
#define endl "\n"
string to_string(string s) { return '"' + s + '"';}
string to_string(char s) { return string(1, s);}
string to_string(const char* s) { return to_string((string) s);}
string to_string(bool b) { return (b ? "true" : "false");}
template <typename A> string to_string(A);
template <typename A, typename B>string to_string(pair<A, B> p) {return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}
template <typename A> string to_string(A v) {bool f = 1; string r = "{"; for (const auto &x : v) {if (!f)r += ", "; f = 0; r += to_string(x);} return r + "}";}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {cerr << " " << to_string(H); debug_out(T...);}
#define pr(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
const ll N = 100043;
ll fact[N];
ll add(ll x, ll y)
{
	x += y;
	while(x >= MOD) x -= MOD;
	while(x < 0) x += MOD;
	return x;
}
ll mul(ll x, ll y)
{
	return (x * 1ll * y) % MOD;
}
ll mulmod(ll a, ll b)
{
    ll res = 0;
    a = a % MOD;
    while (b>0)
    {
        if (b % 2 == 1)
            res = (res + a) % MOD;
        a = (a * 2) % MOD;
        b /= 2;
    }
    return res % MOD; 
}
ll binpow(ll x, ll y)
{
	ll z = 1;
	while(y > 0)
	{
		if(y % 2 == 1)
			z = mul(z, x);
		x = mul(x, x);
		y /= 2;
	}
	return z;
}
ll inv(ll x)
{
	return binpow(x, MOD - 2);
}
ll divide(ll x, ll y)
{
	return mul(x, inv(y));
}
void precalc()
{
	fact[0] = 1;
	ll i;
	fori(i, 1, N)
		fact[i] = mul(i, fact[i - 1]);
}
ll C(ll n, ll k)
{
	if(k > n)
	    return 0;
	return divide(fact[n], mul(fact[n - k], fact[k]));
}

void solve()
{
    int n;
    cin >> n;
    if(n>=30)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t;
    t=1;
    // cin >> t;
    for(int i=1; i<=t; i++)
    {
        // cout << "Case #" << i << ": ";
        solve();
    }
    return 0;
}

Measured memory_bytes: 3652
/*author : Yashvardhan
Tuesday, July 16, 2019
5:57 PM
*/

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;

#define int ll
#define pb push_back
#define vi vector<int>
#define pi pair<int,int>
#define vpi vector<pi>
#define ff first
#define ss second
#define mp make_pair
#define endl '\n'
#define all(a) a.begin(), a.end()
#define initialise(a, x) memset(a, x, sizeof(a))
#define rev(Y) reverse(all(Y))


#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS

#ifdef __APPLE__
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){cerr << name << " : " << arg1 << endl;}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');
	cerr.write(names, comma - names) << " : " << arg1 << "  ";
	__f(comma + 1, args...);}
#else
#define debug(...)
#endif

template <typename T> ostream& operator << (ostream& os,const vector<T>& v){for(int i=0;i<v.size();++i) os<<v[i]<<" ";return os;} 
template <typename T> ostream& operator << (ostream& os,const set<T>& v){for(auto it:v) os<<it<<" ";return os;} 
template <typename T, typename S> ostream& operator << (ostream& os, const pair<T,S>& v) {os<<v.ff<<" "<<v.ss;return os;}

const int mod = 1e9 + 7;
const int inf = 2e18;
const int ninf = -2e18;

const int N = 22;
const int M = (1<<(21)) + 1;

int n;
int grid[N][N];
int dp[N][M];

int takemod(int a){return ((a%mod)+mod)%mod;}

int pow(int a, int b, int m)
{
	int ans = 1;
	while (b)
	{
		if (b & 1)
			ans = (ans * a) % m;
		b /= 2;
		a = (a * a) % m;
	}
	return ans;
}

int modinv(int a){return takemod(pow(takemod(a), mod-2,mod));}

int solve(int i, int mask){
	//debug(i,mask);
	if(dp[i][mask] != -1) return dp[i][mask];
	if(i == 0) return 1;

	int ans = 0;
	for(int j = 0; j < n; j++){
		int curr = (1<<j);
		if(mask & curr){
			if(grid[i][j+1] == 1){
				int tmp = solve(i-1,mask^curr);
				ans = (ans + tmp)%mod;
			}
		}
	}
	return dp[i][mask] = ans;
}


signed main()
{

	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	#ifdef __APPLE__
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
		freopen("error.txt","w",stderr);
	#endif

	time_t t1, t2;
	t1 = clock();
	
	
	cin>>n;

	for(int i = 1; i <= n ; i++){
		for(int j = 1; j <= n; j++){
			cin>>grid[i][j];
		}
	}

	memset(dp,-1,sizeof(dp));

	cout<<solve(n,(1<<n)-1)<<endl;



	t2 = clock();
	cerr<<endl<<t2-t1<<endl;
	
	return 0;
}



Measured memory_bytes: 360704
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9 + 7);

int main(void) {
	int n, k;
	cin >> n >> k;
	
	vector<ll> h(n);
	for(int i = 0; i < n; ++i) {
		cin >> h[i];
	}
	
	vector<ll> dp(n + 10, 1LL << 60);
	dp[0] = 0; 
	/*
	for(int i = 1; i < n; ++i) {
		for(int j = 1; j <= k; ++j) {
			if( i < j ) continue;
			else dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]));
		}
	}
	*/
	
	for(int i = 0; i < n; ++i) {
		for(int j = 1; j <= k; ++j) {
			if( i + j < n ) dp[i + j] = min(dp[i + j], dp[i] + abs(h[i] - h[i + j]));
		}
	}
	
	cout << dp[n - 1] << endl;
	
	return 0;
}


Measured memory_bytes: 4840
#include <bits/stdc++.h>
using namespace std;
int main () {
  string S;
  cin >> S;
  vector<int> data(3);
  for(char a: S){
    data.at(a - 'a')++;
  }
  sort(data.begin(), data.end());
  cout << (data.at(2) - data.at(0) <= 1?"YES":"NO") << endl;
  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <ctime>
#include <sstream>
#define weewoo ios::sync_with_stdio(false);cin.tie(0)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ld long double
#define ll long long
#define se second
#define fi first
#define ctoi(x) x-'0'
#define pi (acos(-1))
#define llputin(a,n) for(int i=0;i<n;i++){ll x;cin >> x;a.push_back(x);}
#define iputin(a,n) for(int i=0;i<n;i++){int x;cin >> x;a.push_back(x);}

#define MOD ((ll) 1e9 + (ll) 7)
using namespace std;

ll pw(ll x,ll a){
    if(a==0)
        return 1;
    ll t = pw(x,a/2);
    if(a%2==0)
        return (t*t);
    else
        return (t*t*x);
}

bool prime(int x)
{
    if(x < 2) return false;
        for(int i=2; i<= sqrt(x); i++) {
            if ((x%i) == 0) return false;
        }
    return true;
}

vector<pii>s;
vector<int>a;

int main()
{
    weewoo;
    ll n,a;
    cin >> n >> a;
    cout << n/a + (n%a!=0) << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
vector<int> vec[200000];
int counter[200000]={0};

void dfs(int p,int n){
	for(int i=0;i<vec[n].size();i++){
		if(vec[n][i]!=p){
			counter[vec[n][i]]+=counter[n];
			dfs(n,vec[n][i]);
		}
	}
}
int main(){
	int N,Q,a,b,p,x;
	cin>>N>>Q;
	for(int i=0;i<N-1;i++){
		cin>>a>>b;
		a--;b--;
		vec[a].push_back(b);
		vec[b].push_back(a);
	}
	for(int i=0;i<Q;i++){
		cin>>p>>x;
		p--;
		counter[p]+=x;
	}
	dfs(-1,0);
	for(int i=0;i<N;i++)cout<<counter[i]<<" ";
	return 0;
}

Measured memory_bytes: 26624
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) long long((x).size())
#define OUT(x) cout << (x) << endl
typedef long long ll;
typedef vector<ll> V;
typedef vector<vector<ll>> VV;
typedef pair<ll, ll> P;
typedef map<string, ll> M;
typedef unordered_map<ll, ll> HM;
typedef set<ll> S;
typedef multiset<ll> MS;
typedef queue<ll> Q;

int main(){
    ll n; cin>>n;
    ll a[n];
    ll sum = 0, oddSum = 0;
    for(ll i=0; i<n; i++){
        ll tmp; cin>>tmp;
        a[i] = tmp;
        sum += tmp;
        if(i&1) oddSum += tmp;
    }
    ll x[n];
    x[0] = sum - oddSum*2;
    for(ll i=1; i<n; i++)
        x[i] = a[i-1]*2 - x[i-1];
    for(ll i=0; i<n; i++)
        cout << x[i] << " ";
    cout << endl;
}

Measured memory_bytes: 2816
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.*
import kotlin.math.min

val br = BufferedReader(InputStreamReader(System.`in`))
val out = PrintWriter(System.out)

fun main() {
    br.use { out.use {
        solve()
        out.flush()
    } }
}

fun solve() {
    val n = readInteger()
    val xList = readLongList()

    val ans = (1..100L)
        .map { p -> xList.fold(0L) { acc, x -> acc + (x - p) * (x - p) } }
        .min()!!
    out.println(ans)
}

fun readInteger() = Integer.parseInt(br.readLine())
fun readLong() = java.lang.Long.parseLong(br.readLine())
fun readStringList() = br.readLine()!!.split(' ')
fun readIntegerList() = readStringList().map(Integer::parseInt)
fun readLongList() = readStringList().map(java.lang.Long::parseLong)
fun readDoubleList() = readStringList().map(java.lang.Double::parseDouble)


Measured memory_bytes: 36616
#include<bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
const int inf = 1001001001;
int main(){
  int N,M,i,j,k,a,b,c;scanf("%d%d",&N,&M);
  int D[N][N];bool unuse[N][N];
  memset(unuse,0,sizeof(unuse));
  for(i=0;i<N;i++){
    fill(D[i],D[i]+N,inf);
    D[i][i] = 0;
  }
  for(i=0;i<M;i++){
    scanf("%d%d%d",&a,&b,&c);a--;b--;
    D[a][b] = D[b][a] = c;
    unuse[a][b] = unuse[b][a] = 1;
  }
  int prev[N][N];
  for(i=0;i<N;i++) fill(prev[i],prev[i]+N,-1);
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(unuse[i][j]) prev[i][j] = i;
    }
  }
  for(k=0;k<N;k++){
    for(i=0;i<N;i++){
      for(j=0;j<N;j++){
        if(D[i][j] > D[i][k]+D[k][j]){
          D[i][j] = D[i][k]+D[k][j];
          prev[i][j] = prev[k][j];
        }
      }
    }
  }
  int ns,bs,ans = 0;
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      bs = j;ns = prev[i][bs];
      while(ns != -1){
        unuse[ns][bs] = 0;
        bs = ns;
        ns = prev[i][bs];
      }
    }
  }
  for(i=0;i<N;i++) ans += accumulate(unuse[i],unuse[i]+N,0);
  printf("%d\n",ans/2);
}

Measured memory_bytes: 3880
#include <stdio.h>
int main ( )
{
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
if (a>=0 && a<=100 && b>=0 && b<=100 && c>=0 && c<=100)
    {
    if(a<b && b<c)
    {
        printf("Yes\n");
    }
    else
    {
        printf("No\n");
    }
    }

return 0;
}






Measured memory_bytes: 2576
#include<iostream>
#include<cstdio>
#include<queue>
#include<string>
#include<stack>
#include<algorithm>
#include<cstring>
#include<map>
using namespace std;
string s; 
int main()
{
	cin>>s;
	int ans=s.length();
	int l=s.length();
	for(int i=1;i<l;i++)
	{
		if(s[i]!=s[i-1])
		{
			ans=min(ans,max(i,l-i));
		}
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <iomanip>
#include <cmath>
using namespace std;

int main(){
	long long n,a,b,quot,rem;
	cin>>n>>a>>b;
	quot=n/(a+b);
	rem=n-(a+b)*quot;
	cout<<quot*a+min(a,rem)<<endl;
	return 0;
}


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

#define MAXN (100010)
#define ll long long

int n;
ll a[MAXN];

int main(){
	scanf("%d", &n);
	for(int i = 1; i <= n; ++ i){
		scanf("%lld", a + i);
	}
	ll ans1 = 0, ans2 = 0, now1 = 0, now2 = 0;
	for(int i = 1; i <= n; ++ i){
		now1 += a[i];
		now2 += a[i];
		if(i & 1){
			if(now1 <= 0) ans1 += 1 - now1, now1 = 1;
			if(now2 >= 0) ans2 += now2 + 1, now2 = -1;
		}
		else{
			if(now1 >= 0) ans1 += now1 + 1, now1 = -1;
			if(now2 <= 0) ans2 += 1 - now2, now2 = 1;
		}
	}
	printf("%lld\n", std::min(ans1, ans2));
	return 0;
}

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

int main()
{
    int n;
    cin >> n;
    vector<int> h(n);
    for(int i = 0; i < n; i++){
        cin >> h[i];
    }

    vector<int> cost(n);
    cost[0] = 0;
    cost[1] = abs(h[1]-h[0]);
    for(int i = 2; i < n; i++){
        cost[i] = min(cost[i - 2] + abs(h[i] - h[i - 2]), cost[i - 1] + abs(h[i] - h[i - 1]));
    }

    cout << cost[n - 1] << endl;

}

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

typedef long long int ll;

int main()
{
    ll n, ans = 0;
    cin >> n;
    vector<string> s(n);
    for(ll i = 0;i < n;i++){
        cin >> s[i];
    }
    vector<ll> a(5);
    for(ll i = 0;i < n;i++){
        if(s[i][0] == 'M'){
            a[0]++;
        }
        else if(s[i][0] == 'A'){
            a[1]++;
        }
        else if(s[i][0] == 'R'){
            a[2]++;
        }
        else if(s[i][0] == 'C'){
            a[3]++;
        }
        else if(s[i][0] == 'H'){
            a[4]++;
        }
    }

    for(ll i = 0;i < 3;i++){
        for(ll j = i + 1;j < 4;j++){
            for(ll k = j + 1;k < 5;k++){
                ans += a[i] * a[j] * a[k];
            }
        }
    }

    cout << ans;

    return 0;
}

Measured memory_bytes: 6144
#include <bits/stdc++.h>
// statics
using namespace std;
using int64 = long long;
using PAIR = pair<int, int>;
constexpr int INF = 1 << 30;
constexpr int64 LINF = 1LL << 60;
constexpr int MOD = 1e9 + 7;
constexpr int MAX_N = 1e5 + 1;

// init/input
#define int int64
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...) type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T &t) {cin>>t;}
template<typename First, typename...Rest> void MACRO_VAR_Scan(First &first, Rest&...rest) {cin>>first;MACRO_VAR_Scan(rest...);}
#define VEC(type, c, n) vector<type> c(n);for(auto &&i:c)cin>>i;

// out
#define OUT(dist) cout<<(dist);
#define FOUT(n, dist) cout <<fixed<<setprecision(n)<<(dist);
#define SP cout<<" ";
#define BR cout<<"\n";
#define debug(x) cerr << #x << ":" << (x);BR;

// utility
#define ALL(a) (a).begin(), (a).end()
#define EACH(i, a) for(auto &&i:(a))
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RFOR(i, a, b) for(int i=(b)-1;i>=0;--i)
#define REP(i, n) for(int i=0;i<(n);++i)
#define RREP(i, n) for(int i=(n)-1;i>=0;--i)

signed main() {
  INIT;

	VAR(int, w, a, b);
  int ans = min(abs(b - (w + a)), abs(a - (b + w)));
	if (abs(b - a) < w) ans = 0;
	OUT(ans)BR;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (long long i = 0; i < n; i++)
#define RREP(i, n) for (long long i = n - 1; 0 <= i; i--)
#define FOR(i, start, end) for (long long i = start; i < end; i++)
#define RFOR(i, start, end) for (long long i = start - 1; 0 <= i; i--)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1'000'000'007
using ll = long long;
using namespace std;
const int INF32       = 1'050'000'000;
const long long INF64 = 4'000'000'000'000'000'000;
const int MOD7        = 1'000'000'007;
const int MOD9        = 1'000'000'009;
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;
}
void print() { std::cout << '\n'; }
template <class H, class... T> void print(H &&head, T &&... args) {
    std::cout << head;
    sizeof...(args) == 0 ? std::cout << "" : std::cout << ' ';
    print(std::forward<T>(args)...);
}
template <class T> void print(std::vector<T> &v) {
    for (int i = 0; i < v.size(); i++) {
        std::cout << v[i];
        i == v.size() - 1 ? std::cout << '\n' : std::cout << ' ';
    }
}
template <class T> void print(std::vector<std::vector<T>> &v) {
    for (int i = 0; i < v.size(); i++) {
        for (int j = 0; j < v[i].size(); j++) {
            std::cout << v[i][j];
            j == v[i].size() - 1 ? std::cout << '\n' : std::cout << ' ';
        }
    }
}

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

    string s;
    cin >> s;

    stack<char> st;
    REP(i, s.size()) {
        if (s[i] == 'S') {
            st.push('S');
        } else if (s[i] == 'T' && !st.empty() && st.top() == 'S') {
            st.pop();
        } else {
            st.push('T');
        }
    }
    print(st.size());

    return 0;
}

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

bool d[111111];
int main() {
    int n,s=0,x;
    d[0]=1;
    for (scanf("%d", &n); n--;) {
        scanf("%d", &x);
        for (int i=s; i>=0; --i) if (d[i]) d[i+x]=1;
        s+=x;
    }
    while (s>0 and (s%10==0 || !d[s])) --s;
    printf("%d\n", s);
    return 0;
}


Measured memory_bytes: 256
import heapq
X, Y, Z, K = map(int, input().split())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
C = [int(x) for x in input().split()]
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
id = '0' * 9
v = A[0] + B[0] + C[0]
D = {}
D[id] = v
Q = [[-v, id]]
for i in range(K):
  q = heapq.heappop(Q)
  print(-q[0])
  ida = q[1][:3]
  idb = q[1][3:6]
  idc = q[1][6:9]
  if int(ida) < len(A) - 1:
    _ida = int(ida) + 1
    v = A[_ida] + B[int(idb)] + C[int(idc)]
    id = '{:03}'.format(_ida) + idb + idc
    if id not in D:
      D[id] = v
      heapq.heappush(Q, [-v, id])
  if int(idb) < len(B) - 1:
    _idb = int(idb) + 1
    v = A[int(ida)] + B[_idb] + C[int(idc)]
    id = ida + '{:03}'.format(_idb) + idc
    if id not in D:
      D[id] = v
      heapq.heappush(Q, [-v, id])
  if int(idc) < len(C) - 1:
    _idc = int(idc) + 1
    v = A[int(ida)] + B[int(idb)] + C[_idc]
    id = ida + idb + '{:03}'.format(_idc)
    if id not in D:
      D[id] = v
      heapq.heappush(Q, [-v, id])

Measured memory_bytes: 5024
object Main {

  def gcd(a: Long, b: Long): Long = if(b!=0) gcd(b,a%b) else a

  def lcm(a: Long, b: Long): Long = a * b / gcd(a,b)

  def loop(s: String){
    if (s != null) {
      val Array(a,b,_*) = s.split(" ").map(_.toLong)
      println(gcd(a,b)+" "+lcm(a,b))
      loop(scala.io.StdIn.readLine)
    }
  }


  def main(args: Array[String]): Unit = {
    loop(scala.io.StdIn.readLine)
  }
}

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

const int N = 100000+9;

int n,a[N],b[N];
LL delta;

inline int read() {
	char c=getchar(); int f=1,ret=0;
	while (c<'0'||c>'9') {if(c=='-')f=-1;c=getchar();}
	while (c<='9'&&c>='0') {ret=ret*10+c-'0';c=getchar();}
	return ret * f;
}

int main() {
	n = read();
	for (int i=1;i<=n;i++) {
		a[i] = read();
		b[i] = read();
	}
	for (int i=n,tmp;i;i--) {
		tmp = (a[i] + delta) % b[i];
		if (tmp) tmp = b[i] - tmp;
		delta += tmp;
	}
	printf("%lld\n",delta);
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, N) for (int i = 0; i < (int)N; i++)
#define all(a) (a).begin(), (a).end()

ll N, K;

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

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

  ll ans = 0;
  for(ll b = K+1; b <= N; b++) {
    ans += (N/b)*(b-K) + max(0LL, N % b - K + 1);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); ++(i))
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<int, pii> pip;
typedef pair<int, lint> pil;
typedef pair<lint, lint> pll;
typedef pair<pair<lint, int>, pair<int, int>> ppp;
typedef complex<double> xy_t;
typedef vector<lint> poly;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}

const lint mod = 1e9 + 7;
const lint INF = mod*mod;
const int MAX = 100010;

int n, deg[MAX];
vector<int> G[MAX];
map<pii, int> mp;
pii E[MAX];

void dfs(int v, int prev, int pc){
    int cur=1;
    for(int nv: G[v])if(nv!=prev){
        if(cur==pc) ++cur;
        mp[make_pair(v, nv)]=cur;
        mp[make_pair(nv, v)]=cur;
        dfs(nv, v, cur++);
    }
}

int main(){
    scanf("%d", &n);
    int root=-1, dmax=0;
    rep(i, n-1){
        int a, b;
        scanf("%d%d", &a, &b);
        --a; --b;
        G[a].push_back(b);
        G[b].push_back(a);
        E[i]=make_pair(a, b);
        ++deg[a]; ++deg[b];
        if(dmax<deg[a]){dmax=deg[a]; root=a;}
        if(dmax<deg[b]){dmax=deg[b]; root=b;}
    }
    dfs(root, -1, 0);
    printf("%d\n", dmax);
    rep(i, n-1) printf("%d\n", mp[E[i]]);
}

Measured memory_bytes: 20608
import java.util.Arrays;
import java.util.Scanner;

//Dirichlet's Theorem on Arithmetic Progressions
public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		boolean[] f = new boolean[1000000];
		Arrays.fill(f, true);
		f[0] = f[1] = false;
		for(int i=2;i<1000000;i++){
			if(f[i])for(int j=i*2;j<1000000;j+=i)f[j]=false;
		}
		while(true){
			int a = sc.nextInt();
			int d = sc.nextInt();
			int n = sc.nextInt();
			if((a|d|n)==0)break;
			int x = a;
			while(true){
				if(f[x])n--;
				if(n==0)break;
				x += d;
			}
			System.out.println(x);
		}
	}
}

Measured memory_bytes: 0
#include <iostream>
using namespace std;
int main(void){
    // Here your code !
    string s, p;
    cin >> s >> p;
    bool q=false;
    for(int i=0;i<s.size();i++) {
        for(int j=0;j<p.size();j++) {
            if(s[(i+j)%s.size()] != p[j]) {
                break;
            }
            if(j == p.size() - 1) {
                q = true;
            }
        }
    }
    if(q) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3224
fun main(args: Array<String>) {

    val (n, a, b) = readLine()!!.split(" ").map(String::toInt)

    println(fun133a(n, a, b))
}

fun fun133a(n: Int, a: Int, b: Int): Any? {

    val aCost = n * a

    return if (aCost > b) {
        b
    } else {
        aCost
    }
}


Measured memory_bytes: 37816
import sys
import numpy as np
import math

from collections import deque 
from functools import reduce
from functools import lru_cache

# input = sys.stdin.readline

n = int(input())

gcd_num = 0

for i in range(1, n+1):
    for j in range(1, n+1):
        g = math.gcd(i, j)
        for k in range(1, n+1):
            gcd_num += math.gcd(g, k)
print(gcd_num)

Measured memory_bytes: 27152
N, A, B = map(int,input().split())
#ans = 0
if N == 1:
    if A == B:
        print(1)
    else:
        print(0)
else:
    if A <= B:
        print((A+B*(N-1))-(A*(N-1)+B)+1)
    else:
        print(0)

Measured memory_bytes: 2940
#include <iostream>
#include <string>

using namespace std;

int main(){
  string S;
  cin >> S;
  int size = S.size();

  long long sum = 0;
  for (long bit = 0; bit < (1<<(size-1)); bit++) {
    string s = S;
    int prv = 0;
    for (int i = 0; i < size-1; i++) {
      if (bit & (1<<i)) {
        sum+=stol(s.substr(prv,i-prv+1));
        prv = i+1;
      }
    }
    sum+=stol(s.substr(prv,size-prv));
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 256
def calc(a):
    sml = (0 + a-1) * a //2
    lar = sml + a*(n-a+1)
    return lar - sml + 1
ans = 0
mod = 10**9 + 7
n,k = map(int,input().split())
for i in range(k,n+2):
    ans += calc(i) % mod
print(ans % mod)


Measured memory_bytes: 9172
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1000000010
#define EPS 1e-9
#define fst first
#define scd second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  string s;
  cin>>s;
  bool c=false;
  rep(i,s.size() ){
    if(c){
      if(s[i]=='F'){cout<<"Yes"<<endl;return 0;}
    }else{
if(s[i]=='C') c=true;
    }
  }
  cout<<"No"<<endl;


  return 0;
}

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

using namespace std;

int n;
vector<int> v;
int main(){
	cin >> n;
	for(int i = 0; i < 2*n; i++){
		int x; cin >> x;
		v.push_back(x);
	}
	sort(v.begin(), v.end());
	int ans = 0;
	for(int i = 0; i < 2*n; i += 2){
		ans += min(v[i], v[i+1]);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
S = input()

s = list(S)
f = s[:int((len(s)-1)/2)]
l = s[int((len(s)+3)/2-1):]

if f == l:
    while len(f) > 1:
        if f[0] == f[-1]:
            f.pop(0)
            f.pop()
    if len(f) <= 1:
        while len(l) > 1:
            if l[0] == l[-1]:
                l.pop(0)
                l.pop()
        if len(l) <= 1:
            print('Yes')
        else:
            print('No')
    else:
        print('No')
else:
    print('No')

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

//type
#define ll long long
typedef pair<int, int> P;
//定数
#define INF 1000000000000 //10^12:∞
#define MOD 1000000007    //10^9+7:合同式の法
#define MAXR 100000       //10^5:配列の最大のrange
//略記
#define PB push_back //挿入
#define MP make_pair //pairのコンストラクタ
#define F first      //pairの一つ目の要素
#define S second     //pairの二つ目の要素
#define Z class
// OTHER
// xの二乗を返す (関数テンプレート版)
template <typename T>
T square(T x) { return x * x; }
#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))
// loop
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= ll(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= ll(b); i--)
#define FORA(i, I) for (const auto &i : I)

// vector
#define ALL(x) x.begin(), x.end()

// output
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n", (x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define ln cout << '\n'
template <Z A>
void pr(A a)
{
  cout << a;
  ln;
}
template <Z A, Z B>
void pr(A a, B b)
{
  cout << a << ' ';
  pr(b);
}

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

int main()
{
  int n;
  cin >> n;
  pr(square(n));
  return 0;
}


Measured memory_bytes: 3640
#include <iostream>
#include <string>
#include <algorithm>
#include <utility> 
#include <unordered_set>
#include <vector>
#include <list> 
#include <string>
#include <iterator> 
#include <deque>
#include <array>
#include <forward_list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <climits>
#include <bitset>
#include <numeric>
using namespace std;


const long double PI = 3.14159265358979323846264338327950;
const int N = 100;

template <class T>
T gcd(T a, T b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

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

	map<string, int> mp;
	string s;
	int n, m;
	m = 0;
	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> s;
		++mp[s];
		m = max(m, mp[s]);
	}
	for (auto it = mp.begin(); it != mp.end(); ++it) {
		if (it->second == m)
			cout << it-> first << '\n';
	}
}


Measured memory_bytes: 19144
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 1e5 + 5;
LL n, m, s, nxt, ans;
LL a[N << 1], b[N << 1];
int main(){
	ios::sync_with_stdio(false);
	cin >> n >> m;
	cin >> s;
	-- s;
	for(int i = 1; i < n; ++ i){
		cin >> nxt;
		-- nxt;
		if(nxt == s || nxt == (s+1) % m) ;
		else if(nxt > s){
			a[nxt] += nxt - s - 1;
			b[nxt] --;
			b[s+1] ++; 
		}else{
			a[nxt+m] += nxt + m - s - 1;
			b[nxt+m] --;
			b[s+1] ++;
		}
		ans += (nxt - s + m) % m;
		s = nxt;
	}
	for(int i = 2*m-1; i >= 0; -- i){
		a[i] += a[i+1];
		b[i] += b[i+1];
		a[i] += b[i+1];
	}
	for(int i = 0; i < m; ++ i) a[i] += a[i+m];
	cout << ans - *max_element(a, a+m) << endl;
}


Measured memory_bytes: 3328
N = int(input())
S = input()

west = [0]*N
east = [0]*N

tmp = 0
for i in range(1,N):
    if S[i-1] == 'W':
        tmp += 1
        west[i] = tmp
    else:
        west[i] = tmp

tmp = 0
for i in range(N-2,-1,-1):
    if S[i+1] == 'E':
        tmp += 1
        east[i] = tmp
    else:
        east[i] = tmp

ans = float('inf')
for i in range(N):
    ans = min(ans,west[i]+east[i])
print (ans)


Measured memory_bytes: 23540
#include <stdio.h>
 
int main(void) {
  int i, j, H, W;
  while( 1 ) {
    scanf("%d %d", &H, &W);
    if(H == 0 && W == 0) break;
    for(i = 1; i <= H; i++) {
      for(j = 1; j <= W; j++) {
        if((i + j) % 2 == 0) printf("#");
        else printf(".");
      }
      printf("\n");
    }
    printf("\n");
  }
  return 0;
}


Measured memory_bytes: 2080
#include<iostream>
#include<vector>
#include<algorithm>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
typedef long long ll;
vector<ll> A, B, C, D, E, L;

int main(){
    int x, y ,z, k;
    int tmp;
    cin >> x >> y >> z >> k;
    A.resize(x);
    B.resize(y);
    C.resize(z);
    for(int i=0; i<x; i++) cin >> A[i];
    for(int i=0; i<y; i++) cin >> B[i];
    for(int i=0; i<z; i++) cin >> C[i];
    rep(i,x){
        rep(j,y){
            L.push_back(A[i]+B[j]);
        }
    }
    sort(L.begin(),L.end(),greater<ll>());
    tmp = min(x*y, k);
    rep(i,tmp) D.push_back(L[i]);
    rep(i,tmp){
        rep(j,z){
            E.push_back(D[i]+C[j]);
        }
    }
    sort(E.begin(),E.end(),greater<ll>());
    rep(i,k) cout << E[i] << endl;
    return 0;
}

Measured memory_bytes: 42960
#include <bits/stdc++.h>
using namespace std;
//#define cerr if (false) cerr
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define dbv(v) cerr << #v << "="; for (auto _x : v) cerr << _x << ", "; cerr << endl
#define dba(a, n) cerr << #a << "="; for (int _i = 0; _i < (n); ++_i) cerr << a[_i] << ", "; cerr << endl
typedef long long ll;
typedef long double ld;
const ll MOD = 1e9 + 7;
int main() {
	int n, k;
	scanf("%d%d", &n, &k);
	vector<int> a(n);
	for (int i = 0; i < n; ++i) {
		scanf("%d", &a[i]);
	}
	ll inv2 = (MOD + 1) / 2;
	ll ans = 0;
	for (int i = 0; i < n; ++i) {
		ll later = 0, tot = 0;
		for (int j = 0; j < n; ++j)
			if (a[i] > a[j]) {
				++tot;
				if (j > i) ++later;
			}
		ans = (ans + later * k + tot * (k - 1) % MOD * k % MOD * inv2) % MOD;
	}
	printf("%lld\n", ans);
}


Measured memory_bytes: 256