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

// 型名の省略
typedef unsigned int uint;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> P;
typedef pair<lint, lint> Plint;
 
const int MOD = 1e9+7;
const int INF = 1<<18;
const lint INFLINT = 1LL<<60;
const double PI=acos(-1.0);
 
// cinとcoutの高速化
#define endl "\n"
struct cinacc{cinacc(){cin.tie(0);ios::sync_with_stdio(false);}}cinaccc;
struct coutacc{coutacc(){cout.setf(ios::fixed);cout.precision(12);}}coutaccc;
 
// 繰り返し
#define rep(i,n) for(lint i=0;i<(lint)(n);i++)
#define reps(i,n) for(lint i=0;i<=(lint)(n);i++)
#define rrep(i,n) for(lint i=(lint)(n)-1;i>0;i--)
#define rreps(i,n) for(lint i=(lint)(n)-1;i>=0;i--)

#define pb push_back

#define ALL(s) (s.begin(), s.end())
#define SZ(s) (s.size())

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

// Union-Find-Tree
class UnionFind {
	vector<int> par;
	UnionFind(int n):par(n){rep(i,n)par[i]=i;}
	int root(int x){if(par[x]==x)return x;return par[x]=root(par[x]);}
	void unite(int x,int y){int rx=root(x);int ry=root(y);if(rx==ry)return;par[rx]=ry;}
	bool same(int x,int y){return root(x)==root(y);}
};

// Final Weapon!
// #define int lint

int main() {
    int a, b, x, y, n, m, k;
    string s;
    
    cin >> k >> s;
    
    if(s.length() <= k) cout << s;
    else cout << s.substr(0, k) << "...";
    
    return 0;
}


Measured memory_bytes: 3612
import java.util.*;

public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);


    int n = sc.nextInt();
    String[] mozi = new String [n];

    int k = sc.nextInt();
    String i = mozi[k - 1];


    String s = sc.next();

    String ans = "";
    for (int y = 0; y < n; y++) {
      if (y == k - 1) {
        ans += String.valueOf(s.charAt(y)).toLowerCase();
      }
      else {
        ans += String.valueOf(s.charAt(y));
      }
    }

    System.out.println(ans);


	}
}


Measured memory_bytes: 23124
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <queue>
#include <algorithm>
using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef pair<int, int> P;
const int c_INF = 111111111;
const int c_mINF = -111111111;
const int c_YET = -1;
const int c_Dx[4] = { 0,0,1,-1 };
const int c_Dy[4] = { 1,-1,0,0 };
const int c_div = 1000000007; //10^9 + 7


int ans[100];

int main() {

	int N, M,A[200],B[100];
	scanf("%d%d", &N, &M);
	for (int i = 0; i < 2*M; i++) {
		scanf("%d", &A[i]);
	}


	for (int i = 0; i < 2*M; i++) {
		ans[A[i] - 1]++;

	}

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





}


Measured memory_bytes: 128
#include <iostream>
#include <set>
#include <string.h>
#include <vector>
using namespace std;

const int SIZE = 101;

int solve( int table[ SIZE ][ SIZE ], int s, int e, int initTtl, int numRooter )
{
	if( initTtl < 2 ){
		return 0;
	}
	bool bPast[ SIZE ];
	memset( bPast, 0, sizeof( bPast ) );
	bPast[ s ] = true;
	vector< int > pList;
	for( int i = 1; i <= numRooter; ++i ){
		if( table[ s ][ i ] ){
			if( i == e ){
				return 2;
			}
			bPast[ i ] = true;
			pList.push_back( i );
		}
	}

	int ttl = initTtl;
	while( pList.size() > 0 ){
		--ttl;
		if( ttl < 1 ){
			return 0;
		}
		vector< int > pList2;
		for( int i = 0; i < pList.size(); ++i ){
			int p = pList[ i ];
			if( p == e ){
				return initTtl - ttl + 1;
			}
			for( int j = 1; j <= numRooter; ++j ){
				if( table[ p ][ j ] && !bPast[ j ] ){
					bPast[ j ] = true;
					pList2.push_back( j );
				}
			}
		}
		pList = pList2;
	}

	return 0;
}

