akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
 
typedef long long LL;
 
const int maxn=1005;
 
int n,m,x,y,uu[maxn],dd[maxn];
int mp[maxn][maxn];
char s[maxn][maxn];
 
void make(int x1,int x2,int y1,int y2)
{
	if (x1>x2 || y1>y2) return;
	fo(i,x1,x2)
	{
		bool has=0;
		fo(j,y1,y2) if (mp[i][j]!=0) {has=1; break;}
		if (has)
		{
			fo(j,y1,y2) if (mp[i][j]==0 && j>y1 && mp[i][j-1]!=0)
				mp[i][j]=mp[i][j-1] ;
			fd(j,y2,y1) if (mp[i][j]==0 && j<y2 && mp[i][j+1]!=0)
				mp[i][j]=mp[i][j+1] ;
		} else
		{
			if (i==x1) continue;
			if (mp[i-1][y1]!=0)
				fo(j,y1,y2) mp[i][j]=mp[i-1][j] ;
		}
	}
	fd(i,x2,x1)
	{
		bool has=0;
		fo(j,y1,y2) if (mp[i][j]!=0) {has=1; break;}
		if (has)
		{
			fo(j,y1,y2) if (mp[i][j]==0 && j>y1 && mp[i][j-1]!=0)
				mp[i][j]=(mp[i][j-1]) ?mp[i][j-1]:mp[i][j-1] ;
			fd(j,y2,y1) if (mp[i][j]==0 && j<y2 && mp[i][j+1]!=0)
				mp[i][j]=(mp[i][j+1]) ?mp[i][j+1] :mp[i][j+1] ;
		} else
		{
			if (i==x2) continue;
			if (mp[i+1][y1]!=0)
				fo(j,y1,y2) mp[i][j]=(mp[i+1][j]) ?mp[i+1][j] :mp[i+1][j] ;;
		}
	}
}
 
int main()
{
    int kk;
    scanf("%d %d%d",&n,&m,&kk);
    fo(i,1,n) scanf("%s",s[i]+1);   
    int tot=0;
    for (int i=1;i<=n;i++)
        for (int j=1;j<=m;j++) if (s[i][j]=='#') mp[i][j]=++tot;
    
    fo(i,1,n)
        fo(j,1,m) if (mp[i][j]>1) {x=i, y=j; break;}
    
    int up=1, down=n;
    fo(r,y,m) if (r!=y && mp[x][r]!=0) break; else
    {
        fo(i,1,x-1) if (mp[i][r]!=0) up=max(up,i+1);
        fo(i,x+1,n) if (mp[i][r]!=0) down=min(down,i-1);
        uu[r]=up, dd[r]=down;
    }
    up=1, down=n;
    int ansl=y, ansr=y, ansu=x, ansd=x, ans=1;
    fd(l,y,1) if (l!=y && mp[x][l]!=0) break; else
    {
        fo(i,1,x-1) if (mp[i][l]!=0) up=max(up,i+1);
        fo(i,x+1,n) if (mp[i][l]!=0) down=min(down,i-1);
        fo(r,y,m) if (r!=y && mp[x][r]!=0) break; else
        {
            int u=max(up,uu[r]), d=min(down,dd[r]);
            if ((r-l+1)*(d-u+1)>ans)
            {
                ans=(r-l+1)*(d-u+1);
                ansl=l, ansr=r, ansu=u, ansd=d;
            }
        }
    }
 
    fo(i,ansu,ansd)
        fo(j,ansl,ansr) mp[i][j]=mp[x][y];
    make(1,n,1,ansl-1);
    make(1,n,ansr+1,m);
    make(1,ansu-1,ansl,ansr);
    make(ansd+1,n,ansl,ansr);
    
    fo(i,1,n) {
        for (int j=1;j<=m;j++) printf("%d ",mp[i][j]);
        puts("");
    }
}

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

signed main() {
    int R, G, B, N;
    cin >> R >> G >> B >> N;

    int ans = 0;
    for (int r = 0; r * R <= N; r++) {
        for (int g = 0; g * G <= N; g++) {
            int b = N - r * R - g * G;
            if (b < 0 || b % B) continue;
            ans++;
        }
    }
    cout << ans << endl;
}


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

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

