akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=1000000007,MAX=205,INF=1<<30;
int cnt[MAX][2];
bool seen[MAX][2];

struct UF{
    int n;
    vector<int> par,size,u,v;
    
    void init(int n_){
        n=n_;
        par.assign(n,-1);
        size.assign(n,1);
        u.assign(n,0);
        v.assign(n,0);
        
        for(int i=0;i<n;i++){
            par[i]=i;
        }
    }
    
    int root(int a){
        if(par[a]==a) return a;
        else return par[a]=root(par[a]);
    }
    
    void unite(int a,int b){
        if(root(a)!=root(b)){
            size[root(a)]+=size[root(b)];
            u[root(a)]|=u[root(a)];
            v[root(a)]|=v[root(a)];
            par[root(b)]=root(a);
        }
    }
    
    bool check(int a,int b){
        return root(a)==root(b);
    }
};


int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N,H;cin>>N>>H;
    UF uf;
    uf.init(2*H+1);
    
    for(int i=0;i<N;i++){
        int a,b,c,d;cin>>a>>b>>c>>d;
        
        if(c==0){
            cnt[a][0]++;
            seen[a][0]=1;
            
            if(d==0){
                cnt[b][1]--;
                seen[b][1]=1;
                
                uf.unite(a,H+b);
            }
            else{
                cnt[d][0]--;
                seen[d][0]=1;
                
                uf.unite(a,d);
            }
        }else{
            cnt[c][1]++;
            seen[c][1]=1;
            
            if(d==0){
                cnt[b][1]--;
                seen[b][1]=1;
                
                uf.unite(H+c,H+b);
            }
            else{
                cnt[d][0]--;
                seen[d][0]=1;
                
                uf.unite(H+c,d);
            }
        }
    }
    
    int sum1=0,sum2=0;
    bool ok=true;
    
    set<int> SE;
    
    for(int i=0;i<=H;i++){
        sum1+=cnt[i][0];
        sum2+=cnt[i][1];
        
        if(cnt[i][0]<0) ok=false;
        else if(seen[i][0]) SE.insert(uf.root(i));
        if(cnt[i][1]>0) ok=false;
        else if(seen[i][1]) SE.insert(uf.root(H+i));
        
        if(cnt[i][0]>0) uf.u[uf.root(i)]=1;
        if(cnt[i][1]<0) uf.v[uf.root(H+i)]=1;
    }
    
    for(int a:SE){
        if(!uf.u[a]) ok=false;
        if(!uf.v[a]) ok=false;
    }
    
    if(sum1>sum2&&ok) cout<<"YES\n";
    else cout<<"NO\n";
    
}


Measured memory_bytes: 3644
<?php
$n=trim(fgets(STDIN));
$a=explode(" ",trim(fgets(STDIN)));
$sum=array_sum($a);
$a=array_count_values($a);
$q=trim(fgets(STDIN));
$i=0;
while($i<$q){
  list($b,$c)=explode(" ",trim(fgets(STDIN)));
  $sum+=$a[$b]*($c-$b);
  echo "$sum\n";
  $a[$c]+=$a[$b];
  $a[$b]=0;
  ++$i;
}

Measured memory_bytes: 25848
N = int(input())
A = [int(i) for i in input().split()]
flag = 1
p = 0
while flag :
    flag = 0
    for j in range(N-1,0,-1) :
        if A[j] < A[j-1] :
            t = A[j]
            A[j] = A[j-1]
            A[j-1] = t
            p += 1
            flag = 1
for i in range(N) :
    if i == N-1 :
        print(A[i])
    else :
        print(A[i],end=" ")
print(p)






Measured memory_bytes: 5612
typedef long unsigned int size_t;
extern int printf (const char *__restrict __format, ...);
extern int scanf (const char *__restrict __format, ...) ;
extern int getchar (void);
extern int putchar (int __c);
int nextInt(){int f=0;char s=0;char c=getchar();while((c<48)||(57<c)){if(c==45){s=1;c=getchar();break;}c=getchar();}while((48<=c)&&(c<=57)){f=f*10+(c-48);c=getchar();}return s?-f:f;}
short int nextShort(){short f=0;char s=0;char c=getchar();while((c<48)||(57<c)){if(c==45){s=1;c=getchar();break;}c=getchar();}while((48<=c)&&(c<=57)){f=f*10+(c-48);c=getchar();}return s?-f:f;}
long long int nextLong(){long long int f=0;char s=0;char c=getchar();while((c<48)||(57<c)){if(c==45){s=1;c=getchar();break;}c=getchar();}while((48<=c)&&(c<=57)){f=f*10+(c-48);c=getchar();}return s?-f:f;}
void println(){putchar(10);}
void print(char *f){while(*f){putchar(*f);f++;}}
void printInt(int f){char c[10];if(!f){putchar(48);return;}if(f<0){f=-f;putchar(45);}char i=0;while(f){c[++i]=(f%10)+48;f/=10;}while(i){putchar(c[i--]);}}
void printLong(long long int f){char c[19];if(!f){putchar(48);return;}if(f<0){f=-f;putchar(45);}char i=0;while(f){c[++i]=(f%10)+48;f/=10;}while(i){putchar(c[i--]);}}
typedef int (*__compar_fn_t) (const void *, const void *);
extern void *bsearch (const void *__key, const void *__base, size_t __nmemb, size_t __size, __compar_fn_t __compar)__attribute__ ((__nonnull__ (1, 2, 5))) ;
extern void qsort (void *__base, size_t __nmemb, size_t __size, __compar_fn_t __compar) __attribute__ ((__nonnull__ (1, 4)));
int compare_int(const void *a, const void *b){return *(int*)a - *(int*)b;}
int compare_long(const void *a, const void *b){if(*(long long int*)a - *(long long int*)b < 0){return -1;}else if(*(long long int*)a - *(long long int*)b > 0){return 1;}else{return 0;}}
int n, i;
long long int b[200001];
long long int ans, now;
char f;
int main(){
 n = nextInt();
 b[0] = 0;
 for(i=0; i<n; i++){
  b[i+1] = b[i] + nextInt();
 }
 qsort(b, n+1, sizeof(long long int), compare_long);
 for(i=0; i<n; i++){
  if(b[i+1]==b[i]){
   if(f){now++;}
   else{now=2; f=1;}
  }else{
   if(f){ans+=now*(now-1)/2; f=0;}
  }
 }
 if(f){ans+=now*(now-1)/2; f=0;}
 printLong(ans); println();
}


