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

// 水が溢れる直前の体積の求め方
// (底面積) (c + b) * a / 2 * (高さ) * a == x
// c = 2 * x / a / a - b
double trapezoid(double a,double b,double x) {
    return 2 * x / a / a - b;
}

// c = 2 * x / a * b
double triangle(double a,double b,double x) {
    return 2 * x / (a * b);
}

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

    // 体積
    double v = a * a * b;
    if (x > v / 2) {
        // 断面図が台形っぽいつ
        double c = trapezoid(a, b, x);
        double radian = atan((b - c) / a);
        printf("%.10f", 180 * radian / M_PI);
    } else {
        // 断面図が三角形になる
        double c = triangle(a, b, x);
        double radian = atan(b / c);
        printf("%.10f", 180 * radian / M_PI);
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define sz(a) a.size()
#define re return 
#define MP make_pair
#define pb push_back
#define pii pair<int,int>
#define se second
#define fi first
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repd(i,a,b) for(int i=a;i>=b;i--)
using namespace std;

signed main(){
	ios_base::sync_with_stdio(0);
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	int n,k;
	cin>>n>>k;
	cout<<(n%k?1:0);
	re 0;
}

Measured memory_bytes: 3656
// RAM RAM

#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define ppb pop_back
#define vi vector<int>
#define mp make_pair
#define arrayin(a,n) for(int i=0;i<n;i++){cin>>a[i];}
#define N 55
const int MOD=1000000007;
using namespace std;
unordered_map<int,bool> done;

int32_t main()
{
	ios_base::sync_with_stdio(false);cin.tie(0);
	


    string a;cin>>a;
    for(int i=0;i<a.length();i++)
    	if(a[i]==',')
    		a[i]=' ';
    cout<<a<<endl;
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
// defines
#define rep(i,a,b) for(int i = a; i < b; ++i)
#define invrep(i,b,a) for(int i = b; i >= a; --i)
#define umap unordered_map
#define uset unordered_set
// typedefs
typedef unsigned long long int ull;
typedef long long int ll;
// -------------------------------
int n, s, a[3000];
const ll MOD = 998244353LL;
ll memo[3000][3001][2];
ll dp(int i, int c, int b) {
    if (i == n) return c == 0;
    ll& ans = memo[i][c][b];
    if (ans != -1) return ans;
    if (b == 0) {
        ans = (dp(i, c, 1) + dp(i+1, c, 0)) % MOD;
    } else {
        assert (b == 1);
        ans = dp(i+1, c, 1);
        if (a[i] <= c) ans = (ans + dp(i+1, c - a[i], 1)) % MOD;
        if (c == 0) ans = (ans + 1) % MOD;
    }
    return ans;
}
int main() {
    ios::sync_with_stdio(false); 
    cin.tie(0);
    cin >> n >> s;
    rep(i,0,n) cin >> a[i];
    rep(i,0,n) rep(j,0,s+1) rep(k,0,2) memo[i][j][k] = -1;
    cout << dp(0,s,0) << '\n';
    return 0;
}

Measured memory_bytes: 141184
require 'set'

class Hash
  def push(key, value)
    self[key] = [] if self[key] == nil
    self[key].push(value)
  end
end

class Array
  def lower_bound(value)
    left = -1;
    right = self.length;
    while left + 1 < right
      mid = left + (right - left) / 2;
      if self[mid] >= value
        right = mid
      else
        left = mid
      end
    end
    right
  end

  def unique
    res = [self.first]
    each_cons(2) do |a, b|
      if a != b
        res.push(b)
      end
    end
    res
  end
end

def get_ints
  gets.split.map(&:to_i)
end

def get_ints_minus_one
  get_ints.map { |x| x - 1 }
end

def get_int
  gets.chomp.to_i
end

class UnionFind
  attr_accessor :par

  def initialize(n)
    @par = Array.new(n) { |i| i }
  end

  def root(x)
    return x if @par[x] == x

    return @par[x] = root(@par[x])
  end

  def unite(x, y)
    rx = root(x)
    ry = root(y)

    return if rx == ry

    @par[rx] = ry
  end

  def same(x, y)
    root(x) == root(y)
  end

  def to_h
    @par.each.with_index.each_with_object({}) do |(_, i), sum|
      ri = root(i)
      sum[ri] = [] unless sum[ri]
      sum[ri].push(i)
    end
  end
end


N, M, K = get_ints
A, B = [], []
union_find = UnionFind.new(N)
hash = Hash.new(0)

M.times do |i|
  A[i], B[i] = get_ints_minus_one
  union_find.unite(A[i], B[i])
  hash[A[i]] += 1
  hash[B[i]] += 1
end

C, D = [], []
K.times do |i|
  C[i], D[i] = get_ints_minus_one
  if union_find.same(C[i], D[i])
    hash[C[i]] += 1
    hash[D[i]] += 1
  end
end

test = union_find.to_h

ans = N.times.map do |i|
  test[union_find.root(i)].length - hash[i] - 1
end

puts ans.join(' ')


Measured memory_bytes: 29904
#include <iostream>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <map>

using namespace std;

int main(void) {
  long A, B;
  cin >> A >> B;
  for (int i = 1; i <= B; i++) {
    if (A * i % B == 0) {
      cout << A * i << endl;
      break;
    }
  }
  return 0;
}

Measured memory_bytes: 256
def grid_repeating2(H: int, W: int, S: list) -> bool:
    """マスに塗っていい回数の上限がないので、上下左右に黒ます
    がひとつでもあれば OK。つまり、孤立点の有無で判断すればよ
    い。
    """
    for h in range(H):
        for w in range(W):
            if S[h][w] == '.':
                # 白塗り部分は無視
                continue
            # 上下左右のどれかが黒(#)なら OK
            if w > 0 and S[h][w-1] == '#':
                continue
            if w+1 < W and S[h][w+1] == '#':
                continue
            if h > 0 and S[h-1][w] == '#':
                continue
            if h+1 < H and S[h+1][w] == '#':
                continue

            # 上の条件分岐にすべて失敗したなら孤立点
            return False
    return True


if __name__ == "__main__":
    H = 0
    W = 0
    H, W = map(int, input().split())
    S = [input() for _ in range(H)]
    yes = grid_repeating2(H, W, S)
    print('Yes' if yes else 'No')


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


int main()
{
    char s[100];
    scanf("%s",s);

    int len = strlen(s);
    int tf = 0;

    int i;
    for (i = 0; i < len; i++)
    {
        if(s[i] != s[len - 1 - i])break;
    }
    if(i == len){
        for (i = 0; i < (len - 1) / 2; i++)
        {
            if(s[i] != s[(len - 1) / 2 - 1 - i])break;
        }
        if(i == (len - 1) / 2){
            for (i = (len + 3) / 2 - 1; i < len; i++)
            {
                if(s[i] != s[len - 1 - i])break;
            }
            if(i == len){
                printf("Yes");
            }
            else
            {
                printf("No");
            }
            
        }
        else
        {
            printf("No");
        }
        
    }
    else
    {
        printf("No");
    }
    

}


Measured memory_bytes: 256
#include <bits/stdc++.h> //全てのヘッダファイルをインクルード

//ループ
#define rep(i, n) for(int i = 0; i < (n); i++) //普通のループ
#define repr(i, n) for(int i = n; i >= 0; i--) //逆ループ

//型名省略
typedef long long ll;
//値
static const ll MX = 100005;
static const ll MX_ll = 1e18;

using namespace std;

//ソート
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))

