akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define sz(x) (int)x.size()
#define pb push_back
#define mp make_pair
#define ll long long 
#define mod 1000000007
void setIO(string name) {
  ios_base::sync_with_stdio(0); cin.tie(0);
  freopen((name+".in").c_str(),"r",stdin);
  freopen((name+".out").c_str(),"w",stdout);
}
void fast(){
  ios_base::sync_with_stdio(false);cin.tie(NULL);
}
int main() {
   fast();
   int h,w;
   cin>>h>>w;
   char a[h][w];
   for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin>>a[i][j];
    }
   }
   int x=0;
   int f=0;
   int y=0;
   int k=0;
   while(x<h){
    int t;
     for(int i=0;i<w;i++){
       if(a[x][i]=='#'){
          t=i;
          break;
       }
     }
     if(t==y){
      f=1; 
      int p;
      for(int i=y;i<w;i++){
        if(a[x][i]=='#'){
          k++;
          p=i;
        }else{
          break;
        }
      }
      y=p;


     }else{
      f=0;
      break;
     }
     x++;
     
   }
   if(!f){
     cout<<"Impossible"<<"\n";
   }else{
    int l=0;
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
        if(a[i][j]=='#'){
          l++;
        }
      }
    }
    if(l==k){
        
      cout<<"Possible"<<"\n";
    }else{
        //cout<<l<<" "<<k<<"\n";
      cout<<"Impossible"<<"\n";
    }
   }
   




} 

Measured memory_bytes: 3672
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <iostream>
#include <functional>
using namespace std;
#define ll long long
#define fi first
#define se second
const int maxn=0x3fffffff;
const int N=1e6+10;
void read(int &a)
{
    a=0;
    int d=1;
    char ch;
    while(ch=getchar(),ch>'9'||ch<'0')
        if(ch=='-')
            d=-1;
    a=ch-'0';
    while(ch=getchar(),ch>='0'&&ch<='9')
        a=a*10+ch-'0';
    a*=d;
}
void write(int x)
{
    if(x<0)
        putchar(45),x=-x;
    if(x>9)
        write(x/10);
    putchar(x%10+'0');
}
struct note
{
    int next;
    int to;
    int dis;
}edge[200005];
int num=0,dis[100005],head[100005];
bool vis[100005];
int ans[N];
void add(int from,int to,int dis)
{
    edge[++num].next=head[from];
    edge[num].to=to;
    edge[num].dis=dis;
    head[from]=num;
}
struct node
{
    int dis;
    int pos;
    bool operator < (const node &x) const
    {
        return x.dis<dis;
    }
};
priority_queue <node> q;
inline void dijkstra(int st,int n)
{
    for(register int i=1;i<=n;i++) dis[i]=maxn,vis[i]=0;
    dis[st]=0;
    q.push((node){0,st});
    while(!q.empty())
    {
        node x=q.top();
        q.pop();
        int d=x.dis;
        int p=x.pos;
        if(vis[p]) continue;
        vis[p]=true;
        for(register int i=head[p];i;i=edge[i].next)
        {
            int t=edge[i].to;
            if(dis[t]>dis[p]+edge[i].dis)
            {
                dis[t]=dis[p]+edge[i].dis;
                if(!vis[t])
                    q.push((node){dis[t],t});
            }
        }
    }
}
int main()
{
    //freopen("in.txt","r",stdin);
    int n,x,y;
    read(n);read(x),read(y);
    for(register int i=1;i<n;i++)
    {
        add(i,i+1,1);
        add(i+1,i,1);
    }
    add(x,y,1),add(y,x,1);
    for(register int i=1;i<=n;i++)
    {
        dijkstra(i,n);
        for(register int j=i+1;j<=n;j++) ans[dis[j]]++;
    }
    for(register int i=1;i<=n-1;i++) printf("%d\n",ans[i]);
    return 0;
}

Measured memory_bytes: 4352
#include<cstdio>
#include<algorithm>
using namespace std;

int n,m;
int a,b,x;
short dp[5000][5000];

