akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

namespace HABIT{
    #define f(a,b,c,d) for(register int a=b,c=d;a<=c;a++)
    #define g(a,b,c,d) for(register int a=b,c=d;a>=c;a--)
    #define LOCAL
    typedef int i32;
    typedef unsigned int u32;
    typedef long long int i64;
    typedef unsigned long long int u64;
    typedef pair<i32,i32> pii;
    const i32 MAXN=1024;
    typedef i32 ar[MAXN];
    
    template<typename T> inline T Max(T a) { return a; }
    template<typename T,typename... Args> inline T Max(T a,Args... args){
        T b=Max(args...);
        return (a>b)?a:b;
    }
    template<typename T> inline T Min(T a) { return a; }
    template<typename T,typename... Args> inline T Min(T a,Args... args){
        T b=Min(args...);
        return (a<b)?a:b;
    }

    #ifdef LOCAL
        inline char gc() { return getchar(); }
    #else
        inline char gc() {
            static char s[1<<20|1]={0},*p1=s,*p2=s;
            return (p1==p2)&&(p2=(p1=s)+fread(s,1,1<<20,stdin),p1==p2)?EOF:*(p1++);
        }
    #endif
    inline i64 read(){
        register i64 ans=0;register char c=gc();register bool neg=0;
        while(c<48||c>57) neg^=!(c^'-'),c=gc();
        while(c>=48&&c<=57) ans=(ans<<3)+(ans<<1)+(c^48),c=gc();
        return neg?-ans:ans;
    }

    char Output_Ans[1<<20|1],*Output_Cur=Output_Ans;
    inline void output() { Output_Cur-=fwrite(Output_Ans,1,Output_Cur-Output_Ans,stdout); }
    inline void print(char c){
        if(Output_Cur-Output_Ans+1>>20) output();
        *(Output_Cur++)=c;
    }
    inline void print(char *s) { while(*s) print( *(s++) ); }
    inline void print(u64 x){
        if(!x) { print('0'); return ; }
        char buf[30]={0},*p=buf+28;
        while(x) *(p--)=x%10+48,x/=10;
        print(p+1);
    }
    inline void print(u32 x) { print( (u64)x ); }
    inline void print(i64 x){
        if(x<0) print('-'),x=-x;
        print( (u64)x );
    }
    inline void print(i32 x){
        if(x<0) print('-'),x=-x;
        print( (u64)x );
    }
}
using namespace HABIT;

int main(){
    print( read()*read() );
    output();
    return 0;
}

Measured memory_bytes: 3680
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <climits>
#include <ctime>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <deque>
#include <complex>
#include <string>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <valarray>
#include <iterator>
using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) container.begin(), container.end()
#define RALL(container) container.rbegin(), container.rend()
#define SZ(container) ((int)container.size())
#define mp(a,b) make_pair(a, b)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

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; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}

const int INF = 1<<28;
const double EPS = 1e-8;
const int MOD = 1000000007;


int n, m, a;
int g[101][1001];
main(){
	while(cin >> n >> m >> a, n){
		memset(g, 0, sizeof(g));
		REP(i, m){
			int h, p, q;
			cin >> h >> p >> q;
			g[p][h] = q;
			g[q][h] = p;
		}
		int h = 0;
		RREP(i, 1001){
			if(g[a][i]) a = g[a][i];
		}
		cout << a << endl;
	}
	return 0;
}

Measured memory_bytes: 1564
// 1:05 -> 1:10
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
map<string ,ll>mp;
int main (){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin>>n; 
	for(int i=0;i<n;i++){
		string s; 
		cin>>s;
		sort(s.begin(),s.end());
		mp[s]++; 
	}
	ll ans = 0;
	ll x;
	for(auto p:mp){
		x=p.second;
		ans+=(x*(x-1)/2);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 11264
// #include <bits/stdc++.h>
#include <iostream>
#include <map>
#include <cmath>
#include <ios>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <stack>
#include <numeric>
// #include <windows.h>
using namespace std;
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;
template<class T> using VVV = V<VV<T>>;
template<class T> using G = greater<T>;
template<class T1, class T2> using P = pair<T1, T2>;
using I = int;
using D = double;
using B = bool;
using C = char;
using S = string;
using LL = long long;
using LD = long double;
using ULL = unsigned long long;
using PII = P<I, I>;
using VPII = V<PII>;
using PLL = P<LL, LL>;
using VPLL = V<PLL>;
using VI = V<I>;
using VVI = VV<I>;
using VLL = V<LL>;
using VVLL = VV<LL>;
using VC = V<C>;
using VVC = VV<C>;
using VS = V<S>;
using VVS = VV<S>;
using VB = V<B>;
using VVB = VV<B>;
#define REP(type, i, n) for (type i = 0; i < (type)(n); ++i)
#define REP2(type, i, m, n) for (type i = (m); i < (type)(n); ++i)
#define REPR(type, i, n) for (type i = (n)-1; i >= 0; --i)
#define REPR2(type, i, m, n) for (type i = (n)-1; i >= (m); --i)
#define REPx(x, a) for(auto x : a)
#define ALL(a) a.begin(), a.end()
#define SORT(a) sort(ALL(a))
#define SORTR(a, type) sort(ALL(a), G<type>())
#define REVERSE(a) reverse(ALL(a))
#define SIZE(a, type) ((type)(a).size())
#define bit_search(bit, n) REP(LL, bit, 1LL<<(n))
#define bit_check(bit, i) ((bit>>(i)) & 1)
#define setpre(n) fixed << setprecision((n))
#define UNIQUE(a) do {SORT(a); (a).erase(unique(ALL(a)), (a).end());} while(0)
#define MAX(a) *max_element(ALL(a))
#define MIN(a) *min_element(ALL(a))
#define bisect_left(a, x) lower_bound(ALL(a), (x)) - a.begin()
#define bisect_right(a, x) upper_bound(ALL(a), (x)) - a.begin()
#define INPUT(a) REPx(&x, a) cin >> x;
#define INPUTP(a) REPx(&x, a) cin >> x.first >> x.second;
#define OUTPUT_PERMUTATION(n) do{VI v(n); iota(ALL(v), 1); do{REPx(x, v) cout << x << " "; ENDL} while(next_permutation(ALL(v)));} while(0);
#define MAKE_PERMUTATION(n, PER) do{VVI a(fact(n), VI(n)); int idx = 0; VI v(n); iota(ALL(v), 1); do{REP(roop, n) a[idx][roop] = v[roop]; idx++;} while(next_permutation(ALL(v))); PER = a;} while(0); // int fact(), VVI PERを宣言しておく、n=10が限界(500 ms)
#define ENDL cout << endl;

const int INF = 2e9;
const LL MOD = 1e9 + 7;

template<class T> using PRIORITY_QUEUE = priority_queue< T, V<T>, G<T> >;
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;}
template<class T> inline void debug1(V<T> A){REP(int, i, SIZE(A, int)){if (A[i] == INF) cout << "I "; else cout << A[i] << " ";}}
template<class T> inline void debug2(VV<T> A){REP(int, i, SIZE(A, int)){REP(int, j, SIZE(A[i], int)){if (A[i][j] == INF) cout << "I "; else cout << A[i][j] << " ";}ENDL}}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int k, a, b;
  cin >> k >> a >> b;
  REP2(int, i, a, b+1)
  {
    if (i % k == 0)
    {
      cout << "OK";
      return 0;
    }
  }
  cout << "NG";

  return 0;
}