int main(){
int q,b;
cin>>q>>b;
int count=0;
for(int i=q;i<=b;i++){
int a[5];
a[0]=i/10000;
a[1]=(i-a[0]*10000)/1000;
a[2]=(i-a[0]*10000-a[1]*1000)/100;
a[3]=(i-a[0]*10000-a[1]*1000-a[2]*100)/10;
a[4]=i-a[0]*10000-a[1]*1000-a[2]*100-a[3]*10;
//cout<<a[0]<<" "<<a[1]<<" "<<a[2]<<" "<<a[3]<<" "<<a[4]<<endl;
if(a[0]==a[4]&&a[1]==a[3])
count++;

}
cout<<count<<endl;


  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int asc(const void*, const void*);
int main(void) {
  int N,M,X[100000],i,dif[99999];
  long ans=0;
  scanf("%d %d",&N,&M);
  for(i=0;i<M;i++)scanf("%d",&X[i]);
  qsort(X,M,sizeof(int),asc);
  for(i=0;i<M-1;i++)dif[i]=X[i+1]-X[i];
  qsort(dif,M-1,sizeof(int),asc);
  if(N<M)for(i=0;i<M-N;i++)ans+=dif[i];
  printf("%ld",ans);
}
int asc(const void *a, const void *b) {
  return *(int *)a - *(int *)b;
}

Measured memory_bytes: 1396
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define int long long
using namespace std;

typedef pair<int, int> Pii;

template<typename T>
void readvec(vector<T> &a);
void readindex(vector<int> &a);

int extgcd(int a, int b, int &x, int &y){
    int d = a;
    if(b != 0){
        d = extgcd(b, a % b, y, x);
        y -= (a / b) * x;
    }else{
        x = 1;
        y = 0;
    }
    return d;
}

int mod_inverse(int a, int m){
    int x, y;
    extgcd(a, m, x, y);
    return (m + x % m) % m;
}


signed main(){

    int M = 998244353;
    int N, A, B, K;
    cin >> N >> A >> B >> K;

    int ans = 0;
    vector<int> fact(N + 1, 1);
    FOR(i, 1, N + 1){
        fact[i] = (fact[i - 1] * i) % M;
    }
    REP(a, N + 1){
        if((K - a * A) % B == 0){
            int b = (K - a * A) / B;
            if(b < 0 || b > N) continue;
            int tmp1 = (((fact[N] * mod_inverse(fact[a], M)) % M) * mod_inverse(fact[N - a], M)) % M;
            int tmp2 = (((fact[N] * mod_inverse(fact[b], M)) % M) * mod_inverse(fact[N - b], M)) % M;
            ans = (ans + tmp1 * tmp2) % M;
        }
    }

    cout << ans;

    return 0;
}


template<typename T>
void readvec(vector<T> &a){
    REP(i, a.size()){
        cin >> a[i];
    }
}
void readindex(vector<int> &a){
    REP(i, a.size()){
        cin >> a[i];
        a[i]--;
    }
}

Measured memory_bytes: 2560
class Dice
  def initialize(args)
    @labels = args
  end

  def top
    @labels[0]
  end

  def move(a,b,c,d)
    arr = [@labels[a], @labels[b], @labels[c], @labels[d]]
    t = arr.shift
    arr << t
    @labels[a], @labels[b], @labels[c], @labels[d] = arr
  end

  def move_n
    move(0,1,5,4)
  end

  def move_e
    move(0,3,5,2)
  end

  def move_s
    move(4,5,1,0)
  end

  def move_w
    move(2,5,3,0)
  end
end

input = gets.split.map(&:to_i)
dice = Dice.new(input)

gets.chomp.chars.map do |v|
  case v
  when 'E'
    dice.move_e
  when 'N'
    dice.move_n
  when 'S'
    dice.move_s
  when 'W'
    dice.move_w
  end
end

p dice.top

Measured memory_bytes: 6112
#[allow(unused_macros)]
macro_rules! invec {
    ( $t:ty ) => {{
        let mut s = String::new();
        match std::io::stdin().read_line(&mut s) {
            Ok(0) => Vec::<$t>::new(),
            Ok(n) => s.trim().split_whitespace().map(|s| s.parse::<$t>().unwrap()).collect::<Vec<$t>>(),
            Err(_) => Vec::<$t>::new(),
        }
    }}
}

#[allow(unused_macros)]
macro_rules! input {
    ( $($t:ty),* ) => {{
        let mut s = String::new();
        std::io::stdin().read_line(&mut s);
        let mut splits = s.trim().split_whitespace();
        ($(
            {
                 splits.next().unwrap().parse::<$t>().unwrap()
            },
        )*)
    }}
}

struct Combinations<T: Copy, R: Copy> {
    a: Vec<T>,
    b: Vec<R>,
    a_counter: usize,
    b_counter: usize,
}

impl<T: Copy, R: Copy> Combinations<T, R> {
    fn new(a: Vec<T>, b: Vec<R>) -> Combinations<T, R> {
        Combinations { a: a, b: b, a_counter: 0, b_counter: 0 }
    }
}

impl<T: Copy, R: Copy> Iterator for Combinations<T, R> {
    type Item = (T, R);

    fn next(&mut self) -> Option<Self::Item> {
        if self.a_counter >= self.a.len() {
            return None;
        }

        let val = Some((self.a[self.a_counter], self.b[self.b_counter]));
        if self.b_counter + 1 < self.b.len() {
            self.b_counter += 1;
        } else {
            self.a_counter += 1;
            self.b_counter = 0;
        }
        return val;
    }
}

#[allow(unused_must_use)]
#[allow(unused_variables)]
fn solve() {
    let (n, k) = input!(usize, usize);
    let arr = invec!(i64);

    let max = (n-1) * (n-2) / 2;

    if max < k {
        println!("-1");
        return;
    }

    let add = max - k;
    let mut edge = Vec::with_capacity(n - 1 + add);
    for i in 1..n {
        edge.push((i, n));
    }

    edge.append(&mut Combinations::new((1..n).collect(), (1..n).collect())
                    .filter(|&(a, b)| a < b)
                    .take(add)
                    .collect());
    
    println!("{}", edge.len());

    for val in edge {
        println!("{} {}", val.0, val.1);
    }
}

fn main() {
    solve();
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#include <cmath>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define been(ix) (ix).begin(),(ix).end()
using namespace std;
typedef long long ll; 
typedef vector<int> vi;
typedef vector<long long> vl;
const ll INFL = 1e18;
const int INF = 1001001001; 
typedef pair<int,int> P;
#define foreach(ix,i) for(auto& (ix) : (i))
typedef long double ld;
const int mod =1000000007;
int main(){
  string s,t;
  cin>>s>>t;
  int res[s.length()],ans[t.length()];
  map<char,int>me;
  for(char v ='a';v<='z';v++){
    me[v]=0;
  }
  int x =1;
  rep(i,s.length()){
    if(me[s[i]]==0){
      me[s[i]]=x;
      x++;
    }
    res[i]=me[s[i]];
  }
  for(char v ='a';v<='z';v++){
    me[v]=0;
  }
  x =1;
  rep(i,s.length()){
    if(me[t[i]]==0){
      me[t[i]]=x;
      x++;
    }
    ans[i]=me[t[i]];
  }
  bool f =true;
  rep(i,s.length()){
    if(ans[i]!=res[i])f=false;
    //cout<<ans[i]<<res[i]<<endl;
  }
  if(f)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 2312
#include<stdio.h>
int main(){
	int m,n,a,b,t,f;
	scanf("%d %d %d %d",&m,&n,&a,&b);
	t=m*n;
	f=a*b;
	if(t>f) printf("%d",t);
	else printf("%d",f);
	return 0;
}


Measured memory_bytes: 128
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>
#include <stack>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> void printvec(const vector<T>& v) {
  for (auto x : v) { cout << x << " "; }
  cout << endl;
}
template<class T> void printtree(const vector< vector<T> >& tree) {
  for (long long i = 0; i < tree.size(); ++i) {
    cout << i + 1 << ": "; printvec(tree[i]);
  }
}
template<class T, class U> void printmap(const map<T, U>& mp) {
  for (auto x : mp) { cout << x.first << "=>" << x.second << endl; }
}

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

#define rep(i, n) for(ll i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()
#define sz(x) (ll)(x).size()
#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;
typedef vector<ll> vl;
typedef vector<P> vp;

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7

int main(int argc, char** argv) {
  cin.tie(NULL);
  cout.tie(NULL);
  ios_base::sync_with_stdio(false);
  //cout << setprecision(10) << fixed;

  ll n;
  cin >> n;
  vector<ll> a(n);
  vector<ll> b(n);
  rep(i,n) {
    cin >> a[i] >> b[i];
  }

  if (n%2 == 0) { // even
    sort(all(a));
    ll minX2 = a[n/2] + a[n/2-1];

    sort(all(b));
    ll maxX2 = b[n/2] + b[n/2-1];

    ll ans = (maxX2 - minX2) + 1;
    cout << ans << endl;
  } else { // odd
    sort(all(a));
    ll minX = a[n/2];
    sort(all(b));
    ll maxX = b[n/2];
    cout << (maxX - minX) + 1 << endl;
  }
}


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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  int res = 0, c = 1;
  for (int i = 0; i < N; i++) {
    if (c == A[i]) {
      c++;
      res++;
    }
  }
  cout << (res != 0 ? N - res : -1) << '\n';
  return 0;
}


Measured memory_bytes: 1024
S = input()

N = 13
# dp[k] -> 13で割った余りがKのパターン数
dp = [0] * N
dp[0] = 1

# 後ろから解くアルゴリズム
# 1?2?3   0 -> 3 -> ?3 -> 2?3 -> ...
mod = 10**9 + 7

mul = 1
for i in range(len(S))[::-1]:
    # 次の状態
    nextDP = [0] * N
    if S[i] == '?':
        for k in range(10):
            for j in range(N):
                nextDP[(k * mul + j) % N] += dp[j]
                nextDP[(k * mul + j) % N] %= mod
    else:
        k = int(S[i])
        for j in range(N):
            nextDP[(k * mul + j) % N] += dp[j]
            nextDP[(k * mul + j) % N] %= mod
    mul *= 10
    mul %= N
    dp = nextDP

print(dp[5])

Measured memory_bytes: 43500
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define set_bits(a) __builtin_popcount(a)
#define pb push_back
#define pf push_front
#define mod 1000000007
#define fi first
#define se second
#define endl '\n'
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);


