akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;
 //Compiler version g++ 6.3.0

 int main()
 {
 	int a,b,c;
 	int ans;
 	cin >> a>>b >>c;
 	if(b+a>=c){
 		ans=b+c;
 	}else{
 		ans=b+b+a+1;
 	}
 	cout << ans << endl;
 }

Measured memory_bytes: 256
#include <iostream> // C++の入出力
#include <stdio.h> // C の入出力
#include <algorithm> // sort などのアルゴリズム
#include <string.h> // C の文字列用
#include <ctype.h> // C の文字種用
#include <string> // C++の文字列
using namespace std;
int keisan(string in){
    int sum=0,memo=0;
    int kei[4]={1000,100,10,1};
    string moji="mcxi";
    int digit[8]={2,3,4,5,6,7,8,9};
    string suu="23456789";
    for(int i=0;i<in.length();i++){
        if(isdigit(in[i])){//数字ならば
            for(int t=0;t<8;t++){
                if(suu[t]==in[i]){
                    memo=digit[t];
                    break;
                }
            }
        }else{
            for(int t=0;t<4;t++){//文字ならば
                if(moji[t]==in[i]){
                    if(memo!=0){
                        sum+=kei[t]*memo;
                        memo=0;
                    }else{
                        sum+=kei[t];
                    }
                }
            }
        }
    }
    return sum;
}
string hen(int input){
    string out="";
    int digit[8]={2,3,4,5,6,7,8,9};
    string suu="23456789";
    if(input>=1000){
        int test = input/1000;
        if(test>1){
            for(int t=0;t<8;t++){
                if(digit[t]==test){
                    out+=suu[t];
                    break;
                }
            }
        }
        out+="m";
        input=input%1000;
    }
    if(input>=100){
        int test = input/100;
        if(test>1){
            for(int t=0;t<8;t++){
                if(digit[t]==test){
                    out+=suu[t];
                    break;
                }
            }
        }
        out+="c";
        input=input%100;
    }
    if(input>=10){
        int test = input/10;
        if(test>1){
            for(int t=0;t<8;t++){
                if(digit[t]==test){
                    out+=suu[t];
                    break;
                }
            }
        }
        out+="x";
        input=input%10;
    }
    if(input>=1){
        if(input>1){
            for(int t=0;t<8;t++){
                if(digit[t]==input){
                    out+=suu[t];
                    break;
                }
            }
        }
        out+="i";
    }
    return out;
    
}
int main(void){
    int n;
    cin>>n;
    for(int s=0;s<n;s++){
        string in,in2;
        cin>>in>>in2;
        int sum = keisan(in);
        int sum2 = keisan(in2);
        string henkan;
        henkan= hen(sum+sum2);
        cout<<henkan<<endl;
    }
    return 0;
}

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

using namespace std;

int main(){
    string s, t; cin >> s >> t;
    int begin=-1;
    for(int i=s.size()-t.size(); i>=0; --i){
        bool found=true;
        for(int j=0; j<t.size(); ++j){
            char c=s[i+j];
            if(!(c==t[j] || c=='?')){
                found=false;
                break;
            }
        }
        if(found){
            begin=i;
            break;
        }
    }
    if(begin!=-1){
        for(int i=0; i<begin; ++i){
            cout << (s[i]=='?' ? 'a' : s[i]);
        }
        cout << t;
        for(int i=begin+t.size(); i<s.size(); ++i){
            cout << (s[i]=='?' ? 'a' : s[i]);
        }
        cout << endl;
    } else{
        cout << "UNRESTORABLE\n";
    }
    return 0;
}


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