int main(){
  scanf("%d%d",&n,&m);
  for(int i=0;i<n;i++)
    for(int j=0;j<=i;j++)dp[i][j] = -1;

  for(int i=0;i<m;i++){
    scanf("%d%d%d",&a,&b,&x);
    a--; b--;
    dp[a][b] = max(dp[a][b],(short)x);
  }

  for(int i=0;i<n;i++){
    for(int j=0;j<=i;j++){
      if(i){
	dp[i][j] = max(dp[i][j],(short)(dp[i-1][j]-1));
	if(j)dp[i][j] = max(dp[i][j],(short)(dp[i-1][j-1]-1));
      }
    }
  }

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

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

#define ll          long long
#define pb          push_back
#define endl        '\n'
#define mii         map<ll,ll>
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        1000000007
#define INF         (1ll<<60)
#define rep(i,a,b)  for(ll i=a;i<=b;i++)
#define rrep(i,a,b)  for(ll i=a;i>=b;i--)
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
const int N=100005;
void solve(){
    string s;
    cin>>s;
    if(s[0]=='S' && s[1]=='U')  cout<<7<<endl;
    else if(s[0]=='S' && s[1]=='A') cout<<1<<endl;
    else if(s[0]=='M') cout<<6<<endl;
    else if(s[0]=='T' && s[1]=='U') cout<<5<<endl;
    else if(s[0]=='W') cout<<4<<endl;
    else if(s[0]=='F') cout<<2<<endl;
    else cout<<3<<endl;
}
signed main()
{
    ios
    int TESTS=1;
    //cin>>TESTS;
    while(TESTS--){
        solve();
    }
    time
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ldb = long double;
using pa = pair < ll, ll >;
using vec = vector < ll >;
#define pb push_back
#define po pop_back
#define mp make_pair
#define mt make_tuple
#define F  first
#define S  second
#define f(i,x,n) for(ll i=x;i<n;i++) 
#define unique_sort(x) sort(all(x)), x.resize(distance(x.begin(), unique(all(x))))
#define all(c) c.begin(),c.end()
#define str string
#define edl "\n"
#define add insert
#define cot continue
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL)
const int MOD = 1e9 + 7, INF = INT_MAX, N = 1e5 + 10;
const double PI = acos(-1);
const ll LINF = LLONG_MAX;




int main() 
{

 fast();
  
  // #ifndef ONLINE_JUDGE
  //   freopen("input.txt", "r", stdin);
  //   freopen("output.txt","w",stdout);
  // #endif
  
  ll n;

  cin>>n;
  cout<<ll(3)*ll(n*n);
  

  

  


    




    cerr << "Time taken: " << int((clock() * 1000.) / CLOCKS_PER_SEC) << "ms\n";
    return 0;
}
 

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

int main(){
  int n,m;
  cin>>n>>m;
  vector<long long int> a(n),b(n);
  for(int i=0;i<n;i++) cin>>a[i]>>b[i];
  vector<long long int> c(m),d(m);
  for(int i=0;i<m;i++) cin>>c[i]>>d[i];

  for(int i=0;i<n;i++){
    long long int min_dis=1e15;
    int res=-1;
    for(int j=0;j<m;j++){
      if(abs(a[i]-c[j])+abs(b[i]-d[j])<min_dis){
	min_dis=abs(a[i]-c[j])+abs(b[i]-d[j]);
	res=j;
      }
    }
    cout<<res+1<<endl;
    
  }
  return 0;

}


Measured memory_bytes: 256
import sys,collections as cl,bisect as bs,math
from decimal import *
getcontext().prec = 50
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False
"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

a,b,c = m()

if Decimal(a).sqrt() + Decimal(b).sqrt() < Decimal(c).sqrt():
    print("Yes")
else:
    print("No")


Measured memory_bytes: 61036
/* ---------- STL Libraries ---------- */

// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

/* ---------- Namespace ---------- */

using namespace std;

/* ---------- Type Abbreviation ---------- */

using ll = long long;

template <typename T>
using PQ = priority_queue<T>;
template <typename T>
using GPQ = priority_queue<T, vector<T>, greater<T>>;

#define mp make_pair
#define mt make_tuple

/* ---------- conversion ---------- */

#define INT(c) static_cast<int>(c)
#define CHAR(n) static_cast<char>(n)
#define LL(n) static_cast<ll>(n)
#define DOUBLE(n) static_cast<double>(n)

/* ---------- container ---------- */

#define gsort(b, e) sort(b, e, greater<decltype(*b)>())

/* ----------- debug ---------- */

template <class T>
ostream& operator<<(ostream& os, vector<T> v) {
    os << "[";
    for (auto vv : v)
        os << vv << ",";
    return os << "]";
}

template <class T>
ostream& operator<<(ostream& os, set<T> v) {
    os << "[";
    for (auto vv : v)
        os << vv << ",";
    return os << "]";
}

template <class L, class R>
ostream& operator<<(ostream& os, pair<L, R> p) {
    return os << "(" << p.first << "," << p.second << ")";
}

/* ---------- Constants ---------- */

// const ll MOD = 1e9 + 7;
// const int INF = 1 << 25;
// const ll INF = 1LL << 50;
// const double PI = acos(-1);
// const double EPS = 1e-10;
// mt19937 mert(LL(time(0)));

/* ---------- Short Functions ---------- */

template <typename T>
inline T sq(T a) { return a * a; }

template <typename T>
T gcd(T a, T b) {
    if (a > b) return gcd(b, a);
    return a == 0 ? b : gcd(b % a, a);
}

template <typename T, typename U>
T mypow(T b, U n) {
    if (n == 0) return 1;
    if (n == 1) return b /* % MOD */;
    if (n % 2 == 0) {
        return mypow(b * b /* % MOD */, n / 2);
    } else {
        return mypow(b, n - 1) * b /* % MOD */;
    }
}

ll pcnt(ll b) {
    return __builtin_popcountll(b);
}

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */

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

    string ans = "second";
    for (int i = 0; i < N; ++i) {
        int a;
        cin >> a;
        if (a % 2 == 1) ans = "first";
    }

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


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

using namespace std;

int main(){
    int N;
    cin >> N ;
    map<string, int> mp;
    string S;
    for(int i = 0; i < N; i++){
        cin >> S;
        mp[S]++;
    }
    
    cout << mp.size() << endl;

}

Measured memory_bytes: 19196
# vim: set fileencoding=utf-8:


def main():
    N, M = map(int, input().split())  # 1 <= M <= N <= 50
    A = [input() for _ in range(N)]
    B = [input() for _ in range(M)]
    ct = 0
    flag = 0
    ans = 'No'

    # N^3だとしても、50*50*50=12,500で、pythonで計算が間に合いそう

    for B_row in B:
        flag = 0
        for A_row in A:
            if(N-M) == 0:
                if B_row == A_row:
                    ct += 1
                    flag = 1
            else:
                for i in range(N-M):
                    # M <= N であるから、B_row が A_rowに含まれているかを探索していく
                    if B_row == A_row[i:M]:
                        ct += 1
                        flag = 1
                        break

            if flag == 1:
                break

    if ct == M:
        ans = 'Yes'

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
import scala.io.StdIn._
object Main {
 def main(args :Array[String]) = {
	var mtrl = readInt
	val (hour, sec) = (3600, 60)
	val (i, j, k) = (mtrl/hour, (mtrl%hour)/sec, mtrl%sec)
	println(i+":"+j+":"+k)
 }
}

Measured memory_bytes: 43412
array = list(map(int,input().split()))
cnt5 = 0
cnt7 = 0
for i in array:
  if i == 5:
    cnt5 += 1
  if i == 7:
    cnt7 +=1
if cnt5 ==2 and cnt7 ==1:
  print('YES')
else:
  print('NO')

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

int main(){
    string S;
    cin >> S;

    if(S == "SUN") cout << "7" << endl;
    if(S == "MON") cout << "6" << endl;
    if(S == "TUE") cout << "5" << endl;
    if(S == "WED") cout << "4" << endl;
    if(S == "THU") cout << "3" << endl;
    if(S == "FRI") cout << "2" << endl;
    if(S == "SAT") cout << "1" << endl;
}

Measured memory_bytes: 3600
frege_count, oven_count, coupon_count = map(int,input().split())	
frege_prices = list(map(int,input().split()))	
oven_prices = list(map(int,input().split()))	
coupon_list = [list(map(int, input().split())) for i in range(coupon_count)]

minprice = min(frege_prices) + min(oven_prices)
for coupon in coupon_list:
  total_cost = frege_prices[coupon[0]-1] + oven_prices[coupon[1]-1] - coupon[2]
  if minprice > total_cost:
          minprice = total_cost
print(minprice)

Measured memory_bytes: 38568
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
#define mod 1000000007
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define f first
#define s second
#define pb push_back
#define mp make_pair

int n, a[202020], t, ans, l, r;

int main(){
cin >> n;
rep(i, 0, n-1)cin >> a[i];
sort(a, a+n);
l=0;r=0;
while(l<=r && r<n && l<n){
    if(a[r]-a[l]<=2)r++;
    else l++;
    ans = max(r-l, ans);
}
cout << ans << endl;



return 0;}


Measured memory_bytes: 640
import math

a=input()
a=int(a)
sum=0

def gcda(x,y,z):
    temp=math.gcd(x,y)
    return math.gcd(temp,z)

for i in range(1,a+1):
    for j in range(1,a+1):
        for k in range(1,a+1):
            sum+=gcda(i,j,k)

print(sum)



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

const long long MOD = 1e9 + 7;
const int MAXN = 1e6 + 10;

vector<long long> factorial(MAXN, 1);

inline long long add(long long x, long long y) {
	return ((x % MOD) + (y % MOD))% MOD;
}

inline long long subtract(long long x, long long y) {
	x = x % MOD;
	y = y % MOD;

	if(x >= y) return x - y;
	else return x - y + MOD;
}

inline long long multiply(long long x, long long y) {
	return ((x % MOD) * (y % MOD)) % MOD;
}

inline long long power(long long x, long long y) {
	long long res = 1;
	x = x % MOD;

	while(y > 0) {
		if(y & 1) {
			res = multiply(res, x);
		}
		y = y / 2;
		x = multiply(x, x);
	}

	return res;
}

inline long long divide(long long x, long long y) {
	return multiply(x, power(y, MOD-2));
}

inline long long C(long long n, long long r) {
	if(n < r or r < 0 or n < 0) return 0;
	return divide(factorial[n], multiply(factorial[r], factorial[n-r]));
}

void precompute() {
	for(int i = 1; i < MAXN; i++) {
		factorial[i] = multiply(factorial[i-1], i);
	}
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	
	precompute();

	int r, c;
	cin >> r >> c;

	long long ans = 0;
	int sr = 0, sc = 0;
	int er = 0, ec = 0;

	for(int i = 0; i < MAXN; i++) {
		int x = sr - r;
		int y = c - sc;
		if(x >= 0 and y >= 0 and x == y and x <= i) {
			ans =  C(i, x);
			break;
		}
		sr += 2;
		sc += 1;
		er += 1;
		ec += 2;
	}

	cout << ans << '\n';

	return 0;
}

Measured memory_bytes: 8700
import heapq
def dijkstra(start,goal,graph):

    INF = 2 << 20
    node_num = len(graph) 
    visited = [False] * node_num
    costs = [INF] * node_num
    pq = []
    costs[start] = 0
    #print costs[start]
    heapq.heappush(pq, [0,start])
    
    while not len(pq) == 0:
        cur_cost,cur_node = heapq.heappop(pq)

        if visited[cur_node]:
            continue
        if all(visited[1:]):
            break

        #print cur_cost,cur_node

        visited[cur_node] = True
        costs[cur_node] = cur_cost
        #print costs
        
        for i in xrange(node_num):
            if not visited[i]:
                heapq.heappush(pq,[graph[cur_node][i] + costs[cur_node],i])
    return costs[goal]

n = input()
m = input()
INF = 2 << 20
graph = [[INF] * (n+1) for _ in xrange(n+1)]
for _ in xrange(m):
    a,b,c,d = map(int,raw_input().split(","))
    #graph[from][to] = cost
    graph[a][b] = c
    graph[b][a] = d
home,shop,reward,price = map(int,raw_input().split(","))
graph[home][home] = 0
cost = dijkstra(home,shop,graph)
graph[home][home] = INF
graph[shop][shop] = 0
cost += dijkstra(shop,home,graph)
print reward - price - cost

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

#define IOS                               \
	ios_base::sync_with_stdio(false); \
	cin.tie(0);                       \
	cout.tie(0);                      \
	cin.exceptions(cin.failbit);
#define int long long int //Comment when Unnecessary
#define ll long long
#define sz(a) (int)((a).size())
#define all(a) a.begin(), a.end()
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define pii pair<int, int>
#define vi vector<int>
#define F first
#define S second
#define endl "\n" // Remove on Interactive

const int N = 300009;
const int mod = 1000000007;

int n, r;

void pre()
{
}

int32_t main()
{
	IOS;
	pre();
	cin >> n >> r;
	if (n >= 10)
	{
		cout << r << endl;
	}
	else
	{
		cout << (r + ((10 - n) * 100)) << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) rep(i,x.size()) cout << x[i] << " "
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;
const int mod = 1e9+7;

int main() {
    int a, b, c; cin >> a >> b >> c;
    map<int,int> mp;
    mp[a]++; mp[b]++; mp[c]++;
    if (mp[5] == 2 && mp[7] == 1) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 3612
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<stack>
#include<vector>
#include<cmath>
#include<string>
#include<queue>
#include<map>
#include<cstring>
#include<sstream>
#include<vector>
#include<algorithm>
#include<functional>
#include<set>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<time.h>
typedef long long ll;
using namespace std;

queue<pair<string, int> > q;

int main() {
	//freopen("run.in", "r", stdin);
	//freopen("run.out", "w", stdout);

	int N, Q;
	cin >> N >> Q;
	string name;
	int time;
	for (int i = 1; i <= N; i++) {
		cin >> name;
		cin >> time;
		q.push(make_pair(name, time));
	}
	int sum = 0;
	while (!q.empty()) {
		int  a = q.front().second;
		string  b = q.front().first;
		if (a <= Q) {
			sum += a;
			cout << b << ' ' << sum << endl;
			q.pop();
		}
		else {
			a -= Q;
			sum += Q;
			q.pop();
			q.push(make_pair(b, a));
		}
	}






	return 0;
}

Measured memory_bytes: 6176
#include <iostream>
#include <vector>
#include <bitset>
#include <utility>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
 
using namespace std;
typedef long long ll;
 
int main(){
  int N;
  cin >> N;

  vector<int> a(N);
  vector<vector<ll>> dp(N+1,vector<ll>(N+1));

  for (int i = 0; i < N; i++){
    cin>> a[i];
  }
  bool taro=(N%2==1);
  for(int i=1;i<=N;i++){
    for (int j = 0; j <=N-i; j++){
      if(taro){
        dp[j][j+i]=max( a[j]+dp[j+1][j+i], a[j+i-1]+dp[j][j+i-1]);
      }else{
        dp[j][j+i]=min(-a[j]+dp[j+1][j+i],-a[j+i-1]+dp[j][j+i-1]);
      }
      //cout << j <<" "<< j+i << " " << dp[j][j+i] <<endl;
    }
    taro^=true;
  }

  cout<< dp[0][N] << endl;

  return 0;
}


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

int main() {
  int A,B;
  A=0;
  int N;
  cin >> N;
  vector<int>a(N);
  vector<int>b(N-1);
  for(int i=0;i<(N-1);i++){
    cin >> b.at(i);
  }
  A=b.at(0)+b.at(N-2);
  for(int i=1;i<N-1;i++){
    A=A+min(b.at(i-1),b.at(i));
  }
  
cout << A << endl;

}

Measured memory_bytes: 256
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

n = INT()
s = STR()
ans = 0
x = 0
for i in range(n):
    if s[i] == 'I':
        x += 1
    elif s[i] == 'D':
        x -= 1
    ans = max(ans, x)
print(ans)

Measured memory_bytes: 60268
a='abcdefghijklmnopqrstuvwxyz'
b='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
d={}
for i in range(26):
    d[b[i]]=a[i]
n,k=map(int,input().split())
S=list(input().strip())
t=S[k-1]
S[k-1]=d[t]
print(*S,sep='')

Measured memory_bytes: 3060
#include<stdio.h>

#define K 10000

int main(){
  int n,i,num,A[2000001],B[2000001],C[K];

  scanf("%d",&n);

  for(i = 1;i <= n;i++){
    scanf("%d",&A[i]);
  }

  for(i = 0;i <= K;i++) C[i] = 0;

  for(i = 1;i <= n;i++) C[A[i]]++;

  for(i = 1;i <= K;i++) C[i] = C[i] + C[i-1];

  for(i = n;i >= 1;i--){
    B[C[A[i]]] = A[i];
    C[A[i]]--;
  }
  for(i = 1;i <= n;i++){
    if(i > 1) printf(" ");
    printf("%d",B[i]);
  }printf("\n");
  return 0;
}



Measured memory_bytes: 17464
#include <iostream>
#include <list>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <string>
using namespace std;

#define fi(x) get<0>(x)
#define se(x) get<1>(x)

typedef long long lli;
typedef vector<lli> vll;
typedef vector<bool> vbl;
typedef vector<vector<lli> > mat;
typedef vector<vector<bool> > matb;
typedef vector<string> vst;
typedef pair<lli,lli> pll;
typedef pair<double,double> pdd;
typedef vector<pll> vpl;

string t;
string p;
lli q;

vll sa;
vll tmp;
vll rnk_;
vll rnk;



int main(){
    cin >> t;
    sa = vll(t.size());rnk = vll(t.size()),rnk_ = vll(t.size());tmp = vll(t.size());
    for(lli i = 0;i < t.size();i++) sa[i] = i;
    for(lli i = 0;i < t.size();i++) rnk[i] = t[i];
    sort(sa.begin(),sa.end(),[](lli a,lli b){
        return rnk[a] < rnk[b];
    });
    for(lli k = 1;k < 2*t.size();k *= 2){
        lli from = 0;
        lli to = 0;
        do{
            from = to;
            while(to < rnk.size() && rnk[sa[from]] == rnk[sa[to]]) to++;
            for(lli i = from;i < to;i++) rnk_[sa[i]] = sa[i]+k < rnk.size() ? rnk[sa[i]+k] : -1;
            sort(sa.begin()+from,sa.begin()+to,[](lli a,lli b){
                return rnk_[a] < rnk_[b];
            });
        }while(to < sa.size());
        tmp[sa[0]] = 0;
        for(lli i = 1;i < sa.size();i++){
            lli c = 1;
            if(rnk[sa[i-1]] == rnk[sa[i]] && rnk_[sa[i-1]] == rnk_[sa[i]]) c = 0;
            tmp[sa[i]] = tmp[sa[i-1]] + c;

        }
        for(lli i = 0;i < sa.size();i++){
            rnk[sa[i]] = tmp[sa[i]];
        }
    }
    sort(sa.begin(),sa.end(),[](lli a,lli b){
        return rnk[a] < rnk[b];
    });
    //for(lli i = 0;i < sa.size();i++) cout << sa[i] << endl;
    /*
    for(lli i = 0;i < sa.size();i++){
        for(lli j = sa[i];j < t.size();j++) cout << t[j];
        cout << endl;
    }
    */
    
    cin >> q;
    for(lli i = 0;i < q;i++){
        cin >> p;
        auto from = sa.begin();
        auto to = sa.end();
        for(lli i = 0;i < p.size();i++){
            from = lower_bound(from,to,p[i],[i](lli x,char c){
                if(x+i >= t.size()) return false;
                return t[x+i] < c;
            });
            to = lower_bound(from,to,p[i],[i](lli x,char c){
                if(x+i >= t.size()) return false;
                return t[x+i] < c+1;
            });
            //cout << from-sa.begin() << " " << to-sa.begin() << endl;
        }
        if(to-from > 0) cout << 1 << endl;
        else cout << 0 << endl;
    }
    return 0;
}

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


const int MAX_V = 10000;
const int MAX_E = 100000;
int finde[MAX_V];

struct Edge {
	int first;
	int second;
	int weight;
};
vector<Edge> e;

bool operator < (const Edge& a, const Edge& b) {
	return a.weight < b.weight;
}

bool Judge(int m, int n) {
	while (finde[m] != m) m = finde[m];
	while (finde[n] != n) n = finde[n];
	if (m == n) {
		return false;
	}
	 finde[n]= m;
	return true;
}

int min_span_tree(int n, int m) {

	for (int i = 0; i < m; i++) finde[i] = i;
	int count = 0;
	int ret = 0;
	int f, s;
	for (int i = 0;count<m-1; i++) {
		f = e[i].first;
		s = e[i].second;
		if (Judge(f,s)) {		
			ret += e[i].weight;
			count++;
		}
	}
	return ret;
}
int main() {
	int n, m;
	cin >> m >> n;
	for (int i = 0; i < n; i++) {
		int s, t, w;
		cin>>s>>t>>w;
		e.push_back(Edge{ s, t, w });
	}
	sort(e.begin(), e.end());
	int ret = min_span_tree(n, m);
	cout << ret << endl;
	return 0;
}

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

using namespace std;

using ll = long long;
#define pb push_back
#define dbg(x) cerr << #x << " " << x << "\n"

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

    int x, n;
    cin >> x >> n;
    int p;
    vector <int> f (103, 0);
    for (int i = 1; i <= n; i++)
        cin >> p, f[p]++;
    int ans = 0;
    for (int i = 0; i <= 101; i++)
        if (not f[i])
            if (abs (i - x) < abs (x - ans))
                ans = i;
    cout << ans << "\n";
    return 0;
}


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

const int MAXC = 80;


int main() {
	int H, W; cin >> H >> W;
	vector<vector<int>> a(H, vector<int>(W));
	vector<vector<int>> b(H, vector<int>(W));
	
	for(int h = 0; h < H; ++h) for(int w = 0; w < W; ++w) cin >> a[h][w];
	for(int h = 0; h < H; ++h) for(int w = 0; w < W; ++w) cin >> b[h][w];
	
	vector<vector<int>> diff(H, vector<int>(W));
    for(int h = 0; h < H; ++h) for(int w = 0; w < W; ++w) diff[h][w] = abs(a[h][w] - b[h][w]);
	
	int MAX = MAXC * (H + W - 2);
	bool dp[H][W][MAX];
	for(int h = 0; h < H; ++h) for(int w = 0; w < W; ++w) for(int k = 0; k < MAX; ++k) dp[h][w][k] = false;
	dp[0][0][diff[0][0]] = true;	

	for(int h = 0; h < H; ++h) for(int w = 0; w < W; ++w) for(int k = 0; k < MAX; ++k) {
        int d = diff[h][w];
        if (h - 1 >= 0 && abs(k - d) < MAX) dp[h][w][abs(k - d)] |= dp[h - 1][w][k];
        if (w - 1 >= 0 && abs(k - d) < MAX) dp[h][w][abs(k - d)] |= dp[h][w - 1][k];
        if (h - 1 >= 0 && k + d < MAX) dp[h][w][k + d] |= dp[h - 1][w][k];
        if (w - 1 >= 0 && k + d < MAX) dp[h][w][k + d] |= dp[h][w - 1][k];
    };
	
    for (int k = 0; k < MAX; ++k) {
        if (dp[H - 1][W - 1][k]) {
			cout << k << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 79360
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
    int n;
    cin >> n;
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        int a;
        cin >> a;
        if (i % 2 == 1 && a % 2 == 1)
            ans++;
    }
    
    cout << ans << endl;
    
    return 0;
}


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

void fnInput(vector<string>& rvsGacha)
{
  int nGachaSiz;
  cin >> nGachaSiz;
  rvsGacha.resize(nGachaSiz);

  for (string& rsGacha : rvsGacha)
    cin >> rsGacha;
}
  
int fnGachaCnt(const vector<string>& cnrvsGacha)
{
  set<string> stGacha;

  for (string sGacha : cnrvsGacha)
    stGacha.insert( sGacha );

  return stGacha.size();
}
  
int main()
{
  vector<string> vsGacha;

  fnInput(vsGacha);
  cout << fnGachaCnt(vsGacha) << endl;

  return 0;
}

Measured memory_bytes: 25104
import math
n, k = map(int,input().split())
dat = list(map(int, input().split()))

i = dat.index(1) + 1 # 1 origin で i 個目に 1 がある

reached = k # 最初の1歩はkマス塗れる
# a: 残りはk-1マス塗れるので、残っている分を塗る(k<nなのでマイナスは考えない)
a = math.ceil((n - reached) / (k - 1))
print(1 + a)

Measured memory_bytes: 13812
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>

using namespace std;

const int MOD = 1000000007;
typedef pair<int, int> P;
typedef long long ll;
#define rep(i, n) for(int i=0;i<n;i++)
#define rep2(i, m, n) for(int i=m;i<n;i++)
#define rrep(i, n, m) for(int i=n;i>=m;i--)
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

vector<ll> divisor(ll N) {
    vector<ll> res;
    for (ll i = 1L; i * i< N; ++i) {
        if (N % i == 0) {
            res.push_back(i);
            ll j = N / i;
            if (j != i)  {
                res.push_back(j);
            }
        }
    }
    sort(res.begin(), res.end());
    return res;
}


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

    ll N, M;
    cin >> N >> M;
    vector<ll> div = divisor(M);

    ll ans = 1;
    for (auto d : div) {
        if(d * N <= M) {
            ans = max(ans, d);
        }
    }
    cout << ans << endl;
}


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

using namespace std;
map<long long,int> rem;
int main()
{
  long long i,n ,k, a, j;
  std::vector<int> v;
  cin >> n >> k;

  for(i=0;i<n;i++)
    {cin>>a; v.push_back(a);}

  long long sum[200001] = {0};

  long long ans=0;

  sum[0]=v[0]%k;
  if(sum[0] == (0+1) && 0<k)ans++;
  for(i=1;i<n;i++)
  {
    sum[i]=sum[i-1]+v[i];
    sum[i] = sum[i]%k;
    if(sum[i] == (i+1) && i<k)ans++;
  }
  for(i=0;i<n;i++)
  {
    sum[i] = ((sum[i]-i+k)%k-1 +k)%k;
    //if(sum[i]==0 && i<k)ans++;
  //  cout<<sum[i]<<" ";
  }
  //cout<<endl;

int st=0, en=0;
  for(i=0;i<n;i++)
  {
    if(i<k)
    {
      ans+=rem[sum[i]];
    //  cout<<rem[sum[i]]<<" ";
      rem[sum[i]]++;
      en++;
    }
    else {
      rem[sum[st]]--;
      ans+=rem[sum[i]];
      //cout<<rem[sum[i]]<< " ";
      rem[sum[en]]++;
      st++;
      en++;
    }
  }
  cout << ans;
}

Measured memory_bytes: 15092
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define ll long long int
#define pb push_back
#define mp make_pair
#define ld long double
#define sz(a) (ll)(a).size()

typedef tree<pair<ll,ll> ,null_type,less<pair<ll,ll> >,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
//K-th smallest
//cout << k << "kth smallest: " << *A.find_by_order(k-1) << endl;
//NO OF ELEMENTS < X
//cout << "No of elements less than " << X << " are " << A.order_of_key(X) << endl;

const int MAXN = 405;

ll n, a[MAXN], dp[MAXN][MAXN], sum[MAXN][MAXN];      // Minimum cost to combine elements from st to en

ll rec(ll st, ll en)
{
	if(st == en) return dp[st][en] = 0;
	if(dp[st][en] != -1) return dp[st][en];
	ll ans = 1e18;
	for(int i=st;i<en;i++)
		ans = min(ans, rec(st, i) + rec(i + 1, en) + sum[st][i] + sum[i+1][en]); 
	return dp[st][en] = ans;
}

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

	cin >> n;
	for(int i=0;i<n;i++) cin >> a[i];
	memset(dp, -1, sizeof(dp));
	for(int i=0;i<n;i++)
	{
		sum[i][i] = a[i];
		for(int j=i+1;j<n;j++) sum[i][j] = sum[i][j-1] + a[j];
	}
	cout << rec(0, n-1) << endl;
    return 0;
}

Measured memory_bytes: 2944
#include<stdio.h>
int main()
{
    int W,H,x,y,r;
    scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
    if(x>=0 && (x+r)<=W && y>=0 && (y+r)<=H)
    {
        printf("Yes\n");
    }
    else
    {
        printf("No\n");
    }
    return 0;

}



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

#define all(v) (v).begin(), (v).end()
#define sortv(v) sort(all(v))
#define uniqv(v) (v).erase(unique(all(v)), (v).end())
#define pb push_back
#define FI first
#define SE second
#define lb lower_bound
#define ub upper_bound
#define mp make_pair
#define test 1
#define TEST if(test)

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

const int MOD = 1000000007; // 998244353
const int INF = 2e9;
const ll INFLL = 1e18;
const int MAX_N = 100000;

int N, K;
int dp[MAX_N+1];
int from[MAX_N+1];
string str;

deque<int> dq;

int main(){
	cin>>N>>K>>str;
	if(str[N]=='1' || str[0]=='1'){
		printf("-1");
		return 0;
	}
	dq.pb(N);
	for(int i=N-1; i>=0; i--){
		if(str[i]=='1' || dq.empty())	continue;
		while(!dq.empty() && dq.front()>i+K){
			dq.pop_front();
		}
		if(dq.empty())	continue;
		from[i] = dq.front(); dp[i] = dp[dq.front()]+1;
		while(!dq.empty() && dp[dq.back()]>=dp[i]){
			dq.pop_back();
		}
		dq.pb(i);
	}
	if(dp[0]==0 || from[0]==0){
		printf("-1");
		return 0;
	}
	int t = 0;
	while(t!=N){
		printf("%d ", from[t] - t);
		t = from[t];
	}
	return 0;
}


Measured memory_bytes: 1408
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	X := sc.nextInt()
	n := 1
	for {
		if X <= (n*(n+1))/2 {
			break
		}
		n++
	}

	fmt.Fprintln(wtr, n)
	wtr.Flush()
}