int main()
{
    double n;
    cin>>n;
    ll i,j;
    long  double length = (double)n/(double)3;

    n-=length;
    //cout<<n<<endl;

    long double breadth = (double)n/(double)2;

    //cout<<length<<" "<<breadth<<endl;
    long double height = (double)n-(double)breadth;
    //cout<<height<<endl;

    double ans = length*breadth*height;
    cout<<fixed<<setprecision(6)<<ans<<endl;
}


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

using namespace std;

int dp[101][4][4][4]; 

int main(){

    int N;
    cin >> N;

    //長さ０の文字列は1である。
    //0,1,2に関する制約しかない。
    dp[0][3][3][3] = 1;

    int mod = 1e9 + 7;

    //文字列の文字数
    for(int len = 0; len < N; len++){
        //最後から一文字目の文字
        for(int c1 = 0; c1 < 4; c1++){
            //最後から二文字目の文字
            for(int c2 = 0; c2 < 4; c2++){
                //最後から三文字目の文字
                for(int c3 = 0; c3 < 4; c3++){
                    //条件に当てはまるものがない場合はcontinue
                    if(dp[len][c1][c2][c3] == 0) continue;

                    //新しく追加する文字
                    for(int a = 0; a < 4; a++){
                        //ダメな５つの条件をカットする。
                        if(a == 2 && c1 == 1 && c2 == 0) continue;
                        if(a == 2 && c1 == 0 && c2 == 1) continue;
                        if(a == 1 && c1 == 2 && c2 == 0) continue;
                        if(a == 2 && c1 == 1 && c3 == 0) continue;
                        if(a == 2 && c2 == 1 && c3 == 0) continue;

                        //ダメな条件を抜けたら、aを足した文字列が作れるので、
                        dp[len+1][a][c1][c2] += dp[len][c1][c2][c3];
                        dp[len+1][a][c1][c2] %= mod;
                    }
                }
            }
        }
    }

    int ans = 0;
    
    for(int c1 = 0; c1 < 4; c1++){
        for(int c2 = 0; c2 < 4; c2++){
            for(int c3 = 0; c3 < 4; c3++){
                ans += dp[N][c1][c2][c3];
                ans %= mod;
            }
        }
    }

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,b,a) for(int i=b;i>=a;i--)
#define fori(a) for(auto i : a )
#define all(a) begin(a), end(a)
#define set(a,b) memset(a,b,sizeof(a))
#define sz(a) a.size()
#define pi 3.14159
#define ll long long
#define ull unsigned long long
#define pb push_back
#define PF push_front //deque
#define mp make_pair
#define pq priority_queue
#define mod 1000000007
#define f first
#define s second
#define pii pair< int, int >
#define vi vector<int>
#define vpii vector<pii>
#define debug(v) for(auto i:v) cout<<i<<" ";
#define tc int t; cin >> t; while(t--)