Measured memory_bytes: 3596
#include<iostream>
#include<string>
using namespace std;
int main(){
  int h,w,i,j,num;cin >> h >> w;
  char s[h][w];
  for(i=0;i<h;i++){
    for(j=0;j<w;j++) cin >> s[i][j];
  }
  for(i=0;i<h;i++){
    for(j=0;j<w;j++){
      if(s[i][j]=='.'){
        num = 0;
        if(i!=0){
          if(j!=0 && s[i-1][j-1]=='#') num++;
          if(j+1!=w && s[i-1][j+1]=='#') num++;
          if(s[i-1][j]=='#') num++;
        }
        if(j!=0 && s[i][j-1]=='#') num++;
        if(j+1!=w && s[i][j+1]=='#') num++;
        if(i+1!=h){
          if(j!=0 && s[i+1][j-1]=='#') num++;
          if(j+1!=w && s[i+1][j+1]=='#') num++;
          if(s[i+1][j]=='#') num++;
        }
        cout << num;
      }
      else cout << "#";
    }
    cout << endl;
  }  
}

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

int main() {
  string x;
  cin>>x;
  int n=x.size();
  int p=0;
  int q=0;
  rep(i,n){
    if(x[i]=='T'&&q==0){
      p++;
    }else if(x[i]=='T'&&q>0){
      p--;
      q--;
    }else if(x[i]=='S'){
      p++;
      q++;
    }
  }
  cout<<p<<endl;
}

Measured memory_bytes: 644
# n = 1000000000000000000 // 2
def A027868(n):
    return 0 if n < 5 else n // 5 + A027868(n // 5)
# A027868(n) # 124999999999999995

def ABC148E(n):
    if n % 2 == 1:
        print(0)
    else:
        print(A027868(n // 2))

n = int(input())
ABC148E(n)


Measured memory_bytes: 2940
//#include <bits/stdc++.h>
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

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

    int N;

    cin >> N;

    vector<int> v(N);

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

    sort(v.begin(), v.end());

    double ans = v[0];

    for(int i = 1; i < N; i++)
    {
        ans = (ans + v[i]) / 2;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
A = []
for i in range(3):
    a = list(input().split())
    A.append(a)
N = int(input())
B = []
for i in range(N):
    b = input()
    B.append(b)

bingo = [[False] * 3, [False] * 3, [False] * 3]

for i in range(3):
    for j in range(3):
        for x in range(N):
            if A[i][j] == B[x]:
                bingo[i][j] = True
ans = 'No'

for i in range(3):
    if bingo[0][i] and bingo[1][i] and bingo[2][i]:
        ans = 'Yes'
    if bingo[i][0] and bingo[i][1] and bingo[i][2]:
        ans = 'Yes'
if bingo[0][0] and bingo[1][1] and bingo[2][2]:
    ans = 'Yes'
if bingo[0][2] and bingo[1][1] and bingo[2][0]:
    ans = 'Yes'

print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
  int N; cin>>N;
  long g; cin>>g;
  for(int i=1;i<N;i++){
    long a; cin>>a;
    g = __gcd(g,a);
  }
  cout<<g<<endl;
  return 0;
}

Measured memory_bytes: 256
fn main() {
    let nm = read_line();
    let mut vec = vec![];
    for _ in 0..nm[0] {
        let s = read_line_str().replace("\n", "");
        vec.push(s);
    }

    vec.sort();
    for i in vec {
        print!("{}", i);
    }
    println!("");
}

fn read_line() -> Vec<i32> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    let v = s.trim()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect();
    return v
}

fn read_line_str() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    return s;
}

Measured memory_bytes: 4352
N, K = gets.split(/\s+/).map(&:to_i)
numerator = 0.0
kakeru = 1
waru   = 1.0
N.downto(1){|dice|
	until K <= dice * kakeru
		kakeru *= 2
		waru   /= 2.0
	end
	numerator += waru
}
p(numerator / N)


Measured memory_bytes: 3836
"use strict";
    