Measured memory_bytes: 640
//master
import java.io.*;
import java.util.*;
public class Main {
    static int[][] memo;
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        int n = sc.nextInt();
        int m = sc.nextInt();
        if(n<=m) p("unsafe");
        else p("safe");
    }

    public static <T> void p(T message) {
        System.out.println(message);
    }

    public static <T> void pe(T message) {
        System.err.println(message);
    }

    public static <T> void pp(T message) {
        System.out.print(message);
    }
    
}
class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
 
    private int readByte() {
        if (hasNextByte())
            return buffer[ptr++];
        else
            return -1;
    }
 
    private boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }
 
    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr]))
            ptr++;
        return hasNextByte();
    }
 
    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
 
    public long nextLong() {
        if (!hasNext())
            throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
 
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }
 
    public double nextDouble() {
        return Double.parseDouble(next());
    }
}


Measured memory_bytes: 32628
#include<cstdio>
#include<algorithm>
#include<functional>
using namespace std;
int main(void)
{
	int a,b,s;
	scanf("%d %d",&a,&b);
	a--;	b--;
	s=b/a;
	if(b%a!=0)	s++;
	printf("%d\n",s);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

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

	string S; cin >> S;
	map<char,int> D; D.clear();
	rep (i, (int)S.length()){
		++D[S[i]];
	} // end rep

	bool res = (D['N'] > 0 && D['S'] > 0) || (D['N'] == 0 && D['S'] == 0);
	res &= (D['E'] > 0 && D['W'] > 0) || (D['E'] == 0 && D['W'] == 0);

	cout << (res ? "Yes" : "No") << endl;
 
	return 0;
}