using namespace std;
string repeat(string s, int n) {
    string s1 = "";
    for (int i=0; i<n;i++)
        s1+=s;
    return s1;
}
string getString(char x) {
    string s(1, x);
    return s;
}

void optimizeIO(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
int gcd(int a, int b){
    if (a == 0)  return b;
    return gcd(b % a, a);
}
void  solve(){
  int a[5];
  rep(i,0,5) cin>>a[i];
  vector<pair<int,int>>v ;
  rep(i,0,5) if(a[i]%10!=0) v.pb({a[i]%10,i});
  sort(all(v));
  int idx=-1;
  if(v.size()>0) idx= v[0].s;

  ll ans=0;
  rep(i,0,5){
    if(idx!=i) ans+= ((a[i]+9)/10)*10;
  }
  if(idx!=-1) ans+= a[idx];
  cout<<ans<<endl;
}
int main(){
    optimizeIO();
    // tc
    { solve();
    }
}


Measured memory_bytes: 3640
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#define r(i,n) for(int i=0; i<n; i++)
typedef long long ll;
using namespace std;

int main(void){
  int x, n, a;
  cin >> x >> n >> a;
  cout << (x-n)%a << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define L 100000
int main(){
  int i,j,k;
  int A[L+1];
  int min=0;
  for(i=0;i<=L;i++)
    A[i]=0;
  
  int N;
  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf("%d ",&j);
    A[j]++;
  }
  
  for(i=0;i<=L;i++){
    if(i==L){
      if(A[i-1] + A[i] > min){
        min = A[i-1] + A[i];
      }
    }
    else if(i == 0){
      if(A[i] + A[i+1] >min){
        min = A[i] + A[i+1];
      }
    }
    else{
    if(A[i-1] + A[i] + A[i+1] > min){
      min = A[i-1] + A[i] + A[i+1];
    }}
  }
  
  printf("%d\n",min);
  return 0;
}
    

Measured memory_bytes: 512
#include <iostream>
#include <utility>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
using namespace std;
#define MAXSIZE 200
#define MAXL 100
typedef long long int lli;

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

    vector<lli> c_vec, s_vec, f_vec;
    for(lli i = 0; i < n - 1; i++){
        lli c_input, s_input, f_input;
        cin >> c_input >> s_input >> f_input;
        c_vec.push_back(c_input);
        s_vec.push_back(s_input);
        f_vec.push_back(f_input);
    }

    for(lli inist = 0; inist < n; inist++){
        if(inist == n - 1){
            cout << "0" << endl;
        }else{
            lli eltime = 0;
            for(lli curst = inist; curst < n - 1; curst++){
                if(curst == inist){
                    eltime += s_vec[curst] + c_vec[curst];
                }else{
                    if(eltime >= s_vec[curst]){
                        lli jtime = (eltime - s_vec[curst]) % f_vec[curst];
                        if(jtime == 0){
                            eltime += c_vec[curst];
                        }else{
                            eltime += f_vec[curst] - jtime + c_vec[curst];
                        }
                    }else{
                        eltime += s_vec[curst] - eltime + c_vec[curst];
                    }
                }
            }
            cout << eltime << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
typedef vector<vector<P>> vvP;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

int main() {
    string s;
    cin >> s;
    cout << s.substr(0, 5) << " " << s.substr(6, 7) << " " << s.substr(14, 5) << endl;
    re0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e15;
const ll MOD = 100000000;
const ll MOD2 = 998244353;
typedef pair<ll,ll> P;
const ll MAX = 200010;
constexpr ll nx[8] = {1,0,-1,0,-1,-1,1,1};
constexpr ll ny[8] = {0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,m,x;
    cin >> n >> m >> x;
    vector<vector<ll>> book(n,vector<ll>(m));
    vector<ll> cost(n);
    rep(i,n){
        cin >> cost[i];
        rep(j,m) cin >> book[i][j];
    }
    ll ans = INF;
    rep(bit,(1<<n)){
        vector<ll> cnt(m,0);
        ll c = 0;
        rep(i,n){
            if (bit&(1<<i)){
                c += cost[i];
                rep(j,m){
                    cnt[j] += book[i][j];
                }
            }
        }
        bool ok = 1;
        rep(i,m){
            if (cnt[i] < x) ok = 0;
        }
        if (ok) chmin(ans,c);
    }
    if (ans != INF) PRINT(ans);
    else PRINT(-1);
}


Measured memory_bytes: 3664
N = gets.to_i
A = gets.split.map &:to_i

t = [ 0, 0, 0 ]

result = 1
for i in 0..N-1
  if t.count( A[i] ) == 0
    result = 0
    break
  end
  result = ( result * t.count( A[i] ) ) % 1000000007
  for j in 0..2
    if t[j] == A[i]
      t[j] += 1
      break
    end
  end
end
puts result

Measured memory_bytes: 10628
# F - XOR Matching
from collections import deque

m, k = map(int, input().split())

# k>=2^mの時は成立しない
if k>=pow(2,m):
    print(-1)

# m=0の時
elif m==0:
    print(0, 0)

# m=1の時
elif m==1:
    if k==0:
        print(0, 0, 1, 1)
    else:
        print(-1)

# m>=2の時
else:
    ans = deque()
    ans.append(k)
    for i in range(pow(2,m)):
        if i!=k:
            ans.append(i)
            ans.appendleft(i)
    ans.append(k)
    print(' '.join(map(str, ans)))

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

int main() {
  std::string s;
  std::cin >> s;
  int ans;
  for (int bit = 0; bit < (1 << 4); ++bit) {
    int res = s[0] - '0';
    for (int i = 0; i < 3; ++i) {
      if (bit & (1 << i)) {
        res += (s[i + 1] - '0');
      } else {
        res -= (s[i + 1] - '0');
      }
    }
    if (res == 7) {
      ans = bit;
      break;
    }
  }
  std::string ops = "";
  for (int i = 0; i < 3; i++) {
    if (ans & (1 << i)) {
      ops += '+';
    } else {
      ops += '-';
    }
  }
  std::cout << s[0] << ops[0] << s[1] << ops[1] << s[2] << ops[2] << s[3] << "=7" << "\n";
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define endl "\n" 
using namespace std;
#define debug(x) cout<<"The value of "<<#x<<" is "<<x<<endl;
typedef long long ll;
typedef unsigned long long ull;

int main()
{
    cin.sync_with_stdio(0); cin.tie(0); 
    int k,n;
    cin>>k>>n;
    vector<int>arr(n);
    for(auto& i:arr)
    cin>>i;
    vector<int>dis;
    for(int i=0;i<n-1;i++)
    dis.push_back(arr[i+1]-arr[i]);
    dis.push_back(arr[0]+(k-arr.back()));
    //take n-1 elements 
    //how??
    int sum=0;
    for(auto i:dis)
    sum+=i;
    int ans=k;
    for(int i=0;i<dis.size();i++)
    ans=min(ans,sum-dis[i]);
    cout<<ans<<endl;
}


Measured memory_bytes: 5064
#include <iostream>
#include <iomanip>
// std::cout << std::setprecision(2) << 3.141; // "3.1"
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <map>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;

static const int giga = pow(10,9);
// double pi = 3.141592653589793238463;

int main(void){
  int a,b,c;
  cin >> a >> b >> c;
  if(((a < c) && (c < b)) || ((b < c) && (c < a))){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
   

  return 0;
}

Measured memory_bytes: 256
// E - Colorful Hats 2
#include <bits/stdc++.h>

using namespace std;

#define	MOD	1000000007

int main(int argc, char *argv[])
{
	ios::sync_with_stdio(false); cin.tie(0);
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) cin >> a[i];
	vector<long long> dp(n), c(n);
	for (int i = 0; i < n; i++) {
		int x = a[i];
		long long m = (x == 0 ? 3LL : c[x - 1]) - c[x];
		if (i == 0) dp[i] = x == 0 ? 3LL : 0;
		else dp[i] = dp[i - 1] * m % MOD;
		c[x]++;
	}

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

	return 0;
}


Measured memory_bytes: 2304
#include<iostream>
using namespace std;
int main(){
  int n, m;
  while(cin >> n >> m , n){
    bool can[500] = {}, precan[500][500] = {{}};
    while(m--){
      int a, b;
      cin >> a >> b;
      if( a > b ) swap( a, b);
      if( a == 1 ) can[b - 1]++;
      else precan[b - 1][a - 1]++, precan[a - 1][b - 1]++;
    }
    bool ret[500] = {};
    for(int i = 1 ; i < n ; i++ ){
      if(can[i]){
        for(int j = 1 ; j < n ; j++ ){
          if(precan[i][j]) ret[j]++;
        }
      }
    }
    int cnt = 0;
    for(int i = 1 ; i < n ; i++ ){
      if(can[i] || ret[i]) cnt++;
    }
    cout << cnt << endl;
  }
}

Measured memory_bytes: 1412
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; 
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

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

    int n;cin>>n;
    queue<int> q;
    rep(i,n){
        int a;cin>>a;
        q.push(a);
    }
    int ans=0;
    int num=1;
    while(!q.empty()){
        if(q.front()==num){
            num++;
            q.pop();
        }else{
            ans++;
            q.pop();
        }
    }
    if(ans==n) cout<<-1<<endl;
    else cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1152
#include <iostream>
#include <stdio.h>
#include <string>
#include <list>
#include <vector>
#include <algorithm>

#define rep(i,n) for(int i = 0;i < n;i++)
#define REP(i,n,k) for(int i = n;i < k;i++)
#define P(p) cout << (p) << endl;//print
typedef long long ll;
using namespace std;

int main(){
    cin.tie(0);
   	ios::sync_with_stdio(false);
    
    int n;
    cin >> n;
    int ans=0;
    rep(i,n){
        int s,e;
        cin >> s >> e;
        ans = ans + e - s + 1;
    }
    P(ans);
}


Measured memory_bytes: 256
#include<bits/stdc++.h> 
using namespace std;
typedef long long ll;
template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;}
template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;}
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
long double eps = 1e-9;
long double pi = acos(-1);


signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);


    ll a,b,x,y;
    cin>>a>>x>>b>>y;
    ll t;
    cin>>t;
    bool pos = true;
    if(y>=x)pos=false;
    else{
        swap(x,y);
        y -= x;
        y *= t;
        ll dif = abs(a-b);
        if(dif > y)pos= false;
    }
    if(pos)cout << "YES\n";
    else cout << "NO\n";
}

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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

const string YES = "Yes";
const string NO = "No";

int main(){
    int x, y;
    cin >> x >> y;
    rep(c, x+1) {
        int t = x - c;
        if (2*c+4*t == y) {
            cout << YES << endl;
            return 0;
        }
    }
    cout << NO << endl;
    return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
long long n,m;
int main(){
	cin>>n;
	cin>>m;
	if(n==1||m==1){
		cout<<1<<endl;
		return 0;
	}
	if((n*m)%2){
		cout<<n*m/2+1;
	}
	else cout<<n*m/2<<endl;
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;

namespace AC
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = ReadArrayInt();
            var X = input[0];
            var Y = input[1];
            var ans = false;
            for (int i = 0; i <= X; i++)
            {
                var legs = i * 2 + (X - i) * 4;
                if (legs == Y)
                {
                    ans = true;
                    break;
                }
            }

            Console.WriteLine(ans ? "Yes" : "No");
            Console.ReadLine();
        }

        static string Read() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Read()); }
        static long ReadLong() { return long.Parse(Read()); }
        static string[] ReadArrayString() { return Read().Split(' '); }
        static int[] ReadArrayInt() { return Read().Split(' ').Select(s => int.Parse(s)).ToArray(); }
        static long[] ReadArrayLong() { return Read().Split(' ').Select(s => long.Parse(s)).ToArray(); }
    }
}