//#include "./lib/generic/search.h"

int main(){
    int n, x, y, z, ans=0, max=0;
    cin >> n;
    for(int i=1; i<=n; i++){
        ans=0; max=0;
        if(i<=5){
            cout << "0" << endl;
            continue;
        }
        x=1;
        while(1){
            if(x*x+x-i+4<=0){
                x++;
            }
            if(x*x+x-i+4>0){
                max=x-1;
                break;
            }
        }
        for(x=1; x<=max; x++){
            for(y=x; y<=max; y++){
                for(z=y; z<=max; z++){
                    if(x*x+y*y+z*z+x*y+y*z+z*x==i){
                        if(x==y && y==z) ans++;
                        else if(x==y && y!=z) ans+=3;
                        else if(x!=y && y==z) ans+=3;
                        else if(x==z && y!=z) ans+=3;
                        else ans+=6;
                    }
                }
            }   
        }
        cout << ans << endl;
    }

    return 0;
}

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


using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define all(n) n.begin(),n.end()
#define eb emplace_back
#define endl "\n"

const ll maxn=3e3+50;

const ll maxx=1e13;
const ll mod1=1000000007;
const ll mod=998244353;



ll dp[maxn][maxn][4];
ll a[maxn];
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //freopen("test.txt","r",stdin);
    //freopen("FRAC.INP", "r", stdin);
    // freopen("WALKING.OUT", "w", stdout);
     ll n, s;
     cin>>n>>s;
      for (int i=0;i<=n;i++)
     {
         for (int j=0;j<=s;j++)
         {
            for (int k=0;k<=2;k++)
            {
                dp[i][j][k]=0;
            }

         }
     }
     dp[0][0][0]=1;
     for (int i=1;i<=n;i++) cin>> a[i];
     for (int i=1;i<=n;i++)
     {
         for (int j=0;j<=s;j++)
         {
             dp[i][j][0]=(dp[i][j][0]+dp[i-1][j][0])%mod ;
             dp[i][j][1]=(dp[i][j][1]+dp[i-1][j][0]+dp[i-1][j][1])%mod ;
             dp[i][j][2]=(dp[i][j][2]+dp[i-1][j][0]+dp[i-1][j][1]+dp[i-1][j][2])%mod ;
             if (j>=a[i])
             {
                 dp[i][j][1]=(dp[i][j][1]+dp[i-1][j-a[i]][1]+dp[i-1][j-a[i]][0])%mod ;
                  dp[i][j][2]=(dp[i][j][2]+ dp[i-1][j-a[i]][1]+dp[i-1][j-a[i]][0])%mod ;

             }

         }
     }
     cout <<dp[n][s][2];
}


Measured memory_bytes: 286976
#include "bits/stdc++.h"
using namespace std;
 
using ll = long long;
 
const ll inf = 1e18;
const int N = 2 * 1e5 + 10;

ll res;
ll a[N];

void solve(){
    string s;
    cin >> s;
    if(s.back() == 's'){
        cout  << s + "es";
    }else{
        cout << s + 's';
    }
}
 
int main(int argc, char const *argv[]){
    ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
    ll t = 1;
    //cin >> t;
    while(t--){
        solve();
    }
}
// Radhe Radhe

Measured memory_bytes: 3620
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;

class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {

		Integer top3[] = new Integer[3];
		for (int i = 0; i < 3; i++) {
			top3[i] = 0;
		}

		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		for (int x = 1; x <= 10; x++) {
			Integer h = Integer.parseInt(in.readLine());
			if (h >= 0 && h <= 10000) {
				ArrayList<Integer> tmpTop = new ArrayList<Integer>(4);
				for (int i = 0; i< 3; i++) {
					tmpTop.add(top3[i]);
				}
				tmpTop.add(h);

				Collections.sort(tmpTop);
				Collections.reverse(tmpTop);

				for (int i = 0; i< 3; i++) {
					top3[i] = tmpTop.get(i);
				}
			}
		}

		for (int i = 0; i< 3; i++) {
			System.out.println(top3[i]);
		}
	}

}

Measured memory_bytes: 24228
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long ll;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main() {

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

    if(a <= 0 && b >= 0) {
        cout << "Zero" << endl;
    } else if(a > 0) {
        cout << "Positive" << endl;
    } else {
        if((-a + b + 1) % 2 == 0) cout << "Positive" << endl;
        else cout << "Negative" << endl;
    }

    return 0;
}


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

int main(){

	int N;
	scanf("%d",&N);

	if(N%2 == 0){
		printf("%d",N/2);
	}
	else{
		printf("%d",N/2 + 1);
	}

	return 0;
}

