akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Linq;
using System.Collections.Generic;

class Program
{

    static void Main(string[] args)
    {
        var n = int.Parse(Console.ReadLine());
        var v = new int[n];
        // x:a1,a3,... y:a2,a4,...
        // x,yの値出現回数をカウントする
        var xCounts = new Dictionary<int, int>();
        var yCounts = new Dictionary<int, int>();
        var inputs = Console.ReadLine().Split(' ');
        for (int i = 0; i < n; i++)
        {
            var vi = int.Parse(inputs[i]);
            v[i] = vi;
            Dictionary<int, int> counts = null;
            if (i % 2 == 0)
            {
                counts = xCounts;
            }
            else
            {
                counts = yCounts;
            }
            if (counts.ContainsKey(vi))
            {
                counts[vi]++;
            }
            else
            {
                counts.Add(vi, 1);
            }
        }

        // 出現頻度でソートして最頻値を使用するとコストが最小になる
        var xList = xCounts.OrderByDescending(pair => pair.Value).Select(p => p.Key).ToList();
        var yList = yCounts.OrderByDescending(pair => pair.Value).Select(p => p.Key).ToList();
        if (yList.Count == 1)
        {
            yList.Add(0);
        }
        int cost = int.MaxValue;
        foreach (var x in xList.Take(2))
        {
            foreach (var y in yList.Take(2))
            {
                if (x == y)
                {
                    continue;
                }

                int calc = CalcCost(x, y, v);
                cost = Math.Min(calc, cost);
                calc = CalcCost(x, y, v);
                cost = Math.Min(calc, cost);
            }
        }

        Console.WriteLine(cost);

    }

    static int CalcCost(int x, int y, int[] v)
    {
        int cost = 0;
        for (int i = 0; i < v.Length; i++)
        {
            int value;
            if (i % 2 == 0)
            {
                value = x;
            }
            else
            {
                value = y;
            }

            if (v[i] != value)
            {
                cost++;
            }
        }

        return cost;
    }
}