Measured memory_bytes: 28300
import java.io.*;
import java.nio.CharBuffer;
import java.util.NoSuchElementException;

public class Main {

    public static void main(String[] args) {
        SimpleScanner scanner = new SimpleScanner(System.in);
        PrintWriter writer = new PrintWriter(System.out);

        char[] s = scanner.next().toCharArray();
        int n = s.length;
        long k = scanner.nextLong();
        int lead = 0, tail = 0, mid = 0;
        for (int i = 0; i < n; ) {
            int j = i;
            while (j < n && s[j] == s[i])
                ++j;
            int len = j - i;
            if (i == 0)
                lead = len;
            else if (j == n)
                tail = len;
            else
                mid += len / 2;
            i = j;
        }
        if (lead == n) {
            writer.println(n * k / 2);
        } else if (s[0] == s[n - 1]) {
            writer.println((lead + tail) / 2 * (k - 1) + lead / 2 + tail / 2 + mid * k);
        } else {
            writer.println((lead / 2 + tail / 2 + mid) * k);
        }


        writer.close();
    }

    private static class SimpleScanner {

        private static final int BUFFER_SIZE = 10240;

        private Readable in;
        private CharBuffer buffer;
        private boolean eof;

        SimpleScanner(InputStream in) {
            this.in = new BufferedReader(new InputStreamReader(in));
            buffer = CharBuffer.allocate(BUFFER_SIZE);
            buffer.limit(0);
            eof = false;
        }