const main = arg => {
    arg = arg.split("\n");
    const H = arg[0].split(" ")[0];
    const W = arg[0].split(" ")[1];
    
    const pixels = arg.slice(1, H + 1);
    let answer    = [];
    
    for(let i=0; i<H; i++) {
        answer.push(pixels[i]);
        answer.push(pixels[i]);
    }
    
    console.log(answer.join("\n"));
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 21064
#include <iostream>

int main() {
    char b;
    std::cin >> b;
    char ret;
    if (b == 'A') ret = 'T';
    if (b == 'T') ret = 'A';
    if (b == 'G') ret = 'C';
    if (b == 'C') ret = 'G';
    std::cout << ret << std::endl;
    return 0;
}


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

using namespace std;

typedef long long ll;

int f[200005][60];
ll g[200005][60];

int num[400005],last[200005];

void pre(int n) {
  for(int i=0;i<n;i++) num[n+i]=num[i];
  for(int i=2*n-1;i>=0;i--) {
  	if (i<n) {
  		f[i][0]=(last[num[i]]+1)%n;
  		g[i][0]=last[num[i]]-i+1;
	  }
	last[num[i]]=i;
  }
  for(int i=1;i<60;i++)
    for(int j=0;j<n;j++) {
    	f[j][i]=f[f[j][i-1]][i-1];
    	g[j][i]=min(g[j][i-1]+g[f[j][i-1]][i-1],(ll)1e18);
	}
}

int query(ll k) {
  int x=0;
  for(int i=59;i>=0;i--)
    if (g[x][i]<=k) {
    	k-=g[x][i];
    	x=f[x][i];
	}
  return k;
}

int st[200005];
bool vis[200005];

int main() {
  int n;
  ll k;
  scanf("%d%lld",&n,&k);
  for(int i=0;i<n;i++) scanf("%d",&num[i]);
  pre(n);
  int d=query(n*k),top=0;
  for(int i=n-d;i<n;i++) {
  	int x=num[i];
    if (vis[x]) {
    	while (vis[x]) {
    		vis[st[top]]=0;
    		top--;
		}
	}
	else {
		vis[x]=1;
		st[++top]=x;
	}
  }
  for(int i=1;i<=top;i++) printf("%d ",st[i]);
  printf("\n");
  return 0;
}

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

int main(void){
  char o[50],e[50];

  scanf("%s%s",o,e);

  for(int i = 0;i < strlen(e);i++){
    printf("%c%c",o[i],e[i]);
  }

  if(strlen(e) != strlen(o)) printf("%c",o[strlen(o)-1]);
  printf("\n");

  return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <iostream>
#include <complex>
#include <cmath>
#include <cstdio>
#include <utility>
#include <vector>
using namespace std;
using W = long double;
using P = complex<W>;
using L = pair<P,P>;
using C = pair<P,W>;
using Poly = vector<P>;
#define X real()
#define Y imag()
const W EPS = (1e-8), pi = acos(-1);

W cross(const P &a, const P &b){ return a.X*b.Y-a.Y*b.X; }

//円と円の交点
vector<P> cpcc(C a, C b){
  P ca = a.first, cb = b.first;
  W d = abs(ca-cb), ra = a.second, rb = b.second;
  W t = (ra*ra-rb*rb+d*d)/2/d, h = sqrt(ra*ra-t*t);
  P m = t/abs(cb-ca)*(cb-ca)+ca;
  vector<P> cp(2,m);
  P n = (ca-cb)*P(0,1);
  n *= h/abs(n);
  cp[0] -= n;
  cp[1] += n;
  if(cross(cb-ca,cp[0]-ca) < -EPS) swap(cp[0],cp[1]);
  return cp;
}

bool is_cross(const C &A, const C &B){
  W d = abs(A.first-B.first);
  return A.second+B.second >= d and abs(A.second-B.second) <= d;
}

vector<pair<W,W>> modify(const pair<W,W> &A){
  // while(A.first < -pi-EPS) A.first += 2*pi;
  // while(A.second > pi+EPS) A.second -= 2*pi;
  if(A.first < A.second) return {A};
  return {{A.first,pi},{-pi,A.second}};
}

bool is_included(const C &A, const C &B){
  if(A.second > B.second-EPS) return false;
  W d = abs(A.first-B.first);
  return abs(A.second-B.second) >= d;
}

int main(){
  int n;
  while(cin >> n, n){
    vector<C> circ;
    for(int i = 0; i < n; ++i){
      W x, y, r;
      cin >> x >> y >> r;
      circ.emplace_back(P(x,y),r);
    }
    W ans = 0;
    for(int i = 0; i < n; ++i){
      bool f = false;
      for(int j = 0; j < n; ++j){
        if(i == j) continue;
        if(is_included(circ[i],circ[j])){
          f = true;
          break;
        }
      }
      if(f) continue;
      vector<pair<W,W>> A;
      for(int j = 0; j < n; ++j){
        if(i == j) continue;
        if(not is_cross(circ[i],circ[j])) continue;
        vector<P> cps = cpcc(circ[i],circ[j]);
        if(abs(cps[0]-cps[1]) < EPS) continue;
        pair<W,W> a(arg(cps[1]-circ[i].first),arg(cps[0]-circ[i].first));
        vector<pair<W,W>> s = modify(a);
        for(auto e : s) A.push_back(e);
      }
      sort(A.begin(),A.end());
      W ang = -pi, t = 0;
      for(auto e : A){
        t += max<W>(0,e.first-ang);
        ang = max(ang,e.second);
      }
      t += max<W>(0,pi-ang);
      ans += t*circ[i].second;
      // fprintf(stderr,"Circle %d : %.12f\n",i,t*circ[i].second);
      // for(auto e : A){
      //   fprintf(stderr,"[%.6f, %.6f]\n",e.first,e.second);
      // }
    }
    printf("%.12Lf\n",ans);
  }
}



Measured memory_bytes: 3156
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define VSORT(v) sort(v.begin(), v.end());
#define VREV(v) reverse(v.begin(), v.end());
using namespace std;
using ll = long long;
using pll = pair<ll,ll>;
using vll = vector<ll>;
using vdouble = vector<double>;
using vstr = vector<string>;
typedef pair<int,int> P;
int dx[4] = {1, 0, -1, 0},dy[4] = {0, 1, 0, -1};
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
template<class T> inline bool chmax(T& a, T b){if(a<b) {a=b; return 1;} return 0; }
template<class T> inline bool chmin(T& a, T b){if(a>b) {a=b; return 1;} return 0; }
const ll INF = 1LL << 60;
const ll mod = 1000000007;


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

ll N;
ll W, weight[MAX_N], value[MAX_N];

ll dp[MAX_N][MAX_V];
//dp[i][j]=i-1番目の品物から価値の条件を達成するように選んだ時の重さの総和の最大値。

int main(){
	//乱数srand((unsigned)time(NULL));
	
	//入力
	cin>>N>>W;
	rep(i,N)cin>>weight[i]>>value[i];
	
	rep(i,MAX_N)rep(j,MAX_V) dp[i][j]=INF;
	
	dp[0][0]=0;
	
	//dpテーブル埋め
	rep(i,N){
		rep(j,MAX_V){
			if(j-value[i]>=0){
				chmin(dp[i+1][j],dp[i][j-value[i]]+weight[i]);
			}
			
			chmin(dp[i+1][j],dp[i][j]);
		}
	}
	
	ll res=0;
	
	rep(i,MAX_V){
		if(dp[N][i]<=W) res=i;
	}
	//dp[i][j]の値がW以下のjの最大値（ここでjは価値の総和の最大値）
	cout<<res<<endl;
}

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

int main()
{
    ll a, b, c;
    cin >> a >> b >> c;
    cout << (a + b + 2 * sqrtl(a*b) < c ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string.h>
#include <stdio.h>
using namespace std;

int main()
{
   char s[5];
   scanf("%s",s);
   int x=(s[0]-'0')*10+(s[1]-'0');
   int y=(s[2]-'0')*10+(s[3]-'0');
   if(x>=1&&x<=12)
   {
       if(y>=1&&y<=12)
        printf("AMBIGUOUS\n");
       else
        printf("MMYY\n");
   }

   else
   {
        if(y>=1&&y<=12)
            printf("YYMM\n");
        else
            printf("NA\n");
   }








    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp> 
//using namespace boost::multiprecision; 

using namespace std;

//#Rohitpratap311
//#Keep Calm And Stay Happy

typedef long long ll;
typedef long double ld;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t=1;
    //cin>>t;
    while(t--)
    {
        string s;
        cin>>s;
        if(s[s.size()-1]=='s')
        {
            cout<<s<<"es";
        }
        else
        {
            cout<<s<<"s";
        }
    }
    return 0;
}

Measured memory_bytes: 3576
# https://atcoder.jp/contests/keyence2020/tasks/keyence2020_b

# 4       n
# 2 4     x_i l_1
# 4 3
# 9 3
# 100 5   x_n l_n

n = gets.to_i
array_robot = []

n.times do
  x_temp, l_temp = gets.split.map(&:to_i)
  array_robot << [x_temp-l_temp, x_temp+l_temp]
end

array_robot.sort_by! {|from, to| to }
end_pos = array_robot[0][0]
ans = 0

array_robot.each do |from, to|
  if end_pos <= from
    ans += 1
    end_pos = to
  end
end

puts ans


Measured memory_bytes: 24208
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<ctime>
#include<vector>
#include<set>
#include<map>
#include<stack>
using namespace std;
int main()
{     long long n,m,i,j,k;
      cin>>n>>m;
      if(n>m)
         cout<<m-(n-m)<<endl;
         else 
           cout<<m+(m-n)<<endl;
	  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int P = sc.nextInt();
		int Q = sc.nextInt();
		int R = sc.nextInt();
		int ans = P + Q + R - Math.max(P, Math.max(Q, R));
		System.out.println(ans);
	}

}


Measured memory_bytes: 21844
a=[None]*10
b=[None]*10

for i in range(10):
    a[i]=input()
a=list(map(int,a))

for i in range(10):
    b[i]=input()
b=list(map(int,b))

a.sort(reverse=True)
b.sort(reverse=True)

k=a[0]+a[1]+a[2]
l=b[0]+b[1]+b[2]

print(str(k)+' '+str(l))



Measured memory_bytes: 5600
N,A,B = map(int,input().split())
S = str(input())
now = 0
kaigai = 0
for i in range(N):
  temp = S[i]
  if temp == "a" and now < A+B:
    print("Yes")
    now +=1
  elif temp == "b" and now < A+B and kaigai < B:
    print("Yes")
    kaigai += 1
    now += 1
  else:
    print("No")

Measured memory_bytes: 9120
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Coer
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskK solver = new TaskK();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskK {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int k = in.nextInt();
            int[] a = new int[n + 1];
            for (int i = 1; i <= n; i++) {
                a[i] = in.nextInt();
            }
            boolean[] dp = new boolean[k + 1];
            for (int i = 1; i <= k; i++) {
                for (int j = 1; j <= n; j++) {
                    if (i >= a[j] && dp[i - a[j]] == false) {
                        dp[i] = true;
                    }
                }
            }
            if (dp[k] == true) {
                out.println("First");
            } else {
                out.println("Second");
            }
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}

Measured memory_bytes: 24660
import java.io.*;
import java.util.*;


public class Main {

    public static void main(String[] args) throws Exception {

        new Main().go();
    }

    PrintWriter out;
    Reader in;
    BufferedReader br;

    Main() throws IOException {

        try {

            //br = new BufferedReader( new FileReader("input.txt") );
            in = new Reader("input.txt");
            out = new PrintWriter( new BufferedWriter(new FileWriter("output.txt")) );
        }
        catch (Exception e) {

            //br = new BufferedReader( new InputStreamReader( System.in ) );
            in = new Reader();
            out = new PrintWriter( new BufferedWriter(new OutputStreamWriter(System.out)) );
        }
    }

    void go() throws Exception {

        int t = 1;
        while (t > 0) {
            solve();
            //out.println();
            t--;
        }

        out.flush();
        out.close();
    }


    int inf = 2000000000;
    int mod = 1000000007;
    double eps = 0.000000001;

    int n;
    int m;

    //ArrayList<Integer>[] g = new ArrayList[1000];

    void solve() throws IOException {

        int n = in.nextInt();

        out.println(n/3);
    }

    int gcd(int a, int b) {

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

    class Pair implements Comparable<Pair>{

        int a;
        int b;

        Pair(int a, int b) {

            this.a = a;
            this.b = b;
        }

        public int compareTo(Pair p) {

            if (a > p.a) return 1;
            if (a < p.a) return -1;
            if (b > p.b) return 1;
            if (b < p.b) return -1;
            return 0;
        }
    }

    class Item {

        int a;
        int b;
        int c;

        Item(int a, int b, int c) {
            this.a = a;
            this.b = b;
            this.c = c;
        }

    }

    class Reader {

        BufferedReader  br;
        StringTokenizer tok;

        Reader(String file) throws IOException {
            br = new BufferedReader( new FileReader(file) );
        }

        Reader() throws IOException {
            br = new BufferedReader( new InputStreamReader(System.in) );
        }

        String next() throws IOException {

            while (tok == null || !tok.hasMoreElements())
                tok = new StringTokenizer(br.readLine());
            return tok.nextToken();
        }

        int nextInt() throws NumberFormatException, IOException {
            return Integer.valueOf(next());
        }

        long nextLong() throws NumberFormatException, IOException {
            return Long.valueOf(next());
        }

        double nextDouble() throws NumberFormatException, IOException {
            return Double.valueOf(next());
        }


        String nextLine() throws IOException {
            return br.readLine();
        }

    }

}

Measured memory_bytes: 21332
#include<bits/stdc++.h>
using namespace std;
int main(){
    char s[5];
    int a,b,c,d,e,f,g,i,k,n;
    cin>>n;
    n=n%10;
    if((n==2)||(n==4)||(n==5)||(n==7)||(n==9)) cout<<"hon";
    else if(n==3) cout<<"bon";
    else cout<<"pon";
}

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

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

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

using Pi = pair<int, int>;
using Ti = tuple<int, int, int>;
using vint = vector<int>;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int N;
  cin >> N;
  vint A(N), B(N), C(N);
  rep(i, N) cin >> A[i];
  rep(i, N) cin >> B[i];
  rep(i, N) cin >> C[i];
  sort(all(A));
  sort(all(B));
  sort(all(C));
  int dpB[100010] = {};
  rep(i, N) {
    int ci = upper_bound(all(C), B[i])-C.begin();
    dpB[i] = N-ci;
  }
  for(int i = N-2; i >= 0; i--)
    dpB[i] += dpB[i+1];
  int ans = 0;
  rep(i, N) {
    int bi = upper_bound(all(B), A[i])-B.begin();
    ans += dpB[bi];
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3456
#include<iostream>
#include<iomanip>
#include<math.h>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
#define REP(i, N) for(ll i = 0; i < N; ++i)
#define FOR(i, a, b) for(ll i = a; i < b; ++i)
#define ALL(a) (a).begin(),(a).end()
#define pb push_back
#define INF (long long)1000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main(void) {
	while(true) {
		int n;
		cin>>n;
		if(n == 0) break;
		int m;
		cin>>m;
		vector<P> z(m);
		string sr = "";
		string sl = "";
		vector<int> ans;
		REP(i, m) {
			int x, y;
			cin>>x>>y;
			z[i].first = x;
			z[i].second = y;
		}
		FOR(i, 1, m) {
			sr += to_string(abs(z[i].first - z[i - 1].first) + abs(z[i].second - z[i - 1].second));
			sl = to_string(abs(z[i].first - z[i - 1].first) + abs(z[i].second - z[i - 1].second)) + sl;
			if(i != m - 1) {
				P l1, l2;
				l1.first = z[i].first - z[i - 1].first;
				l1.second = z[i].second - z[i - 1].second;
				l2.first = z[i + 1].first - z[i].first;
				l2.second = z[i + 1].second - z[i].second;
				ll gs = l1.first * l2.second - l1.second * l2.first;
				if(gs > 0) {
					sr += "r";
					sl = "l" + sl;
				}
				else {
					sr += "l";
					sl = "r" + sl;
				}
			}
		}
		REP(i, n) {
			cin>>m;
			string t;
			vector<P> Z(m);
			REP(j, m) {
				int x, y;
				cin>>x>>y;
				Z[j].first = x;
				Z[j].second = y;
			}
			FOR(j, 1, m) {
				t += to_string(abs(Z[j].first - Z[j - 1].first) + abs(Z[j].second - Z[j - 1].second));
				if(j != m - 1) {
					P l1, l2;
					l1.first = Z[j].first - Z[j - 1].first;
					l1.second = Z[j].second - Z[j - 1].second;
					l2.first = Z[j + 1].first - Z[j].first;
					l2.second = Z[j + 1].second - Z[j].second;
					ll gs = l1.first * l2.second - l1.second * l2.first;
					if(gs > 0) t += "r";
					else t += "l";
				}
			}
			if(sr == t || sl == t) ans.pb(i + 1);
		}
		REP(i, ans.size()) {
			cout<<ans[i]<<endl;
		}
		cout<<"+++++"<<endl;
	}
}

Measured memory_bytes: 3180
/*
オーダー
10**6	余裕を持って間に合う	
10**7	おそらく間に合う	余裕を持って間に合う
10**8	非常にシンプルな処理でない限り厳しい	おそらく間に合う
10**9		非常にシンプルな処理でない限り厳しい
logn	:OK
n		:10^7
nlogn	:10^6
n**2	:10^4
n**3	:300
2**n	:20
n!		:10



// 各桁の和を計算する関数
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

sort(a, a + N, greater<int>());  // a[0:N] を大きい順にソート

int num[110] = {0};  // バケット
for (int i = 0; i < N; ++i) {
    num[d[i]]++;  // d[i] が 1 個増える
}

map<string, int> mp; // 連想配列 map<キー型, 値型> オブジェクト名
for (int i = 0; i < N; ++i) {
    auto itr = mp.find(s[i]);        // s[i] が設定されているか？
    if(itr != mp.end() ) {
         mp[s[i]] += 1;
    }
    else {
         mp[s[i]] += 1 ;
    }
}
stack<int> s;	//intをデータとするスタックを用意
s.push(1);		//{} -> {1}
printf("%d\n", s.top());	// 3
s.pop();

queue<int> que;	//intをデータとするキューを用意
que.push(1);		//{} -> {1}
printf("%d\n", que.front());	// 1
que.pop();
*/

#include <iostream>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <string.h>

using namespace std;

// #define for(i,a,b) for (int i=(a);i<(b);++i)
typedef long long ll;
typedef pair<ll,ll> P;
#define REP(i,n) for(long long i = 0; i < (long long)(n); i++)
#define pb push_back // vectorに要素追加
#define INF (ll)1e18
// int 
// // 各桁の和を計算する関数
// int findSumOfDigits(int n) {
//   int amari = 0;
//   int keta = 0;
//   while (n > 0) { // n が 0 になるまで
//     amari += n % 2;
//     if (keta%2==0)
//     n /= 10;
//   }
//   return sum;
// }
 
ll gcd(ll a, ll b) {
	if(b == 0) return a;
	return gcd(b, a % b);
}

// const ll MAX_N = 1e5;
// ll N;
// ll h[MAX_N];
// ll dp[MAX_N+1]; // メモ化テーブル
 
// // i番目以降の品物から重さの総和がj以下になるように選ぶ
// void rec(ll i){
// 	if (i==0) dp[i] = 0;
// 	else if (i==1) dp[i] = abs(h[1]-h[0]);
// 	else dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]));
// 	return;
// }
 
 
int main() {
	// 入力
	ll A,B,K;
	cin >>A>>B>>K;
 
	// 解法
	ll i = 1;
	ll ans = 0;
	ll count = 0;
	ll C = min(A,B);
	for (ll i = C; i >= 1; --i){
		if (A%i==0 && B%i==0){
			count++;
			if (count==K){
				printf("%lld\n", i);
				break;
			}
		}
	}
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){
  int i;
  int n,s;
  int bi[10],pre_sum;
  int count,ans_count;

  for(;;){
    scanf("%d%d",&n,&s);
    if(n==0 && s==0)
      break;

    ans_count=0;

    for(i=0;i<10;i++)
      bi[i]=0;

    for(;bi[9]!=2;){
      count=0;
      for(i=0;i<10;i++)
        if(bi[i]==1)
          count++;

      pre_sum=0;
      if(count==n){
        for(i=0;i<10;i++){
          if(bi[i]==1)
            pre_sum+=i;
        }
        if(pre_sum==s)
          ans_count++;
      }

      bi[0]++;
      for(i=0;i<9;i++)
        if(bi[i]==2){
          bi[i+1]++;
          bi[i]=0;
        }
    }

    printf("%d\n",ans_count);
  }

  return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
int main(void){
  int x,y;
  while(scanf("%d %d",&x,&y),x>0||y>0){
      if(x>y){
          printf("%d %d\n",y,x);
      }
      else{
          printf("%d %d\n",x,y);
      }
       
  }
  return 0;
    
}


Measured memory_bytes: 2072
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#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;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;

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

    int nxt1[10][10] = {}, nxt2[10][10] = {};
    int half[10][10] = {};
    for(int i=0; i<10; i++) {
        for(int j=0; j<10; j++) {
            int s = i + j;
            if(s < 10) nxt1[i][j] = nxt2[i][j] = s, half[i][j] = 1;
            else nxt1[i][j] = s / 10, nxt2[i][j] = s % 10, half[i][j] = 0;
        }
    }

    ll ans = 0;
    vector<ll> elem;
    for(int i=0; i<M; i++) {
        ll d, c; cin >> d >> c;

        int v1 = d, v2 = d;
        while(c) {
            if(c % 2 == 1) {
                elem.emplace_back(v1);
                if(--c == 0) break;
            }
            int n1 = nxt1[v1][v2], n2 = nxt2[v1][v2];
            int h = half[v1][v2];
            ans += c / 2;
            if(h) c /= 2;
            v1 = n1, v2 = n2;
        }
    }

    while(elem.size() > 1) {
        int v1 = elem.back(); elem.pop_back();
        int v2 = elem.back(); elem.pop_back();
        ans++;
        if(v1 + v2 < 10) {
            elem.emplace_back(v1 + v2);
        }
        else {
            int n1 = (v1 + v2) / 10;
            int n2 = (v1 + v2) % 10;
            elem.emplace_back(n1);
            elem.emplace_back(n2);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 34660
#include<bits/stdc++.h>
using namespace std;
vector<int> vv[100022];
int mh[100022],par[100022];
void dfs(int node,int pa)
{
	par[node] = pa;
	for(int i=0;i<vv[node].size();i++)
	{
		int nn = vv[node][i];
		if(nn==pa)
			continue;
		dfs(nn,node);
		mh[node] = max(mh[node],mh[nn]+1);
	}
}
int main()
{
	int n,u,v;
	scanf("%d%d%d",&n,&u,&v);
	for(int i=1;i<n;i++)
	{
		int a,b;
		cin>>a>>b;
		vv[a].push_back(b);
		vv[b].push_back(a);
	}
	dfs(v,-1);
	int dis = 0,tt = u;
	while(tt!=v)
	{
		dis++;
		tt = par[tt];
	}
	dis = (dis-1)/2;
	while(dis--)
		u = par[u];
	int len = mh[u];
	while(u!=v)
	{
		len++;
		u = par[u];
	}
	cout<<(len-1)<<endl;
	return 0;
}

Measured memory_bytes: 12928
#include<bits/stdc++.h>
#define rep(i,n) for(int (i) = 0;(i) < (n);(i)++)
#define SORT(c) sort((c).begin(),(c).end())
#define INF 1000000007
//S.size()

using namespace std;


typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef vector<bool> VB;
typedef unsigned long long ll;



int main(void){
  string S;cin>>S;
  if(S[0] == S[1] && S[2] == S[3] &&S[1] != S[2]||
    S[0] == S[2] && S[1] == S[3] && S[1] != S[2]||
    S[0] == S[3] && S[1] == S[2] && S[0] != S[1]) {

    cout<<"Yes";
  }
  else cout<<"No";
}


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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');
            int A = int.Parse(s[0]);
            int B = int.Parse(s[1]);
            int T = int.Parse(s[2]);
            Console.WriteLine((T / A) * B);
        }
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 int a,b,c;
 cin>>a>>b;
 
 if(a-b<0){
 	cout<<0<<endl;
 }
 else {
 	cout<<a-b<<endl;
 }
  
 return 0;
 }

Measured memory_bytes: 256
n = int(input())
v = list(map(int, input().split()))
a, b = [0] * 100005, [0] * 100005
for i in range(len(v)):
    if i % 2: a[v[i]] += 1
    else: b[v[i]] += 1
a2, b2 = [], []
for i in range(100001):
    a2.append([a[i], i])
for i in range(100001):
    b2.append([b[i], i])
a2.sort()
a2.reverse()
b2.sort()
b2.reverse()

#a2 = [[2, 3], [1, 1], [0, 2], ...]
#b2 = [[2, 3], [1, 2], [0, 1], ...]
if a2[0][1] != b2[0][1]:
    print(n - a2[0][0] - b2[0][0])
else:
    print(n - max(a2[1][0] + b2[0][0], a2[0][0] + b2[1][0]))

#print(a2[:3])
#print(b2[:3])

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

using ll=long long;
const ll MOD=1e9+7;
int main(){
    int n,m;
    cin>>n>>m;
    vector<int> l(m),r(m),x(m);
    for(int i=0;i<m;i++){
        cin>>l[i]>>r[i]>>x[i];
    }
    vector<vector<int>> events(n+1);
    for(int i=0;i<m;i++){
        events[r[i]].push_back(i);
    }
    vector<vector<vector<ll>>> dp(n+1,vector<vector<ll>>(n+1,vector<ll>(n+1,0)));
    dp[1][0][0]=1;
    dp[0][1][0]=1;
    dp[0][0][1]=1;
    for(int mc=1;mc<=n;mc++){
        for(int loop=0;loop<3;loop++){
            for(int i=0;i<mc;i++){
                for(int j=0;j<mc;j++){
                    //dp[mc][i][j]
                    int r,g,b;
                    if(loop==0) r=mc,g=i,b=j;
                    if(loop==1) r=j,g=mc,b=i;
                    if(loop==2) r=i,g=j,b=mc;
                    for(int k=0;k<events[mc].size();k++){
                        int idx=events[mc][k];
                        int cnt=(int)(l[idx]<=r)+(int)(l[idx]<=g)+(int)(l[idx]<=b);
                        if(x[idx]!=cnt){
                            dp[r][g][b]=0;
                        }
                    }
                    if(mc!=n){
                        (dp[mc+1][g][b]+=dp[r][g][b])%=MOD;
                        (dp[r][mc+1][b]+=dp[r][g][b])%=MOD;
                        (dp[r][g][mc+1]+=dp[r][g][b])%=MOD;
                    }   
                }
            }
        }
    }
    ll res=0;
    for(int i=0;i<=n;i++){
        for(int j=0;j<=n;j++){
            for(int k=0;k<=n;k++){
                if(i==n || j==n || k==n){
                    (res+=dp[i][j][k])%=MOD;
                }
            }
        }
    }
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 216832
n, k = map(int, input().split())

if k % 2 == 1:
    print((n // k) ** 3)
elif n % k < k // 2:
    print((n // k) ** 3 + (n // k) ** 3)
else:
    print((n // k) ** 3 + (n // k + 1) ** 3)

Measured memory_bytes: 61804
n,m=map(int, input().split())
a=list(map(int, input().split()))
bc_list=[]
for i in range(m):
    b,c=map(int, input().split())
    bc_list.append([b,c])

a.sort()
import operator
bc_list.sort(key=operator.itemgetter(1),reverse=True)

s=0

ans=0
for i in range(m):
    for j in range(s,s+bc_list[i][0]):
        if j>=n:
            break
        if a[j]<bc_list[i][1]:
            ans+=bc_list[i][1]
            s+=1
        else:
            break

for i in range(s,n):
    ans+=a[i]
print(ans)

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

using namespace std;

#define endl "\n"
typedef long long int ll;

inline void fastio(){ios::sync_with_stdio(false); cin.tie(0);}
inline void setPrecision(int n){cout.precision(n);}

//DEBUG
#define dbg(x) cerr<<(#x)<<": "<<x<<endl
#define dbgV(x) cerr<<(#x)<<": "; for(auto it: x) cerr<<it<<" "; cerr<<endl;
#define dbgS(x) cerr<<(#x)<<": "; for(auto it: x) cerr<<it<<" "; cerr<<endl;
#define dbgM(x) cerr<<(#x)<<": "; for(auto it: x) cerr<<"["<<it.f<<", "<<it.s<<"] "; cerr<<endl;
#define dbg2D(x) cerr<<(#x)<<": \n"; for(auto y: x) { for(auto it: y) cerr<<it<<" "; cerr<<endl; } cerr<<endl;
#define dbgA(x, n) cerr<<(#x)<<": "; for(int i=0;i<n;++i) cerr<<x[i]<<" "; cerr<<endl;
#define dbgVP(x) cerr<<(#x)<<": "; for(auto it: x) cerr<<"["<<it.f<<", "<<it.s<<"] "; cerr<<endl;

ll INF = 1e10;
ll MOD = 1e9+7;

int n;
int a[21][21];

ll done[1<<21];

ll pairs(int state){
    int idx = __builtin_popcount(state);
    if(idx == n) return 1;
    if(done[state] != -1) return done[state];
    ll ans = 0;
    for(int i=0;i<n;++i)
        if(a[idx][i] && !(state&(1<<i))){
            ans = (ans + pairs(state|(1<<i)))%MOD;
        }
    done[state] = ans;
    return ans;
}

int main(){
    fastio();
    cin>>n;
    for(int i=0;i<n;++i)
        for(int j=0;j<n;++j)
            cin>>a[i][j];
    memset(done, -1, sizeof(done));
    cout<<pairs(0);
    return 0;
}


Measured memory_bytes: 19984
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const int64_t LINF=8931145141919364364,LMOD=998244353;
// const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

using fint64 = int_fast64_t;
template<fint64 MOD>
struct ModInt{
    fint64 x;
    ModInt():x(0){}
    ModInt(fint64 x):
        x(x>=0?x%MOD:(MOD-(-x)%MOD)%MOD)
        {}
    // 負号
    ModInt operator -() const{
        return ModInt(-x);
    }
    // 加算
    ModInt &operator +=(const ModInt &rhs){
        x+=rhs.x;
        if(x>=MOD) x-=MOD;
        return (*this);
    }
    ModInt operator +(const ModInt &rhs) const{
        return ModInt(*this)+=rhs;
    }
    // 減算
    ModInt &operator -=(const ModInt &rhs){
        x+=MOD-rhs.x;
        if(x>=MOD) x-=MOD;
        return (*this);
    }
    ModInt operator -(const ModInt &rhs) const{
        return ModInt(*this)-=rhs;
    }
    // 乗算
    ModInt &operator *=(const ModInt &rhs){
        x*=rhs.x;
        if(x>=MOD) x%=MOD;
        return (*this);
    }
    ModInt operator *(const ModInt &rhs) const{
        return ModInt(*this)*=rhs;
    }
    // 除算
    ModInt &operator /=(const ModInt &rhs){
        (*this)*=rhs.inverse();
        return (*this);
    }
    ModInt operator /(const ModInt &rhs) const{
        return ModInt(*this)/=rhs;
    }
    // 等号
    bool operator ==(const ModInt &rhs){
        return x==rhs.x;
    }
    bool operator !=(const ModInt &rhs){
        return x!=rhs.x;
    }
    // 累乗
    ModInt pow(fint64 n) const{
        fint64 tmp=x;
        fint64 ret=1;
        while(n>0){
            if(n&1) ret=ret*tmp%MOD;
            tmp=tmp*tmp%MOD;
            n>>=1ll;
        }
        return ModInt(ret);
    }
    // 逆元
    ModInt inverse() const{
        fint64 a=x,b=MOD,s=1,t=0;
        while(b>0){
            fint64 u=a/b;
            a-=u*b;
            s-=u*t;
            swap(a,b);
            swap(s,t);
        }
        return ModInt(s);
    }
    // 入出力
    friend istream &operator >>(istream &lhs,ModInt<MOD> &rhs){
        fint64 x; lhs>>x;
        rhs=ModInt<MOD>(x);
        return lhs;
    }
    friend ostream &operator <<(ostream &lhs,const ModInt<MOD> &rhs){
        return lhs<<rhs.x;
    }
};

using mint = ModInt<MOD>;
mint dp[100010][2];
int main(){
    string l; cin>>l;
    int n=l.size();
    dp[0][0]=2,dp[0][1]=1;
    for(int i=1;i<n;i++){
        if(l[i]=='0'){
            dp[i][0]+=dp[i-1][0];
            dp[i][1]+=dp[i-1][1]*3;
        }
        if(l[i]=='1'){
            dp[i][0]+=dp[i-1][0]*2;
            dp[i][1]+=dp[i-1][1]*3+dp[i-1][0];
        }
    }
    cout<<dp[n-1][0]+dp[n-1][1]<<endl;
    return 0;
}


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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;

template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }

int main() {
    ll N;
    cin >> N;
    if (N & 1) { cout << 0 << endl; return (0); }
    
    ll cnt = 0;
    for (ll i = 10; i <= N; i *= 5) {
        cnt += N / i;
    }

    cout << cnt << endl;
    return (0);
}

Measured memory_bytes: 256
import java.util.*;
import java.util.stream.Collectors;

public class Main {
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		String str = sc.next();
		String[] strArray = str.split("");
		List<Integer> list = new ArrayList<Integer>();
		for (int tmp = 0; tmp < strArray.length ; tmp++) {
			list.add(Integer.parseInt(strArray[tmp]));
		}
		int count = 0;
		for(int tmp=0; tmp < list.size(); tmp++) {
			if(list.get(tmp) == 1) {
				count++;
			}
			tmp++;
			if(tmp >= list.size()) {
				break;
			}
			if(list.get(tmp) == 0) {
				count++;
			}
		}
		int countB = 0;
		for(int tmp=0; tmp < list.size(); tmp++) {
			if(list.get(tmp) == 0) {
				countB++;
			}
			tmp++;
			if(tmp >= list.size()) {
				break;
			}
			if(list.get(tmp) == 1) {
				countB++;
			}
		}
		if(count < countB) {
			System.out.println(count);
		}else {
			System.out.println(countB);
		}
	}
}

Measured memory_bytes: 33616
N = int(input())
D = [tuple(map(int,input().split())) for _ in range(N)]
D = sorted(D,key=lambda x:x[2], reverse=True)
for cx in range(101):
    for cy in range(101):
        ind = 1
        x,y,h = D[0]
        H = abs(x-cx)+abs(y-cy)+h
        for i in range(1,N):
            x,y,h = D[i]
            if h>0 and abs(x-cx)+abs(y-cy)+h!=H:
                ind = 0
                break
            elif h==0 and abs(x-cx)+abs(y-cy)<H:
                ind = 0
                break
        if ind==1:
            CX = cx
            CY = cy
            break
    if ind==1:break
print(CX,CY,H)

Measured memory_bytes: 3064
#!/usr/bin/python3

import os
import sys


INF = 2 * 10 ** 9 + 1


def main():
    V, E = read_ints()
    G = [[INF] * V for _ in range(V)]
    for _ in range(E):
        s, t, d = read_ints()
        G[s][t] = d
    ans = solve(V, E, G)
    if not ans:
        print('NEGATIVE CYCLE')
    else:
        for a in ans:
            print(*a)


def solve(V, E, G):
    dists = [[INF] * V for _ in range(V)]
    for i in range(V):
        for j in range(V):
            if i == j:
                dists[i][j] = 0
            elif G[i][j] != INF:
                dists[i][j] = G[i][j]

    for k in range(V):
        for i in range(V):
            for j in range(V):
                if (dists[i][k] != INF and dists[k][j] != INF and
                    dists[i][j] > dists[i][k] + dists[k][j]):
                    dists[i][j] = dists[i][k] + dists[k][j]

    for i in range(V):
        if dists[i][i] < 0:
            return None

    for i in range(V):
        for j in range(V):
            if dists[i][j] == INF:
                dists[i][j] = 'INF'
    return dists


###############################################################################
# AUXILIARY FUNCTIONS

DEBUG = 'DEBUG' in os.environ


def inp():
    return sys.stdin.readline().rstrip()


def read_int():
    return int(inp())


def read_ints():
    return [int(e) for e in inp().split()]


def dprint(*value, sep=' ', end='\n'):
    if DEBUG:
        print(*value, sep=sep, end=end)


if __name__ == '__main__':
    main()



Measured memory_bytes: 6536
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define sp(n) cout << fixed << setprecision(n)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
using namespace std;
int main(void){
    int h,w,k;cin>>h>>w>>k;
    char c[h][w];
    int sum=0;
    rep(i,h)rep(j,w){
        cin>>c[i][j];
        if(c[i][j]=='#')sum++;
    }
    int res=0;
    vector<int> a(w,0),b(h,0);
    rep(i,h)rep(j,w)if(c[i][j]=='#'){
        b[i]++;
        a[j]++;
    }
    int buf=sum-k;
    for(int i=0;i<(1<<w);i++){
        int b1=0;
        vector<int> v;
        rep(j,w)if(i&(1<<j)){
            b1+=a[j];
            v.push_back(j);
        }
        for(int j=0;j<(1<<h);j++){
            int b2=0;
            rep(l,h)if(j&(1<<l)){
                b2+=b[l];
                rep(r,v.size()){
                    if(c[l][v[r]]=='#')b2--;
                }
            }
            if(b1+b2==buf){
                res++;
            }
        }
    }
    cout<<res<<endl;
}

Measured memory_bytes: 3624