Measured memory_bytes: 24928
#include <bits/stdc++.h>
#define lol long long
using namespace std;
int main(){
    int a,b,c[5];
    string s,t,q;
    cin>>c[0]>>c[1]>>c[2];
    sort(c,c+3);
    cout<<c[0]+c[1]<<"\n";
    return(0);
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
vector<int>g[100005];
int n;
inline int dfs(int x, int fa)
{
    int l1=g[x].size();
    int res=0;
    for(int i=0;i<l1;i++) 
	{
        int v=g[x][i];
        if(v!=fa)
            res+=dfs(v,x);
    }
    if(res>=2) 
	{
        printf("First\n");
        exit(0);
    }
    if(res==0) 
		return 1;
    return 0;
}
int main() 
{
	scanf("%d",&n);
	for(int i=1;i<n;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		g[x].push_back(y);
		g[y].push_back(x);
	}
    if(dfs(1,-1)) 
        printf("First\n");
    else
        printf("Second\n");
}

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

typedef struct restaurant{
    int number;
    char city[10];
    int point;
}RESTAURANT;

int compare(const void *a, const void *b){
    RESTAURANT ra = *(RESTAURANT *)a;
    RESTAURANT rb = *(RESTAURANT *)b;
    int cmp = strcmp(ra.city,rb.city);
    if(cmp==0){
        return rb.point - ra.point;
    }else{
        return cmp;
    }
}

int main(){

    int n;
    scanf("%d",&n);
    struct restaurant a[n];
    for(int i=0;i<n;i++){
        a[i].number =i+1;
        scanf("%s %d",a[i].city,&(a[i].point));
    }

    qsort(a,n,sizeof(RESTAURANT),compare);

    for(int i=0;i<n;i++){
        printf("%d\n",a[i].number);
    }

    return 0;
}

Measured memory_bytes: 128
import java.util.*;

public class Main{
  public static void main(String[] args) {
    Scanner sc=new Scanner(System.in);
    int r=sc.nextInt();
    if(r<1200){
      System.out.println("ABC");
    }else{
      if(r<2800){
         System.out.println("ARC");
      }else{
         System.out.println("AGC");
      }
    }
    
  }
}


Measured memory_bytes: 23760
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
typedef long long ll;
using namespace std;
const ll mod = 1000000007;
ll A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z;
void KagamiMochi() {
	int N;
	cin >> N;
	int t[101];
	fill(t, t + 101, 0);
	int res = 0;
	for (size_t i = 0; i < N; i++)
	{
		int a;
		cin >> a;
		t[a]++;
		if (t[a] == 1) res++;
	}
	cout << res << endl;
}
int main() {
	KagamiMochi();
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;
using vl = vector<ll>;
using Map = map<ll,ll>;
using T = tuple<ll,ll,ll>;
using vvl = vector<vector<ll>>;
#define all(v) v.begin(), v.end()
#define prt(v) cout<<v<<"\n";
#define fi(v) get<0>(v)
#define se(v) get<1>(v)
#define th(v) get<2>(v)
#define endl "\n"
template <typename T> bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template <typename T> bool chmin(T &a, const T &b){if (a>b){a=b;return 1;}return 0;}
const ll INF=1LL<<60;
const ll MOD=1000000007;


signed main(void){
    cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    vector<ll> A(N+1,0);
    for(ll i=0;i<N+1;++i)cin>>A[i];

    //コーナーケース
    if(N==0){
        if(A[0]==1){
            prt(1)return 0;
        }
        else {
            prt(-1)return 0;
        }
    }
    if(N==1){
        if(A[0]==0&&A[1]==2){
            prt(3)return 0;
        }
        if(A[0]==0&&A[1]==1){
            prt(2)return 0;
        }
        else {
            prt(-1)return 0;
        }
    }

    //以下N>=2のとき
    //C[i]は深さiで葉でないものの個数の最大値の後ろからの評価
    vector<ll> C(N+1,0);

    if(A[0]){prt(-1)return 0;}

    for(ll i=N-1;i>=0;--i)C[i]=C[i+1]+A[i+1];

    //D[i]は深さiで葉でないものの個数の最大値
    vector<ll> D(N+1,0);
    D[0]=1;
    for(ll i=1;i<=N;++i){
        D[i]=2*D[i-1]-A[i];
        chmin(D[i],C[i]);
        if(D[i]<0){prt(-1)return 0;}
    }

    ll ans=0;
    for(ll i=0;i<=N;++i)ans+=D[i]+A[i];
    prt(ans)

    return 0;
}


Measured memory_bytes: 5572
/* ex4_1
   key_tree */

#include <stdio.h>
#include <math.h>

int main(void){
    //　入力
    int N, D; 
    scanf("%d %d", &N, &D);
  
    // 監視員1人が監視できる木の本数
    int num_tree = 1 + 2*D;
  
    /* 木の全数を監視可能本数で割ったとき、割り切れたら商が、監視に必要な人数
  　   余りが出たら、商+1が監視に必要な人数 */
    int num_people = ceil((double)N / num_tree);
  
    printf("%d\n", num_people);
  
    return 0;
}

Measured memory_bytes: 128
/*
ID: anonymo14
TASK: wormhole
LANG: C++                 
*/
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back
#define REP(i,a,b) for(int i=a; i<=b; i++)
#define MOD 1000000007

void solve(int test_case) {//209
	string s;
	cin>>s;
	bool n = true;
	for(char c:s)if(c!='9')n=0;
	int m=0;
	if(n) {
		m=9*s.length();
	} else {
		for(char c:s)m+=c-'0';
	}
	int beg = s[0]-'1';
	int ans = 0;
	ans+=9*((int)s.length()-1);
	ans+=beg;
	cout<<max(m,ans);
}

int main() {
	
	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	//prefill();
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}	


Measured memory_bytes: 3660
#include<stdio.h>
#include<stdlib.h>

int maxprofit(int *A,int n)
{
  int i,pro,min;
  pro=A[1]-A[0];
  min=A[0];
  for(i=1;i<n;i++){
    /* min???A[0]..A[i-1]?????§???????°???????*/
    /* pro?????????????????§?????? */
    if(A[i]-min>pro) pro=A[i]-min;
    if(min>A[i]) min=A[i];
  }
  return pro;
}

int main()
{
  int *A;
  int i,n;
  scanf("%d",&n);
  A=malloc(n*sizeof(int));
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  printf("%d\n",maxprofit(A,n));
  return 0;
}

Measured memory_bytes: 2580
#include<bits/stdc++.h>
using namespace std;
 
int main()
{
  
  int n;
  cin>>n;
  
  int a[n],b[n],c[n-1];
  
  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-1;i++)
  cin>>c[i];
  
  int s=0;
  
  for(int i=0;i<n;i++)
  s+=b[i];
  
 
  
  for(int i=1;i<n;i++)
  {
      int b1=a[i],b2=a[i-1]+1;
      if(b1==b2)
      {
          s+=c[a[i-1]-1];
          
         
      }
     
  }
  
  
  cout<<s;
 return 0; 
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    
    int S = 0;
    int a, b, c;
    int d,e;
    
    scanf("%d",&S);
    
    if(-1<S && S<86401){
        a = S/3600;
        d = S%3600;
        b = d/60;
        e = d%60;
        
        printf("%d:%d:%d\n",a,b,e);
    }else{
        return 0;
    }
    
    return 0;
}

Measured memory_bytes: 592
#include <cstdio>

int main(int argc, const char * argv[]) {
   
    int a,b;
    
    scanf("%d %d",&a,&b);
    
    if(a==b) printf("%d\n",a);
    else if(a>b){ //11 3
        printf("%d\n",a-1);
    }else { //3 11
        printf("%d\n",a);
    }
    
    
    return 0;
}

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

int main(void){
	int t=0,i,ans;
	int f1[30][30],f2[30];
	char s[5],sl;

	memset(f1, 0, sizeof(f1));
	memset(f2, 0, sizeof(f2));
	while(1){
		if(t==0){
			printf("?aaa\n");
			f1[0][0]=1;
			i=0;
		}else{
			for(i=0;i<26;i++){
				if(f1[sl-'a'][i]==0){
					printf("?%c%ca\n", sl, i+'a');
					f1[sl-'a'][i]=1;
					break;
				}
			}
		}

		t++;
		fflush(stdout);
		scanf("%s",s);
		ans=0;
		sl=s[strlen(s)-1];
		if(s[0]!='a')ans=1;
		else{
			if(strlen(s)==1){//s=*
				if(f2[26]==1)ans=1;
				else f2[26]=1;
			}
			else{//s=**
				if(f2[sl-'a']==1)ans=1;
				else f2[sl-'a']=1;
			}
		}

		if(ans==1){
			printf("!OUT\n");
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 1256
//==========//============================================================================
// Name        : Hello5.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <vector>
#include <bits/stdc++.h>
#include <numeric>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using p = pair<int,int>;//<key,value>


int main() {
char c;
cin>>c;
c=(c-'a'+1)%26+'a';
cout<<c<<endl;
return 0;
}







Measured memory_bytes: 256
#62b
H,W = map(int, input().split())

for i in range(W+2):
    print("#",end="")
    
print("")

for i in range(H):
    s = str(input())
    s = ["#",s,"#"]
    print(''.join(map(str,s)))
for i in range(W+2):
    print("#",end="")

Measured memory_bytes: 3060
ns = gets.chomp.chars.map(&:to_i)
ns_num = ns.size
count = 0
(ns_num - 1).times do |i|
  if ns[i] == ns[i + 1]
    ns[i + 1] = ns[i] == 0 ? 1 : 0
    count += 1
  end
end
puts count

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

typedef long long ll;

int N;
ll mod;
ll dp[2][3010];
ll P[10000000] = {1};
ll F[3010] = {1},R[3010],D[3010] = {2};
ll ans = 0;

ll pow_mod(ll a,ll b)
{
    if(b == 0)return 1;
    ll res = pow_mod(a * a % mod,b / 2);
    if(b & 1)res = res * a % mod;
    return res;
}

ll con(int a,int b)
{
    return F[a] * R[b] % mod * R[a - b] % mod;
}

int main()
{
    scanf("%d%lld",&N,&mod);

    for(int i = 1; i < 3010; i++)F[i] = F[i - 1] * i % mod;
    for(int i = 1; i < 10000000; i++)P[i] = P[i - 1] * 2 % mod;
    for(int i = 1; i < 3010; i++)D[i] = D[i - 1] * D[i - 1] % mod;
    for(int i = 0; i < 3010; i++)R[i] = pow_mod(F[i],mod - 2);
    dp[0][0] = 1;
    for(int i = 0; i <= N; i++)
    {
        for(int j = 0; j <= N; j++)
        {
            //if(dp[i][j] == 0)continue;
            dp[1][j] += dp[0][j];
            dp[1][j] += dp[0][j] * j;
            dp[1][j + 1] += dp[0][j];
            dp[1][j] %= mod;
            dp[1][j + 1] %= mod;
            ll tmp = ((dp[0][j] * P[(N - i) * j] % mod * D[N - i] % mod * con(N,i) % mod)) % mod;
            if(i % 2)ans -= tmp;
            else ans += tmp;
            ans = (ans + mod) % mod;
        }
        for(int j = 0; j <= N; j++)
        {
            dp[0][j] = dp[1][j];
            dp[1][j] = 0;
        }
    }

    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 78464
#include<stdio.h>
int main(){
	int N,M,a,b,p=0,m=0,i;
	scanf("%d%d",&N,&M);
	for(i=0;i<M;i++){
		scanf("%d%d",&a,&b);
		if(N-a>0)p=p+N-a;
		if(m<N-a)m=N-a;
	}
	printf("%d\n",p-m);
	return 0;
}



Measured memory_bytes: 2104
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

#define mod 1000000007 
#define check exit(0)
#define nl cout<<endl;
#define inp 200005
#define ordered_set tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update>
#define ll long long int
#define trace(x) cerr<<#x<<" : "<<x<<endl;
#define deb(v) for(int i=0;i<v.size();i++) {cout<<v[i]; (i==v.size()-1) ? cout<<"\n":cout<<" "; }
#define jaldi ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

using namespace __gnu_pbds;
using namespace std;

// Pick yourself up, 'cause...

int main()
{
    jaldi
 
    int n,w;
    cin>>n>>w;

    vector<ll> dp(w+1,0);

    for(int i=1;i<=n;i++)
    {
        int weight , value;
        cin>>weight>>value;

        for(int j=w;j>=weight;j--) { dp[j]=max(dp[j],dp[j-weight]+value); }
    }

    cout<<dp[w];

    return 0;
}


Measured memory_bytes: 3956
#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;
	cin >> n;

	vector<ll> a(n);
	rep(i, n) cin >> a.at(i);

	ll min_val = a.at(0);
	ll max_val = 0;

	ll flag = 0;

	rep(i,n){
		min_val = max(min_val, a.at(i));

		if(min_val> a.at(i)){
			flag += min_val - a.at(i);
		}
	}

	cout << flag;
}


Measured memory_bytes: 4736
#include <iostream>
#include <queue>
#include <string>
using namespace std;
int main(){
  int H, W;
  cin >> H >> W;
  string M[H];
  for(int i = 0; i < H; ++i){
    cin >> M[i];
  }
  int s_x, s_y, g_x, g_y;
  for(int i = 0; i < H; ++i){
    for(int j = 0; j < W; ++j){
      if(M[i][j] == '%'){
        s_x = i;
        s_y = j;
      }
      if(M[i][j] == '@'){
        g_x = i;
        g_y = j;
      }
    }
  }
  int d[H][W];
  for(int i = 0; i < H; ++i) fill(d[i],d[i]+W,-1);
  d[s_x][s_y] = 0;
  queue< pair<int,int> > que;
  que.push(make_pair(s_x, s_y));
  int dx[] = {1,0,-1,0}, dy[] = {0,1,0,-1};
  while(!que.empty()){
    int x = que.front().first, y = que.front().second;
    que.pop();
    for(int i = 0; i < 4; ++i){
      int next_x = x + dx[i], next_y = y + dy[i];
      if(next_x >= 0 && next_x < H && next_y >= 0 && next_y < W && d[next_x][next_y] < 0 && M[next_x][next_y] != '#'){
        d[next_x][next_y] = d[x][y] + 1;
        que.push(make_pair(next_x, next_y));
      }
    }
  }
  int princess = 100000000, soldier = princess;
  for(int i = 0; i < H; ++i){
    for(int j = 0; j < W; ++j){
      if(M[i][j] == '@') princess = min(princess, d[i][j]);
      if(M[i][j] == '$') soldier = min(soldier, d[i][j]);
      
    }
  }
  if(princess < soldier) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3360
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#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 bg begin()
#define ed end()
#define all(x) x.bg, x.ed
#define vi vector<int>
template <class t, class u>
bool chmax(t &a, u b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class t, class u>
bool chmin(t &a, u b)
{
    if (b < a)
    {
        a = b;
        return true;
    }
    return false;
}

signed main()
{
    int n;
    cin >> n;
    vi a(n);
    vi b(n);
    rep(i, n)
    {
        cin >> a[i] >> b[i];
    }
    ll total = 0;
    per(i, n)
    {
        ll r = (a[i] + total) % b[i];
        if (r != 0)
        {
            total += b[i] - r;
        }
    }
    cout << total << endl;
    return 0;
}

Measured memory_bytes: 4016
#include <bits/stdc++.h>
using namespace std;
int main() {
    string S; cin >> S;
    string s[4] = {"dream" , "dreamer", "erase" ,"eraser"};
    int at = (int)S.length();
    while(at > 0){
        bool f = false;
        for(int i = 0; i < 4;i++){
            if(at < s[i].length()) continue;
            string tmp = S.substr(at-s[i].length(),s[i].length());
            if(tmp == s[i]){
                f = true;
                at -= s[i].length();
                break;
            }
        }
        if(!f){
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
	return 0;
}

Measured memory_bytes: 512
N = int(input())
num = [int(x) for x in input().split()]

if N == 1:
    print("Yes")
elif N == 2:
    if num[0] - num[1] < 2:
        print("Yes")
    else:
        print("No")
else:
    flag = True
    for i in range(N - 2, 0, -1):
        diff = num[i] - num[i + 1]
        if diff <= 0:
            pass
        elif diff == 1:
            num[i] -= 1
        else:
            flag = False
            break
    print("Yes" if flag else "No")

Measured memory_bytes: 14224
// God put a smile upon your face <3

#include <bits/stdc++.h>

#define slld(longvalue) scanf("%lld", &longvalue)

#define ll long long
#define ull unsigned long long
#define pll pair < long long, long long >

#define fastio ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0)

#define pb push_back

#define bug printf("BUG\n")

#define mxlld LLONG_MAX
#define mnlld -LLONG_MAX

#define mxd 2e8
#define mnd -2e8

#define pi 3.14159265359

using namespace std;

bool check(ll n, ll pos)
{
	return n & (1LL << pos);
}

ll Set(ll n, ll pos)
{
	return n = n | (1LL << pos);
}

int main()
{
    ll i, j, k, l, m, n, o, r, q;
    ll testcase;
    ll input, flag, tag, ans;

//    freopen("input.txt", "r", stdin);

//    freopen("output.txt", "w", stdout);

    ans = 0;

    while(cin >> n)
    {
		ans = 0;

		for(ll i = 1; i <= n; i++)
		{
			for(ll j = 1; j <= n; j++)
			{
				for(ll k = 1; k <= n; k++)
				{
					ans += __gcd(i, __gcd(j,k));
				}
			}
		}

		cout << ans << "\n";
    }


}






Measured memory_bytes: 3560
#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>
#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 POWT(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define MODU 1000000007
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;

const pii four_Dir[4] = {
	{ 0,-1 },{ -1 ,0 },{ 0 ,1 },
	{ 1 ,0 }
};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*) array, (T*) (array + N), val);
}

signed main() {
	int h, w;
	scanf("%d %d", &h, &w);
	vector<vector<char>> m(h + 2, vector<char>(w + 2));
	int c = 0;
	REP(i, h) {
		scanf("%*c");
		REP(j, w) {
			scanf("%c", &m[i + 1][j + 1]);
			if (m[i + 1][j + 1] == '#')
				c++;
		}
	}
	if (c != (h + w - 1)) {
		printf("Impossible\n");
		return 0;
	}
	m[0][1] = '#';
	m[h][w - 1] = '#';
	rep(i, 1, h) {
		rep(j, 1, w) {
			if (m[i][j] == '#') {
				if (m[i + 1][j] == '#' && m[i][j + 1] == '#') {
					printf("Impossible\n");
					return 0;
				}
				if (m[i + 1][j] != '#' && m[i][j + 1] != '#') {
					printf("Impossible\n");
					return 0;
				}
				if (m[i - 1][j] == '#' && m[i][j - 1] == '#') {
					printf("Impossible\n");
					return 0;
				}
				if (m[i - 1][j] != '#' && m[i][j - 1] != '#') {
					printf("Impossible\n");
					return 0;
				}
			}
		}
	}
	printf("Possible\n");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <bitset>
#include <functional>
#include <random>
#define REP(_i,_a,_n) for(int _i=_a;_i<=_n;++_i)
#define PER(_i,_a,_n) for(int _i=_n;_i>=_a;--_i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(_a) ({REP(_i,1,n) cout<<_a[_i]<<',';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;}
//head



const int N = 5e3+10;
int n,a,b,f[N],g[N][2];
void add(int &x, ll y) {x=(x+y)%P;}
int main() {
	scanf("%d%d%d", &n, &a, &b);
	if (a>b) swap(a,b);
	f[1] = f[2] = 1;
	REP(i,3,n) {
		f[i] = f[i-1];
		REP(j,1,i-a-1) add(f[i],f[j]);
	}
	REP(i,1,b-1) g[i][1] = f[i];
	REP(i,1,a-1) g[i][0] = 1;
	REP(i,a,b-1) REP(j,1,b-1-i) add(g[i+j][1],f[j]);
	REP(i,1,n) {
		REP(j,1,min(n-i,a-1)) add(g[i+j][0],g[i][1]);
		REP(j,1,min(n-i,b-1)) add(g[i+j][1],(ll)g[i][0]*f[j]);
	}
	int ans = (g[n][0]+g[n][1])%P;
	REP(i,a,b-1) REP(j,1,b-1-i) add(ans,(ll)g[n-i-j][0]*f[j]);
	ans = (qpow(2,n)-ans)%P;
	if (ans<0) ans += P;
	printf("%d\n", ans);
}


Measured memory_bytes: 3876
import java.util.Scanner;
class Main
{
	public static void main(String args[])
	{
        Scanner sc=new Scanner(System.in);
        int a=sc.nextInt();
        int b=sc.nextInt();
        int c=sc.nextInt();

        int ab=a+b;
        int ac=a+c;
        int bc=b+c;

        System.out.println(Math.min(Math.min(ab,ac),bc));
    }
}

Measured memory_bytes: 24020
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SORT(a) sort(a.begin(),a.end())
using namespace std;
int main(){
    //Seiranchan!
    string S;
    cin >> S;
    bool flag = false;

    for(char c = 'a'; c <='z';c++){
        REP(i,S.size()){
            if( c == S[i] ){
                flag  = true;
            }
        }
            if(flag){
                flag = false;
            }else{
                cout << c << endl;
                return 0;
            }
        
    }
    cout << "None"<<endl;
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <functional>
using namespace std;
typedef long long ll;
template<class T> using vec = vector<T>;
template<class T> using vvec = vector<vec<T>>;
using P = pair<int,int>;
const ll mod = 1e9+7;
struct mint {
    ll x;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime mod
    mint inv() const {
        return pow(mod-2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res/=a;
    }
};


int main(){
    int N,M;
    cin >> N >> M;
    vec<int> S(N);
    for(int i=0;i<N;i++){
        cin >> S[i];
        S[i]--;
    }
    vvec<int> g(N);
    for(int i=0;i<N;i++) for(int j=i+1;j<N;j++){
        if(S[i]>S[j]){
            g[i].push_back(j);
            g[j].push_back(i);
        }
    }
    vec<int> c(N,-1);
    vvec<int> cmp;
    function<bool(int,int,vec<int>&)> dfs = [&](int n,int col,vec<int>& v){
        c[n] = col;
        bool ok = true;
        for(auto& e:g[n]){
            if(c[e]==-1) ok &= dfs(e,1-col,v);
            else if(c[e]==col) return false;
        }
        v[col]++;
        return ok;
    };
    for(int i=0;i<N;i++) if(c[i]==-1){
        vec<int> res = vec<int>(2,0);
        bool ok = dfs(i,1,res);
        if(!ok){
            cout << 0 << endl;
            return 0;
        }
        cmp.push_back(res);
    }
    int n = cmp.size();
    vvec<mint> dp(n+1,vec<mint>(N+1,0));
    dp[0][0] = 1;
    for(int i=0;i<n;i++) for(int j=0;j<N;j++){
        for(int k=0;k<2;k++){
            if(j-cmp[i][k]>=0) dp[i+1][j] += dp[i][j-cmp[i][k]];
        }
    }
    mint ans = 0;
    for(int i=N-M;i<=M;i++) ans += dp[n][i];
    cout << ans.x << endl;
}


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

#ifdef NON_SUBMIT
#define TEST(n) (n)
#define tout cerr
#else
#define TEST(n) ((void)0)
#define tout cin
#endif

using namespace std;

vector<int> adj[200000];
int dist[200000];

int bfs(int c)
{
	queue<int> Q;
	memset(dist,0x7f,sizeof(dist));
	dist[c]=0;
	Q.push(c);
	while(!Q.empty()) {
		c=Q.front();
		Q.pop();
		for(auto n: adj[c]) {
			if(dist[n]>dist[c]+1) {
				dist[n]=dist[c]+1;
				Q.push(n);
			}
		}
	}
	return c;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	TEST(freopen("input.txt", "r", stdin));
	TEST(freopen("output.txt", "w", stdout));
	TEST(freopen("debug.txt", "w", stderr));
	int N, t;
	queue<int> Q;
	cin>>N;
	for(int i=1;i<N;i++) {
		int a, b;
		cin>>a>>b;
		adj[--a].push_back(--b);
		adj[b].push_back(a);
	}
	cout<<(dist[bfs(bfs(0))]%3==1 ? "Second\n":"First\n");
	return 0;
}

Measured memory_bytes: 13556
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.Collectors;

public class Main {

    public static void main(String[] args) throws Exception {
        try (BufferedInputStream in = new BufferedInputStream(System.in);
             PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out))) {

            Scanner sc = new Scanner(in);

            // 15:48-

            String s = sc.next();

            int[] res = new int[s.length()];

            doit(s, res, 1);

            s = reverse(s);

            int[] res1 = new int[s.length()];
            doit(s, res1, 0);
            rev(res1);

            for (int i = 0; i < res1.length; i++) res[i] += res1[i];

            String r = Arrays.stream(res).mapToObj(x -> x + "").collect(Collectors.joining(" "));
            out.println(r);
        }
    }

    private static void rev(int[] r) {
        for (int i = 0; i < r.length / 2; i++) {
            int t = r[i];
            r[i] = r[r.length - 1 - i];
            r[r.length - 1 - i] = t;
        }
    }

    private static void doit(String s, int[] res, int b) {
        int i = 0;
        while (i + 1 < s.length()) {
            int run = 1;
            while (s.charAt(++i) == 'R') run++;
            run--;
            res[i - 1] = b + run / 2;
            res[i] = b + (run + 1) / 2;
            while (i + 1 < s.length() && s.charAt(++i) == 'L');
        }
    }

    private static String reverse(String s) {
        char[] chars = s.toCharArray();
        for (int i = 0; i < chars.length / 2; i++) {
            char t = chars[i];
            chars[i] = chars[chars.length - i - 1];
            chars[chars.length - i - 1] = t;
        }

        for (int i = 0; i < chars.length; i++) {
            char c = chars[i];
            chars[i] = c == 'L' ? 'R' : 'L';
        }

        return new String(chars);
    }

}


Measured memory_bytes: 45852
#include<stdio.h>
int main()
{
	int ar[3];
	int fiv=2;
	int sev=1;
	for(int i=0;i<3;i++)
	{
		scanf("%d",&ar[i]);
		if(ar[i]==5)fiv--;
		if(ar[i]==7)sev--;
	}
	if(fiv==0&&sev==0){
		printf("YES");
	}
	else printf("NO");
	return 0;
	}

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

int main() {
	//おまじない
	cin.tie(0);
	ios::sync_with_stdio(false);


	int N;
	string S;
	cin >> N >> S;

	int SE[300002] = {};
	int SW[300002] = {};

	rep1(i, N) {
		if (S[i - 1] == 'E') SE[i]++;
		else SW[i]++;
		SE[i + 1] = SE[i];
		SW[i + 1] = SW[i];
	}


	int minimum = 300000;
	rep(i, N) {
		int rouryoku = SW[i] + SE[N] - SE[i + 1];
		minimum = min(minimum, rouryoku);
	}

	cout << minimum << "\n";

	Would you please return 0;
}

Measured memory_bytes: 2964
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>


using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD (ll)1000000007
#define P pair<ll, ll>

ll n, x[60], y[60], mx;
vector<P> s;
map<P, ll> m;
int main() {
	cin >> n;
	REP(i, n) {
		cin >> x[i] >> y[i];
		s.push_back(P(x[i], y[i]));
	}
	sort(ALL(s));
	REP(i, n) {
		FOR(j, i + 1, n) {
			m[P(s[i].first - s[j].first, s[i].second - s[j].second)]++;
		}
	}
	for (auto& i : m)
	{
		mx = max(mx, i.second);
	}
	cout << n - mx << endl;
}


Measured memory_bytes: 384
import heapq
import itertools
inf = 10 * 18

H, W = map(int, input().split())
map = [input() for _ in range(H)]
heuristic = {(i, j): int(((H - i) ** 2 + (W - j) ** 2) ** 0.5) for j in range(W) for i in range(H)}
count_white = sum([s.count(".") for s in map])

def astar(init_pos, goal):
    passed_list = [init_pos]
    init_score = distance(passed_list) + heuristic.setdefault(init_pos, inf)
    checked = {init_pos: init_score}
    searching_heap = []
    heapq.heappush(searching_heap, (init_score, passed_list))
    while len(searching_heap) > 0:

        score, passed_list = heapq.heappop(searching_heap)
        last_passed_pos = passed_list[-1]
        if last_passed_pos == goal:
            return passed_list
        for pos in nexts(last_passed_pos):
            new_passed_list = passed_list + [pos]
            pos_score = distance(new_passed_list) +  heuristic.setdefault(pos, inf)
            if pos in checked and checked[pos] <= pos_score:
                continue

            checked[pos] = pos_score
            heapq.heappush(searching_heap, (pos_score, new_passed_list))

    return []

def distance(path):
    return len(path)

def nexts(pos):
    i = pos[0]
    j = pos[1]
    res = []
    
    for p in [(i + 1, j), (i - 1, j), (i, j - 1), (i, j + 1)]:
        if 0<=p[0]<=H-1 and 0<=p[1]<=W-1 and map[p[0]][p[1]] != "#":
            res.append(p)

    return res
    
path = astar((0,0), (H-1,W-1))

if len(path) == 0:
    print(-1)
else:
    print(count_white - len(path))

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

using namespace std;

//#define fr(i,s,e) for(i=s;i<e;i++)

int main() {
    int a,b,c,mx,k;
    cin>>a>>b>>c>>k;
    mx=max(a,max(c,b));
    int x=mx;
        x=x*pow(2,k);
      
    cout<<a+b+c+x-mx;
 return 0;
}


Measured memory_bytes: 256
from functools import reduce

def formulas(s):
    formula_list = []
    def aux(current, i):
        if i < len(s):
            aux(current + [s[i]], i + 1)
            aux(current + ['+', s[i]], i + 1)
        else:
            formula_list.append(''.join(current))                
    
    aux([s[0]], 1)
    return formula_list
        
    
if __name__ == '__main__':
    s = input()
    print(reduce(lambda x, y: x + eval(y), formulas(s), 0))

Measured memory_bytes: 3572
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long N = sc.nextInt();
        long K = sc.nextInt();
        long res = 0;
        if (K == 0) {
            System.out.println(N*N);
        } else {
            for (int b = 1 ; b <= N ; b++) {
                long p = N / b ;
                long r = N % b;
                res += p * Math.max(0,  b - K) + Math.max(0,  r - K + 1);
            }
            System.out.println(res);
        }

    }

}


Measured memory_bytes: 23252
import std.stdio;
import std.array;
import std.conv;
import std.algorithm;
struct Reader {
    char[][] inputs;
    ulong idx;
    bool nextLine() {
        char[] buf;
        if(readln(buf)==0) return 0;
        inputs=split(buf);
        idx=0;
        return 1;
    }
    char[] nextItem() {
        if(idx==inputs.length) {
            nextLine();
            idx=0;
        }
        return inputs[idx++];
    }
    int nxtInt() {
        return to!int(nextItem());
    }
    double nxtDouble() {
        return to!double(nextItem());
    }
    char[] nxtStr() {
        return nextItem();
    }
}
void main() {
    Reader r;
    int N=r.nxtInt();
    int[] a;
    for(int i=0;i<N;i++) a~=r.nxtInt();
    a.length-=a.sort.uniq.copy(a).length;
    writeln(a.length);
}

Measured memory_bytes: 380
#include<algorithm>  
#include<iostream>  
#include<cstdio>  
#include<set>  
using namespace std;  
string s, t;  
set<string> S;  
  
  
int main()  
{  
    cin >> s >> t;  
        int lens = s.size();  
    int lent = t.size();  
    for(int i = 0; i < lens; i++)  
    {  
        if(s[i] == '?' || s[i] == t[0])
        {  
            string tmp = s;             
            for(int j = 0; j < i; j++)  
                if(tmp[j] == '?')  
                    tmp[j] ='a';      
            bool can = false;  
            for(int j = 0; j < lent; j++)    
            {  
  
                if(tmp[i+j]!= '?' && tmp[i+j] != t[j])  
                    break;  
                tmp[i+j] = t[j];  
                if(j == lent - 1) can = true;  
            }  
            if(can)  
            {  
                for(int j = i + lent; j < lens; j++) if(tmp[j] == '?') tmp[j] = 'a';
                S.insert(tmp);  
            }  
        }  
    }  
    if(S.size() == 0) cout << "UNRESTORABLE" << endl;  
    else cout << *S.begin() << endl;  
}  

Measured memory_bytes: 256
/*
//TLE
#pragma GCC optimize("Ofast",3,"inline")
#include<bits/stdc++.h>
using namespace std;
string s[805];
int ans=0x7f7f7f7f;
int n,m,k;
int sx,sy;
int aford[4][2]={
	{1,0},
	{0,1},
	{-1,0},
	{0,-1}
};
bool check(int x,int y){
	if(x<0||x>=n||y<0||y>=m)return 0;
	if(s[x][y]=='#')return 0;
	s[x][y]='#';
	return 1;
}
void road(int x,int y){
	int num=min(min(n-1-x,x),min(m-1-y,y));
	ans=min(ans,num);
}
void dfs(int step,int x,int y){
	road(x,y);
	if(step>=k)return;
	for(int i=0;i<4;i++){
		if(check(x+aford[i][0],y+aford[i][1]))dfs(step+1,x+aford[i][0],y+aford[i][1]),s[x+aford[i][0]][y+aford[i][1]]='.';
	}
}
void out(){
	cout<<'\n';
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			if(i!=sx||j!=sy)cout<<s[i][j];
			else cout<<'S';
		}
		cout<<'\n';
	}
}
int main(){
	cin>>n>>m>>k;
	for(int i=0;i<n;i++){
		cin>>s[i];
		for(int j=0;j<m;j++){
			if(s[i][j]=='S'){sx=i,sy=j;break;}
		}
	}
	s[sx][sy]='#';
	dfs(0,sx,sy);
//	cout<<ans<<'\n';
//	out();
	cout<<((ans+k-1)/k+1);
	return 0;
}
*/
//AC
#include<bits/stdc++.h>
using namespace std;
char c[880][880];
int n,m,k,x,y,dis[880][880],mm=1e9;
int dx[]={1,-1,0,0},dy[]={0,0,1,-1};
int main()
{
	cin>>n>>m>>k;
	for(int i=0;i<n;i++)
	{
		cin>>c[i];
		for(int j=0;j<m;j++)
			if(c[i][j]=='S')
			{
				x=i;
				y=j;
			}
	}
	queue<pair<int,int> >que;
	que.push(make_pair(x,y));
	memset(dis,-1,sizeof(dis));
	dis[x][y]=0;
	while(!que.empty())
	{
		int a=que.front().first;
		int b=que.front().second;
		que.pop();
		if(dis[a][b]>k)
			break;
		if(a==0||b==0||a==n-1||b==m-1)
		{
			cout<<1<<endl;
			return 0;
		}
		mm=min(mm,min(min(a,n-a-1),min(b,m-b-1)));
		for(int i=0;i<4;i++)
		{
			int u=a+dx[i],v=b+dy[i];
			if(c[u][v]!='#'&&dis[u][v]==-1)
			{
				dis[u][v]=dis[a][b]+1;
				que.push(make_pair(u,v));
			}
		}
	}
	cout<<(mm+k-1)/k+1<<endl;
	return 0;
}


Measured memory_bytes: 3968
#include <bits/stdc++.h>
#define loop(n, i) for(int i=0;i<n;i++)
#define HERE cout << "HERE: " << __LINE__ << endl;
#define INSP(v) cout << v << " at " << __LINE__ << endl;
using namespace std;
using ll = long long;
template <class T>
using V = vector<T>;
using P = pair<ll, ll>;


void solve(long long H, long long W, long long h, long long w){
    cout << (H - h) * (W - w) << endl;
}

int main(){
    long long H;
    scanf("%lld",&H);
    long long W;
    scanf("%lld",&W);
    long long h;
    scanf("%lld",&h);
    long long w;
    scanf("%lld",&w);
    solve(H, W, h, w);
    return 0;
}



Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;

const int MAXN=1e5+5;
char a[MAXN];

int main()
{
	string str;
	while(cin>>str){
		int cnt;
		memset(a,0,sizeof(a));
		for(int i=0;i<str.size();i++){
			cnt=str[i]-'a'+1;
			a[cnt]++;
		}
		for(int i=1;i<=26;i++){
			if (!a[i]){
				printf("%c\n",'a'+i-1);
				return 0;
			}
		}
		cout<<"None"<<endl;
	}
	return 0;
}

Measured memory_bytes: 512
from collections import deque
from collections import Counter
from itertools import product, permutations,combinations
from operator import itemgetter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right, bisect
#pypyではscipy, numpyは使えない
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, minimum_spanning_tree
#from scipy.sparse import csr_matrix, coo_matrix, lil_matrix
#import numpy as np
from fractions import gcd
from math import ceil,floor, sqrt, cos, sin, pi, factorial
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')

def main():
  n, a, b = map(int, readline().split())
  print(min(n*a,b))
  
  
  
  
  
if __name__ == '__main__':
  main()

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

using namespace std;

int m, n, q;

struct Qs{
    int a, b, c, d;
};

vector<Qs> vec;

int curr[20];

int max_pt = 0;

void jaegui(int val, int idx){
    if(idx==n){
        int curr_score = 0;
        for(auto& v: vec){
            if(curr[v.b]-curr[v.a] == v.c){
                curr_score += v.d;
            }
        }
        max_pt = max(curr_score, max_pt);
        return;
    }
    for(int i=val;i<=m;i++){
        curr[idx] = i;
        jaegui(i, idx+1);
    }
}

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

    cin>>n>>m>>q;
    for(int i=0;i<q;i++){
        int a, b, c,d;
        cin>>a>>b>>c>>d;
        --a;--b;
        vec.push_back({a,b,c,d});
    }
    jaegui(1, 0);
    cout<<max_pt;
    return 0;
}

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

int main() {
  int n;
  cin >> n;
  
  int x = n;
  int sum = 0;
  
  while(x > 0){
    sum = sum+(x % 10);
    x/= 10;
  }
  
  if( n % sum ==0){
    cout << "Yes" <<endl;
  }
  
  else{
    cout << "No" <<endl;
  }
 
}

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

int main(){
  int n; cin >> n;
  vector<string> s(n);
  for (int i = 0; i < n; i++){
    cin >> s.at(i);
    sort(s.at(i).begin(), s.at(i).end());
  }
  map<string, int> m;
  set<string> t;
  for (int i = 0; i < n; i++){
    m[s.at(i)]++;
    t.insert(s.at(i));
  }
  int64_t ans = 0;
  for (string u : t){
    int64_t n = m.at(u);
    ans += n * (n - 1) / 2;
  }
  cout << ans << endl;
}

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

using namespace std;

using ll = long long;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m, q;
    cin >> n >> m >> q;
    vector< vector<int> > cnt(n + 1, vector<int>(n + 1, 0));
    for (int i = 0; i < m; i++) {
        int l, r;
        cin >> l >> r;
        l--; r--;
        cnt[0][r]++;
        cnt[l + 1][n]++;
        cnt[0][n]--;
        cnt[l + 1][r]--;
    }

    for (int i = 0; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            cnt[i][j] += cnt[i][j - 1];
        }
    }

    for (int i = 1; i <= n; i++) {
        for (int j = 0; j <= n; j++) {
            cnt[i][j] += cnt[i - 1][j ];
        }
    }

    for (int i = 0; i < q; i++) {
        int x, y;
        cin >> x >> y;
        x--; y--;
        cout << cnt[x][y] << endl;
    }
    return 0;
}

Measured memory_bytes: 1920
#include <bits/stdc++.h>
#define REP(i, n) for(long long i=0; i<n; i++)
#define REPR(i, n) for(long long i=n-1; i>=0; i--)
#define FOR(i, m, n) for(long long i=m; i<=n; i++)
#define FORR(i, m, n) for(long long i=m; i>=n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

using namespace std;
using ll = long long;
using ull = unsigned long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;
const ll mod = 1e9+7;
const ll inf = 1e15;
ll power(ll a,ll b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}


int main(){FIN
    ll n;cin>>n;
    ll ans=1;
    REP(i,n){
        ll a;cin>>a;
        ans = a / __gcd(a, ans) * ans;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3600
def f(x,y,out,dp):
    if dp[y][x] != "#":
        return dp[y][x]
    if [[x-1,y],[x,y]] in out:
        if [[x,y-1],[x,y]] in out:
            dp[y][x] = 0
            return 0
        else:
            dp[y][x] = f(x,y-1,out,dp)
            return dp[y][x]
    if [[x,y-1],[x,y]] in out:
        dp[y][x] = f(x-1,y,out,dp)
        return dp[y][x]
    else:
        dp[y][x] = f(x-1,y,out,dp)+f(x,y-1,out,dp)
        return dp[y][x]

def solve():
    gx,gy = map(int,input().split())
    p = int(input())
    out = []
    for i in range(p):
        x1,y1,x2,y2 = map(int,input().split())
        out.append([[min(x1,x2)+1,min(y1,y2)+1],[max(x1,x2)+1,max(y1,y2)+1]])
    
    dp = [[0]*(gx+2)]
    for i in range(gy+1):
        dp.append([0]+["#"]*(gx+1))
    dp[1][1] = 1
    ans = f(gx+1,gy+1,out,dp)
    if ans == 0:
        print("Miserable Hokusai!")
    else:
        print(ans)
        #for i in dp:
        #    print(i)
    return 0

n = int(input())
for i in range(n):
    solve()


Measured memory_bytes: 5624
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<algorithm>
#include<cmath>
#include<set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;

int main(){
    int N;
    string s;
    cin>>N;
    cin>>s;
    int r=0;
    for(int i=0;i<N;i++){
        if(s[i]=='R'){
            r++;
        }
    }
    int b=N-r;
    if(r>b){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define int long long
#define vi vector<int>
#define pii pair<int,int>
#define vpii vector<pii>
#define endl '\n'
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define in insert
#define pi 3.14159265358979323846
#define rep(i,a,b) for(int i = a ; i < b ; i++)
#define repr(i,a,b) for(int i = b ; i > a ; i--)
  
long long fact(long long a, long long b){
    int r= max(a, b);
    int v= min(a, b);
    int l=1;
    // if(v==0)
    for(int i=r+1; i<=a+b; i++){
        l*=i;
    }
    for(int i=v; i>=2; i--){
        l/=i;
    }
    return l;
}

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

int powr(int a) { 
    int var=1;
    for(int i=0; i<a; i++){
        var*=2;
    }
    return var;
}

void func(int a, bool i){
    cout << a;
    if(a==100){
        i=1;
    }
    else if(a==0){
        return;
    }
    if(!i)
        func(a+1, i);
    else
        func(a-1, i);
}

signed main(){   
    fast;
    int n, w;
    cin >> n >> w;
    int W=w;
    int a[2][n];
    rep(i,0,n){
        cin >> a[0][i] >> a[1][i];
    }
    int ans=0;
    int dp[n+1][w+1];
    for(int i=0; i<=n; i++){
        for(int j=0;j<=W; j++){
            if(i==0 || j==0) 
               dp[i][j] = 0;
            else if(j-a[0][i-1]>=0)
                dp[i][j] = max(a[1][i-1]+dp[i-1][j-a[0][i-1]], dp[i-1][j]);
            else
                dp[i][j]=dp[i-1][j];
            // cout << dp[i][j] << " ";
        }
        // cout << endl;
    }
    cout << dp[n][w];
    return 0;
}

Measured memory_bytes: 82440
#include <bits/stdc++.h>
#define cout16 cout << setprecision(16) 
#define rep(i,n) for(int i=0;i<n;i++ )
#define rep2(i,f,n) for(int i=f;i<n;i++ )
#define SORT(A) sort(A.begin(),A.end())
#define REV(A) reverse(A.begin(),A.end())
typedef long long int ll;
using vi = std::vector<int>;
using vvi = std::vector<std::vector<int>>;
using vll = std::vector<ll>;
using vvll = std::vector<std::vector<ll>>;
using P = std::pair<int,int>;
using vp = std::vector<P>;
using namespace std;
#define INF 1001001001
#define LL_INF 1001001001001001001
#define fi first
#define se second

bool isOK(vi &s, int n){
	rep(i,n-1) if(s[i]!=s[i+1]) return false;
	return true;
}

int main(void) {
	string s; cin >> s;
	vi a(s.size());
	rep(i,s.size()) a[i] = s[i] - 'a';
	int ans = INF;
//	rep(j,s.size()) cout << a[j] << " ";
//	cout << endl;	
	rep(i,26){
		int x = i;
		int n = a.size();
		vi b = a;
		int cnt = 0;
		while(!isOK(b,n)){
			n--;
			vi c = b;
			rep(j,n){
				if(c[j]==x) b[j] = c[j];
				else if(c[j+1]==x) b[j] = c[j+1];
				else b[j] = c[j];
			}
//			rep(j,n) cout << b[j] << " ";
//			cout << endl;
			cnt++;
		}
		ans = min(ans,cnt);
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fr(i,n) for (int i=0;i<n;i++)
#define ll long long int
using namespace std;
int main()
{
    ll n;cin>>n;
    double p[n];fr(i,n)cin>>p[i];
    double dp[n+1][n+1];
    fr(i,n+1)fr(j,n+1)dp[i][j]=0;
    dp[1][0]=1-p[0];
    dp[1][1]=p[0];
    for(int j=0;j<=n;j++)dp[0][j]=0;
    dp[0][0]=1;

    for(int i=1;i<=n;i++)
    {
        dp[i][0] = dp[i-1][0]*(1-p[i-1]);
    }

    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=i;j++)
        {
            // if(j==i && i==n)continue;
            dp[i][j] = dp[i-1][j]*(1.0-p[i-1]) + dp[i-1][j-1]*(p[i-1]);
        }
    }
    double ans = 0 ;
    fr(i,n+1)
    {
        if(i>n/2)ans+=dp[n][i];
        // cout<<dp[n][i]<<" ";
    }
    cout<<setprecision(20)<<ans<<endl;


}

Measured memory_bytes: 70656
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iostream>

using namespace std;



int main(){
	string S, T;
	cin >> S >> T;
	int cnt = 0;
	for (auto i = 0; i < S.size(); i++) {
		if (S.at(i) != T.at(i)) cnt++;
	}
	cout << cnt << endl;
}

Measured memory_bytes: 3916