akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(n); ++i)
#define repr(i, a, b) for (int i=a; i<(b); ++i)
#define reprev(i, n) for (int i=n-1; i>=0; --i)
#define reprrev(i, a, b) for (int i=b-1; i>=(a); --i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main() {
    cout << fixed << setprecision(10);
    ll MOD = 1e9 + 7;
    int H, W; cin >> H >> W;
    vector<string> a;
    a.resize(H);
    rep(i, H) {
        cin >> a[i];
    }
    vector<vector<ll>> dp(H+1, vector<ll>(W+1, 0));
    dp[1][1] = 1;

    repr(i, 1, H+1) {
        repr(j, 1, W+1) {
            if (i == 1 && j == 1) continue;
            // cout << "check_2" << endl;
            // 0のまま
            if (a[i-1][j-1] == '#') continue;

            dp[i][j] = (dp[i-1][j] + dp[i][j-1]) % MOD;
        }
        /*
        repr(k, 1, H+1) {
            repr(l, 1, W+1) {
                cout << dp[k][l] << " ";
            }
            cout << endl;
        }
        cout << endl;
        */
    }
    cout << dp[H][W] << endl;
    return 0;
}

Measured memory_bytes: 9216
#include<stdio.h>
#include<algorithm>
#include<vector>
using namespace std;
vector<int> e[10];
int dp[11][2001];
int main(){
	int a,b;
	scanf("%d%d",&a,&b);
	for(int i=0;i<a;i++){
		int c,d;
		scanf("%d%d",&c,&d);
		e[d-1].push_back(c);
	}
	for(int i=0;i<10;i++)std::sort(e[i].begin(),e[i].end());
	for(int i=0;i<11;i++)
		for(int j=0;j<2001;j++)
			dp[i][j]=-99999999;
	dp[0][0]=0;
	for(int i=1;i<=10;i++){
		for(int j=0;j<=b;j++){
			int now=0;
			for(int k=0;k<=j&&k<=e[i-1].size();k++){
				dp[i][j]=max(dp[i][j],dp[i-1][j-k]+now+k*(k-1));
				if(k<e[i-1].size())now+=e[i-1][e[i-1].size()-1-k];
			}
		}
	}
	printf("%d\n",dp[10][b]);
}

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

#define for_(i,a,b) for(int i=a;i<b;++i)

int main() {
	int N;

	while (scanf("%d", &N), N) {		
		int ans = 1, f = 0;
		
		for_(i,0,N) {
			int k; scanf("%d", &k);
			if (k) ++ans;
			else continue;
			if (k > 1) f = 1;
		}
		
		if (f) printf("%d\n", ans);
		else printf("NA\n");
	}
	
	return 0;
}

Measured memory_bytes: 1196
import java.util.*;
public class Main {
	public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      String line = sc.nextLine();
      String str[] = line.split(" ");
      long a = Long.parseLong(str[0]);
      long b = Long.parseLong(str[1]);
      long x = Long.parseLong(str[2]);
      long count = 0;
      if(a%x==0){
        count = b/x -a/x+1;
      } else {
        count = b/x -a/x;
      }
      System.out.println(count);
	}
}

Measured memory_bytes: 22612
function main(input) {
	const args = input.split(' ');
	const N = parseInt(args[0], 10);
	const M = parseInt(args[1], 10);
    console.log(conbination(N, M));
    
}