Measured memory_bytes: 3324
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

r = I()
if r < 1200:
    print('ABC')
elif 1200 <= r < 2800:
    print('ARC')
else:
    print('AGC')

Measured memory_bytes: 38256
a = input()
b = input()
n, m = len(a), len(b)

dp = [[0] * (m + 1) for _ in range(n + 1)]

for i in range(n):
    for j in range(m):
        if a[i] == b[j]:
            dp[i + 1][j + 1] = dp[i][j] + 1
        else:
            dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1])
#print(*dp, sep="\n")

c, d = n, m
ans = ""
while c > 0 and d > 0:
    if dp[c - 1][d] == dp[c][d]:
        c -= 1
    elif dp[c][d - 1] == dp[c][d]:
        d -= 1
    else:
        ans = a[c - 1] + ans
        c -= 1
        d -= 1
print(ans)


Measured memory_bytes: 112220
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define PI 3.141592653589793
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = a; i < (n); i++)
#define rrep(i, n, k) for (int i = (n); i >= (k); i--);
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
#define pi pair<int, int>
#define pl pair<ll, ll>
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}
const int MOD = 1e9+ 7;
const int INF = numeric_limits<int>::max() - 1e8;
const ll INFLL = numeric_limits<ll>::max() - 1e17;

signed main() {
    ll sum = 0;
    ll N;
    cin >> N;
    for (int i = 1; i <= N; i++) {
        if (i % 3 == 0 || i % 5 == 0) continue;
        sum += i;
    }
    cout << sum << endl;
}


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

using namespace std;

#define MAX_V 1000
#define MAX_E 2000
#define INF 1e9

struct edge{
  int from,to,cost;
};

int V,E,d[MAX_V];
edge es[MAX_E];

bool find_negative_loop(int s){
  int cnt = 0;
  for(int i = 0 ; i < V ; i++){
    d[i] = INF;
  }
  d[s] = 0;
  while(true){
    bool update = false;
    cnt++;
    for(int i = 0 ; i < E ; i++){
      edge e = es[i];
      if(d[e.from] != INF && d[e.to] > d[e.from] + e.cost){
        d[e.to] = d[e.from] + e.cost;
        if(cnt == V){ return true; }
        update = true;
      }
    }
    if(!update){ break; }
  }
  return false;
}