Measured memory_bytes: 256
import sys
def main():
    N = int(input())
    S = input()
    now = 0
    count = 0
    while True:
        count += 1
        now_color = S[now]
        while now_color == S[now]:
            now += 1
            if now == N:
                print(count)
                exit()

if __name__ == "__main__":
    main()


Measured memory_bytes: 3316
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for (int i = 0; i < n; i++)
static const int inf = 1 << 30;

int main(void) {
  int N, X;
  vector<int> m;
  cin >> N >> X;
  int sum = 0;
  REP(i, N) {
    int v;
    cin >> v;
    sum += v;
    m.push_back(v);
  }
  sort(m.begin(), m.end());
  X = X - sum;
  cout << N + int(X / m[0]) << endl;
}

Measured memory_bytes: 256
n = int(input())
S = list(map(int, input().split()))
q = int(input())
T = list(map(int, input().split()))
count = 0

Sm, SM = S[0], S[n - 1]
for x in T:
    if x < Sm or SM < x:
        continue
    l, r = 0, n - 1
    while l <= r:
        m = (l + r) // 2
        if S[m] == x:
            count += 1
            break
        elif S[m] > x:
            r = m - 1
        else:
            l = m + 1
print(count)

Measured memory_bytes: 18668
#include<bits/stdc++.h>
#define mo 1000000007
#define add(a,b) (a+b>=mo)?(a+=b-mo):(a+=b)
using namespace std;
int f[2][22][1<<19],a[22][22];
int lowbit(int s){return s&(-s);}
int main()
{
	int n,m,q;scanf("%d%d%d",&n,&m,&q);
	memset(a,255,sizeof(a));
	while (q--)
	{
		int u,v,w;scanf("%d%d%d",&u,&v,&w);
		a[u][v]=w;
	}
	f[1][0][0]=1;
	for (int i=1;i<=m;i++)
	{
		memset(f[(i&1)^1],0,sizeof(f[(i&1)^1]));
		for (int j=0;j<n-1;j++)
		for (int s=0;s<(1<<(n-1));s++) if (f[i&1][j][s])
		{
			if ((a[i][j+1]!=1)&&((s&(1<<j))==0)) add(f[i&1][j+1][s],f[i&1][j][s]);
			if (a[i][j+1]!=0)
			{
				if (s&(1<<j)) add(f[i&1][j+1][s],f[i&1][j][s]);
				else add(f[i&1][j+1][s-(lowbit(s>>j)<<j)+(1<<j)],f[i&1][j][s]);
			}
		}
		for (int s=0;s<(1<<(n-1));s++) if (f[i&1][n-1][s]) add(f[(i&1)^1][0][s],f[i&1][n-1][s]);
	}
	int ans=0;
	for (int s=0;s<(1<<(n-1));s++) add(ans,f[m&1][n-1][s]);
	printf("%d\n",ans);
}