if A % 2 == 0:
    Acan = set(list(range((100 * A) // 8, (100 * (A+1)) // 8)))
else:
    Acan = set(list(range((100 * A) // 8 + 1, (100 * (A+1)) // 8)))
Bcan = set(list(range(10 * B, 10 * (B+1))))

can = Acan & Bcan
if len(can) == 0:
    print(-1)
else:
    print(min(list(can)))
    

Measured memory_bytes: 3064
#include <iostream>
#include <map>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <math.h>
#include <string>
#include <set>
using namespace std;
typedef long long ll;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    int a[n];
    for ( int i = 0 ; i < n ; i++ ) cin >> a[i];
    sort(a, a + n);
    cout << a[n - 1] - a[0];
}


Measured memory_bytes: 256
package main

import (
	"fmt"
)

type Arm struct {
	position int
	length   int
}

type Arms []Arm

func (x Arms) Len() int {
	return len(x)
}

func (x Arms) Swap(i, j int) {
	x[i], x[j] = x[j], x[i]
}

func (x Arms) Less(i, j int) bool {
	return x[i].position < x[j].position
}

func isCross(a, b Arm) bool {
	rightA := a.position + a.length
	leftB := b.position - b.length
	return rightA > leftB
}

func main() {
	var h, n int
	fmt.Scan(&h)
	fmt.Scan(&n)

	var a []int
	a = make([]int, n)
	var sum int = 0
	for i := 0; i < n; i++ {
		var x int
		fmt.Scan(&x)
		a[i] = x
		sum += x
	}

	if sum >= h {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

func scanNums(len int) (nums []int) {
	var num int
	var i int
	for i = 0; i < len; i++ {
		fmt.Scan(&num)
		nums = append(nums, num)
	}
	return
}


Measured memory_bytes: 5504
S = input()
judge = True
if len(S)%2==1:
  print('No')
  exit()
for i in range(len(S)):
  if i%2==0:
    if S[i]=='h':
      continue
    else:
      judge=False
      break
  else:
    if S[i]=='i':
      continue
    else:
      judge=False
      break
      
if judge:
  print('Yes')
else:
  print('No')


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

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

    string T;

    for (char c : S) {
        T.push_back((c - 'A' + N) % 26 + 'A');
    }

    cout << T << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<unordered_map>
#define mp make_pair 
#define pb push_back
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;

using namespace std;
typedef pair<ll,ll> P;
struct Ver{
    ll x,y;
    bool operator==(const Ver&key)const{
	return key.x==this->x&&key.y==this->y;
    }
    bool operator!=(const Ver&key)const{
	return !(this->operator==(key));
    }
    struct Hash{
	ll operator()(const Ver&key)const{
	    return key.x*mod+key.y;
	}
    };
    Ver(ll x,ll y){this->x=x,this->y=y;}
};
unordered_map<Ver,vector<P>,Ver::Hash> mas,rng;
#define N 200010
ll n,k,x[N],y[N];

int main(){
    cin>>n>>k;
    string s;cin>>s;
    ll a=0,b=0;
    lol(i,n){
	x[i]=a,y[i]=b;
	int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
	char z[]={'E','N','W','S'};
	lol(r,4)if(z[r]==s[i])a+=dx[r],b+=dy[r];
    }
    if(a==0&&b==0)k=1,a=b=1;
    if(a<0){lol(i,n)x[i]=-x[i];a=-a;}
    if(b<0){lol(i,n)y[i]=-y[i];b=-b;}
    if(a==0&&b>0){
	swap(a,b);
	lol(i,n)swap(x[i],y[i]);
    }
    lol(i,n){
	x[i]+=N,y[i]+=N;
	ll dis=x[i]/a;
	ll wid=k-1+(i==0);
	mas[Ver(x[i]%a,y[i]-dis*b)].pb(mp(dis,dis+wid));
    }
    for(auto it:mas){
	auto ver=it.first;
	auto vec=it.second;
	vector<P> qry;
	for(auto i:vec){
	    qry.pb(mp(i.first,+1));
	    qry.pb(mp(i.second+1,-1));
	}
	sort(qry.begin(),qry.end());
	ll cms=0,left;
	for(auto i:qry){
	    ll tim=i.first,dir=i.second;
	    if(dir==-1){
		cms--;
		if(cms==0)rng[ver].pb(mp(left,tim-1));
	    }
	    if(dir==+1){
		if(cms==0)left=tim;
		cms++;
	    }
	}
    }
    ll ans=0;
    for(auto it:rng){
	auto ver=it.first;
	vector<P> qry;
	ll dx[]={0,1,0,1},dy[]={0,0,1,1};
	lol(r,4){
	    ll xx=ver.x+dx[r];
	    ll yy=ver.y+dy[r];
	    bool over=0;
	    if(xx==a)xx-=a,yy-=b,over=1;
	    if(rng.find(Ver(xx,yy))==rng.end())continue;
	    for(auto i:rng[Ver(xx,yy)]){
		qry.pb(mp(i.first-over,+1));
		qry.pb(mp(i.second-over+1,-1));
	    }
	}
	sort(qry.begin(),qry.end());
	ll cms=0,left;
	for(auto i:qry){
	    ll tim=i.first,dir=i.second;
	    if(dir==-1){
		if(cms==4)ans+=tim-left;
		cms--;
	    }
	    if(dir==+1){
		cms++;
		if(cms==4)left=tim;
	    }
	}
    }
    cout<<ans<<endl;
    return 0;
}



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

struct Node{
  int key;
  struct Node *right, *left, *parent;
};

struct Node *root, *NIL;
struct Node * find(struct Node*,int);
void insert(int);
void inorder(struct Node*);
void preorder(struct Node*);
int main(){
  int n, i, x;
  char com[50];
  int cnt = 0;
  struct Node *t;

  scanf("%d",&n);
  if(n > 500001)
   exit(1);

  for(i = 0; i < n; i++){
    scanf("%s",com);

    if(com[0] == 'f'){
      scanf("%d",&x);
      t = find(root,x);
      if(t != NIL)
	printf("yes\n");
      else
	printf("no\n");
    }
    else if(strcmp(com,"insert") == 0){
      scanf("%d",&x);
      if(x < -2000000000 || x > 2000000000)
	exit(1);
      insert(x);
    }
    else if(strcmp(com,"print") == 0){
      cnt++;
      if(cnt > 10)
	exit(1);
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }
  return 0;
}

struct Node * find(struct Node*u,int k){
  while(u != NIL && k != u->key){
    if(k < u->key)
      u = u->left;
    else
      u = u->right;
  }
  return u;
}

void insert(int k){
  struct Node *y = NIL;
  struct Node *x = root;
  struct Node *z;

  z = (struct Node*)malloc(sizeof(struct Node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL){
    y = x;
    if(z->key < x->key){
      x = x->left;
    }
    else
      x = x->right;
  }

  z->parent = y;
  
  if(y == NIL)
    root = z;
  else{
    if(z->key < y->key)
      y->left = z;
    else
      y->right = z;
  }
}

void inorder(struct Node *u){
  if(u == NIL)
    return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}

void preorder(struct Node *u){
  if(u == NIL)
    return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}



Measured memory_bytes: 20456
N, D = map(int, input().split())
P = [list(map(int, input().split())) for _ in range(N)]
sq = set(i**2 for i in range(200))
ans = 0
for i, p in enumerate(P[:-1]):
  for q in P[i+1:]:
    d_sq = 0
    for x, y in zip(p, q):
      d_sq += (x-y)**2
    if d_sq in sq:
      ans += 1
print(ans)
    

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

int main() {
  int i=0;
  int n;
  cin >> n;
  while(i<n){
    string s;
    cin >> s;
    if(s=="Y"){
      cout << "Four" << endl;
      goto END;
    }
    i++;
  }
  cout << "Three" << endl;
  END:;
}



Measured memory_bytes: 256
/*                         _
                        _ooOoo_
                       o8888888o
                       88" . "88
                       (| -_- |)
                       O\  =  /O
                    ____/`---'\____
                  .'  \\|     |//  `.
                 /  \\|||  :  |||//  \
                /  _||||| -:- |||||_  \
                |   | \\\  -  /'| |   |
                | \_|  `\`---'//  |_/ |
                \  .-\__ `-. -'__/-.  /
              ___`. .'  /--.--\  `. .'___
           ."" '<  `.___\_<|>_/___.' _> \"".
          | | :  `- \`. ;`. _/; .'/ /  .' ; |
          \  \ `-.   \_\_`. _.'_/_/  -' _.' /
===========`-.`___`-.__\ \___  /__.-'_.'_.-'================

                  Please give me AC.
*/

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>

using namespace std;

using int64 = long long;
using uint64 = unsigned long long;
using vi = vector<int>;
using vl = vector<int64>;
using pii = pair<int, int>;
using pll = pair<int64, int64>;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define print(x) cout << (x) << '\n'
#define print2(x, y) cout << (x) << ' ' << (y) << '\n'
#define print3(x, y, z) cout << (x) << ' ' << (y) << ' ' << (z) << '\n'
#define printn(v) rep(i, (v).size() - 1) cout << (v)[i] << ' '; cout << (v)[n - 1] << '\n';
#define debug(x) cerr << #x << ": " << (x) << '\n'
#define debug2(x, y) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v) for (size_t _ = 0; _ < v.size(); ++_){cerr << #v << "[" << _ << "] : " << v[_] << '\n';}
// constant
const int INF = (1<<30) - 1;
const int64 INF64 = (1LL<<62) - 1;

// End of template.


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

    string s;
    cin >> s;
    if (s == "Sunny")
        print("Cloudy");
    else if (s == "Cloudy")
        print("Rainy");
    else
        print("Sunny");

    return 0;
}



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

using namespace std;

#define all(v)				((v).begin()), ((v).end())
#define allr(v)				((v).rbegin()), ((v).rend())
#define sz(v)				((int)((v).size()))
#define ll long long
#define pb					push_back
#define fIO ios_base::sync_with_stdio(0);cin.tie(0);

const ll oo = 1e8;
const double pi = 3.1415926535897;


const double EPS = (1e-7);
int dcmp(double x, double y) {	return fabs(x-y) <= EPS ? 0 : x < y ? -1 : 1;	}


typedef vector<int>                vi;
typedef vector<pair<int,int>>      vii;
typedef vector<ll>                 vll;
typedef vector<double>             vd;
typedef vector< vi >               vvi;
typedef vector< vd >               vvd;
typedef vector<string>             vs;
typedef pair<int, int>             pii;

/**
    * PLEASEEE READDD PROBLEEEM CARFULLY ****
    * Always check for OVERFLOW ll vs int
    * Always check for array bounds
    * Check for function return
    * READ OUTPUT SECTION AGAIN!!!
**/

struct edge{
    int from, to, w;

    edge(){}
    edge(int x, int y, int we): from(x), to(y), w(we){}

    bool operator < (const edge &rhs) const{
        return w > rhs.w;
    }

};

int main(){
    fIO
//    freopen("", "r", stdin);
//    freopen("", "w", stdout);

    int a, b;
    cin >> a >> b;

    cout << a * b;

}








Measured memory_bytes: 3636
package main
import (
	"bufio"
	"fmt"
	"os"
)
var r = bufio.NewReader(os.Stdin)
func main() {
	var S int
	fmt.Fscan(r, &S)
	
	h := S / 3600
	min := S % 3600 / 60
	s := S % 60
	fmt.Printf("%d:%d:%d\n",h,min,s)
	
}


Measured memory_bytes: 1148
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
using ull = unsigned long long;
using ll = long long;
using namespace std;

int main(void) {
    int n;
    cin >> n;
    vector<int> a(n);

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

    vector<int> ans;
    if (n&1) {
        // odd
        for(int i = 0; i < n; ++i) {
            if (i&1) {
                ans.push_back(a[i]);
            } else {
                ans.insert(ans.begin(), a[i]);
            }
        }

    } else {
        // even
        for(int i = 0; i < n; ++i) {
            if(i&1) {
                ans.insert(ans.begin(), a[i]);
            } else {
                ans.push_back(a[i]);
            }
        }
    }

    for(size_t i = 0; i < ans.size(); ++i) {
        cout << ans[i] << " ";
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 3828
fn main() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let v: Vec<usize> = s.trim().split_whitespace().map(|x| x.parse().unwrap()).collect();
    let d: usize = std::cmp::max(v[0], v[1]) - std::cmp::min(v[0], v[1]);
    if d > 1 {println!("0"); return}
    const Q: usize = 1000000007;
    let mut x = 1;
    let mut y = 1;
    for i in 1..v[0]+1 {
        x = (x * i) % Q;
    }
    for i in 1..v[1]+1 {
        y = (y * i) % Q;
    }
    println!("{}", if d == 1 {(x * y) % Q} else {(2 * ((x * y) % Q)) % Q});
}



Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> r(m * 2), c(n);
  
  for (int i = 0; i < m * 2; i++) {
    cin >> r.at(i);
    for (int j = 0; j < n; j++) {
      if(j + 1 == r.at(i))
        c.at(j)++;
    }
  }
  
  for (int j = 0; j < n; j++)
    cout << c.at(j) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//useful library
int long long gcd(int long long a, int long long b){
    return b?gcd(b,a%b):a;
} //最大公約数
int long long lcm(int long long a, int long long b){
    return a/gcd(a,b)*b;
} //最小公倍数
int long long GetDigit(int long long num){
    int long long digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
} //桁数
int long long GetDigitN(int long long num, int long long N){
    int long long digit=0;
    while(num!=0){
        num /= N;
        digit++;
    }
    return digit;
} //十進数でnumの際のN進数における桁数

int main(){
    int N;
    cin >> N;
    string S = to_string(N);
    if((S.at(0) == '7') || (S.at(1) == '7') || (S.at(2) == '7')){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3664
#include<bits/stdc++.h>
# define ll long long
# define mo 1000000009
using namespace std;
int main()
{
	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++)
	cin>>a[i];
	for(int i=0;i<n;i++)
	{
		if(a[i]%2==0)
		{
			if(a[i]%3!=0&&a[i]%5!=0){
				cout<<"DENIED";
				return 0;
			}
		}
	}
	cout<<"APPROVED";
	return 0;
}

Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def solve():
    N, K = map(int, rl().split())
    A = list(map(int, rl().split()))
    
    pos = dict()
    for idx, ai in enumerate(A):
        pos[ai] = idx + 1
    
    roop = 0
    u_set = set()
    u_set.add(1)
    counter = dict()
    counter[1] = 0
    ca = A[0]
    cnt = 1
    roop_s = 0
    b = 0
    while 1:
        if ca in u_set:
            if ca == roop_s:
                roop = cnt - counter[ca]
                break
            elif roop_s == 0:
                counter[ca] = cnt
                roop_s = ca
                b = cnt
        u_set.add(ca)
        ca = A[ca - 1]
        cnt += 1
    
    ans = 0
    if K < b:
        ca = A[0]
        cnt = 1
        while 1:
            if cnt == K:
                ans = ca
                break
            ca = A[ca - 1]
            cnt += 1
    else:
        m = (K - b) % roop
        ca = A[pos[roop_s] - 1]
        cnt = 0
        while 1:
            if cnt == m:
                ans = ca
                break
            ca = A[ca - 1]
            cnt += 1
    print(ans)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 142328
#!/usr/bin/env python
import sys
from collections import Counter, defaultdict

def main():
    N = int(input())
    names = [input() for _ in range(N)]
    c = Counter(names)

    ans_name = c.most_common(1)[0][0]
    ans_val = c.most_common(1)[0][1]
    
    ans_set = set()
    ans_set.add(ans_name)

    for key in c:
        if key not in ans_set and c[key] == ans_val:
            ans_set.add(key)


    ans = list(ans_set)
    ans.sort()
    print(*ans, sep='\n')


if __name__ == '__main__':
    main()

Measured memory_bytes: 114256
A, B, M = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
minimum = a[0]+b[0]

for k in range(M):
    x,y,c = map(int,input().split())
    tmp = a[x-1]+b[y-1]-c
    if minimum > tmp:
        minimum = tmp

a.sort()
b.sort()

for i in a:
    if i + b[0] > minimum:
        break
    for j in b:
        tmp = i + j
        if minimum > tmp:
            minimum = tmp
        else:
            break

print(minimum)

Measured memory_bytes: 18740
# -*- coding: utf-8 -*-

import sys, re

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

s=input()
# 任意の0文字以上
if re.match('.*C.*F.*', s):
    Yes()
else:
    No()


Measured memory_bytes: 3316
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;

class Program
{
    static void Main(string[] args)
    {
        int n = int.Parse(Console.ReadLine());
        for (int k = 0; k < n; k++)
        {
            int[] line = Console.ReadLine().Split(' ').Select(p => int.Parse(p)).ToArray();
            int s = line[0];
            int d = line[1];
            int sum = 0;
            while (s != d)
            {
                if (s % 2 != 0)
                {
                    sum++;
                    s++;
                }
                if (d % 2 != 0)
                {
                    sum++;
                    d--;
                }
                s /= 2;
                d /= 2;
            }
            Console.WriteLine(sum);
            // 000000000000000
            // -0-0-0-0-0-0-0- 000000000000000
            // ---0---0---0--- -0-0-0-0-0-0-0-
            // -------0------- ---0---0---0---
        }
    }
}

Measured memory_bytes: 9548
// AOJ 2801: Suntan
// 2017.11.20 bal4u@uu

#include <stdio.h>
#include <stdlib.h>

long long s[100001], t[100001]; int N;
long long a[100001];

char buf[50], *p;
long long getlong()
{
	long long n = 0;
	while (*p >= '0') n = (n<<3) + (n<<1) + (*p++ & 0xf);
	return n;
}

int bsch(long long x)
{
	int m, l = 0, r = N+1;

    while (l < r) {
        m = (l + r) >> 1;
		if (t[m] == x) return m;
        if (t[m] < x) l = m + 1; else r = m;
    }
	return l-1;
}

int main()
{
	int i, k;
	long long T, ans, x;
	
	fgets(p=buf, 50, stdin), T = getlong();
	fgets(p=buf, 50, stdin), N = atoi(buf);
	for (i = 1; i <= N; i++) {
		fgets(p=buf, 50, stdin);
		s[i] = getlong(), p++, t[i] = getlong();
		a[i] = a[i-1] + (t[i]-s[i]);
	}

	ans = 0;
	for (i = 1; i <= N; i++) {
		k = bsch(T+s[i]), x = a[k]-a[i-1];
		if (k < N && s[i] + T > s[k+1]) {
			if (s[i] + T > t[k+1]) x = s[k+1];
			else x += s[i] + T - s[k+1];
		}
		if (x > ans) ans = x;
	}
	printf("%lld\n", ans);
	return 0;
}

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

int main (void){
  long long int n = 0,m = 0,s = 0,t = 0;

  cin >> n;
  cin >> m;

  vector<long int> a(m,0);
  for(int i = 0;i < m;i++){
    cin >> a[i];
  }

  for(int i = 0;i < m;i++){
    s = s + a[i];
  }

  t = n - s;

  if(t < 0){
    cout << "-1\n";
  }else{
    cout << t << endl;
  }

  return 0;


}

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

int bubbleSort(int A[], int N) {
    int sw = 0;
    bool flag = 1;
    for(int i = 0; flag; i++) {
        flag = 0;
        for(int j = N - 1; j >= i + 1; j--) {
            if(A[j] < A[j - 1]) {
                swap(A[j], A[j - 1]);
                flag = 1;
                sw++;
            }
        }
    }
    return sw;
}

int main() {
    int A[100], N, sw;

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

    sw = bubbleSort(A, N);

    for(int i = 0; i < N; i++) {
        if(i) cout << " ";
        cout << A[i];
    }
    cout << endl;
    cout << sw << endl;

    return 0;
}


Measured memory_bytes: 3104
import java.util.Scanner;
import java.util.InputMismatchException;

class Main {
   public static void main(String args[]) {
      int x=0 ,y=0;
      int sum = 0;
      try {
         Scanner scanner = new Scanner(System.in);
         x = scanner.nextInt();
         scanner.close();
      } catch (InputMismatchException e) {
         System.out.println("error");
      }
      y = x/100;
      int z = x - y*100;
      if ((y<1 || y>12) && (z<1 || z>12)) {
         System.out.println("NA");
      } else if (y>0 && y<13 && z>0 && z<13) {
         System.out.println("AMBIGUOUS");
      } else if (y>0 && y<13) {
         System.out.println("MMYY");
      } else if (z>0 && z<13) {
         System.out.println("YYMM");
      }
   }
}


Measured memory_bytes: 23764
#include <iostream>
#include <string>
#include <vector>
#include <cstdio>
using namespace std;
vector<int> T={5,7,5,7,7};
int solve(const vector<string>&v){
	for(int i=0;i<v.size();i++){
		for(int j=i,n=0,y=0;j<v.size();j++){
			n+=v[j].size();
			if(n==T[y]){
				if(++y==T.size())return i+1;
				n=0;
			}
		}
	}
	return -1;
}
int main(){
	int N;
	for(;cin>>N,N;){
		vector<string>v(N);
		for(int i=0;i<N;i++)cin>>v[i];
		printf("%d\n",solve(v));
	}
}

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

namespace TYC
{
	typedef long long ll;

	const int N = 187, M = 17;

	int H, W, A[N][N], F[M][N][N][N], down[N][N], L[N][N][N], R[N][N][N];
	char str[N];

	inline int read()
	{
		int x = 0, f = 0, ch = getchar();
		while (!isdigit(ch))
			f |= (ch == '-'), ch = getchar();
		while (isdigit(ch))
			x = x * 10 + ch - '0', ch = getchar();
		return f ? -x : x;
	}

	void work()
	{
		H = read(), W = read();
		for (int i = 1; i <= H; i++)
		{
			scanf("%s", str + 1);
			for (int j = 1; j <= W; j++)
				A[i][j] = str[j] == '#';
		}
		for (int i = H; i; i--)
			for (int j = 1; j <= W; j++)
				down[i][j] = (i == H || A[i][j] != A[i + 1][j]) ? i : down[i + 1][j];
		for (int i = H; i; i--)
			for (int l = 1; l <= W; l++)
				for (int r = l, v = INT_MAX; r <= W && A[i][l] == A[i][r]; r++)
					F[0][i][l][r] = v = min(v, down[i][r]);
		if (F[0][1][1][W] >= H)
			return void(puts("0"));
		for (int k = 0; k + 1 < M; k++)
		{
			memset(L, 0x3f, sizeof(L));
			memset(R, 0, sizeof(R));
			for (int i = 1; i <= H; i++)
			{
				for (int l = 1; l <= W; l++)
					for (int v = F[k][i][l][l], r = l; ~v; v--)
					{
						while (r < W && F[k][i][l][r + 1] == v)
							++r;
						R[i][l][v] = r;
					}
				for (int r = W; r; r--)
					for (int v = F[k][i][r][r], l = r; ~v; v--)
					{
						while (l > 1 && F[k][i][l - 1][r] == v)
							--l;
						L[i][r][v] = l;
					}
			}
			for (int i = 1; i <= H; i++)
				for (int l = 1; l <= W; l++)
					for (int r = l; r <= W; r++)
					{
						int lv = i, rv = H, mid, ans = 0;
						while (lv <= rv)
						{
							mid = (lv + rv) >> 1;
							if (R[i][l][mid] + 1 >= L[i][r][mid])
								ans = mid, lv = mid + 1;
							else
								rv = mid - 1;	
						}
						F[k + 1][i][l][r] = max(F[k][F[k][i][l][r] + 1][l][r], ans);
					}	
			if (F[k + 1][1][1][W] == H)
				return void(printf("%d\n", k + 1));
		}
	}
}

int main()
{
	TYC::work();
	return 0;
}

Measured memory_bytes: 484864
#include <iostream>
using namespace std;
typedef long long ll;
ll N,w,W[100010],V[100010],dp[110][100010] = {};

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

Measured memory_bytes: 81408
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, a, b, c, d;
  cin >> N;
  a = N / 1000;
  b = (N - 1000*a) / 100;
  c = (N - 1000*a - 100*b) / 10;
  d = N - 1000*a - 100*b - 10*c;
  if ((a==b && b==c) || (b==c && c==d)) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
using System;

public class Hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = int.Parse(line[0]);
        var x = int.Parse(line[1]);
        line = Console.ReadLine().Trim().Split(' ');
        var a = Array.ConvertAll(line, int.Parse);
        var ans = Math.Abs(a[0] - x);
        if (n == 1) { Console.WriteLine(ans); goto end; }
        for (int i = 1; i < n; i++)
            ans = Gcd(ans, Math.Abs(a[i] - x));
        Console.WriteLine(ans);
        end:;
    }
    public static int Gcd(int a, int b)
    {
        if (a < b) return Gcd(b, a);
        while (b != 0)
        {
            var w = a % b;
            a = b;
            b = w;
        }
        return a;
    }
}


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

int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
  int N,K; cin>>N>>K;
  int A[N] , dp[N];
  for(int i = 0;i<N; i++) cin>>A[i];
  dp[0] = 0;
  for(int i = 1; i < N ; i++){
    int ans = INT_MAX;
    int m = max(i-K,0);
  	for(int j = i-1; j >= m ; j--){
    	ans = min(dp[j] + abs(A[i] - A[j]) , ans);
    }
    dp[i] = ans;
  }
  cout<<dp[N-1];
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 
int main() {
  string S,T,U;
  cin>>S>>T>>U;
  if(S.back()==T[0]&&T.back()==U[0]) {
cout<<"YES"<<endl;
  }
  else {
cout<<"NO"<<endl;
  }
}

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

int main() {
  char a;
  cin >> a;
  if (a >= 'a')
    cout << 'a' << endl;
  else
    cout << 'A' << endl;
}


Measured memory_bytes: 3616
#include<bits/stdc++.h>
 
using namespace std;
 
const int INF = 1 << 30;
 
int main()
{
  int N, W;
  int dp[10001] = {}, deq[10001], deqv[10001];
 
  cin >> N >> W;
  for(int i = 0; i < N; i++) {
    int v, w, m;
    cin >> v >> w >> m;
    for(int k = 0; k < w; k++) {
      int s = 0, t = 0;
      for(int l = 0; l * w + k <= W; l++) {
        int val = dp[l * w + k] - l * v;
        while(s < t && deqv[t - 1] <= val) --t;
        deq[t] = l;
        deqv[t++] = val;
        dp[l * w + k] = deqv[s] + l * v;
        if(deq[s] == l - m) ++s;
      }
    }
  }
 
  cout << dp[W] << endl;
}


Measured memory_bytes: 3220
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int N;
    cin >> N;
    double ans = 0.0;
    for (int i = 0; i < N; i++)
    {
        double x;
        string u;
        cin >> x >> u;
        if (u == "BTC")
        {
            ans += x * 380000.0;
        }
        else
        {
            ans += x;
        }
    }
    cout << setprecision(15) << fixed << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,d,ans,x[20][20];
int main() {
    cin>>n>>d;
    for(int i=1; i<=n; i++)
        for(int j=1; j<=d; j++)
            cin>>x[i][j];

    for(int i=1; i<n; i++)
        for(int j=i+1; j<=n; j++) {
            int sum=0;
            for(int k=1; k<=d; k++)
                sum+=(x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
            if(int(sqrt(sum))==sqrt(sum))
                ans++;
        }


    printf("%d",ans);
}

Measured memory_bytes: 384
#include<stdio.h>
int main(void){
    int n,i,a;
    scanf("%d",&n);
    for(i=1;i<=n;i++){
        a=i;
        if((a%3)==0){
            printf(" %d",i);
        }else{
            for(;a;){
                if((a%10)==3){
                    printf(" %d",i);
                    a=0;
                }
                a=a/10;
            }
        }
    }
    putchar('\n');
    return 0;
}


Measured memory_bytes: 2052
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <math.h>
#define fi first
#define se second
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rrep(i,n) for(ll i = 1; i <= (n); ++i)
#define drep(i,n) for(ll i = (n)-1; i >= 0; --i)
#define all(v) v.begin(),v.end()
#define len(x) (ll)(x).length()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (ll)(x).size()
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
ll gcd(ll a,ll b){if(a%b==0){return b;}else{return(gcd(b,a%b));}}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
const int INF=1e9;
const ll MX = 1e18;
const int MOD=INF+7;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};
const double PI=acos(-1);
 
int main() {
  int n,r;
  cin>>n>>r;
  if(n>=10){
    cout<<r<<endl;
    return 0;
  }
  cout<<r+(10-n)*100<<endl;
}

Measured memory_bytes: 3584
/*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
*$* WRITER:kakitamasziru/OxOmisosiru *$*
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/
#ifdef LOCAL_JUDGE
#define _GLIBCXX_DEBUG //FOR THE DEBUG! COMMENT OUT THIS WHEN SUBMITTING!
#endif
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <iomanip>
#include <limits>//setprecision
//#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
#include <bitset> // bitset
//It is so troublesome that I include bits/stdc++.h !
using namespace std;

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; }
const long long INF = 100100100100;
const long long MOD = 1000000007;
typedef pair<int,int> P;
//NのM乗を求める(繰り返し二乗法)
long long mod_pow(long long N, long long M) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % MOD, M / 2);
    //最下位ビット(*N)が1の時は単独でNをかける
    if (M & 1) res = (res * N) % MOD;

    return res %= MOD;
}
long long nCr(long long n, long long r) {
    long long A = 1, B = 1;
    //Aが分子Bが1/r!
    for (long long i = n - r + 1; i <= n; i++) {
        A = A * i % MOD;
    }
    for (long long i = 1; i <= r; i++) {
        B = B * i % MOD;
    }
    B = mod_pow(B, MOD - 2);
    B %= MOD;
    //Bは割るのではなく掛ける
    return (A * B) % MOD;
}

long long gcd(long long a, long long b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}
 
long long lcm(long long a, long long b) {
    return a * b / gcd(a, b);
}

long long A,B;
bool ok(long long key,long long index){
    string S = to_string(index);
    long long nagasa = S.size();
    if(index*A+nagasa*B > key) return true;
    else if(index*A+nagasa*B <= key) return false;
}
long long binary_search(long long key,long long size){
    //left,right,midはいずれもindex
    long long left = -1,right = size;
    while(right - left > 1){
        long long mid = left + (right-left)/2;
        long long hantei = ok(key,mid);
        if(hantei) right = mid;
        else left = mid;
    }
    if(left == -1)return 0;
    return left;
}

int retu[11][11];

int main() {
    int N,D;cin >> N >> D;
    for(int i = 0;i<N;i++)for(int j = 0;j<D;j++)cin >> retu[i][j];

    int ans = 0;
    double dist = 0;


    for(int i = 0;i<N;i++){
        for(int j = 0;j<N;j++){
            if(i == j) continue;
            for(int k = 0;k<D;k++){
                dist += mod_pow(abs(retu[i][k] - retu[j][k]),2);
            }
            int A = sqrt(dist);
            if(A*A == dist) ans++;
            dist = 0;
        }
    }

    cout << ans/2 << endl;


    // PLEASE GIVE ME THE "ACCEPTED" !
}


Measured memory_bytes: 256
from functools import reduce
from operator import add
N,M,C=map(int,input().split())
B = [int(i) for i in input().split()]
A=[]
ans = 0
for i in range(N):
    A = [int(i) for i in input().split()]
    AB = [A[i]*B[i] for i in range(M)]
    result = reduce(add,AB)+C
    if result>0:
        ans+=1
print(ans)

Measured memory_bytes: 3572
#!usr/bin/env python3
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect


def LI(): return [int(x) for x in sys.stdin.readline().split()]


def I(): return int(sys.stdin.readline())


def LS(): return [list(x) for x in sys.stdin.readline().split()]


def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res


def IR(n):
    return [I() for i in range(n)]


def LIR(n):
    return [LI() for i in range(n)]


def SR(n):
    return [S() for i in range(n)]


def LSR(n):
    return [LS() for i in range(n)]


sys.setrecursionlimit(1000000)
mod = 1000000007


def solve():
    n = I()
    h = LI()
    dp = [0]*n
    dp[1] = abs(h[0] - h[1])
    for i in range(2, n):
        dp[i] = min(abs((h[i] - h[i-1])) + dp[i-1],
                    abs((h[i] - h[i-2])) + dp[i-2])
    print(dp[n-1])
    return


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


Measured memory_bytes: 52256
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
#define PI 3.141592653589793


vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

int main(){
  int N; cin >> N; ll a[N], tmp[N]; ll LCM[1010100] = {};
  rep(i, N){
    cin >> a[i];
    for(auto p:prime_factorize(a[i])){
      LCM[p.first]=max(LCM[p.first], p.second);
    }
  }
  ll lcm=1;
  rep(i, 1010100){
    rep(j, LCM[i]){
      lcm*=i; lcm%=mod;
    }
  }
  ll ans = 0;
  rep(i, N){
    ans+=(lcm*modinv(a[i], mod));
    ans%=mod;
  }
  cout << ans << endl;
}  

Measured memory_bytes: 8192
N = int(input())
c = str(input())
ans = 0
left = 0
right = N-1
while(left < right):
    if c[right] == 'W':
        # 右側で見ているのは白い石。影響がないのでその一つ左を見ることにする
        right -= 1
    elif c[right] == 'R':
        if left < right and c[left] == 'R':
            # 左側で見ているのは赤い石。影響がないのでその一つ右を見ることにする
            left += 1
        elif left < right and c[left] == 'W':
            # この時、左側で見ている白の石と右側で見ている赤の石を交換する。
            ans += 1
            # 左側で見ていた白は赤になり、影響がなくなったので、その一つ右をみる。
            left += 1
            # 右側で見ていた赤は白になり、影響がなくなったので、その一つ左をみる。
            right -= 1

print(ans)

Measured memory_bytes: 9408
A = int(input())
B = int(input())
C = int(input())
X = int(input())

cnt = 0

for a in range(A+1):
    for b in range(B+1):
        for c in range(C+1):
            if 500*a + 100*b + 50*c == X:
                cnt+= 1

print(cnt)

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

int main()
{
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  string s, t;
  cin >> s >> t;
  for (int i = n - 1; i >= 0; --i) {
    if (t.substr(0, i + 1) == s.substr(s.size() - i - 1, i + 1)) {
      cout << n + (n - i - 1) << endl;
      return 0;
    }
  }
  cout << 2 * n << endl;
  return 0;
}



Measured memory_bytes: 256
# frozen_string_literal: true

r, c = readline.split(' ').map(&:to_i)
table = Array.new(r + 1).map{Array.new(c + 1, 0)}
(0...r).each do |i|
  table[i] = readline.chomp.split(' ').map(&:to_i)
  table[i][c] = (0...c).sum { |j| table[i][j] }
  puts table[i].join(' ')
end
(0..c).each do |j|
  table[r][j] = (0...r).sum { |i| table[i][j] }
end
puts table[r].join(' ')



Measured memory_bytes: 7104
#include <algorithm>
#include <array>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

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

bool has_573(int64_t n) {
    bool has7 = false;
    bool has5 = false;
    bool has3 = false;
    while(!(has5 && has7 && has3) && n > 0) {
        int mod = n % 10; 
        if(mod == 3)
            has3 = true;
        if(mod == 5)
            has5 = true;
        if(mod == 7)
            has7 = true;
        n /= 10;
    }
    return has5 && has7 && has3;
}

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

    queue<int64_t> q;
    q.push(0);

    int ret = 0;
    int64_t n = 0;
    while(n <= N) {
        if(has_573(n)) {
            ret++;
        }
        n = q.front();
        q.pop();
        q.push(n*10+3);
        q.push(n*10+5);
        q.push(n*10+7);
    }
    cout << ret << endl;

    return 0;
}


Measured memory_bytes: 3524
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i=0; i<(ll)n; i++)
#define REPR(i, n) for(ll i=(ll)n-1; i>=0; i--)
#define FOR(i, m, n) for(ll i=(ll)m; i<(ll)n; i++)
#define FORR(i, m, n) for(ll i=(ll)m-1; i>=(ll)n; i--)
#define ALL(x) (x).begin(), (x).end()
#define ASC(v) sort(ALL(v));
#define DESC(v) sort(ALL(v), greater<int>());
#define UNIQ(a) sort(ALL(a));(a).resize(unique(ALL(a)) - a.begin());
#define PRINTD(x, d) cout << fixed << setprecision(d) << x << "\n";
#define DEBUG(x) cout<<#x<<": "<<x<<"\n"
const double PI = acos(-1);
ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; }
bool isprime(int x){ int i; if(x<2)return 0; else if(x==2) return 1; if(x%2==0) return 0; for(i=3; i*i<=x; i+=2) if(x%i==0) return 0; return 1; }
int digsum(int n) { int r=0; while(n>0) { r+=n%10; n/=10; } return r; }
vector<string> split(string s, char p){vector<string>v;stringstream m(s);string b;while(getline(m,b,p))v.push_back(b);return v;}
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
struct nya{ nya(){ cin.tie(0); ios::sync_with_stdio(false); } }nyan;

int main(){
    ll H, W, K; cin >> H >> W >> K;
    vector<string> c(H);
    REP(h, H) cin >> c[h];

    ll ans = 0;
    for (ll bit=0; bit<(1<<H); bit++) {
        vector<ll> Sh;
        REP(h, H) if (bit&(1<<h)) Sh.push_back(h);
        // 何か処理
        for (ll bit=0; bit<(1<<W); bit++) {
            ll cnt = 0;
            vector<ll> Sw;
            REP(w, W) if (bit&(1<<w)) Sw.push_back(w);
            // 何か処理
            REP(hi, H) {
                REP(wi, W) {
                    if (find(ALL(Sh), hi) != Sh.end()) {
                        if (find(ALL(Sw), wi) != Sw.end()) {
                            if (c[hi][wi] == '#') cnt++;
                        }
                    }
                }
            }
            if (cnt == K) ans++;
        }
    }
    
    cout << ans << "\n";
}


Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=1LL<<60;
const ll mod=1000000007;

int main() {
    string s;
    cin>>s;
    int a1=0,a2=0;
    for(int i=0;i<s.size();i++){
        if(i%2==0){
            if(s[i]=='0') a2++;
            else a1++;
        }
        else{
            if(s[i]=='0') a1++;
            else a2++;
        }
    }
    cout<<min(a1,a2)<<endl;
}


Measured memory_bytes: 3688
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int h,w,k;
  cin >> h >> w >> k;
  vector<string> s(h);
  rep(i,h) cin >> s[i];
  int ans = 0;
  rep(x,1<<h)rep(y,1<<w){
    int t = 0;
    rep(i,h)rep(j,w){
      if(x>>i&1)continue;
      if(y>>j&1)continue;
      if(s[i][j]=='#') ++t;
    }
    if(t==k) ++ans;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3628
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  string A; cin >> A;
  ll len = A.length();
  ll cnt[26]; CLR(cnt);
  FOR(i,0,len) cnt[A[i]-'a']++;
  ll ans = len * (len - 1) / 2;
  FOR(i,0,26) {
    if(cnt[i] >= 2) {
      ans -= cnt[i] * (cnt[i] - 1) / 2;
    }
  }
  cout << ans + 1 << endl;
  return 0;
}

Measured memory_bytes: 720
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;
#define MuhammedAly ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all(x) (x).begin(),(x).end()
#define allr(x) (x).rbegin(),(x).rend()
#define pb push_back
#define eb emplace_back
#define popc(x) __builtin_popcount(x)
#define LLMX 1e18
#define NotinRange(n,m) i<0||i>=(n)||j<0||j>=(m)
#define mem(x,y) memset((x),(y),sizeof (x))
#define sz(a) (int)(a).size()
#define inFile(s) freopen((s),"r",stdin)
#define	outFile(s) freopen((s),"w",stdout)
#define biEdge(v, a, b) (v)[(a)].pb((b)), (v)[(b)].pb((a))
#define pi (2 * acos(0))
#define X real()
#define Y imag()
#define cross(a, b) ((conj(a) * (b)).Y)
#define dot(a, b) ((conj(a) * (b)).X)
#define vec(a,b) ((b) - (a))
#define ll long long
typedef long double ld;
typedef complex<double>point;
typedef tuple<int, int, int> line;
typedef pair<point, point>segment;
typedef vector<point>polygon;
const int N = 1e5 + 5, M = 20 + 5, OO = 0x3f3f3f3f, mod = 1e9 + 7, base = 131, mod2 = 1000136437, mod3 = 998244353;
const double EPS = 1e-9;

int acc['z' + 1][N];
int main()
{
    MuhammedAly
    string s;
    cin >> s;
    map<char,vector<int>>mp;
    for(int i = 0 ; i < sz(s) ; i++)
    {
        acc[s[i]][i]++;
        mp[s[i]].pb(i);
        for(char c = 'a' ; c <= 'z' ; c++)
            acc[c][i] += acc[c][i - 1];
    }
    for(char c = 'a' ; c <= 'z' ; c++)
    {
        for(int i = 0 ; i < sz(mp[c]) ; i++)
        {
            int l = i + 1, r = sz(mp[c]) - 1, j;
            while(l <= r)
            {
                j = (l + r) / 2;
                int left = ((mp[c][i])? acc[c][mp[c][i] - 1] : 0);
                if(acc[c][mp[c][j]] - left > int((mp[c][j] - mp[c][i] + 1) / 2))
                    return cout << mp[c][i] +  1 << " " << mp[c][j] + 1, 0;
                r = j - 1;
            }
        }
    }
    cout << -1 << " " << -1;
    return 0;
}

Measured memory_bytes: 12240
#include <iostream>

using namespace std;

int calc(int a, int b, int n) {
	int tmp = n-a-b;
	int count = 0;
	for (int c=0; c<10; c++) {
		for (int d=0; d<10; d++) {
			if (tmp == c+d)
				count++;
		}
	}
	return count;
}

void solve(int n) {
	int count = 0;
	for (int a=0; a<10; a++) {
		for (int b=0; b<10; b++) {
			count += calc(a,b,n);
		}
	}
	cout << count << endl;
}

int main() {
	int n;
	while (cin >> n) {
		solve(n);
	}
	return 0;
}


Measured memory_bytes: 3016
#include<stdio.h>

int main(){
  char a[20];
  int i;
  int count=0;

  scanf("%s",a);

for(i=0;a[i]!='\0';i++){
  count++;
}

for(i=1;i<count+1;i++){
  printf("%c",a[count-i]);
}
printf("\n");
  return 0;
}

Measured memory_bytes: 524
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#include <cstdio>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

#define ls st<<1
#define rs st<<1|1
#define LL long long
#define CLR(a,b) memset(a,(b),sizeof(a))

const int MAXN = 1e5+11;
const int mod = 1e9+7;
const int INF = 0x3f3f3f3f;

/* ------------------------基本函数-------------------------*/


LL pow_mod(LL a, LL b) {
	LL ans = 1;
	while(b) {
		if(b&1)
			ans = (ans*a) % mod;
		a = (a*a) % mod;
		b /= 2;
	}
	return ans;
}

int arr[MAXN];
int main() {
	int n;
	cin >> n;
	for(int i = 1; i <= n; i++) {
		cin >>arr[i];
	}
	bool flag = true;
	sort(arr+1,arr+1+n);
	if(n&1) {
		if(arr[1]!=0) flag = false;
		for(int i = 2,j=2; i <= n-1; i+=2,j+=2) {
			//cout<<arr[i]<<' '<<j<< endl;
			if(arr[i] != j) {
				flag = false; break;
			}
		}
	}
	else {
		for(int i = 2,j=1; i<=n; i+=2,j+=2) {
			if(arr[i] != j) {
				flag = false; break;
			}
		}
	}
	if(flag) {
		LL xx = (LL)(n/2);
		//cout << xx<< endl;
		cout << pow_mod(2,xx) << endl;
	}
	else cout << 0 << endl;

return 0;
}


Measured memory_bytes: 640