int main(){
  int r;
  cin >> V >> E >> r;
  for(int i = 0 ; i < E ; i++){
    cin >> es[i].from >> es[i].to >> es[i].cost;
  }
  if(find_negative_loop(r)){
    cout << "NEGATIVE CYCLE" << endl;
  }else{
    for(int i = 0 ; i < V ; i++){
      if(d[i] == INF){
        cout << "INF" << endl;
      }else{
        cout << d[i] << endl;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 1188
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define endl "\n"
#define F first
#define S second
#define mod 1000000007
#define pb push_back
#define FOR(i,a,n) for(int i=a;i<n;i++)
#define REV(i,a,n) for(int i=a;i>=n;i--)
#define all(a) a.begin(),a.end()
#define UB upper_bound
#define LB lower_bound
const int NUM = 2e5 + 5;
int dp[100][100001];
int w[100], v[100];
int32_t main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int num_tests=1; 
    //cin >> num_tests;
    while(num_tests-->0){
        int n,W; cin >> n >> W;
        FOR(i,0,n){
            cin >> w[i] >> v[i];
        }
        dp[0][0] = 0;
        dp[0][w[0]] = v[0];
        for(int i=1;i<n;i++){
            dp[i][0] = 0; // bag is empty
            for(int j=1;j<=W;j++){
                // discarding an object
                dp[i][j] = dp[i-1][j];
                // picking element
                if(j >= w[i])
                    dp[i][j] = max(dp[i][j], v[i] + dp[i-1][j-w[i]]);
            }
        }
        int ans = -1e18;
        FOR(i,0,W+1)
            ans = max(ans,dp[n-1][i]);
        cout << ans;
    }   
}

Measured memory_bytes: 80968
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#define vll vector<ll>
#define vvvl vector<vvl>
#define vvl vector<vector<ll>>
#define VV(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define VVV(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;



struct Merge{
  set<vll> lr;
  ll INF = 1000000000000000009;
  vll remove(ll a, ll b){
    if(a>b) swap(a, b);
    auto itr = lr.lower_bound(vll{b+1, 0});
    if(itr==lr.begin()) return vll{a, b};
    itr--;
    ll lef = a, ri = b;
    while((*itr)[1]>=a){
      ll now_x = (*itr)[0], now_y = (*itr)[1];
      lef = min(lef, now_x), ri = max(ri, now_y);
      if(itr==lr.begin()){
        lr.erase(itr);
        break;
      }
      itr--;
      lr.erase(vll{now_x, now_y});
    }
    return vll{lef, ri};
  }
  void merge(ll a, ll b){lr.insert(remove(a, b));}

  vll get(ll a){
    auto itr = lr.lower_bound(vll{a+1, a+1});
    if(lr.size()==0||itr==lr.begin()) return vll{INF, INF};
    itr--;
    if((*itr)[1]<a) return vll{INF, INF};
    return *itr;
  }
  bool same(ll a, ll b){
    if(get(a)[0]==-1) return false;
    return get(a)[0]==get(b)[0];
  }
};

vll par, v, v2;
vll A;
vvl G;
ll n;

ll dfs(ll now, ll from){
  par[now] = from;
  Merge mg;
  for(auto to:G[now]){
    if(from==to) continue;
    ll tmp = dfs(to, now);
    if(A[now]>A[to]) mg.merge(tmp, tmp+1);
  }
  if(mg.lr.size()!=0&&(*mg.lr.begin())[0]==0){
    v[now] = (*mg.lr.begin())[1];
  }
  return v[now];
}

void dfs2(ll now){
  Merge mg;
  for(auto to:G[now]){
    ll ad = (par[to]==now?v[to]:v2[to]);
    if(A[now]>A[to]) {
      mg.merge(ad, ad+1);
    }
  }
  ll num = 0;
  if(mg.lr.size()!=0&&(*mg.lr.begin())[0]==0) {
    num = (*mg.lr.begin())[1];
  }
  v2[now] = num;
  for(auto to:G[now]){
    if(par[to]!=now) continue;
    dfs2(to);
  }
}

int main(int argc, char const *argv[]) {
  std::cin >> n;

  v.resize(n+1, 0);
  v2.resize(n+1, 0);
  par.resize(n+1, -1);
  A.resize(n+1);
  G.resize(3001);

  for(int i=1;i<=n;i++) scanf("%lld", &A[i]);
  for(int i=0;i<n-1;i++){
    ll a, b;scanf("%lld %lld", &a, &b);
    G[a].push_back(b);
    G[b].push_back(a);
  }
  ll root = 1;
  dfs(root, -1);
  dfs2(root);
  vll ans;
  //for(int i=1;i<=n;i++) std::cout << (v2[i]) << (i==n?"\n":" ");
  for(int i=1;i<=n;i++) if(v2[i]&&A[i]) ans.push_back(i);
  for(int i=0;i<ans.size();i++){
    std::cout << ans[i] << (i==ans.size()-1?"\n":" ");
  }

  return 0;
}


Measured memory_bytes: 1024
#!/usr/bin/env python3
# -*- coding:utf-8 -*-

if __name__=='__main__':
  n, k = map(int, input().strip().split())
  r, s, p = map(int, input().strip().split())
  score = {'r':p, 's':r, 'p':s}
  t = list(input().strip())
  count = {'r':0, 's':0, 'p':0}
  for i in range(n-k):
    if t[i] == t[i+k]:
      t[i+k] = '*'
      count[t[i]] += 1
  ans = 0
  for x in t:
    if x!='*':
      ans += score[x]
  print(ans)

Measured memory_bytes: 4084
a = int(input())
b = int(input())



if a == 1 and b == 2:
    print("3")

if a == 1 and b == 3:
    print("2")

if a == 2 and b == 1:
    print("3") 

if a == 2 and b == 3:
    print("1")

if a == 3 and b == 1:
    print("2")

if a == 3 and b == 2:
    print("1")


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
# define pb push_back
# define FOR(i,a,n) for(int i=a;i<n;i++)
# define mp make_pair
# define RFOR(i,a,n) for(int i=n;i>a;i--)
# define pii pair<long long int,long long int>
#define ub upper_bound
#define lb lower_bound
typedef long long int ll;
vector<ll> g[100009];
ll level[100009];
ll mark[100009];
ll visited[100009];
vector<ll> v;
ll dfs(int u)
{
	if(visited[u]==1)
	return level[u];
	visited[u]=1;
	ll k;
	for(int i=0;i<g[u].size();i++)
	{
		k=g[u][i];
		if(visited[k]==0)
		level[u]=max(level[u],dfs(k));
		else
		level[u]=max(level[u],level[k]+1);
	}
	return level[u]+1 ;
}
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	ll n,m;
	cin>>n>>m;
	ll u,v;
	FOR(i,0,m)
	{
		cin>>u>>v;
		g[u].pb(v);
		mark[v]=1;
	}
	ll bad;
	for(int i=1;i<=n;i++)
	{
		if(visited[i]==0)
		bad=dfs(i);
	}
	ll max=0;
	for(int  i=1;i<=n;i++)
	{
		if(level[i]>max)
		max=level[i];
	}
	cout<<max<<endl;
}

Measured memory_bytes: 10112
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <cmath>
#include <cstring>
#include <assert.h>
#include <utility>
#include <tuple>
#include <array>
#include <bitset>
#include <cstdlib>

using int64 = long long;

using namespace std;

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

    int64 X;
    cin >> X;

    int64 money = 100;
    int day = 0;
    while (money < X) {
        day++;
        money = money + money / 100;
    }
    cout << day << endl;

    return 0;
}



Measured memory_bytes: 3220
import math
from functools import reduce

def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)
N = int(input())
AA = [int(input()) for i in range(N)]
print(lcm(*AA))