Measured memory_bytes: 90496
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int mod = 1_000_000_007;
		int N = sc.nextInt();
		int M = sc.nextInt();
		int[] a = new int[M];
		int[] flag = new int[2];
		HashSet<Integer> set = new HashSet<Integer>();
		for (int i=0;i<M;i++) {
			a[i] = sc.nextInt();
			set.add(a[i]);
			if (a[i]==1) {
				flag[0]=1;
			} else if(a[i]==2) {
				flag[1]=1;
			}
		}
		if (N==1) {
			System.out.println(1);
		} else {
			int[] ans = new int[N+1];
			if (flag[0]==0) {
				ans[1]=1;
			}
			if (flag[1]==0) {
				ans[2]=1;
			}
			for (int i=0;i<N;i++) {
				if (i!=N-1) {
					if (!set.contains(i+2)) {
						ans[i+2]=(ans[i+2]+ans[i])%mod;
					}
				}
				if (!set.contains(i+1)) {
					ans[i+1]=(ans[i+1]+ans[i])%mod;
				}
			}

			System.out.println(ans[N]);
		}
	}
}

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

#define nl '\n'

using namespace std;

typedef long long ll;

void solve() {
  int N;
  cin >> N;

  int cnt = 0;
  for (int a = 1; a < N; a++) {
    for (int b = 1; a*b < N; b++) {
      cnt++;
    }
  }

  cout << cnt;
}

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

  // int t;
  // cin >> t;
  // while (t--) {
  solve();
  cout << nl;
  // }

  return 0;
}