Measured memory_bytes: 128
S=input()
T=input()

ans=0

for i in range(len(S)-len(T)+1):
    c=0
    I=i
    t=0
    for j in range(len(T)):
        if S[I]==T[t]:
            c+=1
        t+=1
        I+=1
    ans=max(c,ans)

print(len(T)-ans)
        














    

                
            





    









        

    









    

        




    















    



    





    






        






    
















        


























            
    


    


    
    














    


    














Measured memory_bytes: 9116
#include <iostream>

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

using namespace std;

int main(){
  string s;
  cin >> s;
  //入力終了

  //sが既に単一文字のみからできているとき
  bool f = true;
  rep(i, s.size()-1 ){
    f = f*(s[i]==s[i+1]);
  }
  if(f){
    cout << 0 << endl;
    return 0;
  }

    
  int ans = 1000;
  
  //どの文字が単一文字になるかで全探索
  for(char c='a'; c<='z'; c++){
    string t1 = s;
    int cnt = 0;
    bool flag = false;
    
    //文字列が単一になるまで繰り返す
    while(!flag){
      string t2;
      //文字列t2の作成
      rep(i, t1.size()-1 ){
	//元の文字列t1にcがあればそれを連結
	if(t1[i]==c || t1[i+1]==c)
	  t2 = t2+c;
	//なければそのまま連結
	else
	  t2 = t2+t1[i];
      }

      //長さが1になれば終了
      if(t2.size() == 1)
	flag = true;
      else{
	//t2が単一文字からできているかの判定
	bool tmp_flag = true;
	rep(i, t2.size()-1 ){
	  tmp_flag = tmp_flag*(t2[i]==t2[i+1] );
	  flag = tmp_flag;
	}
      }

      t1 = t2;
      cnt++;
    } //while

    //最小値の更新
    if(cnt < ans)
      ans = cnt;
    }

  //解答
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 3616
#include <iostream>
#include <algorithm>
#include <fstream>
#include <vector>
#include <deque>
#include <assert.h>
#include <stack>
#include <set>
#include <map>
#include <stdio.h>
#include <string.h>
#include <utility>
#include <math.h>
#include <bitset>
#include <iomanip>
#include <complex>
#include <queue>
using namespace std;
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define print(x) cout<<(x)<<'\n'
#define print_vec(v) rep(i,v.size()){if(i!=0)cout<<" ";cout<<v[i];}cout<<'\n'
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";rep(i,v.size())cout<<" "<<v[i];cout<<'\n'
#define pb push_back
#define mp make_pair
#define MOD 1000000007 //10^9+7
#define fi first
#define sc second
using ll=long long;
using pll=pair<ll,ll>;
using vll=vector<ll>;
using vvll=vector<vll>;
using vstr=vector<string>;

ll N,A,B;

string s;
void solve() {
    cin >> N >> A >> B;
    ll ans;
    if(A==B) ans = 1;
    else if(B<A || N==1) ans = 0;
    else{
        ll d = N-2;
        ans = B*d - A*d + 1;
    }
    print(ans);
}
 
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
	cout<<fixed<<setprecision(20);
    //int q; cin >> q;
	//while (q--)
		solve();
    return 0;
}

Measured memory_bytes: 3616
public class Main{
  public static void main(String[] args){
    int input= new java.util.Scanner(System.in).nextInt();
    int h=input/3600;
    int m=(input-h*3600)/60;
    int s=input-h*3600-m*60;
    System.out.println(h+":"+m+":"+s);
}
}



Measured memory_bytes: 26276
from collections import defaultdict
n = int(input())
cs = 'ATGC'
ng = [
  'AGC',
  'GAC',
  'ACG',
  'AGGC',
  'ATGC',
  'ACGC',
  'AGAC',
  'AGTC'
]

mod = 10**9 + 7
d = defaultdict(int)
for c1 in cs:
  for c2 in cs:
    for c3 in cs:
      s = c1 + c2 + c3
      if s not in ng:
        d[s] += 1
for i in range(3, n):
  nd = defaultdict(int)
  for key in d.keys():
    for c in cs:
      cn = key[1:3] + c
      cn4 = key + c
      if cn not in ng and cn4 not in ng:
        nd[cn] = (nd[cn] + d[key]) % mod
  d = nd
print(sum([d[key] for key in d]) % mod)
      


Measured memory_bytes: 42500
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <stdio.h>
using namespace std;
#define ll long long