Measured memory_bytes: 9580
#include <iostream>
using namespace std;
int main(void){
    int a;
    int num=0;
    cin>>a;
    int i,j;
    for(i=1;i<=9;i++){
        for(j=1;j<=9;j++){
            if(i*j==a){
                num++;
            }
        }
    }
    if(num==0){
        cout<<"No";
    }
    else{
        cout<<"Yes";
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stdio.h>
#include <list>
#include <numeric>
#include <stack>
#include <queue>
#include <tuple>
#include <bitset>
#include <map>
#include <math.h>
//　ceil(a/b)   (a + (b - 1))/ b
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int,int> P;
const int inf=1000000007;
const ll mod=1000000007;
const double PI=3.14159265358979323846;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};

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

int cans(bool f){
  if(f) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}



int main(){
  int H,W;
  cin >> H >> W;
  char c[H][W];
  rep(i,H){
    rep(j,W){
      cin >> c[i][j];
    }
  }
  
  int x = 0, y = 0;
  while(1){
    if(x<W && y<H){
      c[y][x] = '.';
      if(c[y][x+1] == '#' && x+1 < W) x++;
      else if(c[y+1][x] == '#'&& y+1 < H) y++;
      else break;
    }
    else break;
  }
  bool f = true;
  
  rep(i,H){
    rep(j,W){
      if(c[i][j] == '#') f=false;
    }
  }
  
  // rep(i,H){
  //   rep(j,W){
  //     cout << c[i][j];
  //   }
  //   cout << endl;
  // }  

  
  if(f) cout << "Possible" << endl;
  else cout << "Impossible" << endl;
  return 0;
}



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

int main() {
	string str;
	vector<int> s(26, 0);

	cin >> str;

	if (str.size() != 4) {
		cout << "No" << endl;
		return 0;
	}

	for (int i = 0; i < str.size(); i++)
		s[str[i] - 'A']++;

	for (int i = 0; i < 26; i++) {
		if (s[i] != 2 && s[i] != 0) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}

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

using namespace std;

int run(vector<int> h, int l, int r, int diff){
  if( l >= r ){ return 0; }
  //cout << l << "," << r << "," << diff << endl;
  auto min = min_element(h.begin()+l, h.begin()+r);
  int d = *min - diff;
  int dist = distance(h.begin()+l, min);
  return d + run(h, l, l+dist, diff+d) + run(h, l+dist+1, r, diff+d);
}

int main(){
  int N =0;
  cin >> N;
  vector<int> h(N, 0);
  for( int i = 0; i < N; ++i ){
    cin >> h[i];
  }
  cout << run(h, 0, N, 0) << endl;;
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

int main(){
  string s;
  cin >> s;
  vector<vector<mint>> dp(s.size()+1, vector<mint>(2, 0));
  dp.at(0).at(0) = 1;
  rep(i, s.size()){
    if(s.at(i) == '1'){
      dp.at(i+1).at(0) = dp.at(i).at(0) * 2;
      dp.at(i+1).at(1) = dp.at(i).at(0) + dp.at(i).at(1) * 3;
    }else{
      dp.at(i+1).at(0) = dp.at(i).at(0);
      dp.at(i+1).at(1) = dp.at(i).at(1) * 3;
    }
  }
  mint ans = dp.at(s.size()).at(0) + dp.at(s.size()).at(1);
  cout << ans.x << endl;
  return 0;
}

Measured memory_bytes: 8784
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional>
using namespace __gnu_pbds;  
using namespace std;

typedef tree<long long, null_type, less<long long>, rb_tree_tag, 
             tree_order_statistics_node_update> 
    new_data_set; 
    
//defines
typedef long long ll;
typedef long double ld;

ll a,b,c,n,m,k;

ll t=1;


void solve()
{
   cin>>n>>m>>a>>b;
   cout<<max({n*a,n*b,m*a,m*b});
 if(t>0)cout<<"\n";
}

int32_t main()
{
#ifdef ONPC
    freopen("input.txt", "r", stdin);
#endif
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

  //cin>>t;
    while(t--)
    {
        solve();
    }
  //cout<<sum;
        
    return 0;
}

Measured memory_bytes: 3648
#include <math.h>
int main()
{
  int n;
  scanf("%d", &n);
  long a[n];
  int i;
  unsigned long long ans = 0;
  long tmp = pow(10, 9) + 7;
  long long count = 0;
  for (i = 0; i < n; i++)
  {
    scanf("%ld", &a[i]);
    count += a[i];
    count %= tmp;
  }
  for (i = n - 1; i > 0; i--)
  {
    count -= a[i];
    count += tmp;
    count %= tmp;
    ans += a[i] * count;
    ans %= tmp;
  }
  printf("%llu", ans);
}

Measured memory_bytes: 3236
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<ll, ll>;

int main(){
    int n; cin >> n;
    vector<ll> a(n), b(n);
    rep(i,n) cin >> a[i] >> b[i];
    sort(ALL(a));
    sort(ALL(b));
    if(n % 2){
        ll l = a[n/2];
        ll r = b[n/2];
        cout << r - l + 1 << endl;
    }else{
        ll l = a[n/2] + a[n/2-1];
        ll r = b[n/2] + b[n/2-1];
        cout << r - l + 1 << endl;
    }
}

Measured memory_bytes: 6404
#include <iostream>
#include <iomanip>
#include <random>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <sstream>
#include <bitset>
#include <cassert>
#include <fstream>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
	#define DBG(X) cout << #X << "=" << (X) << endl;
#else
	#define DBG(X)
	#define endl '\n'
#endif
 
using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld  = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int INT_INF = (int)(2e9);
const ll  LL_INF  = (ll)(2e18);

const ll mod = 1e9 + 7;
const int NIL = -1;
static mt19937 _g(time(nullptr));

inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for(auto el: v) cout << el << " "; return os; }

void solve()
{
	int n, answ = 0;
	cin >> n;
	
	for(int i = 1; i <= n; ++i)
	{
		int cnt = 0, j = i;

		for(; j; j /= 10)
			++cnt;

		answ += cnt & 1;
	}

	cout << answ << endl;
}

int main()
{
	fast_io();
	solve();

	return 0;
}


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

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

    vector<int> p(a), q(b), r(c);
    rep(i, a) cin >> p[i];
    rep(i, b) cin >> q[i];
    rep(i, c) cin >> r[i];

    sort(p.begin(), p.end(), greater<int>());
    sort(q.begin(), q.end(), greater<int>());
    rep(i, x) r.push_back(p[i]);
    rep(i, y) r.push_back(q[i]);
    sort(r.begin(), r.end(), greater<int>());

    ll ans = 0;
    rep(i, x + y) ans += r[i];

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


Measured memory_bytes: 5552
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef std::pair<int, int> ii;
typedef std::pair<int, ii> iii;
typedef std::vector<int> vi;
typedef std::vector<vi> vvi;
typedef std::vector<ii> vii;
typedef std::vector<iii> viii;
const int INF=10000000;
#define pb(a) push_back(a)
#define m0(x) memset(x,-1,sizeof(x))
#define print(x) cout<<x<<endl;
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
#define ub(v,n) upper_bound(v.begin(), v.end(), n);
#define all(x) (x).begin(), (x).end()
const ll mod=1e9+7;
int N,mingroup,maxgroup,minsize,maxsize;
ll factorial[1005];
ll rfactorial[1005];

ll pow(ll base, ll exp) {
  if(exp==0) return 1;
  if(exp&1) return (base*pow(base,exp-1))%mod;
  else return pow((base*base)%mod,exp/2);
}
 


void start(){
  ll temp=1;
  factorial[0]=1;
  for (int i=1; i<=1000; i++){
    temp=(temp*i)%mod;
    factorial[i]=temp;
  }
}





ll inverse(ll curr){
  return pow(curr,mod-2);
}

ll memo[1001][1001];


ll DP(ll remaining, ll current){
  //cerr<<remaining<<" "<<current<<endl;
  if (remaining==0) return 1;
  else if (remaining<0 or current>maxgroup) return 0;
  else {
    if (memo[remaining][current]==-1){
      ll ans=DP(remaining,current+1);
      
      for (ll i=minsize; i<=maxsize and i*current<=remaining; i++){
          
          ll num=factorial[remaining];
          ll denom=(pow(factorial[current],i)*factorial[remaining-i*current])%mod;
          denom=(denom*factorial[i])%mod;
          denom=inverse(denom);

          ll temp=DP(remaining-i*current,current+1);
          temp=(temp*num)%mod;
          temp=(temp*denom)%mod;

          ans=(ans+temp+mod)%mod;
          //ans=(ans+DP(remaining-i*current,current+1))%mod;
        
      }
      memo[remaining][current]=ans;

    }
    return memo[remaining][current];
  }





}




int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  start();
  m0(memo);
  cin >> N >> mingroup >> maxgroup >> minsize >> maxsize;
  cout<<DP(N,mingroup)<<endl;

  

  



}


Measured memory_bytes: 8192
package main

import (
	"bufio"
	"fmt"
	"os"
)

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	first := nextLine()
	second := nextLine()
	if len(first) > len(second) {
		fmt.Println("GREATER")
		return
	} else if len(first) < len(second) {
		fmt.Println("LESS")
		return
	} else {
		for i := range first {
			if first[i] > second[i] {
				fmt.Println("GREATER")
				return
			}
			if first[i] < second[i] {
				fmt.Println("LESS")
				return
			}
		}
	}
	fmt.Println("EQUAL")
}