function conbination(n, m) {
    const ans1 = (n * (n - 1) / 2) * 10 % 10 === 0 ? n * (n - 1) / 2 : 0;
    const ans2 = (m * (m - 1) / 2) * 10 % 10 === 0 ? m * (m - 1) / 2 : 0;
    return ans1 + ans2;
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

#define int long long

int N, M;
int P[111111], Y[111111];
int cnt[111111];

// 1スタート
// G[県]<年, 番号>
map<int, int> G[111111];

signed main() {
   // 入力
   cin >> N >> M;
   for (int i= 0; i < M; i++) {
      cin >> P[i] >> Y[i];
      G[P[i]][Y[i]] = 0;
   }

   // mapによって年でソートされているため、それに従い番号を振る
   for (int i = 1; i <= N; i++) {
      int cnt = 1;
      for (auto x : G[i]) {
         G[i][x.first] = cnt;
         cnt++;
      }
   }

   for (int i= 0; i < M; i++) {
      int p = P[i], y = Y[i];
      int number = G[p][y]; // G[県][年] = 番号
      printf("%06lld%06lld\n", p, number);
   }

   return 0;
}

Measured memory_bytes: 15360
#include <iostream>
#include <cassert>
#include <iomanip>
#include <utility>
#include <cmath>
#include <numeric>
#include <vector>
#include <set>
#include <algorithm>
#include <queue>
#include <string>

using namespace std;

typedef long long ll;
typedef pair<int, int> p_i;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repext(i, a, b) for (int i = a; i < b; i++)
#define reprev(i, n) for (int i = n - 1; i >= 0; i--)
#define repextrev(i, a, b) for (int i = b - 1; i >= a; i--)
#define vec_all(vec) vec.begin(), vec.end()

// vectorデバッグ
template<typename T>
void dump_vec(vector<T> vec) {
    rep(i, vec.size()) {
        cout << i << ": " << vec[i] << endl;
    }
}

// --- notice ---
// intの和はllにしろ

int main() {
    int n;
    cin >> n;
    vector<int> a(n + 2);
    vector<int> cost(n + 2);
    a[0] = 0;
    a[n + 1] = 0;
    cost[0] = 0;
    rep(i, n) {
        cin >> a[i + 1];
        cost[i + 1] = cost[i] + abs(a[i + 1] - a[i]);
    }
    cost[n + 1] = cost[n] + abs(a[n]);

    ll total_cost = cost[n + 1];
    ll save = 0;
    ll previous_cost;
    ll following_cost;
    repext(i, 1, n + 1) {
        previous_cost = a[i + 1] - a[i];
        following_cost = a[i] - a[i - 1];
        if (previous_cost * following_cost < 0) {
            save = (abs(previous_cost) + abs(following_cost));
            cout << total_cost - save + abs(a[i + 1] - a[i - 1]) << endl;
        } else {
            cout << total_cost << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 2048
def main():
    W, H, N = (int(i) for i in input().split())
    seen = [[True]*W for h in range(H)]

    for i in range(N):
        x, y, a = (int(i) for i in input().split())
        if a == 1:
            for h in range(H):
                for w in range(x):
                    seen[h][w] = False
        elif a == 2:
            for h in range(H):
                for w in range(x, W):
                    seen[h][w] = False
        elif a == 3:
            for h in range(y):
                for w in range(W):
                    seen[h][w] = False
        elif a == 4:
            for h in range(y, H):
                for w in range(W):
                    seen[h][w] = False

    ans = 0
    for i in range(H):
        for j in range(W):
            if seen[i][j]:
                ans += 1
    print(ans)
    # print(*seen, sep='\n')


if __name__ == '__main__':
    main()


Measured memory_bytes: 41968
K = int(input())

ans = 1
x = 7
useds = [0] * (10**6+5)
useds[x] = 1
while True:
    if x%K == 0:
        print(ans)
        break
    x = (x*10 + 7) % K
    ans += 1
    if useds[x]:
        print(-1)
        break
    useds[x] = 1


Measured memory_bytes: 71220
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#define MOD 1000000007LL
using namespace std;

int main(){
	string s;
	cin >> s;
	int cf = 0;
	int ff = 0;
	int cm = 1000;
	int lm = -1;
	for(int i = 0; i < s.size(); i++){
		if(s[i] == 'C' && i < cm){cf = 1; cm = i;}
		if(s[i] == 'F' && i > lm){ff = 1; lm = i;}
	}
	if(cf * ff == 0 || cm > lm) cout << "No" << endl;
	else cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define res register int
#define mod 1000000007
#define N 8005
#define M 200005
#define LL long long
using namespace std;
int n,a[M],b[M],c[N],inv[N];
int f[N][N];
inline int read() {
	int X=0,w=0;
	char ch=0;
	while(!isdigit(ch)) {
		w|=ch=='-';
		ch=getchar();
	}
	while(isdigit(ch)) X=(X<<3)+(X<<1)+(ch^48),ch=getchar();
	return w?-X:X;
}
inline int &g(res x,res y) {
	return f[x+2001][y+2001];
}
inline int calc(int x,int y) {
	return 1LL*c[x]*inv[y]%mod*inv[x-y]%mod;
}
int main() {
	n=read();
	c[0]=1;
	for(res i=1; i<=8000; i++)
		c[i]=1LL*c[i-1]*i%mod;
	inv[1]=1;
	for(res i=2; i<=8000; i++)
		inv[i]=1LL*(mod-mod/i)*inv[mod%i]%mod;
	inv[0]=1;
	for(res i=1; i<=8000; i++)
		inv[i]=1LL*inv[i]*inv[i-1]%mod;
	for(res i=1; i<=n; i++) g(-(a[i]=read()),-(b[i]=read()))++;
	for(res i=-2000; i<=2000; i++)
		for(res j=-2000; j<=2000; j++)
			g(i,j)=((LL)g(i,j)+g(i-1,j)+g(i,j-1))%mod;
	int ans=0;
	for(res i=1; i<=n; i++) ans=((LL)ans+g(a[i],b[i])-calc(a[i]+a[i]+b[i]+b[i],b[i]+b[i]))%mod;
	ans=1LL*ans*inv[2]%mod;
	printf("%d\n",(ans+mod)%mod);
	return 0;
}

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

int main(){
    int n;
    cin>>n;
    ll t[n];
    rep(i,n){
        cin>>t[i];
    }
    ll ans=t[0];
    for(int i=1;i<n;i++){
        ans=ans*(t[i]/gcd(ans,t[i]));
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;

public class Program
{

    public void Proc()
    {
        System.Text.StringBuilder ans = new System.Text.StringBuilder();
        for (int i = 1; i <= 9; i++) {
            for (int j = 1; j <= 9; j++) {
                ans.AppendLine(i + "x" + j + "=" + (i * j));
            }
        }
        Console.Write(ans.ToString());

    }

    public class Reader
	{
		private static StringReader sr;
		public static bool IsDebug = false;
		public static string ReadLine()
		{
			if (IsDebug)
			{
				if (sr == null)
				{
					sr = new StringReader(InputText.Trim());
				}
				return sr.ReadLine();
			}
			else
			{
				return Console.ReadLine();
			}
		}
		private static string InputText = @"


6
)))())



";
	}

	public static void Main(string[] args)
	{
#if DEBUG
		Reader.IsDebug = true;
#endif
		Program prg = new Program();
		prg.Proc();
	}
}

Measured memory_bytes: 8872
n = int(input())
h = list(map(int,input().split()))
h_min = [0]
h_min.append(abs(h[1]-h[0]))
for i in range(2,n):
  h_min.append(min(abs(h[i]-h[i-1])+h_min[i-1],abs(h[i]-h[i-2])+h_min[i-2]))
print(h_min[-1])

Measured memory_bytes: 13928
#include <bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds;   
#define ll long long
#define ull unsigned long long
// #define ordered_set tree<pair<ll, ll>, null_type, less<pair<ll, ll>>, rb_tree_tag, tree_order_statistics_node_update> 
ll mod=1e9+7;
#define PI 3.1415926535897932385
#define inf 9e18
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
typedef pair<long long, long long> ii;
#define S second
#define F first
ll max(ll a,ll b){if(a>b){return a;}return b;}
ll min(ll a,ll b){if(a<b){return a;}return b;}
#define MAXN 200005
// Comment this out for interactice problem
// #define endl '\n'
// string to integer stoi() Remember: it takes string not character
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
 
// To compile--> g++ -std=c++0x -o output one.cpp
// To run--> ./output
ll n,m;
set<ll> adj[MAXN];
ll vis[MAXN];

void dfs(ll u, ll &tot){
    for (auto i = adj[u].begin(); i != adj[u].end(); ++i)
    {
        if(!vis[*i]){
            tot++;
            vis[*i]=true;
            dfs(*i, tot);
        }
    }
}

int main()
{ 
    fastio;
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    cin>>n>>m;
    
    for (int i = 0; i < m; ++i)
    {
        ll a,b;
        cin>>a>>b;
        adj[a].insert(b);
        adj[b].insert(a);
    }

    for (int i = 1; i < n+1; ++i)
    {
        vis[i]=false;
    }

    ll ans=0;
    for (int i = 1; i < n+1; ++i)
    {
        if(!vis[i]){
            vis[i]=true;
            ll tot=1;
            dfs(i, tot);
            ans=max(ans, tot);
        }
    }
    cout<<ans;

    return 0;
}

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

using namespace std;

struct EerTree{
    struct Node{
        Node(int len) : len(len), sdep(0), slink(nullptr), cnt(0){}
        int len, sdep;
        map<char, Node*> ch;
        Node* slink;
        int cnt;
    };
    pair<Node*, Node*> root;
    Node* active_point;
    string s;
    EerTree(){
        root.second = new Node(0);
        root.second->slink = root.first = active_point = new Node(-1);
        root.first->slink = root.first;
    }
    EerTree(string inp) : EerTree(){
        for(auto c : inp)
            add(c);
    }
    Node* make(Node* par, char c){
        if(par->ch.find(c) == par->ch.end()){
            par->ch[c] = new Node(par->len + 2);
            Node* sl = par->slink;
            if(par->len == -1)
                sl = root.second;
            else{
                while(1){
                    if(s[s.size() - sl->len - 2] == c){
                        sl = sl->ch[c];
                        break;
                    }else if(sl->len < 0){
                        sl = root.second;
                        break;
                    }else
                        sl = sl->slink;
                }
            }
            par->ch[c]->slink = sl;
            par->ch[c]->sdep = sl->sdep + 1;
        }
        return par->ch[c];
    }
    void add(char c){
        for(s += c; s[s.size() - active_point->len - 2] != c; active_point = active_point->slink);
        active_point = make(active_point, c);
    }
};

long long search(EerTree::Node* x, EerTree::Node* y){
    long long cnt = 1LL * x->cnt * y->cnt;
    if(x->len <= 0)
        cnt = 0;
    for(auto child : x->ch){
        if(y->ch.find(child.first) != y->ch.end()){
            cnt += search(x->ch[child.first], y->ch[child.first]);
        }
    }
    return cnt;
}

void dump(EerTree::Node* x, std::vector<EerTree::Node*>& v){
    v.emplace_back(x);
    for(auto child : x->ch)
        dump(child.second, v);
}

signed main(){
    string s, t;
    cin >> s >> t;
    EerTree es, et;
    for(auto c : s){
        es.add(c);
        es.active_point->cnt += 1;
    }
    for(auto c : t){
        et.add(c);
        et.active_point->cnt += 1;
    }
    std::vector<EerTree::Node*> sv, tv;
    dump(es.root.first, sv);
    dump(es.root.second, sv);
    dump(et.root.first, tv);
    dump(et.root.second, tv);
    sort(sv.begin(), sv.end(), [](auto x, auto y){return x->sdep > y->sdep;});
    for(auto x : sv)
        x->slink->cnt += x->cnt;
    sort(tv.begin(), tv.end(), [](auto x, auto y){return x->sdep > y->sdep;});
    for(auto x : tv)
        x->slink->cnt += x->cnt;
    cout << search(es.root.first, et.root.first) + search(es.root.second, et.root.second) << endl;

}



Measured memory_bytes: 21160
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
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 <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}
int main()
{
    string S;
    cin >> S;
    if (S[2] == S[3] and S[4] == S[5])
    {
        cout << "Yes";
    }
    else
    {
        cout << "No";
    }

    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text.RegularExpressions;
using System.Text;
using System.Diagnostics;
using static System.Math;
using static System.Array;

//var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
namespace AtCoderSolve
{

    class Solve
    {
        const int mod = 1000000007;
        const int INF = 2147483647;
        const long SINF = 9223372036854775807;

        static string s;
        
        

        public static void Input()
        {
            var cin = new Scanner();
            s = Console.ReadLine();
        }

        static void Main(string[] args)
        {
            Input();

            //var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            //Console.SetOut(sw);

            string ans = "";
            for(var i = 0; i < s.Length; i++)
            {
                if (s[i] == '0'||s[i]=='1')
                {
                    ans += s[i];
                }
                else
                {
                    if (ans == "") { continue; }
                    ans = ans.Substring(0, ans.Length - 1);
                }
            }


            Console.WriteLine(ans);
            //Console.Out.Flush();

        }





    }

    public class Scanner
    {
        public int[] SplitReader()
        {
            int[] array = Console.ReadLine().Split().Select(int.Parse).ToArray();
            return array;
        }
        public long[] SplitReaderL()
        {
            long[] array = Console.ReadLine().Split().Select(long.Parse).ToArray();
            return array;
        }

    }

    public class Graph
    {
        
    }
}

    



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

int main()
{
    int n, a;
    cin >> n;
    int ans = 1000000;
    for (size_t i = 0; i < n; i++)
    {
        cin >> a;
        int c = 0;
        while (a % 2 == 0)
        {
            a /= 2;
            ++c;
        }
        ans = min(ans, c);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1001001001;
const int MOD = 1e9 + 7;

const int MAX = 510000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// 二項係数計算
long long COM(int n, int k) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
  COMinit();
  int s;
  cin >> s;
  int saidai = s / 3;
  ll ans = 0;
  for (int i = 1; i <= saidai; i++) {
    int tmp = s - (i * 3);
    ll tans = COM(tmp + (i - 1), i - 1);
    ans = (ans + tans) % MOD;
  }
  cout << ans << endl;
  return 0;
}

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

int main(){
  int N,M;
  cin >> N >> M;
  vector<vector<int>> homework(1,vector<int>(M));
  int sum=0,tmp;
  for(int i=0;i<M;i++){
    cin >> tmp;
    sum += tmp;
  }
  
  if(sum<=N){
    cout << N-sum << endl;
  }else{
    cout << -1 << endl;
  }
}

Measured memory_bytes: 3704
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
using namespace std;


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

int main(){
  int n, l;
  cin >> n >> l;
  int ans = 0;
  int mi = INT_MAX;
  rep(i, n){
    ans += l + i;
    if(abs(mi) > abs(l + i)){
      mi = l + i;
    }
  }
  ans -= mi;
  cout << ans << endl;
}


Measured memory_bytes: 256
import numpy as np

def input_numbers():
    temp = list(map(int, input().split()))
    return temp

def GCD(a, b):
    if(a < b):
        temp = a
        a = b
        b = temp
    a = a % b
    if(a == 0):
        return b
    else:
        return GCD(a, b)

class point:
    def __init__(self, x ,y):
        self.x = x
        self.y = y

n = int(input())
names = []

for i in range(n):
    names += [input()]

march = 'MARCH'
count = []
for i in range(5):
    count += [0]

for i in range(n):
    for j in range(5):
        if(names[i][0] == march[j]):
            count[j] += 1

ans = 0
for i in range(5):
    for j in range(5):
        for k in range(5):
            if(i < j and j < k):
                ans += (count[i] * count[j] * count[k])

print(ans)

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

using namespace std;

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

    vector<long long> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    long long mod = 998244353;

    vector<vector<long long>> dp(n + 1, vector<long long>(s + 1, 0));
    dp[0][0] = 1;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j <= s; j++) {
            dp[i + 1][j] += 2 * dp[i][j];
            dp[i + 1][j] %= mod;

            if (a[i] + j <= s) {
                dp[i + 1][a[i] + j] += dp[i][j];
                dp[i + 1][a[i] + j] %= mod;
            }
        }
    }

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


Measured memory_bytes: 73740
#include<bits/stdc++.h>
#define ull unsigned long long
#define ll int64_t 
#define f(i,s,e) for(i=s;i<e;++i)
#define endl << "\n"
#define sp << " "
#define INF INFINITY
#define mset(a,b) memset(a,b,sizeof(a))
#define mod 1000000007
#define mp(a,b) make_pair(a,b)
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define PI acos(-1) 
#define pb(a) push_back(a)
#define pf(a) push_front(a)
#define eb(a) emplace_back(a)
#define print(x) for(auto it:x) cout<<it<<' '; cout<<"\n";

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
using namespace std;

int main()
{
	FAST_IO ;
	ll i,j,k,n;
	cin >> n;
	vector <bool> arr(n) ;
	f(i,0,n)
	{
	    cin >> j >> k;
	    if(j==k)
	        arr[i] = 1 ;
	   else
	        arr[i] = 0 ;
	}
	k = 0;
	for(i=0;i<n;++i)
	{
	    if(i+2>=n)
	        break ;
	    if(arr[i]&&arr[i+1]&&arr[i+2])
	    {
	        k = 1;
	        break ;
	    }
	}
	if(k)
	    cout  << "Yes\n" ;
	   else
	    cout  << "No\n" ;
	return 0;
}

/*
If u haven't come up with an approach yet ,skip this one
  Try this when feeling stuck -
  1. Int overflow, array bounds
  2. Special cases (n=1?)
  3. Prove your approach to yourself(mathematical induction,counter-intuitive or stronger test cases)
  4. Calm down and don't look at standings and stop thinking about rating and think about the question
  5. Just do it! 
*/ 

//Benq's advice - 
/* 
	And following advices are must for me -
	* do something instead of nothing and stay organized
	* WRITE STUFF DOWN 
*/

//#define _GLIBCXX_DEBUG 
// It will convert WA verdict to runtime error if that error is caused due to out of bound excess , declare it at the top
//#pragma GCC optimize "trapv" 
// It will convert WA to runtime error if WA was caused due to int overflow error,declare it anywhere

Measured memory_bytes: 3648
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

struct UnionFind {
	vector<int> v;
	UnionFind(int n) : v(n) { for (int i = 0; i < n; i++) v[i] = i; }
	int  find(int x) { return v[x] == x ? x : v[x] = find(v[x]); }
	void unite(int x, int y) { v[find(x)] = find(y); }
};



int main() {
	ll num = 0;
	REP(i, 4)
		REP(j, 4) {
		int a;
		cin >> a;
		num <<= 4LL;
		num += a;
	}

	int clear = -1;
	set<ll> qll;
	set<ll> cqll;
	if (num == 0) {
		cout << 0 << endl;
		return 0;
	}
	qll.insert(num);
	REP(kurikaesu, 5) {
		for (ll ql:qll) {
			vvi cell2(4, vi(4));
			REP(i, 16)
				cell2[i%4][i/4]=(ql>>(15-i)*4) % 16;
			REP(x, 4)
				REP(y, 4) {
				vvi cell;
				cell = cell2;
				queue<pair<pii, int>> bu;
				queue<pair<pii, int>> cbu;
				if (cell[y][x] == 0&&kurikaesu>0)
					continue;
				cell[y][x]++;
				if (cell[y][x] >= 5) {
					bu.push({ {x,y},0 });
					bu.push({ { x,y },1 });
					bu.push({ { x,y },2 });
					bu.push({ { x,y },3 });
					cell[y][x] = 0;
				}
				while (!bu.empty()) {
					pair<pii, int> q = bu.front();bu.pop();
					int sx = q.first.first + dx[q.second];
					int sy = q.first.second + dy[q.second];
					if (0 <= sx&&sx < 4 && 0 <= sy&&sy < 4) {
						if (cell[sy][sx] == 0) {
							cbu.push({ {sx,sy},q.second });
						}
						else {
							cell[sy][sx]++;
						}
					}
					if (bu.empty()) {
						REP(i, 4)
							REP(j, 4)
							if (cell[i][j] >= 5) {
								REP(k, 4)
									cbu.push({ { j,i },k });
								cell[i][j] = 0;
							}

						bu = cbu;
						while (!cbu.empty())
							cbu.pop();
					}
				}
				ll num2 = 0;
				REP(i, 4)
					REP(j, 4) {
					num2 <<= 4LL;
					num2 += cell[i][j];
				}
				if (num2 == 0) {
					clear = kurikaesu + 1;
					break;
				}
				cqll.insert(num2);
			}
			if (clear > 0 )break;
		}
		qll = cqll;
		if (clear > 0)break;
	}
	cout << clear << endl;
}

Measured memory_bytes: 5060
#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; i >= 0; i--)
#define for(i, m, n) for(int i = m; i < n; i++)
#define all(v) v.begin(), v.end()
#define print(x) cout << x << endl;
typedef long long ll;

constexpr ll INF = 1'010'000'000'000'000'017LL;\
constexpr ll MOD = 1'000'000'007LL;\
constexpr double EPS = 1e-12;\
constexpr double PI = 3.14159265358979323846;

int main()
{
    string S;
    cin >> S;
    string T = S;
    reverse(all(T));
    string tmp1 = S.substr(0, (S.length()-1)/2);
    string tmp2 = S.substr((S.length()+1)/2, (S.length()-1)/2);
    string tmp1r = tmp1;
    string tmp2r = tmp2;
    reverse(all(tmp1r));
    reverse(all(tmp2r));
    if (S != T || tmp1 != tmp1r || tmp2 != tmp2r) {
        print("No");
        return 0;
    }
    print("Yes");

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <math.h>
#include <stdlib.h>
#include <algorithm>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

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

//INT_MAX	2,147,483,647 = 2*1.0e9

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

  double sum = 0;
  for(int i = 1; i <= N; i++){
    if(i >= K) sum += 1;
    else{
      int j = 2;
      while(j * i < K) j *= 2;
      sum += 1.0/j;
    }
  }

  double ans = sum / N;
  printf("%.12f\n",ans);

  return 0;
}



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

using namespace std;

int main()
{
    int n,k;
    cin>>n>>k;
    vector<int> p(n);
    for(int i=0;i<n;i++)
        cin>>p[i];

    sort(p.begin(),p.end());

    int sum=0;
    for(int i=0;i<k;i++)
        sum += p[i];
    cout<<sum;
    return 0;
}


Measured memory_bytes: 3624
#include <stdio.h>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;
typedef long long ll;
const ll M = 200013;
ll a[20000005];
int main()
{
    ll i,m,n,minn,ans=0;
    scanf("%lld",&n);
    for(i=1;i<=n;i++)
    {
        scanf("%lld",&a[i]);
    }
    minn=a[1];
    for(i=1;i<=n;i++)
    {
        if(minn>=a[i])
        {
            ans++;
            minn=a[i];
        }
    }
    printf("%lld",ans);
    return 0;
}


Measured memory_bytes: 1664
import sys, os, math, bisect, itertools, collections, heapq, queue, copy, array

# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
# from decimal import Decimal
# from collections import defaultdict, deque

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    print('Yes' if N >= 30 else 'No')


if __name__ == '__main__':
    main()


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

#define ll long long
#define P pair<int,int>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define asort(x) sort(x.begin(),x.end())

int main() {
    int x,n,in,near=0;
    cin >> x >> n;
    if(n == 0) {
        cout << x << endl;
        return 0;
    }
    vector<int> p;
    rep(i,n) {
        cin >> in;
        p.push_back(in);
    }
    vector<int>::iterator itr;
    rep(i,x+1) {
        itr = find(p.begin(),p.end(), i);
        if(itr == p.end()) near = i;
    }
    for(int j = x+1; j < x+(x-near); j++) {
        itr = find(p.begin(),p.end(), j);
        if(itr == p.end()) near = j;
    }
    cout << near << endl;
    return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <cstdio>
#include <cassert>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
#include <cmath>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define FILL(a,x); REP(i,sizeof(a)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define FILL2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"
#define PI 3.141592653589793

//cout << setfill('0') << right << setw(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;}


void bubble_sort(int a[],int N){
    int num = 0;
    REP(i,N){
        for(int j=N-1; j>i; --j){
            if(a[j-1]>a[j]){ swap(a[j-1],a[j]); ++num;}
        }
    }
    REP(i,N-1){
        cout << a[i] <<" ";
    }
    cout << a[N-1] <<"\n";
    
    cout << num <<"\n";
}

int main(){
    int N; cin>>N;
    int a[N]; CINA(a,N);
    bubble_sort(a,N);
}


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

int main() {
  int x, i, j, ans = 1;
  cin >> x;
  
  for(i = 2; i < sqrt(x) + 1; i++){
    for(j = 2; pow(i, j) <= x; j++){
      int a = pow(i, j);
      ans = max(ans, a);
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 384
a, b, k = map(int, input().split())

a_list = []
b_list = []

def make_divisor_list(num):
    if num < 1:
        return []

    elif num == 1:
        return [1]

    else:
        divisor_list = []
        divisor_list.append(1)
        for i in range(2, num // 2 + 1):
            if num % i == 0:
                divisor_list.append(i)

        divisor_list.append(num)

    return divisor_list

a_list = make_divisor_list(a)
b_list = make_divisor_list(b)

ans_list = list(set(a_list) & set(b_list))

ans_list.sort(reverse = True)

print(ans_list[k-1])


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

void call(int n){
	for (int i = 1; i <= n; i++){
		if (i % 3 == 0){
			cout << " " << i;
		} else {
			int x = i;
			while (x){
				if (x % 10 == 3){
					cout << " " << i;
					break;
				}
				x = x / 10;
			}
		}
	}
	cout << endl;
	return;
}

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

Measured memory_bytes: 3072
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int k;
    cin >> k;
    string s;
    cin >> s;
    if (s.length() > k)
    {
        for (int i = 0; i < k; i++)
        {
            cout << s[i];
        }
        cout << "..."
             << "\n";
    }
    else
    {
        cout << s << "\n";
    }
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define mod 1000000007
#define pb push_back
#define nl cout<<"\n"
#define db(x) cout<<x<<" "
#define fi(a,b) for(int i=a;i<b;i++)
#define fj(a,b) for(int j=a;j<b;j++)
#define fk(a,b) for(int k=a;k<b;k++)
#define F first
#define S second
#define UM unordered_map<int,int>
#define MP map<int,int>
#define mxsize (int)1e6
void fun(){
    string s,t;
    cin>>s>>t;
    int n=s.size();
    int m=t.size();
    int ans=INT_MAX;
    for(int i=0;i+m<=n;i++){
        int change=0;
        int j=0,k=i;
        while(k<i+m){
            if(s[k]!=t[j])
                change++;
            k++;
            j++;
        }
        ans=min(ans,change);
    }
    cout<<ans;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("/ATOM/input.txt", "r", stdin);
        freopen("/ATOM/output.txt", "w", stdout);
    #endif
    int t=1;
    // cin>>t;
    while(t--){
        fun();
    }
}   

Measured memory_bytes: 3652
#include<iostream>
#include<vector>
#include<climits>
using namespace std;
typedef long long ll;
#define inRange(x,a,b) (a <= x && x <= b)

int main(){
    int n;
    string m;
    vector<int> p({2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31});
    while(cin >> n >> m, n){
        vector<int> base(11, 0);
        vector<ll> cnt(11, 0);
        int cp = n;
        for(int i = 0; i < 11; i++){
            while(cp%p[i] == 0)  base[i]++, cp /= p[i];
        }
        ll val = 0;
        for(int i = 0; i < m.length(); i++){
            val *= n;
            if(inRange(m[i],'0','9'))   val += m[i]-'0';
            else                        val += 10+m[i]-'A';
        }
        for(int i = 0; i < 11; i++){
            ll x = val;
            while(x){
                cnt[i] += x/p[i];
                x /= p[i];
            }
        }

        ll ans = LLONG_MAX;
        for(int i = 0; i < 11; i++){
            if(base[i] == 0)    continue;
            ans = min(ans, cnt[i]/base[i]);
        }
        cout << ans << endl;
    }
    return 0;
}



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

typedef long long ll;
typedef long double ld;

vector <int> graf[100005];
vector <int> graf1[100005];
vector <int> graf2[100005];
int dp[100005];
int deg[100005];
bool visited[100005];
int in[100005];

int tim;

void dfs1(int v, int parent){
    visited[v] = 1;
    in[v] = ++tim;
    for(auto c : graf[v]){
        if(c == parent) continue;
        if(visited[c]){
            if(in[c] > in[v]) continue;
            graf2[c].push_back(v);
            deg[c]++;
            continue;
        }
        graf1[v].push_back(c);
        dfs1(c, v);
    }
}

void dfs2(int v, int parent){
    for(auto c : graf1[v]){
        dfs2(c, v);
        dp[v] += dp[c];
    }
    if(deg[v]%2) dp[v]++;
    if(v == 1) return;
    if(dp[v]%2) graf2[v].push_back(parent);
    else graf2[parent].push_back(v);
}

int main(){
    ios_base::sync_with_stdio(false);
    cout.precision(10);
    cout<<fixed;

    int n, m;
    cin >> n >> m;
    for(int i=1; i<=m; i++){
        int a, b;
        cin >> a >> b;
        graf[a].push_back(b);
        graf[b].push_back(a);
    }
    dfs1(1, 0);
    int cnt = 0;
    for(int i=1; i<=n; i++){
        deg[i] += graf1[i].size();
        if(deg[i]%2) cnt++;
    }
    /*for(int i=1; i<=n; i++){
        for(auto c : graf1[i]){
            cout << i << " " << c << endl;
        }
    }
    cout << endl;*/
    if(cnt%2){
        cout << "-1";
        return 0;
    }
    dfs2(1, 0);
    for(int i=1; i<=n; i++){
        for(auto c : graf2[i]){
            cout << i << " " << c << "\n";
        }
    }
    return 0;
}


Measured memory_bytes: 23808
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10

#solve
def solve():
    n = II()
    a = LI()
    a.sort()
    d = defaultdict(int)
    for ai in a:
        d[ai] += 1
    ans = 0
    for j in range(n - 1, -1, -1):
        i = 0
        aj = a[j]
        while aj:
            aj >>= 1
            i += 1
        m = 1 << i
        if d[a[j]]:
            if m - a[j] == a[j]:
                x = d[a[j]]
                d[a[j]] -= x
                ans += x // 2
            else:
                x = m - a[j]
                if bisect_right(a, x) - bisect_left(a, x) and d[x]:
                    x = d[a[j]]
                    y = d[m - a[j]]
                    d[a[j]] -= min(x, y)
                    d[m - a[j]] -= min(x, y)
                    ans += min(x, y)

    print(ans)

    return


#main
if __name__ == '__main__':
    solve()


Measured memory_bytes: 102864
#include <stdio.h>
#define MAX 100
#define WHITE 0
#define GLAY 1
#define BLACK 2

int n,color[MAX],d[MAX],f[MAX],time,A[MAX][MAX];

void dfs_visit(int u){
  int v,i;
  color[u]=1;
  d[u]=++time;
  for(v=0;v<n;v++){
    if(A[u][v]==0)continue;
    if(color[v]==0)dfs_visit(v);
  }
  color[u]=2;
  f[u]=++time;
}

void dfs(void){
  int i;
  for(i=0;i<n;i++){
    color[i]=0;
    time=0;
  }
  for(i=0;i<n;i++){

    if(color[i]==0) dfs_visit(i);
  }
  for(i=0;i<n;i++){
    printf("%d %d %d\n",i+1,d[i],f[i]);
  }
}

int main(){

  int i,j,u,k,v;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      A[i][j]=0;
    }
  }
  for(i=0;i<n;i++){
    scanf("%d %d",&u,&k);
    for(j=0;j<k;j++){
      scanf("%d",&v);
      A[u-1][v-1]=1;
    }
  }

  dfs();

  return 0;
}


Measured memory_bytes: 2108
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define ALL(v) (v).begin(), (v).end()

ll digit(ll x) {
  ll ans = 1;
  while (x/10) {
    x /= 10;
    ans++;
  }

  return ans;
}

ll F(ll a, ll b) {
  return max(digit(a), digit(b));
}

int main()
{
  ll N; cin >> N;
  ll root = sqrt(N);

  ll ans = 1<<30;
  for (int a = 1; a <= root; ++a) {
    if (N % a != 0) continue;

    ll b = N/a;
    ans = min(ans, F(a, b));
  }

  cout << ans << endl;
}

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


int main(){
    int N;
    cin >> N;
    int res = ceil(N/1.08);
    int ans = floor(res* 1.08);
    if(ans == N){
        cout << res << endl;
    }
    else cout << ":(" << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main{
	public static void main(String[] args){
		Scanner stdIn=new Scanner(System.in);
		int n,b,f,r,v,i,j,k;
		int[][][] a=new int[4][3][10];
		n=stdIn.nextInt();
		for(i=0;i<n;i++){
			b=stdIn.nextInt();
			f=stdIn.nextInt();
			r=stdIn.nextInt();
			v=stdIn.nextInt();
			a[b-1][f-1][r-1]+=v;
		}
		for(i=0;i<4;i++){
			for(j=0;j<3;j++){
				for(k=0;k<10;k++)System.out.print(" "+a[i][j][k]);
				System.out.println();
			}
			if(i!=3)System.out.println("####################");
		}
	}
}


Measured memory_bytes: 29668
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>

using namespace std;
#define MP make_pair
typedef pair<int,int> PII;

int W, H;


void findconnected(int x, int y, vector<string>& vs, vector<vector<bool>>& vis, int n, vector<PII>& res){
  if(x < 0 || W <= x || y < 0 || H <= y || vis[y][x] || vs[y][x] != n) return;
  res.push_back(MP(x,y));
  vis[y][x] = true;
  findconnected(x-1,y,vs,vis,n,res);
  findconnected(x+1,y,vs,vis,n,res);
  findconnected(x,y-1,vs,vis,n,res);
  findconnected(x,y+1,vs,vis,n,res);
}

void findOn(int x, int y, vector<string>& vs, vector<vector<bool>>& vis, vector<PII>& res){
  /*
  if(vis[y][x]) return;
  vis[y][x] = true;
  */
  if(y == 0 || vs[y-1][x] == '.' || vs[y][x] == vs[y-1][x]) return;
  vector<PII> tmp;
  findconnected(x,y-1,vs,vis,vs[y-1][x],tmp);
  for(PII& pii:tmp){
	findOn(pii.first,pii.second,vs,vis,res);
	res.push_back(pii);
  }
}

int main(){
  while(cin>>W>>H,W){
	vector<string> vs(H);
	for(int i=0;i<H;++i) cin >> vs[i];

	bool ans = true;
	vector<vector<bool>> ok(H,vector<bool>(W, false));
	for(int y=H-1;y>=0;--y){
	  for(int x=0;x<W;++x){
		if(vs[y][x] == '.' || ok[y][x]){
		  ok[y][x] = true;
		  continue;
		}
		vector<PII> pos, ons;
		findconnected(x,y,vs,ok,vs[y][x],pos);
		vector<vector<bool>> use = ok;
		int sum = 0;
		double xl = 10000, xr = -1;
		for(PII pii:pos){
		  if(pii.second == H-1 || 
			 vs[pii.second+1][pii.first] != '.' && vs[pii.second][pii.first] != vs[pii.second+1][pii.first])
			xl = min(xl, 1.*pii.first), xr = max(xr, 1.*pii.first);
		  findOn(pii.first,pii.second,vs,use,ons);
		  sum += pii.first;
		}
		
		for(PII& p: ons) sum += p.first;
		double c = sum * 1. / (pos.size() + ons.size());
		xl -= 0.5, xr += 0.5;
		if(c <= xl || xr <= c){
		  ans = false;// cout << c<<","<<x << "," <<y << endl;
		}
	  }
	}
	
	cout << (ans? "STABLE": "UNSTABLE") << endl;
  }
  
  return 0;
}

Measured memory_bytes: 1228
from sys import stdin
n,m = map(int, stdin.readline().rstrip().split())

count = 0
penalty = 0
qb = [0]*n
was = [0]*n

for i in range(m):
    p,s = map(str,stdin.readline().rstrip().split())
    p = int(p)
    if s == "AC" and qb[p-1] != "AC":
        qb[p-1] = "AC"
        penalty += was[p-1]
        count += 1
    elif s == "WA":
        was[p-1] += 1
    else:
        pass

print(count, penalty)


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

int intpow(int x,int y){
  double a=x,b=y;
  return pow(a,b);
}//(x,y) xをy乗する

int intfabs(int x){
  double a=x;
  return fabs(a);
}//(x) の絶対値

int in(){
  int a;
  cin >> a;
  return a;
}//int型関数の受け取り

void forin(int* x,int y){
  for (int i=0;i<y;i++){
    cin >> x[i];
  }
}//配列の受け取り

main(){
  double t=in(),x=in();
  cout << t/x << endl;
}


Measured memory_bytes: 256
N = int(input())

answer = 0
for i in range(N+1):
    if i % 2 == 1:
        div_count = 0
        for j in range(1, i+1):
            if i % j == 0:
                div_count += 1

        if div_count == 8:
            answer += 1

print(answer)

Measured memory_bytes: 3060
import java.util.*;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    LinkedList<String> strLlist = new LinkedList<String>();
    while (sc.hasNext()) {
      strLlist.add(sc.next());
    }
    String[] strArr = (String[])strLlist.toArray(new String[0]);
    int[] times = new int[strArr.length];
    int maxTimes = 0;
    int maxLength = 0;
    for (int i =0; i < strArr.length; i++) {
      for (int j =0; j < strArr.length; j++) {
        if (strArr[i].equals(strArr[j])) {
          times[i]++;
        }
      }
      if (times[i] > maxTimes) {
        maxTimes = times[i];
      }
      if (strArr[i].length() > maxLength) {
        maxLength = strArr[i].length();
      }
    }
        String mode = null;
        String longest = null;
    for (int i =0; i < strArr.length; i++) {
      if (times[i] == maxTimes) {
        mode = strArr[i];
      }
      if (strArr[i].length() == maxLength) {
        longest = strArr[i];
      }
    }
    System.out.println(mode + " " + longest);
  }
}

Measured memory_bytes: 12000
S = input()

n = S.count("N")
s = S.count("S")
w = S.count("W")
e = S.count("E")

if (n>0 and s>0 or n==s==0) and (w>0 and e>0 or w==e==0):
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3060
from sys import stdin
from itertools import groupby

point = 0

n = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))

li.sort()

su4 = 0
su2 = 0
su = 0

for i in range(n):
    if li[i] % 4 == 0:
        su4 += 1
    elif li[i] % 2 == 0:
        su2 += 1
    else:
        su += 1
    
if su4+1 < su:
    print("No")
    exit()
if su2 % 2 == 0:
    print("Yes")
    exit()
else:
    if su4 -su >= 0:
        print("Yes")
        exit()
    else:
        print("No")
        exit()

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

using namespace std;

typedef long long int ll;

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

  int n, c;
  cin >> n >> c;
  int d[c + 1][c + 1], color[n + 1][n + 1];
  for(int i = 1; i <= c; i++){
    for(int j = 1; j <= c; j++) cin >> d[i][j];
  }
  for(int i = 1; i <= n; i++){
    for(int j = 1; j <= n; j++) cin >> color[i][j];
  }
  int cnt[3][35], cst[3][35];
  for(int i = 0; i < 3; i++){
    for(int j = 0; j < 35; j++){
      cnt[i][j] = 0;
      cst[i][j] = 0;
    }
  }
  for(int i = 1; i <= n; i++){
    for(int j = 1; j <= n; j++){
      if((i + j) % 3 == 0){
        cnt[0][color[i][j]]++;
      }else if((i + j) % 3 == 1){
        cnt[1][color[i][j]]++;
      }else{
        cnt[2][color[i][j]]++;
      }
    }
  }

  for(int i = 0; i < 3; i++){
    for(int j = 1; j <= c; j++){
      for(int k = 1; k <= c; k++){
        cst[i][j] += cnt[i][k] * d[k][j];
      }
    }
  }

  int ans = INT_MAX;
  for(int i = 1; i <= c; i++){
    for(int j = 1; j <= c; j++){
      for(int k = 1; k <= c; k++){
        if(i != j && j != k && k != i){
          ans = min(ans, cst[0][i] + cst[1][j] + cst[2][k]);
        }
      }
    }
  }

  cout << ans << '\n';
}


Measured memory_bytes: 1280
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<(n);i++)
#define loop(i,a,n) for(i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int main(void) {
  int i,j;
  int n,m;
  cin>>n>>m;

  vector<ll> x(n+1),y(m+1);
  x[0]=y[0]=0;
  rep(i,n)cin>>x[i+1];
  rep(i,m)cin>>y[i+1];

  rep(i,n)x[i+1]+=1000000000;
  rep(i,m)y[i+1]+=1000000000;

  rep(i,n)x[i+1]+=x[i];
  rep(i,m)y[i+1]+=y[i];

  ll xsum=0,ysum=0;
  rep(i,n)(xsum+=i*(x[i+1]-x[i])-x[i])%=MOD;
  rep(i,m)(ysum+=i*(y[i+1]-y[i])-y[i])%=MOD;

  cout<<(xsum*ysum)%MOD<<endl;
}


Measured memory_bytes: 1792