int main()
{
	int table[ SIZE ][ SIZE ];

	int n;
	while( cin >> n ){
		memset( table, 0, sizeof(table) );
		for( int i = 0; i < n; ++i ){
			int id, numRooter;
			cin >> id >> numRooter;
			for( int j = 0; j < numRooter; ++j ){
				int to;
				cin >> to;
				table[ id ][ to ] = true;
			}
		}
		int p;
		cin >> p;
		for( int i = 0; i < p; ++i ){
			int from, to, ttl;
			cin >> from >> to >> ttl;
			int result = solve( table, from, to, ttl, n );
			if( result > 0 ){
				cout << result << endl;
			}else{
				cout << "NA" << endl;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 1264
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
int p[5050];
long long c[5050];
int main() {
	long long n, k;
	cin >> n >> k;
	for (int i = 1; i <= n; i++) {
		cin >> p[i];
	}
	for (int i = 1; i <= n; i++) {
		cin >> c[i];
	}
	long long ans = -100000000000000007;
	for (int i = 1; i <= n; i++) {
		long long score = 0;
		long long now = i;
		long long d = 0;
		while (1) {
			now = p[now];
			score += c[now];
			d++;
			if (now == i) {
				break;
			}
		}
		long long ld = 0;
		long long ls = 0;
		long long ln = i;
		long long z = 0;
		while (1) {
			ln = p[ln];
			ls += c[ln];
			ld++;
			long long s = (k - ld) / d;
			if (ld > k) {
				break;
			}
			if (ls + max(z, score) * s > ans) {
				ans = ls + max(z, score) * s;
			}
			if (ln == i) {
				break;
			}
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3556
using System;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');
            int a, b;
            a = int.Parse(str[0]);
            b = int.Parse(str[1]);
            System.Console.WriteLine(a * b + " " + 2 * (a + b));

        }
    }
}

Measured memory_bytes: 9012
#include "bits/stdc++.h"
using namespace std;

int main() {
    long long A,B,K; cin>>A>>B>>K;
    if(A>=K){
        cout<<A-K<<" "<<B<<endl;
    }else{
        if(B-(K-A)<0){
            B = 0;
        }else{
            B = B-(K-A);
        }
        cout<<"0 "<<B<<endl;
    }
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define REP(i, n) for(int i = 0; i < n; ++i)
using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

class Graph
{
private:
	int m_nodeNum;
	vector<vector<int>> m_adList;

	vector<vector<int>> m_connectedComponents;
	vector<int> m_connectedCompunentIndex;

public:
	Graph(const int N) : m_nodeNum(N)
	{
		m_adList = vector<vector<int>>(N);
		m_connectedCompunentIndex = vector<int>(N, -1);
	}

	void Connect(const int v, const int u)
	{
		m_adList[v].push_back(u);
		m_adList[u].push_back(v);
	}

	void ComputeConnectedComponents()
	{
		vector<bool> hasNotVisited(m_nodeNum, true);
		stack<int> stack;
		int ccIndex = 0;
		vector<int> cc;
		for (int v = 0; v < m_nodeNum; ++v)
		{
			if (hasNotVisited[v])
			{
				stack.push(v);
				cc.clear();
				while (!stack.empty())
				{
					int u = stack.top();
					stack.pop();
					hasNotVisited[u] = false;
					m_connectedCompunentIndex[u] = ccIndex;
					cc.push_back(u);
					for (const int n : m_adList[u])
					{
						if (hasNotVisited[n])
						{
							hasNotVisited[n] = false;
							stack.push(n);
						}
					}
				}
				m_connectedComponents.push_back(cc);
				++ccIndex;
			}
		}
	}

	const int GetConnectedComponentSize(const int v)
	{
		int index = m_connectedCompunentIndex[v];
		return static_cast<int>(m_connectedComponents[index].size());
	}

	const int GetConnectedComponentIndex(const int v)
	{
		return m_connectedCompunentIndex[v];
	}

	const int GetMaxComponentSize()
	{
		int ret = 0;
		for (const auto &c : m_connectedComponents)
		{
			int size = c.size();
			ret = max(ret, size);
		}
		return ret;
	}
};

int main()
{
	// 最大クラスターサイズを求めればよい
	int N, M; cin >> N >> M;
	Graph g(N);
	REP(i, M)
	{
		int ai, bi; cin >> ai >> bi; --ai; --bi;
		g.Connect(ai, bi);
	}
	g.ComputeConnectedComponents();
	cout << g.GetMaxComponentSize() << endl;
}


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

int n, zw[2], now = 0, nx, ny, ans = 0;
int a[2005] = {0};

void solve();
int calc(int x);

int main() {
  cin >> n >> zw[0] >> zw[1];
  for(int i = 0; i < n; ++i) cin >> a[i];
  solve();
  cout << ans << endl;
  return 0;
}

void solve() {
  int xy = 0, nextn = 0;
  nx = ny = -1;
  while(1) {
    nextn = n - 1;
    now = abs(zw[!xy] - a[n - 1]);
    if(!xy)
      ans = max(now, ans);
    else
      ans = min(now, ans);
    for(int i = n - 2; i > max(nx, ny); --i) {
      int p = abs(a[n - 1] - a[i]);
      if(!xy) {
        if(p < ans)
          break;
        else if(p >= ans)
          nextn = i;
      }
      else {
        if(p > ans)
          break;
        else if(p < now)
          nextn = i;
      }
    }
    if(nextn == n - 1) break;
    if(nextn == n - 2) {
      ans = abs(a[n - 1] - a[n - 2]);
      break;
    }
    if(!xy)
      nx = nextn;
    else
      ny = nextn;
  }
}

Measured memory_bytes: 256
n,m = [int(i) for i in input().split()]
e = [[int(j) for j in input().split()] for i in range(m)]
new_e =sorted(e,key= lambda x : x[1])
s=[]
for i in new_e:
  if s!= [] and i[0]<=s[-1]:
    pass
  else:
    s.append(i[1]-1)

print(len(s))

Measured memory_bytes: 23596
#include <stdio.h>

int main(void)
{
	float t;
	float t2;
	
	while (scanf("%f %f", &t, &t2) != EOF) {
		if (t < 35.5 && t2 < 71.0) {
			printf("AAA\n");
		}
		else if ((t < 37.5) && (t2 < 77.0)) {
			printf("AA\n");
		}
		else if ((t < 40.0) && (t2 < 83.0)) {
			printf("A\n");
		}
		else if ((t < 43.0) && (t2 < 89.0)) {
			printf("B\n");
		}
		else if ((t < 50.0) && (t2 < 105.0)) {
			printf("C\n");
		}
		else if ((t < 55.0) && (t2 < 116.0)) {
			printf("D\n");
		}
		else if ((t < 70.0) && (t2 < 148.0)) {
			printf("E\n");
		}
		else {
			printf("NA\n");
		}
	}
	return (0);
}

Measured memory_bytes: 604
T = int(input())

for _ in range(T):
    N = int(input())
    A = list(map(int,input().split()))
    S = input()
    l = []
    ans = 0
    
    for a, s in zip(A[::-1], S[::-1]):
        for b in l:
            a = min(a, a^b)
        if a != 0:
            if s == '1':
                ans = 1
            l.append(a)
    
    print(ans)

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

int main(int argc, char const *argv[])
{
    int n; cin >> n;
    int three[3], count[3] = {};
    long long int a[100010];
    for (int i = 0; i < 3; i++) three[i] = -1;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }

    if (n % 3 != 0) {
        for (int i = 0; i < n; i++) {
            if (a[i] != 0) {
            cout << "No"<< endl;
            return 0;
            }
        }
        cout << "Yes" << endl;
        return 0;
    }
    for(int i; i < n; i++) {
        bool next = false;
        for (int j = 0; j < 3; j++)
        {
            if (a[i] == three[j])
            {
                count[j] ++;
                next = true;
                break;
            }

        }
        if (next) continue;
        for (int j = 0; j < 3; j++)
        {
            if (three[j] == -1) {
                three[j] = a[i];
                count[j] ++;
                next = true;
                break;

            }
            /*
            for (int k = 0; k < 3; k++) {
				cout << three[k]<< endl;
            }
            */
        }
        if (!next) {
            cout << "No" << endl;
            return 0;
        }
    }
    /*
    for (int i = 0; i < 3; i++)
    {
        cout << three[i] <<" " << count[i]<< endl;

    }
    */
    if (count[1] == 0 and count[2] == 0)
    {
        if (a[0] == 0) {
            cout << "Yes" << endl;
            return 0;
        }
        cout << "No" << endl;
        return 0;
    }
    if (count[2] == 0) {
        int d;
        if (count[0] > count[1]) d = 0;
        else d = 1;
        if (three[1-d] == 0 and count[d] == 2*count[1-d]) {
            cout << "Yes" << endl;
            return 0;
        }
        cout << "No" << endl;
        return 0;
/*
        int m = max(three[0], three[1]);
        int keta = 1;
        while (m) {
            m /= 2;
            keta ++;
        }
        for (int i = 0; i < keta; i++)
        {
            int a0 = three[d]%2, a1 = three[1-d]%2;
            three[0] /= 2; three[1] /= 2;
            //vector<int> v = {three[0], three[1], three[2]};
            if ((a0*2+a1) % 2 == 1)
            {
                cout << "No" << endl;
                return 0;
            }

        }
        cout << "Yes" << endl;
        return 0;*/
    }

    if (!(count[0] == count[1] and count[1] == count[2]))
    {
        cout << "No" << endl;
        return 0;
    }

    int m = max({three[0], three[1], three[2]});
    int keta = 1;
    while (m) {
        m /= 2;
        keta ++;
    }
    for (int i = 0; i < keta; i++)
    {
        int a0 = three[0]%2, a1 = three[1]%2, a2 = three[2]%2;
        three[0] /= 2; three[1] /= 2; three[2] /= 2;
        //vector<int> v = {three[0], three[1], three[2]};
        if ((a0+a1+a2) % 2 == 1)
        {
            cout << "No" << endl;
            return 0;
        }

    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 1024
#pragma GCC optimize("Ofast")
#include <iostream> // cout, endl, cin
#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 <iomanip> // setprecision
#include <complex> // complex
#include <functional>
#include <math.h> 
#define enld '\n'
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
// constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const int dx[8] = {1, 0, -1, 0,1,1,-1,-1};
const int dy[8] = {0, 1, 0, -1,1,-1,1,-1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ---------------------------------------------------------------------------


int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin >> N;
  vector<int> A(N);
  for(int i=0; i<N; i++) cin >> A[i];
  cout << *max_element(A.begin(),A.end()) - *min_element(A.begin(),A.end()) << "\n";

  return 0;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int x[n+5];
    for(int i=0;i<n;i++)
    {
        cin>>x[i];
    }
    sort(x,x+n);
    int sum=0;
    for(int i=0;i<n-1;i++)
    {
        sum+=x[i];
    }
    sum+=(x[n-1]/2);
    cout<<sum<<endl;
return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define lb(v,n) lower_bound(v.begin(),v.end(),n)
#define ub(v,n) upper_bound(v.begin(),v.end(),n)
#define mae(v) max_element(v.begin(),v.end())
#define mie(v) min_element(v.begin(),v.end())
#define INF 0x7FFFFFFF
#define mod 1000000007
#define fir first
#define sec second
typedef long long ll;
////////////////////////////////////////////////////////////

typedef struct _ufTree{ 
	typedef long idx_type;

	vector<idx_type> par;
	vector<idx_type> rank;
	vector<idx_type> num;
	//n要素で初期化
	void init(idx_type n){
		par.assign(n,0);
		rank.assign(n,0);
		num.assign(n,1);
		for(idx_type i=0;i<n;i++) par[i]=i;
	}
	
	//木の根を求める
	idx_type root(idx_type x){
		if(par[x]==x) return x;
		else return par[x]=root(par[x]);
	}
	
	//xとyが同じ集合に属するかを調べる
	bool same(idx_type x,idx_type y){
		return root(x)==root(y);
	}
	
	//xとyの属する集合を併合
	void unite(idx_type x,idx_type y){
		x=root(x);
		y=root(y);
		if(x==y) return;
		if(rank[x]<rank[y]){
			num[y]+=num[x];
			par[x]=y;
		}
		else{
			num[x]+=num[y];
			par[y]=x;
			if(rank[x]==rank[y]) rank[x]++;
		}
	}

	idx_type size(idx_type x){
		return num[root(x)];
	}

}ufTree;

int main(){

	ll n,m;
	cin >> n >> m;

	stack<pair<ll,ll>> v;
	rep(i,0,m){
		ll f,t;
		cin >> f >> t;
		f--; t--;
		v.push( make_pair( f , t ));
	}

	ufTree uf;
	uf.init(n);

	ll start = n*(n-1)/2;
	stack<ll> ans;
	ans.push(start);

	rep(i,0,m-1){
		auto tmp = v.top();
		v.pop();
		ll f = tmp.fir;
		ll t = tmp.sec;
		if( uf.same( f,t ) )
			ans.push( start );
		else{
			start -=  uf.size(f) * uf.size(t) ;
			ans.push( start );
			uf.unite( f , t );
		}
	}

	while( !ans.empty() ){
		cout << ans.top() << endl;
		ans.pop();
	}

	ret 0;
}

Measured memory_bytes: 5376
import qualified Data.ByteString.Char8 as BS
import Data.Maybe

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words

getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

calc :: [Int] -> Int -> [(Int, Int)]
calc [] _ = []
calc (n : ns) ma = (d, m) : calc ns ma
  where
    n' = ma - n
    d = n' `div` 2
    m = n' `mod` 2

main = do
  ns <- getIntList
  let ts = calc ns (maximum ns)
  let s = sum (map (\t -> fst t) ts)
  let s'
        | l == 0 = s
        | l == 1 = s + 2
        | l == 2 = s + 1
        where
          l = length (filter (\t -> snd t == 1) ts)
  print s'


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

using namespace std;
#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
//rep…「0からn-1まで」の繰り返し
#define rep2(i,s,n) for(long long i=s; i<=(long long)(n);i++)
//rep2…「sからnまで」の繰り返し
#define repr(i,s,n) for(long long i=s;i>=(long long)(n);i--)
//repr…「ｓからnまで」の降順の繰り返し

typedef long long ll;

const int inf = 1e9+7;
const int mod = 1e9+7;

int main(){
    ll n,sum=0;
    cin>>n;

    vector<ll>a(n),cnt(1000000);
    rep(i,n){
        cin>>a[i];
        sum+=a[i];
        cnt[a[i]]++;
    }

    ll q;
    cin>>q;

    vector<ll>b(q),c(q);
    rep(i,q)cin>>b[i]>>c[i];

    rep(i,q){
        sum+=(c[i]-b[i])*cnt[b[i]];
        cout<<sum<<endl;

        cnt[c[i]]+=cnt[b[i]];
        cnt[b[i]]=0;

    }
}


Measured memory_bytes: 13496
#include <bits/stdc++.h>
#include<vector>
using namespace std;
int n;
int sub(string a,char b){
  if(a.size()==n)cout<<a<<endl;
  else{
    for(char c='a';c<=b;c++){
      char d;
      if(c==b)d=char(b+1);
      else d=b;
      sub(a+c,d);
    }
  }
}
int main(){
  cin>>n;
  sub("",'a');
}

Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
 
int a[15];
 
int main(){
    for(int i=0;i<10;i++){
        cin>>a[i];
    }
    sort(a, a+10);
    cout<<a[9]<<endl
        <<a[8]<<endl
        <<a[7]<<endl;
}

Measured memory_bytes: 3112
#include<bits/stdc++.h>
using namespace std;
#define MAX 100000

int main(){
  int n;
  cin >> n;
  int v;
  pair<int, int> odd[MAX+1]; // cnt, num
  pair<int, int> even[MAX+1]; // cnt, num
  // init
  for ( int i = 1; i <= MAX; i++)odd[i] = even[i] = make_pair(0, 0);

  for ( int i = 1; i <= n; i++){
    cin >> v;
    if ( i % 2 == 1){
      if ( odd[v].first == 0){
        odd[v] = make_pair(1, v);
      } else {
        odd[v].first ++;
      }
    } else {
      if ( even[v].first == 0){
        even[v] = make_pair(1, v);
      } else {
        even[v].first ++;
      }
    }
  }

  sort(odd+1, odd+MAX+1);
  sort(even+1, even+MAX+1);
  if( odd[MAX].second != even[MAX].second){
    cout << n - odd[MAX].first - even[MAX].first << endl;
  } else {
    cout << n - max(odd[MAX].first + even[MAX-1].first, odd[MAX-1].first + even[MAX].first) << endl;
  }

  return 0;
}


Measured memory_bytes: 1920
sets=["A","T","G","C"]
outs = ["AGC", "ACG","GAC"]
outs2 = ["ATGC","AGGC","AGTC"]
N = int(input())

befs = {}
afts = {}
for s in sets:
	for t in sets:
		for  u in sets:
			v = s+t+u
			if not v in outs:
				afts[s+t+u] = 1
				befs[s+t+u] = 1
#print([a for a in afts.keys()])
for i in range(4,N+1):
	for a in afts.keys():
		afts[a]=0
	for s in sets:
		for b in befs.keys():
			t = s+b
			if not t[:3] in outs and not t in outs2:
				afts[t[:3]] += befs[b]
	#print([a for a in afts.values()])
	for a in afts.keys():
		befs[a] = afts[a] %1000000007

ans = 0
for a in afts.keys():
	ans += afts[a]
ans %= 1000000007
print(ans)





Measured memory_bytes: 3064
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        String S = sc.next();
        int r_count[] = new int[N+1];
        int g_count[] = new int[N+1];
        int b_count[] = new int[N+1];
        r_count[N]=0;
        g_count[N]=0;
        b_count[N]=0;
        for(int i=N-1; i>=0; i--) {
            char tmp = S.charAt(i);
            r_count[i]=r_count[i+1] + (tmp=='R' ? 1 : 0);
            g_count[i]=g_count[i+1] + (tmp=='G' ? 1 : 0);
            b_count[i]=b_count[i+1] + (tmp=='B' ? 1 : 0);
        }
        long result = 0L;
        result += count(S, 'R', 'G', 'B', r_count, g_count, b_count);
        result += count(S, 'R', 'B', 'G', r_count, b_count, g_count);
        result += count(S, 'G', 'R', 'B', g_count, r_count, b_count);
        result += count(S, 'G', 'B', 'R', g_count, b_count, r_count);
        result += count(S, 'B', 'R', 'G', b_count, r_count, g_count);
        result += count(S, 'B', 'G', 'R', b_count, g_count, r_count);
        System.out.println(String.format("%d", result));
    }
    static long count(String S, char A, char B, char C, int[] a_arr, int[] b_arr, int[] c_arr) {
        long result = 0L;
        for(int a=0; a<S.length(); a++) {
            char tmp_a = S.charAt(a);
            if(tmp_a !=A) continue;
            for(int b=a+1; b<S.length()-1; b++) {
                char tmp_b = S.charAt(b);
                if(tmp_b!=B) continue;
                result+=c_arr[b+1];
                if(b+(b-a)<S.length() && S.charAt(b+(b-a))==C) result--;
            }
        }
        return result;
    }
}


Measured memory_bytes: 36636
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
 
#define EPS 1e-9
#define INF 1070000000LL
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(__typeof((X).begin()) it=(X).begin();it!=(X).end();it++)
#define ite iterator
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define pb push_back
#define sec second
#define sz(x) ((int)x.size())
 
using namespace std;
 
struct timer{
    time_t start;
    timer(){start=clock();}
    ~timer(){cerr<<1.*(clock()-start)/CLOCKS_PER_SEC<<" secs"<<endl;}
};
 
typedef istringstream iss;
typedef long long ll;
typedef pair<int,int> pi;
typedef stringstream sst;
typedef vector<int> vi;
 
ll N,H,d[100010],h[100010],sumd[100010];
 
struct segtree{
    ll x;
    int l,r;
    segtree *cl,*cr;
     
    segtree(int l,int r): l(l),r(r){
        if(l+1==r){
            x=h[l];
            return;
        }
        cl=new segtree(l,l+r>>1);
        cr=new segtree(l+r>>1,r);
        x=max(cl->x,cr->x);
    }
     
    void change(int pos,ll v){
        if(pos<l || r<=pos){
            return;
        }
        if(l+1==r){
            x=v;
            return;
        }
        cl->change(pos,v);
        cr->change(pos,v);
        x=max(cl->x,cr->x);
    }
     
    ll query(int L,int R,int& ind){
        if(R<=l || r<=L){
            return -INF*INF;
        }
        if(l+1==r){
            ind=l;
            return x;
        }
        int ind1,ind2;
        ll res1 = cl->query(L,R,ind1);
        ll res2 = cr->query(L,R,ind2);
        if(res1 >= res2){
            ind=ind1;
            return res1;
        }
        ind=ind2;
        return res2;
    }
} *root;
 
int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(0);
     
    cin>>N>>H;
    rep(i,N-1){
        cin>>d[i]>>h[i];
        sumd[i+1]=sumd[i]+d[i];
    }
    root=new segtree(0,N-1);
    ll ans=0,hp=H,from=0;
    rep(i,N-1){
        hp-=d[i];
        //cout<<hp<<" "<<ans<<" "<<from<<endl;
        while(hp<=0){
            ll need=1-hp;
            int ind;
            ll maxi=root->query(from,i+1,ind);
            from=ind;
            ll HPpre=hp+sumd[i+1]-sumd[ind];
            //cout<<hp<<" "<<HPpre<<endl;
            //cout<<from<<" - "<<i<<" : "<<maxi<<"("<<ind<<")"<<endl;
            ll maxtime=(H-HPpre)/maxi;
            ll want=(need+maxi-1)/maxi;
            //cout<<maxtime<<" "<<want<<endl;
            if(want <= maxtime){
                ans+=want;
                hp+=want*maxi;
                break;
            }else{
                ll rest=(H-HPpre)%maxi;
                if(rest==0)from++;
                else root->change(ind,rest);
                ans+=maxtime;
                hp+=maxtime*maxi;
            }
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 12916
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)

ll mod = 1e09 + 7;

ll nCr(int n, int r);
ll cmb(int n, int r);

ll nCr(int n, int r){
  if(r == 0) return 0;
  return nCr(n, r - 1) * (n - (r - 1)) / r;
}

ll cmb(int n, int r){
  vector<vector<ll> > v(n + 1, vector<ll>(n + 1, 0));
  int l = v.size();
  REP(i, l){
    v[i][0] = 1;
    v[i][i] = 1;
  }
  FOR(j, 1, l){
    FOR(k, 1, j){
      v[j][k] = (v[j - 1][k - 1] + v[j - 1][k]);
    }
  }
  return v[n][r];
}

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

  int n, a, b;
  cin >> n >> a >> b;
  vector<ll> v(n);
  REP(i, n) cin >> v[i];

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

  ll sum = 0;
  REP(i, a) sum += v[i];
  double ave = (double)sum / a;
  cout << fixed << setprecision(10) << ave << endl;

  int p = 0, q = 0;

  for(int i = a - 1; i >= 0; i--){
    if(v[i] != v[a - 1]) break;
    p++;
  }
  for(int i = a; i < n; i++){
    if(v[i] != v[a - 1]) break;
    q++;
  }

  ll ans = 0;
  if(p == a){
    FOR(i, a, min(b, p + q) + 1) ans += cmb(p + q, i);
  }
  else ans = cmb(p + q, p);
  cout << ans << endl;
}


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


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

	int A[30];
	int B[30];
	int C[30];

	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 ans = 0;
	int before = -2;

	for (int i=0; i<N; i++){
		int now = A[i];
		if (now != before + 1){
			ans = ans + B[now-1];
			before = now;
		}
		else{
    	ans = ans + B[now-1];
			ans = ans + C[before-1];
    	before = now;
		}

	}

	cout << ans  << endl;

  return 0;
}

Measured memory_bytes: 256
import heapq

n ,m = map(int,input().split())
li = []
for i in range(n):
    x, y= map(int,input().split())
    li.append([x,y])
li.sort()
heap = []

ans = 0
j = 0
for i in range(1, m + 1):
    while j < n and li[j][0] <= i:
        heapq.heappush(heap,-li[j][1])
        j += 1
    if heap:
        ans += -heapq.heappop(heap)
 
print(ans)

Measured memory_bytes: 23880
gets
a = gets.chomp.split(" ").map(&:to_i)
b = gets.chomp.split(" ").map(&:to_i)
c = gets.chomp.split(" ").map(&:to_i)
score = b[a[0]-1]
a.inject do |i,j|
  score += b[j-1]
  if i+1 == j
    score += c[j-2]
  end
  j
end
print("#{score}")

Measured memory_bytes: 1788
n = int(input())
cnt = 0
x = []
for _ in range(n):
    a, b = map(int, input().split())
    x.append([b, a])
x.sort()
for i in range(n):
    cnt += x[i][1]
    if cnt <= x[i][0]:
        pass
    else:
        print('No')
        break
else:
    print('Yes')


Measured memory_bytes: 35608
#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<complex>
#include<string>
#include<cstring>
using namespace std;
#define rep2(x,from,to) for(int x=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)
#define INF 10000000
#define MAX_OTURI 50005
#define all(x) x.begin(),x.end()
typedef pair<int,int> P;
typedef pair<int,P> PP;
int n;
int a,b,c,d;
int aa,bb,cc,dd;
int aaa,bbb,ccc,ddd;
int ans;
int main()
{
	ans=INF;
	cin>>n>>a>>b>>c>>d;
	a--;b--;c--;d--;
	rep2(i,1,n+1)
	{
		aa=a/i;
		aaa=a%i;
		bb=b/i;
		bbb=b%i;
		cc=c/i;
		ccc=c%i;
		dd=d/i;
		ddd=d%i;
		ans=min(ans,abs(aa-bb)+abs(aaa-bbb)+abs(cc-dd)+abs(ccc-ddd));
	}
	cout<<ans<<endl;
	return 0;
}

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


void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define fill(a)  memset(a, 0, sizeof (a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
typedef long double ld;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

void pre(){


}

void solve(){


}
int dp[109][109];
string s[109];
int main() {
	cin.sync_with_stdio(0); cin.tie(0);
	cin.exceptions(cin.failbit);
	pre();
	int n,m;cin>>n>>m;
	rep(i,n) cin>>s[i];
	if(s[0][0]=='#') dp[0][0] = 1;
	rep(i,n) rep(j,m){
		if(i==0&&j==0) continue;
		dp[i][j] = 2000;
		if(i) {
			if(s[i][j]=='#'&&s[i-1][j]=='.') dp[i][j]=min(dp[i][j],dp[i-1][j]+1);
			else dp[i][j]=min(dp[i][j],dp[i-1][j]);
		}
		if(j) {
			if(s[i][j]=='#'&&s[i][j-1]=='.') dp[i][j]=min(dp[i][j],dp[i][j-1]+1);
			else dp[i][j]=min(dp[i][j],dp[i][j-1]);
		}
	}
	cout<<dp[n-1][m-1];
	return 0;
}



Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  int ans=0;
  int a[n];
  for(int i=0;i<n;i++)
  {
    cin>>a[i];
  }
  int temp=0;
  for(int i=0;i<n;i++)
  {
  	if(a[i]>temp)
  	{
  		a[i]--;
  		temp=a[i];
	}
  }
  int e=0;
  for(int i=0;i<n-1;i++)
  {
  	if(a[i]>a[i+1])
  	{
  		e++;
		  break;	
	}
  }
  if(e)
  {
  	cout<<"No\n";
  }
  else
  {
  	cout<<"Yes\n";
  }
}

Measured memory_bytes: 640
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);

		int n = scan.nextInt();
		for (int i = 0; i < n; i++) {
			int stones = scan.nextInt();
			int people = scan.nextInt();

			if (stones < people)
				System.out.println(stones);
			else if (stones % people == 0)
				System.out.println(people);
			else
				System.out.println(stones % people);

		}
	}
}

Measured memory_bytes: 20356
using System;

public class AtCoder
{
    public static void Main()
    {
        string[] s;
        s = NextS();

        long n, p;
        n = long.Parse(s[0]);
        p = long.Parse(s[1]);
        //w = int.Parse(s[2]);
        long x = 1;
        long m = 2;
        long ans = 0;
        bool f1 = true;
        long y = 1;
        if (n == 1) Console.WriteLine(p);
        else if (n > 40) Console.WriteLine(1);
        else
        {
            while (f1)
            {
                for (int i = 1; i <= n; i++)
                {
                    x *= m;
                    if (x > p)
                    {
                        f1 = false;
                        break;
                    }
                }
                if (f1)
                {
                    m++;
                    x = 1;
                }
            }
            for (int i = 1; i <= m; i++)
            {
                y = (long)Math.Pow(i, n);
                if (p % y == 0) ans = i;
            }
            Console.WriteLine(ans);
        }
       
        
    }

    static void DebugWL(object x) { System.Diagnostics.Debug.WriteLine(x); }
    static string[] NextS() { return Console.ReadLine().Trim().Split(' '); }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <utility>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pair;

int main(){
    int n, k;
    cin >> n >> k;
    vector<int> x(n);
    rep(i, n) {
        cin >> x[i];
    }   

    int ans = 0;

    rep(i, n) {
        if (x[i] <= k - x[i]) {
            ans += x[i] * 2;
            continue;
        }
        else {
            ans += (k - x[i]) * 2;
        }
    }

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


Measured memory_bytes: 3528
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#include<cmath>

#define REP(i,n) for (int i = 0; (i) < (n); ++ (i))
#define FOR(i,n) for (int i = 1; (i) <= (n); ++ (i))
#define dump(x)  cout << #x << " = " << (x) << endl;
#define pb push_back
#define int long long

const int INF = 1e18;
const int MOD = 1e9+7;
//const lint LINF = 1e18;
const double eps = 0.000000001;//もとの値の10^(-16)まで

using namespace std;

//typedef pair<int, int> P;
//priority_queue< P, vector<P>, greater<P> > q;//ダイクストラの時、greaterで小さい順
//cout << fixed << setprecision(10) << ans << endl;
//int gcd(int a,int b){return b?gcd(b,a%b):a;}

signed main(){
    int n;
	cin >> n;
    if(n==1){
        cout << 0 << endl;
        return 0;
    }
    int ans = 0;
    int kk = min(n,(int)1000003);
    int f= 0;
    REP(i,kk){
        if(i==0) continue;
        if(i==1) continue;
        int cnt = 0;
        while(n%i==0){
            n/=i;
            cnt ++;
        }
        if(cnt==0)continue;
        for(int j=1;j<100;j++){
            cnt -= j;
            if(cnt<0) break;
            ans ++;
        }
    }
    if(n!=1) ans ++;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define REP(i,n) for(int64_t i=0;i<(n);i++)
#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REV(c) reverse((c).begin(),(c).end())
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
#define VIN(n,v) for(int64_t i=0;i<(n);i++){cin >> (v).at(i);}

using namespace std;
typedef int64_t I;
typedef pair<I,I> P;
typedef vector<I> V;

I MOD = pow(10,9)+7;

// 最大公約数
I gcd(I a, I b) {
  return b != 0 ? gcd(b, a % b) : a;
}

// 最小公倍数
I lcm(I a, I b) {
  return a * b / gcd(a, b);
}

int ctoi(char c){
  return c - '0';
}

int main(){
  I a;
  string s;
  cin >> a >> s;
  if (a >= 3200){
    cout << s << endl;
  }else{
    cout << "red" << endl;
  }
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define len(x) ((long long)(x).size())
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using pll = pair<ll, ll>;
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U>bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U>bool isin(T el, U container) { return find(all(container), el) != container.end(); }
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<class T>bool even(T n) { return ! (n & 1); }
template<class T>bool odd(T n) { return n & 1; }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
ll intpow(ll a,ll n){ll p=1;while(n){if(n&1)p*=a;a*=a;n>>=1;}return p;}
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;



int main()
{
        string a, b;
        cin >> a >> b;
        string n;
        n = a + b;
        ll num = stoll(n);
        rep(i, 1, num+1) {
                if (i * i == num) {
                        cout << "Yes" << endl;
                        return 0;
                }
        }
        cout << "No" << endl;
}

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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;

const ll mod = 1e9+7;
const int maxn = 1e6 + 5;



int n;
string s;

map<char, vector<int>> mp;

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

    cin>>n>>s;
    for (int i=0; i<n; i++) {
	mp[s[i]].push_back(i);
    }

    int ans = 0;

    for (int pin=0; pin<=999; pin++) {
	string cur = to_string(pin);
	while ((int)cur.length() < 3) {
	    cur = "0" + cur;
	}

	bool ok = true;
	for (char c: cur) {
	    if (mp[c].empty()) ok = false;
	}
	if (!ok) continue;

	ok = false;
	for (int i: mp[cur[1]]) {
	    if (*mp[cur[0]].begin() < i && *mp[cur[2]].rbegin() > i) {
		ok = true;
		break;
	    }
	}

	ans += ok;
    }


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


Measured memory_bytes: 3912
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.nextLine());
		int[] b = new int[n - 1];
		for(int i = 0; i < n - 1; i++) {
			b[i] = Integer.parseInt(sc.next());
		}
		sc.close();
		System.out.println(new Main().maximal_value(n, b));
	}
	
	public int maximal_value(int n, int[] b) {
		int sum = b[n - 2];
		for(int i = n - 2; i > 0; i--) {
			sum += (b[i] <= b[i - 1]) ? b[i] : b[i - 1];
		}
		return sum + b[0];
		
	}
}

Measured memory_bytes: 21844
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class Main {
    public static void main(final String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final int n = scanner.nextInt();

        final Map<String, Integer> countMap = new HashMap<>();
        for (int i = 0; i < n; i++) {
            final String key = scanner.next();
            countMap.compute(key, (k, v) -> v == null ? 1 : v + 1);
        }

        final List<String> answers = new ArrayList<>();
        int max = -1;
        for (final Map.Entry<String, Integer> entry : countMap.entrySet()) {
            if (entry.getValue() > max) {
                answers.clear();
                answers.add(entry.getKey());
                max = entry.getValue();
            } else if (entry.getValue() == max) {
                answers.add(entry.getKey());
            }
        }

        Collections.sort(answers);
        for (final String answer : answers) {
            System.out.println(answer);
        }
    }
}


Measured memory_bytes: 83096
x = 0
while x == 0:
 
 m = map(int,raw_input().split())
 
 if m[0] == 0 and m[1] == 0:
     break
 
 print "#" * m[1]
 for i in xrange(m[0]-2):
    print "#" + "." * (m[1]-2) + "#"
 print "#" * m[1]
 print 

Measured memory_bytes: 6436
//This code was made by Chinese_zjc_.
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#define int long long
#define INF 0x3fffffffffffffff
using namespace std;
int n,k,m,tmp,ans;
bool good[101];
signed main()
{
	std::ios::sync_with_stdio(false);
	cin>>n>>k;
	for(int i=1;i<=k;++i)
	{
		cin>>m;
		for(int l=1;l<=m;++l)
		{
			cin>>tmp;
			good[tmp]=true;
		}
	}
	for(int i=1;i<=n;++i)
	{
		if(!good[i])
		{
			++ans;
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using vpii = vector<pair<int, int>>;
using vpll = vector<pair<ll, ll>>;

int		main(void)
{
	char c;
	cin >> c;
	cout << ++c << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, N) for (int i = 0; i < (N); i++)
#define swap(a, b) (a += b, b = a - b, a -= b)
using namespace std;
int main()

{
    long long N, M;
    cin >> N >> M;
    cout << abs(M * N - (M * 2 + (N - 2) * 2)) << endl;
}

Measured memory_bytes: 256
def solve():
    N,M = [int(i) for i in input().split()]
    ans = 0
    if N > 1:
        ans += N * (N-1) // 2
    if M > 1:
        ans += M * (M-1) // 2
    print(ans)

if __name__ == "__main__":
    solve()

Measured memory_bytes: 9176
import java.util.Scanner;

public class Main {
	
	   

		public static void main(String[] args) {
	        Scanner sc = new Scanner(System.in);
	        int n = sc.nextInt();
	        int m = sc.nextInt();
//	        int z = sc.nextInt();
	        int sum = 0;
	        int cnt = 0;
	        int[] all = new int[n];
	        for(int i = 0 ; i<n; i++) {
	        	all[i] = sc.nextInt();
	        	sum += all[i];
	        }
	        
	        for(int i = 0 ; i<n; i++) {
	        	if(all[i]*4*m >= sum) {
	        		cnt++;
	        	}
	        	
	        }
	        if(cnt >= m)  System.out.println("Yes");
	        else System.out.println("No");
	        
	        
	        
	        
	        
	        
	        
	       // System.out.println(result); 
	        
            

          
	        
            //System.out.println(res); 
	        
	}
}


Measured memory_bytes: 35928
#include <iostream>
#include <algorithm>
#include <cstdlib>

int main()
{
    int n, k, sum{};
    std::cin >> n >> k;
    for (auto i = 0; i < n; ++i)
    {
        int x;
        std::cin >> x;
        sum += std::min(std::abs(x - k), x) * 2;
    }
    std::cout << sum << std::endl;
    return 0;
}


Measured memory_bytes: 764
#include<cstdio>
#include<map>
using namespace std;

#define i64 long long int
#define u64 unsigned long long int
#define mod 10000019
#define inv 8343730571309479835LLU
int n, M;
u64 mu[555555],iv[555555],H;
char s[255555];
i64 res;

map<u64, int> Map;
void rec(int L, int R) {
	if (L == R) {
		i64 h = (s[L] == '+' ? mu[n] : s[L] == '-' ? 0 - mu[n] : 0);
		if (h == H)
			res++;
		return;
	}
	int M = (L + R) / 2;

	int cur = n;
	u64 h = 0;
	Map.clear();
	for (int i = M + 1; i <= R; i++) {
		if (s[i] == '+')
			h += mu[cur];
		else
			if (s[i] == '-')
				h -= mu[cur];
			else
			if (s[i] == '>')
					cur++;
				else
					cur--;
		Map[h] ++;
	}
	h = 0;
	cur = n;
	for (int i = M; i >= L; i--) {
		if (s[i] == '+')
			h += mu[n];
		else {
			if (s[i] == '-')
				h -= mu[n];
			else
				if (s[i] == '>') {
					cur++;
					h *= mod;
				}
				else {
					cur--;
					h *= inv;
				}
		}
		u64 h2 = H - h;
		if (cur > n)h2 *= iv[cur - n];else
			h2 *= mu[n - cur];
		if (Map.count(h2))
			res += Map[h2];
	}

	rec(L, M);
	rec(M + 1, R);
}

int main() {
	scanf("%d%s", &n,s);

	M = 2 * n + 1;
	mu[0] = iv[0] = 1;
	for (int i = 1; i < M; i++) {
		mu[i] = mu[i - 1] * mod;
		iv[i] = iv[i - 1] * inv;
	}
	
	int cur = n;

	u64 h = 0;
	for (int i = 0; i < n; i++) {
		if (s[i] == '+')
			h += mu[cur];
		else
			if (s[i] == '-')
				h -= mu[cur];
			else
				if (s[i] == '>')
					cur++;
				else
					cur--;
	}
	H = h;

	rec(0, n-1);

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


Measured memory_bytes: 16512
#include<stdio.h>



int LIS(void);



int h[201], r[201], m, n;



int main(void)

{

int i, j, t;

while(1)

{

scanf("%d",&n);

if(n==0)break;



for(i=0;i<n;i++)

scanf("%d%d",&h[i] ,&r[i]);



scanf("%d",&m);



for(i=n;i<n+m;i++)

scanf("%d%d",&h[i],&r[i]);



for(i=0;i<n+m;i++)

{

for(j=0;j<n+m;j++)

{

if(h[i]<h[j])

{

t=h[i];

h[i]=h[j];

h[j]=t;

t=r[i];

r[i]=r[j];

r[j]=t;

}

if(h[i]==h[j] && r[i]<r[j])

{

t=h[i];

h[i]=h[j];

h[j]=t;

t=r[i];

r[i]=r[j];

r[j]=t;

}

}

}

printf("%d\n",LIS());

}

return 0;

}


int LIS(void)

{

int i, j, k, L[201], max=0;



for(i=0;i<201;i++)

L[i]=1;



for(i=1;i<n+m;i++)

{

j=i-1;

for(k=0;k<i;k++)

{

if(r[k]<r[i] && h[k]<h[i] && L[k]>=L[i])L[i]=L[k]+1;

}

}

for(i=0;i<n+m;i++)

if(max<L[i])max=L[i];



return max;

}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
#ifdef __LOCAL
#define debug(x) cerr << __LINE__ << ": " << #x << " = " << x << endl
#define debugArray(x, n)                           \
  cerr << __LINE__ << ": " << #x << " = {";        \
  for (long long hoge = 0; (hoge) < (n); ++(hoge)) \
    cerr << ((hoge) ? "," : "") << x[hoge];        \
  cerr << "}" << endl
#else
#define debug(x) (void(0))
#define debugArray(x, n) (void(0))
#endif

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  long long ans = 0;
  long long mxp = 0;
  for (int i = 0; i < N; i++) {
    long long p;
    cin >> p;
    ans += p;
    mxp = max(mxp, p);
  }
  ans -= mxp / 2;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3644
while True:
    a, op, b = input().split()
    a = int(a)
    b = int(b)
    if op == "+":
        print(a + b)
    elif op == "-":
        print(a - b)
    elif op == "*":
        print(a * b)
    elif op == "/":
        print(a // b)
    else:
        break



Measured memory_bytes: 5592
#include <iostream>
#include <cstdint>

int main() {
  char c0, c1 = '\0', c2 = '\0';
  std::int_fast32_t i = 1;
  while (std::cin >> c0) {
    if (c0 == c1) {
      std::cout << i - 1 << ' ' << i << std::endl;
      return 0;
    } else if (c0 == c2) {
      std::cout << i - 2 << ' ' << i << std::endl;
      return 0;
    }
    c2 = c1;
    c1 = c0;
    ++i;
  }
  std::cout << -1 << ' ' << -1 << std::endl;
  return 0;
}

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

int main() {
  int a, b;
  cin >> a >> b;
  string ans = "Impossible";
  if (a % 3 == 0) {
    ans = "Possible";
  } else if (b % 3 == 0) {
    ans = "Possible";
  } else if ((a+b)%3 == 0) {
    ans = "Possible";
  }
  cout << ans << endl;
}

Measured memory_bytes: 256