Measured memory_bytes: 640
#include <stdio.h>
#include <math.h>
 
int main(void)
{
    double x1,y1,x2,y2;
    scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2);
    printf("%f\n",hypot(x2-x1,y2-y1));
    return 0;
}


Measured memory_bytes: 2112
import java.io.*;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) throws IOException {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
//        int t = in.nextInt();
        solver.solve(1, in, out);
        out.close();
    }

    static class Task {
        public void solve(int testNumber, InputReader in, PrintWriter out) throws IOException {
            int n = in.nextInt();
            String s = in.next();
            char prev = s.charAt(0);
            int count = 1;
            for (int i = 0; i < n; i++) {
                char ch = s.charAt(i);
                if (ch != prev){
                    prev = ch;
                    count++;
                }
            }
            out.println(count);
        }
    }

    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 long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

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

        public char nextChar() {
            return next().charAt(0);
        }

        public String nextLine() throws IOException {
            return reader.readLine().trim();
        }
    }
}


Measured memory_bytes: 25044
#include <bits/stdc++.h>
#include <cassert>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define PI 3.14159265358979
using namespace std;
using ll = long long;
using P = pair<int, int>;
struct Edge
{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w) {}
};
// using Graph = vector<vector<Edge>>;
using Graph = vector<vector<int>>;

const long long INF = 1LL << 60;
const int INT_INF = 1000000000;

int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
// int dx[8] = {-1, -1, -1, 0, 0, 1, 1, 1}, dy[8] = {-1, 0, 1, 1, -1, 1, 0, -1};

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int X;
  cin >> X;
  if (X == 3 || X == 5 || X == 7)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <queue>