Measured memory_bytes: 3652
<<NOTE.!
フレームの描画

  以下のような、たて H cm よこ W cm の枠を描くプログラムを作成して下さい。

  ##########
  #........#
  #........#あしな
  #........#
  #........#
  ##########

  上図は、たて 6 cm よこ 10 cm の枠を表しています。

Input
  入力は複数のデータセットから構成されています。各データセットの形式は以下のとおりです：

  H W

  H, W がともに 0 のとき、入力の終わりとします。

  審判データに用いられる入力の条件は、3 ? H, W ? 100 です。

Output
  各データセットについて、たて H cm よこ W cm の枠を出力して下さい。

  各データセットの後に、１つの空行を入れて下さい。
NOTE

def draw_top(w)
  puts '#' * w
end

def draw_middle(w)
  puts '#' + "#{'.' * (w - 2)}" + '#'
end

alias :draw_bottom :draw_top

def draw_rect(h, w)
  draw_top(w)
  (h - 2).times{ draw_middle(w) }
  draw_bottom(w)
  puts
end

ARGF.each_line do |line|
  height, width = line.split.map(&:to_i)
  break if line =~ /^0 0/
  draw_rect(height, width)
end

Measured memory_bytes: 6100
import java.io.*;
import java.util.*;
//import java.util.stream.*;
//import java.math.*;