        private char read() {
            if (!buffer.hasRemaining()) {
                buffer.clear();
                int n;
                try {
                    n = in.read(buffer);
                } catch (IOException e) {
                    n = -1;
                }
                if (n <= 0) {
                    eof = true;
                    return '\0';
                }
                buffer.flip();
            }
            return buffer.get();
        }

        private void checkEof() {
            if (eof)
                throw new NoSuchElementException();
        }

        private char nextChar() {
            checkEof();
            char b = read();
            checkEof();
            return b;
        }

        private String next() {
            char b;
            do {
                b = read();
                checkEof();
            } while (Character.isWhitespace(b));
            StringBuilder sb = new StringBuilder();
            do {
                sb.append(b);
                b = read();
            } while (!eof && !Character.isWhitespace(b));
            return sb.toString();
        }

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

        private long nextLong() {
            return Long.parseLong(next());
        }

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

Measured memory_bytes: 21588
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

int main()
{
	int R, G, B, N;
	cin >> R >> G >> B >> N;
	ll ans = 0;
	for (int r = 0; r <= N; r++) {
		for (int g = 0; g <= N; g++) {
			if (N - r * R - g * G >= 0 && (N - r * R - g * G) % B == 0) ans++;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline

n, m, l = map(int, input().split())

INF = float("INF")

d = [[INF] * n for _ in range(n)]
for i in range(n):
    d[i][i] = 0

for i in range(m):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    d[a][b] = c
    d[b][a] = c

for k in range(n):
    for i in range(n):
        for j in range(n):
            if d[i][j] > d[i][k] + d[k][j]:
                d[i][j] = d[i][k] + d[k][j]

# print()
# print(*d, sep='\n')

for i in range(n):
    for j in range(n):
        if i == j:
            continue

        if d[i][j] <= l:
            d[i][j] = 1
        else:
            d[i][j] = INF

for k in range(n):
    for i in range(n):
        for j in range(n):
            if d[i][j] > d[i][k] + d[k][j]:
                d[i][j] = d[i][k] + d[k][j]

# print()
# print(*d, sep='\n')

q = int(input())
for i in range(q):
    s, t = map(int, input().split())
    s -= 1
    t -= 1

    if d[s][t] == INF:
        print(-1)
    else:
        print(d[s][t]-1)


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

const double pi  = 2 * acos(0.0);
const double eps = 1e-8;

#define REP(i,a,b) for(int i=(a); i<(b);++i)
#define rep(i,n) REP(i,0,n)
#define INF (1<<29)
#define INFLL (1L<<62)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

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

int main(void) {
  ios_base::sync_with_stdio(false); cin.tie(0);
  int D, E;
  while (cin >> D >> E, D && E) {
    double min_cost = INF;
    for (int x = 0; x <= D; x++) {
      int y = D - x;
      min_cost = min(min_cost, fabs(sqrt(x * x + y * y) - E));
    }
    cout << fixed << setprecision(10) << min_cost << endl;
  }
  return 0; 
}

Measured memory_bytes: 3204
import java.util.*;


public class Main {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
      int a=sc.nextInt();
      int b=sc.nextInt();
      if(a==1)a=14;
      if(b==1)b=14;
      System.out.println((a==b)?"Draw":(a<b)?"Bob":"Alice");
      
    }
}


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

int main()
{
  string s,t;cin>>s>>t;
  sort(s.begin(), s.end());
  sort(t.rbegin(), t.rend());
  if(s<t){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int t;
    cin>>t; cin.ignore(); vector < pair<int, string> > v;
    vector <string> v1;
    map <string,int> mp;
    for (int i=0;i<t;i++){
        string a;
        cin>>a;
        mp[a]++;
    }
    int max=0;
    for (auto it=mp.begin();it!=mp.end();it++){
        v.push_back(make_pair(it->second, it->first));
    }
    sort(v.rbegin(),v.rend());
    for (int i=0;i<v.size();i++){
        if (v[i].first>=max){
            v1.push_back(v[i].second);
            max=v[i].first;
        }
    }
    sort(v1.begin(),v1.end());
    for (int i=0;i<v1.size();i++)
        cout<<v1[i]<<endl;
   

}

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

int main(void){
    int n;
    cin >> n;
    vector<int> a(n), b(n), c(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    for(int i = 0; i < n; i++) cin >> b[i];
    for(int i = 0; i < n; i++) cin >> c[i];
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    sort(c.begin(), c.end());
    long long ans = 0;
    long numa = 0, numc = 0;
    for(int i = 0; i < n; i++){
        while(numa < n && a[numa] < b[i]) numa++;
        while(numc < n && c[numc] <= b[i]) numc++;
        ans += numa * (n - numc);
    }
    cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1408
import sys
sys.setrecursionlimit(10**9)
n,m=map(int,input().split())
ab=[[0,0]  for i in range(m)]
for i in range(m):
    ab[i][0],ab[i][1]=map(int,input().split())
ans=0
for i in range(m):
    root=[j for j in range(n+1)]
    root[0]=1
    def r(x):
        if root[x]==x:
            return x
        else:
            root[x]=r(root[x])
            return root[x]
    def unite(x,y):
        x=r(x)
        y=r(y)
        if x==y:
            return
        else:
            x,y=min(x,y),max(x,y)

            root[y]=x
    for j in range(m):
        if j!=i:
            a,b=ab[j][0],ab[j][1]
            unite(a,b)

    if not all(r(j)==1 for j in range(1,n+1)):
        ans+=1
print(ans)



Measured memory_bytes: 68040
#include<iostream>
#include<algorithm>
#include<vector>
#include<math.h>
#include <iomanip>

using namespace std;
int main(){
    int N, M;
    cin >> N>>M;
    int L[M], R[M];
    int lmax = 0; 
    int rmin = N;
    for(int i = 0; i < M; i++){
        cin >> L[i] >> R[i];
        if(L[i] > lmax)lmax = L[i];
        if(R[i] < rmin)rmin = R[i];
    }
    if(lmax > rmin)cout << 0;
    else cout << rmin-lmax +1;

}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) FOR(i,0,n)
#define repr(i,n) for(int i=(n)-1;0<=i;--i)
#define each(e,v) for(auto&& e:(v))
#define all(v) begin(v),end(v)
#define dump(x) cerr<<#x<<": "<<(x)<<endl
using namespace std;
using vint = vector<int>;
using ll = long long;
using vll = vector<ll>;
template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }

template <class E>
using Graph = vector<vector<E>>;

struct Edge {
    int to, cost;
    Edge(int to, int cost): to(to), cost(cost) {}
};

template <class E>
void addEdge(Graph<E>& graph, int from, int to, int cost) {
    graph[from].push_back(E(to, cost));
    graph[to].push_back(E(from, cost));
}

int main() {
    int n, m; cin >> n >> m;
    Graph<Edge> g(n);
    rep(i, m) {
        int a, b; cin >> a >> b;
        addEdge(g, a-1, b-1, 1);
    }
    for(Edge via: g[0]) {
        for(Edge e: g[via.to]) {
            if(e.to == n-1) {
                cout << "POSSIBLE" << endl;
                return 0;
            }
        }
    }
    cout << "IMPOSSIBLE" << endl;
    return 0;
}


Measured memory_bytes: 12776
def resolve():
    N, T = list(map(int, input().split()))
    timings = list(map(int, input().split()))
    total = T
    for i in range(1, len(timings)):
        if timings[i-1] + T > timings[i]:
            total -= timings[i-1] + T - timings[i]
        total += T
    print(total)

if '__main__' == __name__:
    resolve()

Measured memory_bytes: 26708
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <set>
#include <string>
#include <iostream>
#include <cassert>
#include <cmath>
#include <cstdlib>
#include <cstring>
using namespace std;

int main() {
        int n;
        scanf("%d", &n);
        vector<int> cnt(4);
        for (int i = 0; i < n; i ++) {
                string s;
                cin >> s;
                if (s[0] == 'P') cnt[0] ++;
                if (s[0] == 'W') cnt[1] ++;
                if (s[0] == 'G') cnt[2] ++;
                if (s[0] == 'Y') cnt[3] ++;
        }
        int res = 0;
        for (int i = 0; i < 4; i ++) {
                res += cnt[i] > 0;
        }
        puts(res == 3 ? "Three" : "Four");
        return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}




ll ans[55][55];
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  ll H, W;
  cin >> H >> W;

  rep(i,H){
    string inp;
    cin >> inp;
    rep(j,inp.size()){
      if(inp[j] == '#') ans[i+1][j+1] = 10;
    }
  }

  rep(i,H+1)rep(j,W+1){
    if(ans[i][j] != 10){
      ll ret = 0;
      for(ll m = -1; m <= 1; m++){
	for(ll n = -1; n <= 1; n++){
	  if(ans[i+m][j+n] == 10) ret++;
	}
      }
      ans[i][j] = ret;
    }
  }

  rep(i,H+1){
    rep(j, W+1){
      if(i==0  || j ==0) continue;
      if(ans[i][j] == 10) cout << '#' ;
      else cout << ans[i][j] ;
      
    }
    cout << endl;
  }
  
  //cout << fixed << setprecision(16) << ans << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;
const long long MOD=1e09+7;



#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,m,n) for(int i=m;i<n;i++)
#define ALL(v) v.begin(), v.end()
#define pb push_back



      






int main(){
  
  ll n;
  cin>>n;
  
  ll sum=0;
  rep(i,n){
    sum+=i;
  }
  
  cout<<sum<<endl;

}












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

int main()
{
    int N;
    cin>>N;
    vector<vector<int>> E(N);
    for (int i=0; i<N-1; i++)
    {
        int u, v;
        cin>>u>>v;
        E[u-1].push_back(v-1);
        E[v-1].push_back(u-1);
    }

    long long ans = 0;
    for (int i=0; i<N; i++)
    {
        ans += (long long)(i+1)*(N-i);
        for (int e: E[i])
            if (e<i)
                ans -= (long long)(e+1)*(N-i);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 14556
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
s = []
for i in range(10):
    for p in itertools.product(['3','5','7'],repeat=i):
        if '3' in p and '5' in p and '7' in p:
            s.append(int(''.join(p)))
res = 0
for i,t in enumerate(s):
    if t <= n:
        res += 1
print(res)

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

using namespace std;
typedef long long ll;
#define sz size()
#define pb(x) push_back(x) 
#define bg begin()
#define ed end()
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define mp(x,y) make_pair(x,y)

int main(){
	ll N,K; cin>>N>>K;//NコをK色で塗る
	//(K-1)^(N-1) x K
	ll ans=1;
	rep(i,N-1) ans*=(K-1);
	ans*=K;
	cout<<ans;
}

Measured memory_bytes: 256