#include <map>
#include <cstdio>
#include <cmath>
#include <unordered_map>
#include <iomanip>
using namespace std;
 
int main(){
  long a, b, r, x, tmp;
  cin >> a >> b;
  x = a*b;
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }
 
  /* ユークリッドの互除法 */
  r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
	
  cout << (long) x/b << endl;
  
}

Measured memory_bytes: 256
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
typedef long long ll;
const ll MOD = 1e9 + 7 ;
const ll N = 1e6 + 10 ;
const ll INF = 1e18 + 10 ;
int main(){
    fastio
    ll prize[] = {300000, 200000, 100000} ; 
    ll a , b ; 
    cin >> a >> b ; 
    a--, b-- ; 
    ll ans = 0 ; 
    if ( a < 3 ) ans += prize[a] ; 
    if ( b < 3 ) ans += prize[b] ; 
    if ( a == b && a == 0 ) ans += 400000 ; 
    cout << ans << endl;
    return 0 ; 
}

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

const ll maxs = 1e6+5;
const ll lmaxs = 20;
ll mod = 1e9+7;
ll oo = 1e9;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second


int main(){
    ll T = 1;
    //cin>>T;
    while(T--){
        string s;
        ll  n ,p;
        cin>>s;
        n = s.size();
        p = 2019;
        // if(p==2){
        //     ll ANS=0;
        //     for(ll i=0;i<s.size();i++){
        //         if((s[i]-'0')%2==0 )
        //             ANS += i+1;
        //     }
        //     cout << ANS;
        //     continue;
        // }

        // if(p==5){
        //     ll ANS=0;
        //     for(ll i=0;i<s.size();i++){
        //         if((s[i]-'0')%5==0){
        //             ANS += i+1;
        //         }
        //     }
        //     cout << ANS ;
        //     continue;
        // }
        ll ANS=0;
        ll N = 0;
        map<ll,ll> MAP;
        MAP[0]++;
        ll mf=1;
        for(ll i=n-1;i>=0;i--){    
            N = (N + (s[i] - '0')*mf )%p;
            ANS += MAP[N];
            MAP[N]++;
            mf  = (mf*10)%p;
        }
        cout << ANS;
    }

    return 0;
}


Measured memory_bytes: 3700
#include <bits/stdc++.h> 
using namespace std;
using ll = long long;
template<typename T> using v2 = vector<vector<T>>;
template<typename T> inline v2<T> fill(int r, int c, const T& t){ return v2<T>(r, vector<T>(c, t)); }
#define F first
#define S second

void solve(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; ++i) cin >> a[i];
    sort(a.begin(), a.end());
    int ans = 0;
    for(int i = 0; i < n; ++i){
        for(int j = i+1; j < n; ++j){
            for(int k = j+1; k < n; ++k){
                if(a[i] != a[j] && a[j]!=a[k] && a[k]!=a[i])
                ans += a[i]+a[j]>a[k];
            }
        }
    }
    cout << ans << '\n';
}

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

Measured memory_bytes: 3660
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		
		if (c >= a){
			if (c <= b){
				System.out.println("Yes");
			}
			else{
				System.out.println("No");
			}
		}
		else{
			System.out.println("No");
		}
		
	}
}