public class Main {

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

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        Scanner sc = new Scanner(System.in);
        String odd = br.readLine();
        String even = br.readLine();
        String merge = odd + even;
        String s = "";
        int o = 0, e = 0;
        for (int i = 0; i < merge.length(); i++) {
            if (i % 2 == 0) {
                s += odd.charAt(o++);
            } else {
                s += even.charAt(e++);
            }
        }
        System.out.println(s);
        bw.flush();
    }
}


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


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>

using namespace std;
const int N = 200050;
int x[N], y[N], n;
int xid[N], yid[N];
int seq[N], idx = 0;
int sz[N], p[N];
int bsearch(int v)
{
	int lo = 0, hi = idx;
	while(lo < hi)
	{
		int m = lo + hi >> 1;
		if(y[seq[m]] > v) lo = m + 1;
		else hi = m;
	}
	return lo;
}
int find(int x)
{
	return x == p[x] ? x : p[x] = find(p[x]);
}
int main()
{
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i)
	{
		scanf("%d%d", &x[i], &y[i]);
		xid[x[i]] = i;
		yid[y[i]] = i;
		sz[i] = 1;
		p[i] = i;
	}
	for(int x0 = 1; x0 <= n; ++x0)
	{
		int id = xid[x0];
		int y0 = y[id];
		int i = bsearch(y0);
		if(i == idx) seq[idx++] = id;
		else
		{
			for(int k = i; k < idx - 1; ++k)
			{
				p[seq[k]] = seq[idx - 1];
				sz[seq[idx - 1]] += sz[seq[k]];
			}
			p[id] = seq[idx - 1];
			sz[seq[idx - 1]] += sz[id];
			seq[i] = seq[idx - 1];
			idx = i + 1;
		}
	}
	for(int i = 1; i <= n; ++i)
		printf("%d\n", sz[find(i)]);
	return 0;
}