int main() {
	int n, ans = 0;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		if (0 < i && i < 10 || 99 < i && i < 1000 || 9999 < i && i < 100000)ans++;
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
  int N,a,b,c;
  cin >> N ;
  a = floor(N/100);
  b = floor((N-a*100)/10);
  c = N-a*100-b*10;
  if (a == 7 || b == 7 || c == 7){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 3620
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include<vector>
#include<iomanip>
#include<map>
#include <queue>
#include<cmath>
#include<cstdio>
#include<iomanip>
#include<set>
#include <bits/stdc++.h>
 
using namespace std;
using ll = long long int;
 
#define REP(i,n) for(ll i=0;i<(ll)(n);i++) //REP(i, 5) cout<<i;
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define MOD 1000000007 //10^9+7
//#define MOD 1
 
ll gcd(ll a, ll b) {
  ll tmp;
  if ( b > a) {
    tmp = a;
    a = b;
    b = tmp;
  }
  while (a % b !=0) {
    tmp = b;
    b = a % b;
    a = tmp;
  }
  return b;
}
 
const int MAX = 1000;
 
ll table[MAX][MAX];
 
// テーブルを作る前処理
void COMinit() {
    table[0][0] = table[0][1] = 1;
    FOR(i, 1, MAX-1){
      FOR(j, 0, i+1){
        if(j==0) table[i][j] = 1;
        else if(j == i+1) table[i][j] = 1;
        else table[i][j] = table[i-1][j-1]+table[i-1][j];
      }
    }
}
 
// 二項係数計算
ll COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return table[n-1][k];
}

void sosuu(ll n, vector<ll> &v){

  vector<ll> num(n, 0);

  FOR(i, 1, sqrt(n)){
    if(num[i]==0){
      FOR(j, 0, n/i){
        num[i+(j*i)] = 1;
      }
    }
  }
  REP(i, n){
    if(num[i]==0) v.push_back(i+1);
  }
}


int main(void){
 
  string s;
  cin>>s;

  if(s=="ARC") cout<<"ABC" <<endl;
  if(s=="ABC") cout<<"ARC" <<endl;
  return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <set>
using namespace std;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define yes cout << "yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define no cout << "no" << endl

const int INF = 1001001001;
const int mod = 1000000007;
#define PI 3.14159265359;

void P(int x) {cout << x << endl;}
void P(long x) {cout << x << endl;}
void P(double x) {cout << x << endl;}
void P(ll x) {cout << x << endl;}
void P(string x) {cout << x << endl;}
void P(char x) {cout << x << endl;}

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

int main() {
  int a, b, c, k;
  cin >> a >> b >> c >> k;
  int ans = a + b + c;
  int m = max(a, max(b, c));
  ans += (m * pow(2, k)) - m;
  P(ans);
  return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	int i,num;
	for(i=0;i<m;i++){
		scanf("%d",&num);
		n-=num;
	}
	if(n<0) printf("-1\n");
	else printf("%d\n",n);
}

Measured memory_bytes: 1708
import java.util.*

fun main(args: Array<String>) {
    val scan = Scanner(System.`in`)
    val n = scan.nextInt()
    val m = scan.nextInt()
    val sc = (0 until m).map {  scan.next().toInt() to scan.next().toInt() }
    println(problem157c(n, m, sc))
}

fun problem157c(n: Int, m: Int, sc: List<Pair<Int, Int>>): Int {
    val sc = sc.sortedBy { it.first }
    val start = when (n) {
        2 -> 10
        3 -> 100
        else -> 0
    }
    val end = when (n) {
        2 -> 99
        3 -> 999
        else -> 9
    }
    for (i in start..end) {
        val iStr = i.toString()
        if (iStr.length != n) continue
        var isMatch = true
        for (j in 0 until m) {
            val scj = sc[j]
            if (iStr[scj.first - 1].toString() != scj.second.toString()) {
                isMatch = false
                break
            }
        }
        if (isMatch) return i
    }
    return -1
}

Measured memory_bytes: 34116
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
class Solve{
    public Solve(){}
    StringBuilder sb;
    public static int Main(){
        new Solve().Run();
        return 0;
    }
    void Run(){
        sb = new StringBuilder();
        Calc();
        Console.Write(sb.ToString());
    }
    void Calc(){
        string[] str = Console.ReadLine().Split(' ');
        int N = int.Parse(str[0]);
        long T = int.Parse(str[1]);
        str = Console.ReadLine().Split(' ');
        long sum = 0;
        long[] t = new long[N];
        for(int i=0;i<N;i++){
            t[i] = int.Parse(str[i]);
        }
        for(int i=0;i<N-1;i++){
            sum += Math.Min(T,t[i+1]-t[i]);
        }
        sum += T;
        sb.Append(sum+"\n");
    }
}

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

int main(){

    int N, K;
    cin >> N >> K;
    vector<int> l(N);
    for(int i = 0; i < N; i++) cin >> l[i];

    sort(l.rbegin(), l.rend());

    int ans = 0;
    for(int i = 0; i < K; i++) ans += l[i];

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <bitset>
#include <iomanip>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <algorithm>

using namespace std;

bool isInField(int col, int row, const pair<int, int> &point)
{
	const int c = point.second;
	const int r = point.first;
	return (0 <= c && c < col) && (0 <= r && r < row);
}

int main()
{
	long long w, h,max=0;
	cin >> h >> w;

	vector<vector<char>> map(h,vector<char>(w));

	for (long long i = 0; i < h; i++)
	{
		for (long long j = 0; j < w; j++)
			cin >> map[i][j];
	}

	const pair<int, int> points[4] = {
		{-1,0},{1,0},{0,-1},{0,1}
	};

	for (long long i = 0; i < h; i++)
	{
		for (long long j = 0; j < w; j++)
		{
			if (map[i][j] == '.')
			{
				long long buf = 0;
				vector<vector<int>> memo;
				for (int i = 0; i < h; ++i) {
					vector<int> v(w, 0);
					memo.push_back(v);
				}

				queue<pair<long long, long long>> data;
				data.push({i,j});
				pair<long long, long long> start = data.front();

				while (!data.empty()) {
					pair<long long, long long> cur = data.front();
					data.pop();

					for (const auto &point : points)
					{
						pair<long long, long long> next = { (cur.first + point.first),(cur.second + point.second) };

						if (isInField(w, h, next)) {
							const char s = map[next.first][next.second];

							if (s == '.') {
								if (memo[next.first][next.second] == 0 && next != start) {
									data.push(next);
									memo[next.first][next.second] = memo[cur.first][cur.second] + 1;
									if (memo[next.first][next.second] > buf)
										buf = memo[next.first][next.second];
								}
							}
						}
					}
				}
				if (max < buf)
					max = buf;
			}
		}
	}

	cout << max << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <vector>
#include <complex>
#include <utility>
#include <algorithm>
#include <numeric>
using namespace std;
typedef complex<double> P;
typedef pair<P,P> L;
#define X real()
#define Y imag()
const double INF = (1e15), EPS = (1e-8);
const pair<int,double> init(8,INF);
P Points[10];
pair<int,double> ans, DP[2];

inline double dot(P a, P b){ return a.X*b.X + a.Y*b.Y;}
inline double cross(P a, P b){ return a.X*b.Y - a.Y*b.X;}

inline P intersection(L a, L b){
  P bf = b.first, af = a.first-bf, as = a.second-bf, bs = b.second-bf;
  return af + bf + cross(bs,af)/(-cross(bs,as)+cross(bs,af))*(as-af);
}

inline bool on_line(P a, P b, P c){
  b -= a, c -= a;
  if(cross(b,c) > EPS) return false;
  if(cross(b,c) < -EPS) return false;
  if(dot(b,c) < 0) return false;
  if(norm(b) + EPS < norm(c)) return false;
  return true;
}

int main(){
  int n;
  while(cin >> n, n){
    ans = init;
    for(int i = 0; i < n; ++i){
      double x, y;
      cin >> x >> y;
      Points[i] = P(x,y);
    }
    vector<int> perm(n);
    iota(perm.begin(), perm.end(), 0);
    do{
      if(perm[0] == n-1) break;
      if(perm[0] > perm.back()) continue;
      DP[1] = init;
      DP[0] = pair<int,double>(0,abs(Points[perm[1]]-Points[perm[0]]));
      for(int i = 1; i < n-1; ++i){
        if(DP[0] >= ans && DP[1] >= ans) break;
        P prev = Points[perm[i-1]], cur = Points[perm[i]], nex = Points[perm[i+1]];
        int c = !on_line(prev, nex, cur);
        pair<int,double> val = DP[0];
        double l = abs(nex-cur);
        DP[1].second += l;
        DP[0].second += l;
        DP[0].first += c;
        DP[0] = min(DP[0],DP[1]);
        if(i == n-2) break;
        P nexx = Points[perm[i+2]];
        if(norm(cross(cur-prev,nexx-nex)) < EPS or on_line(prev,nex,cur) or on_line(cur,nexx,nex)){
          DP[1] = init;
          continue;
        }
        P cp = intersection(L(prev,cur),L(nex,nexx));
        if((!on_line(cp,nexx,nex)) or (!on_line(prev,cp,cur))){
          DP[1] = init;
          continue;
        }
        DP[1] = val;
        ++DP[1].first;
        DP[1].second += abs(cp-cur) + abs(cp-nex);
      }
      ans = min(ans, DP[0]);
    }while(next_permutation(perm.begin(), perm.end()));
    printf("%d %.5f\n", ans.first, ans.second);
  }
  return 0;
}



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

#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define min4(a,b,c,d) min(min(a,b),min(c,d))
#define max4(a,b,c,d) max(max(a,b),max(c,d))
#define count_one(a) __builtin_popcount(a)  // Returns the number of set bits(1) in a number(a). In long long use __builtin_popcountll(a)
#define parity(i)   __builtin_parity(i)  //even parity 0 and odd parity 1
#define blz(a)   __builtin_clz(a) //Returns the number of leading zeroes in a number(a)
#define btz(a)   __builtin_ctz(a) //Returns the number of trailing zeroes in a number(a)
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define ll long long
#define pb push_back
#define PI M_PI
#define endl "\n"
#define sc scanf
#define pf printf
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
int main()
{
    IOS
    ll a,b,c,d,ans=0;
    cin>>a>>b>>c>>d;
    if(a<=d&&d>0)
    {
        ans+=a;
        d-=a;
    }
    else
    {
        ans+=d;
        d-=d;
    }
    if(d>=b&&d>0)
    {
        d-=b;
    }
    else
    {
        d-=d;
    }
    if(d>0)
     ans-=d;
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 3628
#include <iostream>
#include <cmath>
#include <cstdio>
#include <string>
#include <sstream>

using namespace std;

double sisya(double a) {
	a *= 1000.0;
	//cout << a << endl;
	a += 0.5;
	a = (int)a;
	a /= 1000.0;
	return a; 
}

double ll(double x1, double y1, double x2, double y2) {
	return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}

int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		double x[3], y[3];
		for (int j = 0; j < 3; j++) {
			cin >> x[j] >> y[j];
		}
		double a1, a2, b1, b2, c1, c2;
		a1 = 2.0 * (x[1]-x[0]);
		a2 = 2.0 * (x[2]-x[0]);
		b1 = 2.0 * (y[1]-y[0]);
		b2 = 2.0 * (y[2]-y[0]);
		c1 = x[0]*x[0]-x[1]*x[1]+y[0]*y[0]-y[1]*y[1];
		c2 = x[0]*x[0]-x[2]*x[2]+y[0]*y[0]-y[2]*y[2];
		double X, Y, R;
		X = (b1*c2-b2*c1)/(a1*b2-a2*b1);
		Y = (c1*a2-c2*a1)/(a1*b2-a2*b1);
		R = ll(X, Y, x[0], y[0]);
		//X = sisya(X);
		//Y = sisya(Y);
		//R = sisya(R);
		printf("%.3f %.3f %.3f\n", X, Y, R);
	}
	return 0;
}

Measured memory_bytes: 1244
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
input:
5
5
1
3
2
4

or

3
1
1
1

output:
3

or

1
"""

import sys
from bisect import bisect_left


def solve():
    dis_rec = [float('inf')] * array_length
    dis_rec[0] = array[0]
    length = 1
    for j in range(1, array_length):
        if dis_rec[length - 1] < array[j]:
            dis_rec[length] = array[j]
            length += 1
        else:
            position = bisect_left(dis_rec, array[j])
            dis_rec[position] = array[j]
    return length


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    array_length = int(_input[0])
    array = list(map(int, _input[1:]))
    print(solve())

Measured memory_bytes: 19524
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B,L,R;
string S,T;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;

typedef vector<P> vp;
typedef vector<vp> matP;

ll sn(ll n){
    ll ans = 0;
    while(n > 0){
        ans += n%10;
        n /= 10;
    }
    return ans;
}

int main(){
    cin>>A>>B;
    cout<<(A <= 8 && B <= 8 ? "Yay!" : ":(")<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0 ; i < (int)(n) ; i++)
typedef long long ll;
////////////////////////////////////////////////
int main() {
    int n;
    string c;
    cin >> n >> c;
    int ans = n;
    vector<int> w(n, 0), e(n, 0);
    rep(i,n-1){
        w[i+1]=w[i]+(c[i]=='W');
        e[n-i-2]=e[n-i-1]+(c[n-i-1]=='E');
    }
    rep(i,n){
        ans=min(ans, w[i]+e[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 6060
n = gets.to_i

ss = []
ts = []
n.times do
  s,t = gets.split
  ss.push(s)
  ts.push(t.to_i)
end

x = gets.chomp

start = ss.index(x)
if start == n-1
  puts 0
else
  puts ts[start+1..-1].inject(:+)
end


Measured memory_bytes: 2044
N = int(input())
L = [[int(x) for x in input().split()] for _ in range(N-1)]

ans = [0]*N
for i in range(N-1):
    t = L[i][1]+L[i][0]
    for j in range(i+1, N-1):
        if L[j][1] >= t:
            t = L[j][1]+L[j][0]
        else:
            t = ((t-L[j][1])//L[j][2]+min(1, (t-L[j][1])%L[j][2]))*L[j][2]+L[j][0]+L[j][1]
    ans[i] = t
    
for i in range(N):
    print(ans[i])

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //GCC5.4.1で配列の範囲外アクセスをエラーにする

//cmdで g++ test.cpp とするとコンパイルできる
//制限1秒なら10^6は余裕 10^7は多分間に合う 10^8はよほど単純でないと厳しい
// https://github.com/atcoder/live_library
// cppdbg: test.exeのterminalに標準入力を打てる

#define ALL(x) x.begin(),x.end()
#define get_tp(t,i) get<i>(t)
#define len(x) (ll)(x.size())
#define ub(a,x) (upper_bound(ALL(a),x)-a.begin())
#define lb(a,x) (lower_bound(ALL(a),x)-a.begin())
typedef long long ll; //long long
typedef pair<int,int> pii; //pair<int,int>
typedef pair<long long,long long> pllll; //pair<ll,ll>
typedef vector<int> vi; //vector<int>
typedef vector<vector<int>> vvi; //vector<vector<int>>
typedef vector<ll> vll; //vector<long long>
typedef vector<vector<ll>> vvll; //vector<vector<long long>>
typedef priority_queue<ll, vector<ll>, greater<ll> > gpq; //逆順priority_queue
typedef priority_queue<ll> pq;

//const int MOD=998244353;
const int MOD=1000000007; //10^9+7
const long double PI=3.1415926535897932;

int main(){
    ll N;cin>>N;
    cout<<((N%2)?N*2:N)<<endl;
}

Measured memory_bytes: 3652
#include <stdio.h>
int main() {
  int n,y,x[3],i,j;
  scanf("%d%d",&n,&y);
  for (i=0;i<=n;i++) {
    for (j=0;j<=n-i;j++) {
      if (1000*i+5000*j+10000*(n-i-j)==y) {
        printf("%d %d %d\n",n-i-j,j,i);
        return 0;
      }
    }
  }
  printf("-1 -1 -1\n");
  return 0;
}

Measured memory_bytes: 128
n, a, b = map(int, input().split())
MOD = 10**9+7


def COM(n, r):
    X = Y = 1
    if n-r < r:
        r = n-r
    for i in range(1, r+1):
        Y = Y*i % MOD
        X = X*(n-i+1) % MOD
    Y = pow(Y, MOD-2, MOD)
    return X*Y

ans = pow(2, n, MOD)-1 - COM(n, a)-COM(n, b)
ans %= MOD

print(ans)


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

using namespace std;

#define FOR(i, a, b) for (int i=(a);i<(b);++i)
#define ROF(i, a, b) for (int i=(b)-1;i>=(a);--i)
#define REP(i, n) for (int i=0;i<(n);++i)
#define PRE(i, n) for (int i=(n)-1;i>=0;--i)
#define FOREACH(a, v) for(auto a : v)

#define ALL(a) (a).begin(),(a).end()
#define DEBUG(x) cerr<<#x<<": "<<x<<endl
#define INFILE() freopen("in0.txt","r",stdin)
#define OUTFILE()freopen("out0.txt","w",stdout)

#define INF INT_MAX/3
#define eps 1e-14

#define ll long long
using vint = vector<int>;

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

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

    int ret = 0;
    FOR(i, a, b + 1) {
        string l = to_string(i), r = to_string(i);
        reverse(r.begin(), r.end());
        if (l == r) {
            ret++;
        }
    }

    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <tuple>

#define rep(i,n) for(ll i=0;i<n;i++)
#define dup(x,y) (((x)+(y)-1)/(y)) // dup * y >= x なる最小のdup.
using namespace std;
typedef long long ll;
using Graph = vector<vector<ll>>;
//	std::cout<<std::fixed<<std::setprecision(10);

int main() {
	double N;
	cin >> N;
	int X = (int)(N/1.08);

	if((int)(X*1.08)==(int)N) {
		cout << (int)X << endl;
	} else if((int)((X+1)*1.08)==(int)(N)){
		cout << (int)(X+1) << endl;
	} else {
		cout << ":(" << endl;
	}
	return 0;
}

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

using namespace std;

struct Node {
    int key;
    Node *left = nullptr, *right = nullptr;

    Node(int _key) {
        key = _key;
    }
};

Node *root = nullptr;

void Insert(int key) {
    Node *node = new Node(key);

    Node *y = nullptr;
    Node *x = root;

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

    if (y == nullptr) {
        root = node;
    } else if (key < y->key) {
        y->left = node;
    } else {
        y->right = node;
    }
}

void InOrder(Node *node) {
    if (node == nullptr) {
        return;
    }

    InOrder(node->left);
    cout << " " << node->key;
    InOrder(node->right);
}

void PreOrder(Node *node) {
    if (node == nullptr) {
        return;
    }

    cout << " " << node->key;
    PreOrder(node->left);
    PreOrder(node->right);
}

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

    for (int i = 0; i < n; ++i) {
        string ops;
        int key;
        cin >> ops;

        if (ops == "insert") {
            cin >> key;
            Insert(key);
        } else {
            InOrder(root);
            cout << endl;
            PreOrder(root);
            cout << endl;
        }
    }

    return 0;
}



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

bool search(vector<vector<bool>>& isvisit, vector<vector<int>> c, int i, int j){
    if(!(i >= 0 && i < isvisit.size() && j >= 0 && j < isvisit[i].size())){
        return false;
    }else if(isvisit[i][j]){
        return false;
    }else{
        isvisit[i][j] = true;
        if(c[i][j] == 0) return false;

        for(int ii = -1; ii <= 1; ii += 2){
            search(isvisit, c, i+ii, j);
            search(isvisit, c, i, j+ii);
            search(isvisit, c, i+ii, j+ii);
            search(isvisit, c, i+ii, j-ii);
        }
        return true;
    }
}

int main(){
    int w, h;
    while(true){
        cin >> w >> h;
        if(w == 0 && h == 0) break;
        vector<vector<int>> c(h, vector<int>(w));
        for(int i = 0; i < h; i++){
            for(int j = 0; j < w; j++) cin >> c[i][j];
        }
        int ans = 0;
        vector<vector<bool>> isvisit(h, vector<bool>(w, false));
        for(int i = 0; i < h; i++){
            for(int j = 0; j < w; j++){
                if(search(isvisit, c, i, j)) ans++;
            }
        }
        cout << ans << endl;
    }
    
    return 0;
}


Measured memory_bytes: 29124
import sys
n=int(input())
h=list(map(int,input().split()))
a,b=0,[]
if len(h)==1:
    print('0')
    sys.exit()
for i in range(1000000):
    if h[i]<h[i+1]:
        b.append(i-a)
        a=i+1
    if i+2==len(h):
        b.append(i-a+1)
        break
print(max(b))

Measured memory_bytes: 14224
N = int(input())
strlist = 'abcdefghij'

def dfs(s, i):
  if len(s) == N:
    print(s)
  else:
    for j in range(i+1):
      t = s + strlist[j]
      if j == i:
        dfs(t, i+1)
      else:
        dfs(t, i)

dfs('', 0)

Measured memory_bytes: 4412
#include <iostream>
using namespace std;
int main(){
    int N;
    int A[210];
    int ct = 0;
    int flag = 0;
    cin >> N;
    for(int i=0; i<N; i++)cin >> A[i];
    while(1){
        for(int i=0; i<N; i++){
            if(A[i]%2!=0)flag=1;
        }
        if(flag)break;
        for(int i=0; i<N; i++){
            A[i] /= 2;
        }
        ct++;
    }
        
cout << ct << endl;

}

Measured memory_bytes: 256
def insertionSort(arr, g):
    cnt = 0
    for i in range(g, len(arr)):
        tmp = arr[i]
        j = i - g
        while(j >= 0 and arr[j] > tmp):
            arr[j + g] = arr[j]
            j -= g
            cnt += 1
        arr[j + g] = tmp
    return cnt


def shellSort(arr):
    cnt = 0
    g = []
    h = 0
    while h <= len(arr) / 9:
        h = 3 * h + 1
        g.append(h)
    g = g[::-1]
    m = len(g)

    for i in range(0, m):
        cnt += insertionSort(arr, g[i])
    return (cnt, g)


N = int(input())
arr = [int(input()) for i in range(N)]

(cnt, g) = shellSort(arr)
print(len(g))
print(' '.join(map(str, g)))
print(cnt)
print('\n'.join(map(str, arr)))



Measured memory_bytes: 125988
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int main() {
    int a;

    cin >> a;

    if (a % 2 == 0) {
        cout << a / 2 << endl;
    } else {
        cout << a / 2 + 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
#define pb push_back
#define mp make_pair
#define F .first
#define S .second 
using ll=long long;
using ld=long double;
using namespace std;
const ll mod=1e9+7;
ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }
ll h[110000];
ll dp[110000];
int main(){
    ll n;
    cin>>n;
    rep(i,0,n)cin>>h[i];
    dp[1]=labs(h[1]-h[0]);
    rep(i,2,n)dp[i]=min(dp[i-1]+labs(h[i]-h[i-1]),dp[i-2]+labs(h[i]-h[i-2]));
    cout<<dp[n-1];
}


Measured memory_bytes: 1792
def main():
    S = input()
    r = 0
    t = 0
    pp = 0
    d = False
    for s in S + '<':
        if s == '<':
            if d:
                r += max(pp, t)
                pp = 0
                t = 0
            else:
                r += t
        else:
            if d:
                r += t
            else:
                pp = t
                t = 0
        d = s == '>'
        t += 1

    return r
        

print(main())


Measured memory_bytes: 4212
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) ((a) <= (x) && (x) < (b))
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MODU 1000000007
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int
#define PI 3.141592653589


#define izryt bool
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*)array, (T*)(array + N), val);
}
pii Dir[8] = { //移動
	{ 0 ,1 },{ -1 ,0 },{ 1 ,0 },{ 0 ,-1 },
	{ 1 ,1 },{ 1 ,-1 },{ -1 ,1 },{ -1 ,-1 }
};
int h, w;

int mp[401][401] = {};

vector<string> s;

ll ans = 0;
int bc = 0, wc = 0;

void dfs(int x, int y, int num, char bef) {
	if (x < 0 || x >= w) return;
	if (y < 0 || y >= h) return;
	if (mp[y][x] != 0) return;
	if (bef == s[y][x]) return;

	if (s[y][x] == '#')bc++;
	else wc++;

	mp[y][x] = num;

	REP(i, 4) {
		dfs(x + Dir[i].first, y + Dir[i].second, num, s[y][x]);
	}

}

int main(void) {

	cin >> h >> w;


	REP(i, h) {
		string buf;
		cin >> buf;
		s.push_back(buf);
	}

	int cou = 1;
	REP(i, h) {
		REP(j, w) {
			if (mp[i][j] == 0) {
				dfs(j, i, cou, s[i][j] == '#' ? '.' : '#');
				ans += 1LL*bc * wc;
				bc = 0;
				wc = 0;
				cou++;
			}
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 13568
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define REP(i,n) for (ll i = 0; i < (n); ++i)
#define RREP(i, n) for (ll i = (n) - 1; i >= 0; --i)
#define ALL(v) (v).begin(), (v).end()


int main(){
    ll n, m;
    cin >> n >> m;
    ll total = 0;
    REP(i, m){
        ll ai;
        cin >> ai;
        total += ai;
    }
    if(total <= n){
        cout << n - total << endl;
    }else{
        cout << -1 << endl;
    }
    return 0;
}


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

#define ll long long
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl


void solve(){
    string s;
    cin >> s;
    int cnt = 0;
    vector<int> freq;
    freq.push_back(0);
    for(int i=0;i<3;i++){
        if(s[i]=='R'){
            cnt++;
        }
        else{
            freq.push_back(cnt);
            cnt=0;
        }
    }
    if(cnt>0){
        freq.push_back(cnt);
    }
    int maxr = 0;
    for(int i:freq){
        maxr=max(maxr,i);
    }
    cout << maxr << endl;


}

int main() {
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

    IOS;
    int T;
    T=1;
    //cin >> T;
    while(T--){
    solve();
    }

    

    return 0;
}


Measured memory_bytes: 3616
/*痛みを受け取れ，痛みを知れ*/
#include<bits/stdc++.h>
#define f(i,a,b) for(register int i=a;i<=b;++i)
#define ff(i,a,b) for(register int i=a;i>=b;--i)
#define debug(x) cerr << #x << " : " << x << " " << endl
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<string, string> pss;
const ll mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const double tiaohe = 0.57721566490153286060651209;
ll oula(ll x) { ll res = x;f(i, 2, x / i) { if (x % i == 0) { res = res / i * (i - 1);while (x % i == 0) x /= i; } }if (x > 1) res = res / x * (x - 1);return res; }
ll quickmod(ll a, ll n, ll m) { ll s = 1;while (n) { if (n & 1) { s = s * a % m; }a = (a*a) % m;n = n / 2; }return s; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
void ex_gcd(ll a, ll b, ll &x, ll &y, ll &d) { if (!b) { d = a, x = 1, y = 0; } else { ex_gcd(b, a % b, y, x, d);y -= x * (a / b); } }
ll inv(ll t, ll p) { ll d, x, y;ex_gcd(t, p, x, y, d);return d == 1 ? (x % p + p) % p : -1; }
bool isPrime(ll x) { if (x == 2)return true;if (x % 2 == 0)return false;for (ll i = 2;i*i <= x;i++) if (x % i == 0)return false; return true; }
//double a = log(n) +tiaohe + 1.0 / (2 * n);
double eqa = (1 + sqrt(5.0)) / 2.0;
const int N = 5e5 + 5;

int main()
{
	//freopen("in.txt", "r", stdin);
	int n;
	while (cin >> n)
	{
		if (n >= 400 && n <= 599)puts("8");
		else if (n >= 600 && n<=799)puts("7");
		else if (n >= 800 && n <= 999)puts("6");
		else if (n >= 1000 && n <= 1199)puts("5");
		else if (n >= 1200 && n <= 1399)puts("4");
		else if (n >= 1400 && n <= 1599)puts("3");
		else if (n >= 1600 && n <= 1799)puts("2");
		else puts("1");
	}
	return 0;
}

Measured memory_bytes: 3616
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#define Mod 1000000007
using namespace std;
struct Edge{
	int u,v,c;
}e[2010];
int n,m;
bool cmp(Edge a,Edge b)
{
	return a.c<b.c;
}
int fa[1010];
int find(int x)
{
	return fa[x]==x?x:fa[x]=find(fa[x]);
}
bool merge(int x,int y)
{
	int f1=find(x);
	int f2=find(y);
	if(f1==f2)return false;
	fa[f2]=f1;
	return true;
}
long long work(int x)
{
	long long ans=e[x].c;
	for(int i=1;i<=n;i++)fa[i]=i;
	merge(e[x].u,e[x].v);
	for(int i=1;i<=m;i++)
		if(merge(e[i].u,e[i].v))
			ans+=e[i].c;
	return ans;
}
long long val[2010];
int fpow(int a,int b)
{
	int ans=1,t=a;
	while(b)
	{
		if(b&1)ans=(long long)ans*t%Mod;
		t=(long long)t*t%Mod;
		b>>=1;
	}
	return ans;
}
int main()
{
	long long x;
	scanf("%d %d",&n,&m);
	scanf("%lld",&x);
	for(int i=1;i<=m;i++)
		scanf("%d %d %d",&e[i].u,&e[i].v,&e[i].c);
	sort(e+1,e+m+1,cmp);
	long long ans=1e18;
	for(int i=1;i<=m;i++)
		ans=min(ans,val[i]=work(i));
	if(ans>x){
		printf("0\n");
		return 0;
	}
	int cnt1=0,cnt2=0;
	for(int i=1;i<=m;i++)
		if(val[i]==x)cnt1++;
		else if(val[i]>x)cnt2++;
	if(ans==x)printf("%d\n",((long long)fpow(2,cnt1)-2+Mod)%Mod*fpow(2,cnt2)%Mod);
	else printf("%d\n",((long long)fpow(2,cnt1+1)-2+Mod)%Mod*fpow(2,cnt2)%Mod);
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main
{
  public static void main(String[] args)
  {
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();double sum=0;
    int ar[]=new int[n];
    for(int i=0;i<n;i++)
    {
    ar[i]=sc.nextInt();
    sum+=ar[i];
    }
    double kk=sum/n;
    int gh=(int)Math.round(kk);
    long cost=0;
    for(int i=0;i<n;i++)
    {
        cost+=(ar[i]-gh)*(ar[i]-gh);
    }
    System.out.println(cost);}}
    

Measured memory_bytes: 23636
N = int(input())
mod = 1000000007
from collections import defaultdict as dd
Y = dd(lambda:1)
for i in range(2, N+1):
    M = i
    for j in range(2,i+1):
        while M % j == 0:
            Y[j] += 1
            M //= j

def product(X):
    res = 1
    for x in X:
        res *= x
        res %= mod
    return res    

ans = product(Y.values())
print(ans)


Measured memory_bytes: 9452