Measured memory_bytes: 22612
#include <iostream>
#include <cstdlib>
using namespace std;
int main(){
    int w,a,b;
    cin>>w>>a>>b;
    bool c=(a<=b&b<=a+w)||(a<=b+w&b+w<=a+w);
    if(c){
        cout<<0;
        return 0;
    }
    int l1=abs(a+w-b);
    int l2=abs(b+w-a);
    cout<<min(l1,l2);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#define ll long long
using namespace std;

const ll md = 1e9 + 7;
ll fact[2000001] = {}, res = 0;
int k, n; string s;

ll pw(ll b, ll e)
{
	ll t = 1;
	while (e)
	{
		if (e & 1) t = (t * b) % md;
		b = (b * b) % md; e >>= 1;
	}
	return t;
}

ll cb(ll n, ll r)
{
	return fact[n] * pw(fact[n - r], md - 2) % md * pw(fact[r], md - 2) % md;
}

int main()
{
    ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> k >> s; n = s.size();
	fact[0] = 1;
	for (int i = 1; i <= n + k; i++) {fact[i] = (fact[i - 1] * i) % md;}
	for (int i = n; i <= n + k; i++)
	{
		res = (res + pw(26, n + k - i) * pw(25, i - n) % md * cb(i - 1, n - 1) % md) % md;
	}
	cout << res << "\n";
	return 0;
}

Measured memory_bytes: 19784
#include <iostream>
using namespace std;
int main(void){
    int i,j,count=0;
    int a,b,c,x;
    cin>>i>>j;
    for(a=1;a<10;a++){
        for(b=0;b<10;b++){
            for(c=0;c<10;c++){
                x=10001*a+1010*b+c*100;
                if(x>=i && x<=j){
                    count++;
                }
            }
        }
        
    }
    cout<<count<<endl;
}

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

int main()
{
    int A, B;
    std::cin >> A >> B;
    int n_white, n_black;
    n_white = A - 1;
    n_black = B - 1;
    std::vector<std::vector<char> > grid(50, std::vector<char>(100));
    for (unsigned i = 0; i < grid.size(); ++i) {
        for (unsigned j = 0; j < 100; ++j) {
            if (j < 50) {
                grid.at(i).at(j) = '.';
            } else {
                grid.at(i).at(j) = '#';
            }
        }
    }

    // create white blocks
    for (unsigned i = 0; i < grid.size(); i += 2) {
        for (unsigned j = 1; j < 49; j += 2) {
            if (n_black > 0) {
                grid.at(i).at(j) = '#';
                --n_black;
            }
        }
        for (unsigned j = 51; j < 99; j += 2) {
            if (n_white > 0) {
                grid.at(i).at(j) = '.';
                --n_white;
            }
        }
    }

    std::cout << 50 << " " << 100 << std::endl;
    for (unsigned i = 0; i < grid.size(); ++i) {
        for (unsigned j = 0; j < 100; ++j) {
            std::cout << grid.at(i).at(j);
        }
        std::cout << std::endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <complex>
#include <vector>
#include<limits>
#include<iomanip>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;

const long double pi = 3.141592653589793;

#define debug(x) cout << #x << " = " << (x) << endl;
#define rep(i, n) for(int i = 0;i < n;i++)
#define repi(i, j, n) for(int i = j;i < n;i++)
#define pb push_back
#define mp make_pair
// #define mod 1000000007
#define mod 998244353
#define F first
#define S second

// #define COMMENT

/*

const int NN = 200090;
ll fact[NN];
ll finv[NN];
ll inv[NN];

void inverse_modulao() {
  fact[0] = fact[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;

  for(int i = 2;i < NN;i++) {
    fact[i] = fact[i-1]*i%mod;
    inv[i] = mod-mod/i*inv[mod%i]%mod;
    finv[i] = finv[i-1]*inv[i]%mod;
  }
}

ll nCr(int n, int r) {
  return fact[n]*finv[r]%mod*finv[n-r]%mod;
}

*/

int N, M;
vector<int> g[4][100099];
int gr[4][100099];
int h[100099],a,b;
ll ans[4][500];

ll pwr[1<<20];

int main() {

//  freopen("input.in","r",stdin);
//  freopen("output.out","w",stdout);
  cin>>N;
  rep(i,3){
    cin>>M;
    rep(j,M){
      cin>>a>>b;
      g[i][min(a,b)].pb(max(a,b));
    }
  }
  rep(i,3){
    for(int j=N;j>=1;j--){
      rep(k,1+g[i][j].size()) h[k]=0;
      for(int &x:g[i][j]) h[gr[i][x]]=1;
      rep(k,1+g[i][j].size()) {
        if(h[k] == 0) {
          gr[i][j]=k;break;
        }
      }
    }
  }
  // rep(i,3){
  //   rep(j,N){
  //     cout<<gr[i][j+1]<<" ";
  //   }cout<<endl;
  // }


  pwr[0]=1;
  ll bs = ll(1e18)%mod;
  for(int i=1;i<=3*N+3;i++) {
    pwr[i]=pwr[i-1]*bs%mod;
  }
  rep(i,3){
    rep(j,N){
      (ans[i][gr[i][j+1]] += pwr[j+1])%=mod;
    }
  }

  ll tans=0;
  rep(i,450){
    rep(j,450){
      int k = i^j;
      if(k >= 450) continue;
      (tans+=ans[0][i]*ans[1][j]%mod*ans[2][k]%mod)%=mod;
    }
  }
  cout<<tans<<endl;


  return 0;
}


Measured memory_bytes: 21120
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
#include <cmath>

using namespace std;

long fac_mod(int x);

#define mod 1000000007

int main(){
    int N, M;
    cin >> N >> M;
    
    if(abs(N - M) > 1){
        cout << 0 << endl; 
    }
    else if(N == M){
        cout << (2 * fac_mod(N) * fac_mod(M)) % mod << endl;
    }
    else{
        int A, B;
        A = max(N, M);
        B = min(N, M);
        
        cout << (fac_mod(A) * fac_mod(B)) % mod << endl;
    }
}

long fac_mod(int x){
    long sum = 1;
    
    for(int i = 1; i <= x; i++){
        sum *= i % mod;
        sum %= mod;
    }
    
    return sum;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef pair<ll, ll> P;

const int mod =  1000000007;  //出力は (ans % mod + mod) % mod  (負の剰余を正にする)
const int inf = 1e9;
const long long INF = 1LL << 60;   // INF = 11

int main()
{
    int n; cin >> n;
    ll a[n];
    rep(i,n) cin >> a[i];

    ll ans = 0;
    rep(i,n-1){
        if(a[i] > a[i+1]){
            ans += a[i] - a[i+1];
            a[i+1] = a[i];
        }
    }
    cout << ans;
}

Measured memory_bytes: 5212
#include <iostream>
#include <vector>
#include <queue>
using namespace std;

typedef pair<int, int> P;

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

int main() {
    int H, W;
    cin >> H >> W;
    vector<vector<char>> field(H, vector<char>(W));
    queue<P> que;
    vector<vector<int>> dist(H, vector<int>(W, INF));
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            cin >> field[i][j];
            if (field[i][j] == '#') {
                que.push(P(i, j));
                dist[i][j] = 0;
            }
        }
    }

    while (!que.empty()) {
        P p = que.front(); que.pop();
        for (int i = 0; i < 4; i++) {
            int nx = p.first + dx[i];
            int ny = p.second + dy[i];
            if (nx >= 0 && nx < H && ny >= 0 && ny < W && dist[nx][ny] == INF) {
                que.push(P(nx, ny));
                dist[nx][ny] = dist[p.first][p.second] + 1;
            }
        }
    }

    int res = 0;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            res = max(res, dist[i][j]);
        }
    }

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 13328
n = gets.to_i
balls = gets.split.map(&:to_i)
minus_lists = Array.new(n, 0)
ary = Array.new(n, 0)
hash = balls.each_with_object(Hash.new(0)){|v,o| o[v]+=1}
hash.each do |k, v|
  ary[k-1] = v > 1 ? v * (v - 1) / 2 : 0
  minus_lists[k-1] = v > 2 ? ary[k-1] - (v - 1) * (v - 2) / 2 : ary[k-1]
end
sum = ary.inject(:+)
n.times do |i|
  ans = sum - minus_lists[balls[i] - 1]
  puts ans
end


Measured memory_bytes: 31884
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class Program
{
    static void Main(string[] args)
    {

        int n = int.Parse(System.Console.ReadLine().Trim());
        int[][] search = new int[n][];
        int x =0, y =0, h=0, HKari=0;
             
        for(int i = 0; i < n; i++)
        {
            search[i] = Array.ConvertAll(Console.ReadLine().Trim().Split(' '), int.Parse);
            if (search[i][2] > 0 && h == 0)
            {
                x = search[i][0];
                y = search[i][1];
                h = search[i][2];
            }
        }

        for (int i = 0; i <= 100; i++)
        {
            for (int j = 0; j <= 100; j++)
            {
                
                HKari = h + Math.Abs(i - x) + Math.Abs(j - y);
                int k = 0;
                while (k < n)
                {
                    if (Math.Max(HKari - Math.Abs(i - search[k][0]) - Math.Abs(j - search[k][1]), 0) != search[k][2])
                    {
                        break;
                    }
                    k++;
                }
                if (k == n)
                {
                    System.Console.WriteLine("{0} {1} {2}",i,j, HKari);
                    return;
                }
            }
        }

    }
}


Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

int N, M, Q;
int a[50], b[50], c[50], d[50];
int A[10];

int dfs(int p, int mx) {
	int ans = 0;
	if (p < N) {
		FOR(i, mx, M + 1) {
			A[p] = i;
			chmax(ans, dfs(p + 1, i));
		}
	}
	else {
		ans = 0;
		REP(i, Q) if (A[b[i]] - A[a[i]] == c[i]) ans += d[i];
	}
	return ans;
}

int main() {
	cin >> N >> M >> Q;
	REP(i, Q) cin >> a[i] >> b[i] >> c[i] >> d[i], --a[i], --b[i];
	cout << dfs(0, 1) << endl;
	return 0;
}


Measured memory_bytes: 3592
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
typedef long long ll;
const int maxn = 2010;

int n, x, y;
int ans[maxn];

int main() {
    int len;
    scanf("%d%d%d", &n, &x, &y);
    for (int i = 1; i < n; i++) {
        for (int j = i + 1; j <= n; j++) {
            if (i <= x) {
                len = min(j - i, x - i + 1 + abs(y - j));
            } else {
                len = min(j - i, i - x + 1 + abs(y - j));
            }
            ans[len]++;
        }
    }
    for(int i=1;i<n;i++){
        printf("%d\n",ans[i]);
    }
    return 0;
}

Measured memory_bytes: 1740
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <limits.h>
#include <queue>
using namespace std;

#define rip(i,n) (int i=0;i<(int)(n);i++)

string chang(int i){
    string ans=to_string(i);
    while(ans.size()<6){
        ans='0'+ans;
    }
    return ans;
}

int main(){
    int n,m;
    cin >> n >> m;
    vector<int> p(m),y(m);
    for rip(i,m){
        cin >> p[i] >> y[i];
    }
    vector<vector<pair<int,int>>> da(n,vector<pair<int,int>>(0));
    for rip(i,m){
        da[p[i]-1].push_back(make_pair(y[i],i));
    }
    for rip(i,n){
        sort(da[i].begin(),da[i].end());
    }
    vector<string> ans(m,"");
    for rip(i,n){
        for rip(j,da[i].size()){
            ans[da[i][j].second]=chang(i+1)+chang(j+1);
        }
    }
    for rip(i,m){
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 13312
import Data.List

main::IO()
main=do
  str<-getLine
  putStr (solver str)


solver::String->String
solver str = let sym = map (\ls -> head ls) (group (sort str)) in
             let ls  = filter (\x -> not (elem x sym)) ['a'..'z'] in
             if ls ==[] then "None\n" else (head ls):"\n"

Measured memory_bytes: 11644
#include <iostream>
#include <vector>
#include <algorithm>
#include <fstream>
using namespace std;
vector<string> a;
string c;

int main()
{
    int n,t=1;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>c;

        if(i!=0)
            if(c[0]!=a[i-1][a[i-1].size()-1])
            {
                t=0;
            }
        a.push_back(c);

    }
    sort(a.begin(),a.end());
    for(int i=0;i<n-1;i++)
        if(a[i]==a[i+1])
            t=0;
    if(t)
        cout<<"Yes";
    else
        cout<<"No";
    return 0;
}


Measured memory_bytes: 256
<?php
  	fscanf(STDIN, "%d %d", $N, $D);
	$integerCount = 0;
	$points = array();
	for ($i=0;$i<$N;$i++) {
      	$points[] = explode(" ", trim(fgets(STDIN)));
    }

	for ($i=0;$i<$N;$i++) {
      	$point_y = $points[$i];
      	for ($j=$i+1;$j<$N;$j++) {
      		$point_z = $points[$j];
          	$distance = 0;
          	foreach ($point_y as $index => $coordinate) {
              	$distance += pow(abs($point_y[$index] - $point_z[$index]), 2);
            }
          	if (intval(sqrt($distance)) == sqrt($distance)) {
              	$integerCount++;
            }
    	}
    }

	echo $integerCount;
	

Measured memory_bytes: 4604