Measured memory_bytes: 8536
#include <bits/stdc++.h>
using namespace std;
template<class T> ostream& operator<<(ostream &os, vector<T> V) {
os << "[ "; for(auto v : V) os << v << " "; return os << "]";}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {
    return os << "(" << P.first << "," << P.second << ")";}

// #define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...) 1
#endif
typedef long long ll;
typedef double ld;
#define pll pair<ll,ll>
#define pb push_back
#define mp(x, y) make_pair((x), (y))
#define F first
#define S second
#define I insert
#define vll vector<ll>
#define vpll vector<pll>
#define all(x) (x).begin(), (x).end()
#define sz(x) (ll)(x).size()
   
const ll Mod = 1e9 + 7;
int gcd(int a , int b){
    return (a == 0)? b : gcd(b%a , a);
}
int main(){
   ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); 
   int n ; cin >> n;
   int A[n+1] , prefix[n+1] , suffix[n+2];
   suffix[n+1] = 0; 
   prefix[0]   = 0;
   for(int i = 1 ; i <= n ; i++)
        cin >> A[i];

    int gd = 0 , dg = 0;
    for(int i = 1; i <= n ; i++){
        gd = gcd(gd , A[i]);
        dg = gcd(dg , A[n-i+1]);
        prefix[i] = gd;
        suffix[n-i+1] = dg;
    }

    int ans = 0;
    for(int i = 0;i <= n ; i++){
        ans = max(ans , gcd(prefix[i] , suffix[i+2]));
    }
    cout << ans << endl;
   return 0;
}

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

int a, b;

int main() {
  cin >> a >> b;
  
  if (a + b > a - b && a + b > a * b) cout << a + b << endl;
  else if (a - b > a * b) cout << a - b << endl;
  else cout << a * b << endl;
  
  return 0;
}

Measured memory_bytes: 256
/* 
	بسم الله الرحمن الرحیم
	
	(; طلا یک جهانی
*/	

#include <bits/stdc++.h>
using namespace std;

#define int long long
#define F first
#define S second
typedef pair<int, int> pii;

int32_t main() {
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	int n, m;
	cin >> n >> m;
	multiset<pii> s;
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		s.insert({a, 1});
	}
	for (int i = 0; i < m; i++) {
		int b, c, x = 0;
		cin >> b >> c;
		while (!s.empty() && x < b) {
			auto it = *s.begin();
			if (it.F > c)
				break;
			int tmp = min(it.S, b - x);
			x += tmp;
			it.S -= tmp;
			s.erase(s.begin());
			if (it.S)
				s.insert(it);
		}
		s.insert({c, x});
	}
	long long ans = 0;
	for (auto i: s)
		ans += 1LL * i.F * i.S;
	cout << ans;
}


Measured memory_bytes: 6528
#-------------
s = input()
#-------------
N = len(s)
A = []
Z = []
for i in range(N):
  if s[i] == "A":
    A.append(i)
  if s[i] == "Z":
    Z.append(i)
    
min_A = min(A)
max_Z = max(Z)
print(max_Z-min_A+1)

Measured memory_bytes: 16944
x=int(input())
if 400<=x<600:
    print(8)
elif 600<=x<800:
    print(7)
elif 800<=x<1000:
    print(6)
elif 1000<=x<1200:
    print(5)
elif 1200<=x<1400:
    print(4)
elif 1400<=x<1600:
    print(3)
elif 1600<=x<1800:
    print(2)
elif 1800<=x<2000:
    print(1)

Measured memory_bytes: 9188