akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <stack>
#include <set>
#include <queue>
#include <iomanip>
#include <math.h>
#include <fstream>

using namespace std;

long long mod = 1000000007;

void dfs(int p, int prev, vector<int> &a, vector<int> &dp, int dpl, vector<vector<int>> &v, vector<int> &res)
{
    int l = -1, r = dpl, mid;
    while (r - l > 1)
    {
        mid = (l + r) / 2;
        if (dp[mid] >= a[p])
        {
            r = mid;
        }
        else
        {
            l = mid;
        }
    }
    int temp = dp[r];
    dp[r] = a[p];
    if (temp == -1)
    {
        dpl++;
    }
    res[p] = dpl;
    for (int i = 0; i < v[p].size(); i++)
    {
        if (v[p][i] == prev)
        {
            continue;
        }
        dfs(v[p][i], p, a, dp, dpl, v, res);
    }
    dp[r] = temp;
}

int main()
{
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);
    // ifstream cin("in.txt");
    // ofstream cout("out.txt");
    
    
    // int t;
    // cin >> t;
    // for (int qwe = 0; qwe < t; qwe++)
    // {
    //     cout << "Case #" << qwe + 1 << ": ";
    // }


    int n, m, x;
    cin >> n >> m >> x;
    vector<int> c(n);
    vector<vector<int>> a(n, vector<int>(m));
    for (int i = 0; i < n; i++)
    {
        cin >> c[i];
        for (int j = 0; j < m; j++)
        {
            cin >> a[i][j];
        }
    }
    int rez = 999999999;
    for (int i = 0; i < (1 << n); i++)
    {
        vector<int> v(m, 0);
        int cost = 0;
        for (int j = 0; j < n; j++)
        {
            if ((i & (1 << j)) == 0)
            {
                continue;
            }
            cost += c[j];
            for (int k = 0; k < m; k++)
            {
                v[k] += a[j][k];
            }
        }
        bool good = true;
        for (int j = 0; j < m; j++)
        {
            if (v[j] < x)
            {
                good = false;
                break;
            }
        }
        if (good)
        {
            rez = min(rez, cost);
        }
    }
    if (rez == 999999999)
    {
        rez = -1;
    }
    cout << rez << '\n';


    return 0;
}


Measured memory_bytes: 3196
N = int(input())
S = list(input())
Q = int(input())


class Bit:
    """1-indexed"""

    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)

    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s

    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i


en2asc = lambda s: ord(s) - 97

Bits = [Bit(N) for _ in range(26)]
for i, s in enumerate(S):
    Bits[en2asc(s)].add(i + 1, 1)

for _ in range(Q):
    q = input().split()
    if q[0] == '1':
        i, c = int(q[1]), q[2]
        old = S[i - 1]
        Bits[en2asc(old)].add(i, -1)
        Bits[en2asc(c)].add(i, 1)
        S[i - 1] = c
    else:
        l, r = int(q[1]), int(q[2])
        ans = 0
        for b in Bits:
            ans += bool(b.sum(r) - b.sum(l - 1))
        print(ans)


Measured memory_bytes: 167196
package main

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

var (
	read  = bufio.NewReader(os.Stdin)
	write = bufio.NewWriter(os.Stdout)
)

func main() {
	defer write.Flush()

	var a, b int
	fmt.Fscan(read, &a, &b)

	for i := 1; i <= 1000; i++ {
		if i*8/100 == a && i*10/100 == b {
			fmt.Fprintln(write, i)
			return
		}
	}
	fmt.Fprintln(write, -1)
}


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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int mod = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  
  ll n, k;
  cin >> n >> k;
  
  ll ans;
  if(n % k == 0)
    ans = 0;
  else
    ans = 1;
  
  cout << ans << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include<string>
using namespace std;
int main(void){
    int a,b;
    string s;
    cin>>s;
    for(int i=0;i<s.size();i++){
        if(s[i]!=',') cout<<s[i];
        else cout<<" ";
    }
    return 0;
    // Your code here!
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pint;

int main(){
    int a,b,c;
    cin>>a>>b>>c;
    if(a-b!=0&&a-c!=0) cout<<a<<endl;
    if(b-a!=0&&b-c!=0) cout<<b<<endl;
    if(c-b!=0&&a-c!=0) cout<<c<<endl;
    return 0;
}

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

int main() {
  int n; string s, t; cin >> n >> s >> t;
  char ans[2*n];
  int a = 0, b = 0;
  rep(i, 2*n) {
    if (i%2 == 0) {
      ans[i] = s[a];
      a++;
    }else {
      ans[i] = t[b];
      b++;
    }
  }
  rep(i, 2*n) cout << ans[i];
  return 0;
}

Measured memory_bytes: 256
N, M = map(int,input().split())

A = list(map(int, input().split()))

A.sort(reverse=True)

amount = sum(A)

selectable = 0
for a in A:
    if(not (a*4*M < amount)):
        selectable += 1

if(selectable < M):
    print("No")
else:
    print("Yes")

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=2E5+7;
const ll INF=1e9+7;
ll dp[N];
ll a[N],b[N];
int main(){
    ll h,c;
    cin>>h>>c;
    for(ll i=1;i<=c;i++) cin>>a[i]>>b[i];
    for(ll i=1;i<=2*h;i++) dp[i]=INF;
    for(ll i=1;i<=c;i++){
        for(ll j=1;j<=2*h;j++){
            dp[j]=min(dp[j],dp[max((ll)0,j-a[i])]+b[i]);
        }
    }
    ll ans=INF;
    for(ll i=h;i<=h*2;i++){
        ans=min(ans,dp[i]);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 2304
#include <iostream>
#include <vector>
#include <tuple>
#include <fstream>
#include <stdio.h>
#include <algorithm>
#include <string>
using namespace std;

int main() {

    cin.tie(0);
    ios::sync_with_stdio(false);
 
 
    int x, ans=0, tmp1=0, tmp2=0;
    cin >> x;
    tmp1 = x / 500;
    tmp2 = (x%500) / 5;

    ans = tmp1*1000 + tmp2*5;
    cout << ans;
   
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<ll,ll,ll> T;
const long long INF = 1LL<<60;
const int MOD = 1000000000+7;
#define rev(s) (string((s).rbegin(), (s).rend()))
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };
// cout << fixed << setprecision(10) << ans << endl;
// *min_element(c + l, c + r) *max_element(c + l, c + r)
// int dx[8]={1,1,0,-1,-1,-1,0,1};
// int dy[8]={0,1,1,1,0,-1,-1,-1};
// int dx[4]={1,0,-1,0};
// int dy[4]={0,1,0,-1};
// struct Edge {
//   int to, id;
//   Edge(int to, int id): to(to), id(id) {}
// };

struct Info {
    int l,r,u,d;
};

int main() {
    int H,W;cin>>H>>W;
    vector<string> field(H);
    rep(i,H) cin>>field[i];
    vector<vector<int>> h(H,vector<int>()),w(W,vector<int>());
    rep(i,H) h[i].push_back(-1);
    rep(i,W) w[i].push_back(-1);
    rep(i,H) {
        rep(j,W) {
            if(field[i][j]=='#') {
                h[i].push_back(j);
                w[j].push_back(i);
            }
        }
    }
    rep(i,H) h[i].push_back(W);
    rep(i,W) w[i].push_back(H);

    vector<vector<Info>> info(H,vector<Info>(W));
    rep(i,H) {
        int l = h[i][0],r=h[i][1],nxt=2;
        rep(j,W) {
            if(j==r) {
                l = r;
                r = h[i][nxt];
                nxt++;
            }
            info[i][j].l = l;
            info[i][j].r = r;
        }
    }
    rep(i,W) {
        int u = w[i][0],d = w[i][1], nxt = 2;
        rep(j,H) {
            if(j==d) {
                u = d;
                d = w[i][nxt];
                nxt++;
            }
            info[j][i].u = u;
            info[j][i].d = d;
         }
    }
    int ans = 0;
    rep(i,H) {
        rep(j,W) {
            if(field[i][j]=='#') continue;
            // P hinf = info[i][j].first,winf = info[i][j].second;
            ans = max(ans,info[i][j].r-info[i][j].l-1+info[i][j].d-info[i][j].u-1-1);
        }
    }
    cout<<ans<<endl;  
}

Measured memory_bytes: 107792
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
const int    INF = 100000000;
const double EPS = 1e-10;
const int    MOD = 1000000007;
using namespace std;
typedef pair<int,int> P;

string str;

void solve(){
	cin >> str;
	set<string> s;
	rep(i,str.size()){
		string a = str.substr(0,i), b = str.substr(i,str.size()-i);
		string ra, rb;
		for(int j = a.size()-1; j >= 0; j--) ra.push_back(a[j]);
		for(int j = b.size()-1; j >= 0; j--) rb.push_back(b[j]);
		s.insert(a+b); s.insert(b+a);
		s.insert(ra+b); s.insert(b+ra);
		s.insert(a+rb); s.insert(rb+a);
		s.insert(ra+rb); s.insert(rb+ra);
		
	}
	cout << s.size() << endl;
}

int main(){
	int n;
	cin >> n;
	rep(i,n) solve();
}

Measured memory_bytes: 1300
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);++i)
using namespace std;
int main(){
	int a,b,k;cin>>a>>b>>k;
	int cnt=0;
	vector<int>ans(100);
	for(int i=min(a,b);i>=1;i--){
		if(!(a%i)&&!(b%i)){
			--k;
			if(k==0){
				cout<<i<<endl;
				return 0;
			}
		}
	}
	assert(false);
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#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;
using ll = long long;
using ull = unsigned long long; 
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
//constexpr long long MOD = 998244353LL;
template<class T, class U> inline bool chmax(T &a, U b) { if (a < b) { a = b; return true;} return false; }
template<class T, class U> inline bool chmin(T &a, U b) { if (a > b) { a = b; return true;} return false; }
////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    
   int n,k;
   cin >> n >> k;
   vector<int> p(n); rep(i,n) cin >> p[i];
   sort(all(p));
   
   int res = 0;
   rep(i,k) res += p[i];

   cout << res << ln;
   return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define arep(a,i,n) for(int i=(a);i<(n);i++)
#define rep(i,n) for(int i=0;i<(n);i++)
#define cinf(x,n) for(int i=0;i<(n);i++)cin>>x[i];
#define coutf(x,n) for(int i=0;i<(n);i++)cout<<x[i]<<endl;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

using namespace std;

int main(){
	int w,h,x,y,r;
	cin >> w >> h >> x >> y >> r;
	if(x+r<=w&&x-r>=0&&y-r>=0&&y+r<=h)
		cout << "Yes" << endl;
	else 
		cout << "No" << endl;
}


Measured memory_bytes: 3104
import itertools
A = [0]*5
for i in range(5):
    A[i] = int(input())

T_list = []

for x in itertools.permutations(A):
    t = 0
    for y in x:
        z = 0
        if t%10 > 0:
            z = 10 - t%10
        t += y + z
    T_list.append(t)
print(min(T_list))

Measured memory_bytes: 3060
def trans(S):
    if S == 'a':
        Num = 0
    elif S == 'b':
        Num = 1
    else:
        Num = 2

    return Num

def rev(N):
    if N == 0:
        S = 'A'
    elif N == 1:
        S = 'B'
    else:
        S = 'C'

    return S


S_abc = []
for i in range(3):
    S_abc.append(input())

nex = trans(S_abc[0][0])

S_abc[0] = S_abc[0][1:]

while True:
    if len(S_abc[nex]) == 0:
        print(rev(nex))
        exit()

    tmp = trans(S_abc[nex][0])
    S_abc[nex] = S_abc[nex][1:]

    nex = tmp


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define int int64_t
#define F first
#define S second
#define pb push_back
#define fo(i, n) for(int i = 0; i < n;  i ++)
using namespace std;

int32_t main(){
  int n; cin >> n;
  for(int i = 1; i <= 9; i ++)
    if(n % i == 0 && n / i <= 9){
      cout << "Yes"; return 0;
    }
  cout << "No";
}


Measured memory_bytes: 256
#include <cstring>
#include <algorithm>
#include <math.h>
#include <iostream>
#include <map>
#include <queue>
using namespace std;
typedef long long ll;

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

  ll s = 0;
  for (int i = 1; i < n; i += 2) {
    s += 2 * a[i];
  }

  ll one = sum - s;
  vector<ll> ans(n);
  ans[0] = one;
  for (int i = 1; i < n; ++i) {
    ans[i] = 2 * a[i - 1] - ans[i - 1];
  }

  for (int i = 0; i < n; ++i) {
    cout << ans[i] << " ";
  }
  puts("");
  return 0;
}


Measured memory_bytes: 2944
#include<iostream>
#include<string>
#define M 10000
using namespace std;

int dp[2][2][3][10][550]; //dp[digit][bound][dec or else or inc][prv num][mod]

int zig(string s,int m){
  int n = s.size(),up,mod,ub;

  for(int j=0;j<3;j++)
    for(int k=0;k<10;k++)
      for(int l=0;l<m;l++)
	dp[0][0][j][k][l] = dp[0][1][j][k][l] = 0;
  dp[0][1][1][0][0] = 1;

  for(int i=0;i<n;i++){
    int odd = i&1;
    for(int j=0;j<3;j++)
      for(int k=0;k<10;k++)
	for(int l=0;l<m;l++)
	  dp[1-odd][0][j][k][l] = dp[1-odd][1][j][k][l] = 0;

    for(int j=0;j<2;j++){
      if(j==1)up = s[i]-'0';
      else up = 9;
      for(int k=0;k<3;k++){
	for(int l=0;l<10;l++){
	  for(int x=0;x<=up;x++){
	    if(k==0 && x<=l)continue;
	    if(k==2 && l<=x)continue;
	    for(int y=0;y<m;y++){
	      mod = (y*10 + x) % m;
	      if(j==1 && x==up)ub = 1;
	      else ub = 0;

	      if(k==1 && l==0){
		dp[1-odd][ub][1][x][mod] += dp[odd][j][k][l][y];
		dp[1-odd][ub][1][x][mod] %= M;
	      }else if(x<l){
		dp[1-odd][ub][0][x][mod] += dp[odd][j][k][l][y];
		dp[1-odd][ub][0][x][mod] %= M;
	      }else if(x>l){
		dp[1-odd][ub][2][x][mod] += dp[odd][j][k][l][y];
		dp[1-odd][ub][2][x][mod] %= M;
	      }
	    }
	  }
	}
      }
    }
  }
 
  int ans = 0;
  for(int i=0;i<2;i++)
    for(int j=0;j<3;j++)
      for(int k=0;k<10;k++){
	ans += dp[n&1][i][j][k][0];
	ans %= M;
      }
  return ans;
}

string dec(string a){
  int n = a.size() - 1;
  while(a[n]=='0'){
    a[n--] = '9';
  }
  a[n]--;
  if(a[n] == '0')a = a.substr(1,n-1);
  return a;
}

int main(){
  string a,b;
  int m;
  cin >> a >> b >> m;
  cout << (zig(b,m) - zig(dec(a),m) + M) % M << endl;
}

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

int main() {
  int N; cin >> N;
  vector<vector<int>> G(N);
  vector<int> dist(N, -1), dist2(N, -1);
  rep(i, 0, N - 1) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  using P = pair<int, int>;
  queue<P> Q;
  Q.push({0, 0});
  while(!Q.empty()) {
    P v = Q.front(); Q.pop();
    int cur = v.first;
    int d = v.second;
    dist[cur] = d;
    for(auto p : G[cur]) if(dist[p] == -1) {
      Q.push({p, d + 1});
    }
  }
  Q.push({N - 1, 0});
  while(!Q.empty()) {
    P v = Q.front(); Q.pop();
    int cur = v.first;
    int d = v.second;
    dist2[cur] = d;
    for(auto p : G[cur]) if(dist2[p] == -1) {
      Q.push({p, d + 1});
    }
  }
  int cnt = 0, cnt2 = 0;
  rep(i, 0, N) {
    if(dist[i] <= dist2[i]) cnt++;
    else cnt2++;
  }
  cout << (cnt > cnt2 ? "Fennec" : "Snuke") << endl;
  return 0;
}


Measured memory_bytes: 6656
#include<bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define tp tuple<long long,int,int>
#define mtp make_tuple
using namespace std;

const int N=55;
const long long inf=1e18;
int n,m,s,c[N],d[N];
long long res[N],dist[N][N*N];
vector<tp>adj[N];

void dijkstra()
{
    int lim=50*n;
    for(int i=1;i<=n;i++)
    {
        res[i]=inf;
        for(int j=0;j<=lim;j++) dist[i][j]=inf;
    }
    dist[1][min(s,lim)]=0;
    priority_queue<tp,vector<tp>,greater<tp>>pq;
    pq.push(mtp(0,1,min(s,lim)));
    while(!pq.empty())
    {
        int u,coin;
        long long cost;
        tie(cost,u,coin)=pq.top();
        res[u]=min(res[u],cost);
        pq.pop();
        if(dist[u][coin]!=cost) continue;
        int ncoin=coin;
        while(ncoin<=lim)
        {
            long long t=1ll*d[u]*(ncoin-coin)/c[u];
            if(dist[u][ncoin]>cost+t)
            {
                dist[u][ncoin]=cost+t;
                pq.push(mtp(dist[u][ncoin],u,ncoin));
            }
            ncoin+=c[u];
        }
        for(auto&to:adj[u])
        {
            int v,w,need;
            tie(v,need,w)=to;
            int ncoin=coin;
            if(ncoin>=need&&dist[v][ncoin-need]>cost+w)
            {
                dist[v][ncoin-need]=cost+w;
                pq.push(mtp(dist[v][ncoin-need],v,ncoin-need));
            }
            ncoin+=c[u];
        }
    }
    for(int i=2;i<=n;i++) cout<<res[i]<<'\n';
}

main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin>>n>>m>>s;
    while(m--)
    {
        int u,v,a,b;
        cin>>u>>v>>a>>b;
        adj[u].push_back(mtp(v,a,b));
        adj[v].push_back(mtp(u,a,b));
    }
    for(int i=1;i<=n;i++) cin>>c[i]>>d[i];
    dijkstra();
}



Measured memory_bytes: 37268
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include "bits/stdc++.h"

using namespace std;

typedef unsigned long long ll;
typedef int                     integer;
#define int                     long long
#define ii                      pair<int,int>
#define vii                     vector<pair<int,int>>
#define vi                      vector<int>
#define vvi                     vector<vector<int>>
#define f(a,b,c)                for(int a=b;a<c;a++)
#define s(x)                    in>>x
#define s2(x,y)                 in>>x>>y
#define s3(x,y,z)               in>>x>>y>>z
#define s4(x,y,z,w)             in>>x>>y>>z>>w
#define p(x)                    out<<x<<endl
#define p2(x,y)                 out<<x<<" "<<y<<endl
#define pl(x)                   out<<x
#define p2l(x,y)                out<<x<<" "<<y
#define p1d(a,n)                for(int ix=0;ix<n;ix++) out<<a[ix]<<" "; out<<endl
#define p2d(a,n,m)              for(int ix=0;ix<n;ix++){ for(int jx=0;jx<m;jx++) out<<a[ix][jx]<<" "; out<<endl;}
#define range(v)                v.begin(),v.end()
#define w(x)                    while(x--)
#define rst(x)                  memset(x, -1, sizeof(x))
#define UNVISITED               -1
#define VISITED                 0
#define EXPLORED                2

class ARemainingBalls {
public:
	void solve(std::istream& in, std::ostream& out) {
        string s,t;
        s2(s,t);
        int a,b;
        s2(a,b);
        string u;
        s(u);
        if(u == s) a--;
        else b--;
        out<<a<<" "<<b<<endl;
	}
};


integer main() {
	ARemainingBalls solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
}


Measured memory_bytes: 256
#include <stdio.h>

int main() {
  char line[3];
  char* lp;
  int cnt = 0;
  
  scanf("%s", line);
  lp = line;
  for(int i = 0; i < 3; i++) {
    if(*(lp + i) == '1') {
		cnt++;
    }
  }
  printf("%d", cnt);

  return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <algorithm>
#include <string.h>
using namespace std;

const int MAX_N=100;
const int MAX_W=10000;
int dp[MAX_N+1][MAX_W+1];
int N,W;
int w[MAX_N];
int v[MAX_N];
void solve(){
	for(int i=0;i<N;i++){
		for(int j=0;j<=W;j++){
			if(j<w[i]){
				dp[i+1][j]=dp[i][j];
			}
			else{
				dp[i+1][j]=max(dp[i][j],dp[i+1][j-w[i]]+v[i]);
			}
		}
	}
}
int main(){
	scanf("%d%d",&N,&W);
	for(int i=0;i<N;i++){
		scanf("%d%d",&v[i],&w[i]);
		dp[0][i]=0;
	}

	solve();
	printf("%d\n",dp[N][W]);
	return 0;

}

Measured memory_bytes: 4932
#!/usr/bin/env python
# -*- coding:utf-8 -*-
#from __future__ import print_function
import time
import sys
import io
import re
import math
start = time.clock()
cnt=0
#sute=0
N=int(raw_input())
for j in range(N):
    x=int(raw_input())
    if x<2: pass
#    elif x==2 or x==3 or x==5 or x==7 or x==11: cnt+=1
    elif x==2: cnt+=1
    elif x%2==1:
        for i in xrange(3, int(x**0.5)+1, 2):
            if x%i==0:
                break
        else:
            cnt+=1
print cnt

Measured memory_bytes: 4956
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
int main (){
  int n,count;
  cin >> n;
  vector<int>a(30);
  for (int i=0;i<n;i++)
    cin >> a.at(i);
  for (int i=1;i<n-1;i++){
    if (a.at(i)>a.at(i-1) && a.at(i)<a.at(i+1))
      count++;
     if (a.at(i)<a.at(i-1) && a.at(i)>a.at(i+1))
      count++;
      
  }
  cout << count << endl;

}


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

int main() {
  lint A, B, C, K;
  cin >> A >> B >> C >> K;

  bool ans = false;
  lint base = 3;
  lint exp = K;
  for(lint poly = 0; poly < pow(base, exp); poly++) {
    lint d[3] = {A, B, C};
    lint tmp = poly;
    vector<lint> coef;
    for(lint i=0; i<exp; i++) {
      coef.push_back(tmp % base);
      tmp /= base;
    }

    for(lint i=0; i<exp; i++) {
      d[coef[i]] *= 2;
    }

    ans |= (d[0] < d[1] and d[1] < d[2]);
  }

  cout << (ans ? "Yes" : "No") << endl;
}

Measured memory_bytes: 4036
A, B, C = map(int, input().split())
mod_list = []
def_mod = A%B

for i in range(1,100):
    mod = (def_mod * i) % B
    if mod in mod_list:
        break
    else:
        mod_list.append(mod)
if C in mod_list:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3060
"use strict";
var input=require("fs").readFileSync("/dev/stdin","utf8");
var cin=input.split(/ |\n/),cid=0;
function next(){return +cin[cid++];}
function nextstr(){return cin[cid++];}
function nextbig(){return BigInt(cin[cid++]);}
function nexts(n,a){return a?cin.slice(cid,cid+=n):cin.slice(cid,cid+=n).map(a=>+a);}
function nextm(h,w,a){var r=[],i=0;if(a)for(;i<h;i++)r.push(cin.slice(cid,cid+=w));else for(;i<h;i++)r.push(cin.slice(cid,cid+=w).map(a=>+a));return r;}
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill().map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill().map(x=>"+r+")";return eval(r);}

var myOut = main();
if(myOut !== undefined)console.log(String(myOut));

function main(){
  var n = next();
  var ans = 1000;
  var mn = 200;
  var mx = 100;
  for(var i = 0; i < n; i++){
    var a = next();
    if(a < mx){
      ans = solve(ans, mn, mx);
      mn = mx = a;
    }else{
      if(a < mn)mn = mx = a;
      if(mx < a)mx = a;
    }
  }
  return solve(ans, mn, mx);
}
function solve(a,mn,mx){
  var c = Math.floor(a/mn);
  a -= c*mn;
  return a + c*mx;
}

Measured memory_bytes: 29508
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String o = sc.next();
    String e = sc.next();
    int olen = o.length();
    int elen = e.length();
    String ans = "";
    for(int i = 0; i < olen + elen; i++) {
      if(i % 2 == 0) ans += String.valueOf(o.charAt((i / 2)));
      if(i % 2 == 1) ans += String.valueOf(e.charAt((i / 2)));
    }
    System.out.println(ans);
  }
}

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

#define MP make_pair
#define PB push_back
#define ALL(x)      (x).begin(),(x).end()
#define REP(i,n)    for(int i=0;i<(n);i++)
#define REP1(i,n)   for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n)   for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;

const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;

const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};

int main(){
  int n,k;
  cin >> n >> k;
  cout << (n % k == 0 ? 0 : 1) << endl;
}

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

ll calc_diff(ll a,ll b,ll c){
    ll M = max(a,max(b,c));
    ll m = min(a,min(b,c));
    return M-m;
}

void calc(ll H,ll W,ll& diff){
    for(int i=0;i<=H;i++){
        ll S1,S2,S3;
        S1 = i*W;
        if((H-i)%2==0||W%2==0){ // 残りの面積をきれいに半分にできる場合
            S2 = (H*W - S1)/2;
            S3 = S2;
            diff = min(diff,calc_diff(S1,S2,S3));
        }else{ // きれいに等分できない場合
            if(H-i>W){ // 三の字に切りたい
                S2 = ((H-i)/2)*W;
                S3 = (H-i-(H-i)/2)*W; // 必ずS3はS2以上になる
                diff = min(diff,calc_diff(S1,S2,S3));
            }else{ // Tの字に切りたい
                S2 = W/2 * (H-i);
                S3 = (W-W/2) * (H-i);
                diff = min(diff,calc_diff(S1,S2,S3));
            }
        }
    }
}

int main(){
    ll H,W;
    cin >> H >> W;
    if(H%3==0||W%3==0){
        cout << 0 << endl;
        return 0;
    }
    ll diff = INF;
    calc(H,W,diff);
    calc(W,H,diff);
    cout << diff << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define nodes 400005
#define int long long int
void fast(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
main()
{
    int n;
    cin>>n;
    int ans=1e18;
    for(int i=1;i*i<=n;i++){
        if(n%i==0){
            ans=min(ans,i+n/i);
        }
    }
    cout<<ans-2<<endl;
 
}


Measured memory_bytes: 256
m=10**9+7
s=input()
d=[1]+[0]*12
for i in range(len(s)):
 if s[i]== "?":d=[sum(d[(j-k)*4%13]for k in range(10))%m for j in range(13)]
 else:d=[d[(j-int(s[i]))*4%13]%m for j in range(13)]
print(d[5])

Measured memory_bytes: 9244
#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <utility>
#include <numeric>
#include <set>
#include <map>

int main() {
  intmax_t N;
  scanf("%jd", &N);

  printf("%jd\n", N*(N-1)/2);
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;

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

	int n;
	cin>>n;

	if(n%2==0||n%5==0)
		cout<<-1;
	else
	{
		lli num=7;
		int count=1;
		for(int i=0;i<n;i++)
		{
			if(num%n==0)
			{
				cout<<count;
				return 0;
			} 

			num=(num*10+7)%n;
			count++;
		}

		cout<<-1;
	}
}

Measured memory_bytes: 3624
#include <stdio.h>
#include <stdint.h>

#define min(x, y) ((x) < (y) ? (x) : (y))
#define max(x, y) ((x) > (y) ? (x) : (y))

char s[301];
int64_t a[302];
int64_t dp[301][301];

int main() {
    scanf("%s", s);

    int64_t t = 0, n = 1;
    for (char* p = s; *p != 0; ++p) {
        if (*p == '0') {
            a[n++] = t;
        } else {
            ++t;
        }
    }
    a[n++] = t;

    int64_t k;
    scanf("%ld", &k);
    k = min(k, a[n - 1]);

    int64_t M = 998244353L;

    int64_t mk = 0;
    dp[0][0] = 1;
    for (int64_t i = 0; i < n - 1; ++i) {
        for (int64_t j = mk; j >= 0; --j) {
            auto r = min(k - j, a[i + 1] - a[i]);
            auto mc = a[n - 1]  - a[i + 1];
            for (int64_t b = 1; b <= mc + r; ++b) {
                for (int64_t c = max(0L, b - r); c < b && c <= mc; ++c) {
                    int64_t w = j + b - c;
                    dp[w][c] += dp[j][b];
                    if (dp[w][c] >= M) {
                        dp[w][c] -= M;
                    }
                }
            }

            for (int64_t c = 1; c <= a[n - 1] - a[i + 1]; ++c) {
                dp[j][c] += dp[j][c - 1];
                if (dp[j][c] >= M) {
                    dp[j][c] -= M;
                }
            }
        }
        mk = min(k, mk + a[i + 1] - a[i]);
    }

    int64_t ans = 0;
    for (int64_t i = 0; i <= mk; ++i) {
        ans += dp[i][0];
    }

    printf("%ld\n", ans % M);
}


Measured memory_bytes: 2400
#include <bits/stdc++.h>
#include <stdlib.h>
#include <time.h> 
 
using namespace std;
long long mod = 1e9 + 7;
long long INF = 1e7;
double EPS = 1e-12;
typedef long long int lld;
long double tick(){static clock_t oldt; clock_t newt=clock();
    long double diff=1.0L*(newt-oldt)/CLOCKS_PER_SEC; oldt = newt; return diff; }
#define rep(i,a,n) for(long long int i = (a); i <= (n); ++i)
#define repI(i,a,n) for(int i = (a); i <= (n); ++i)
#define repD(i,a,n) for(long long int i = (a); i >= (n); --i)
#define repDI(i,a,n) for(int i = (a); i >= (n); --i)
inline lld sc() { lld a; scanf("%lld", &a); return a; }
inline int scd() { int a; scanf("%d", &a); return a; }
inline double scf() { double a; scanf("%lf",&a); return a; }
#define prL(a) printf("%lld\n",a)
#define prS(a) printf("%lld ",a)
#define prdL(a) printf("%d\n",a)
#define prdS(a) printf("%d ",a)
#define all(c) (c).begin(), (c).end()
#define sz(a) ((int)a.size())
#define Error(x...) { cout << "(" << #x << ")" << " = ( "; printIt(x); }
template <typename T1> void printIt(T1 t1) { cout << t1 << " )" << endl; }
template <typename T1, typename... T2>
void printIt(T1 t1, T2... t2) { cout << t1 << " , "; printIt(t2...); }
#define errorpair(a) cout<<#a<<" = ( "<<((a).first)<<" , "<<((a).second)<<" )\n";
#define mset(a, v) memset(a, v, sizeof(a))
#define popcount __builtin_popcountll

typedef pair<lld,lld> PA;

lld powP(lld x, lld y) {
    lld ans = 1, po = x % mod;
    while(y > 0) {
        if(y & 1) ans = ans * po % mod;
        y >>= 1; po = po * po % mod;
    }
    return ans;
}
 
bool bitSet(lld n, lld bit){
    if((n & (1LL << bit)) != 0) return true;
    else return false;
}
 
lld findGcd(lld a, lld b){
    while(a != 0) { lld temp = b % a; b = a; a = temp; }
    return b;
}

#define lim 300010
#define lim2 200010
#define qqqqqq 210
// Ab :)
// inline lld sqr(lld x) { return x * x; }
// unordered_map<lld,lld>::iterator it;
// std::ios::sync_with_stdio(false);
// priority_queue<PA> Q;
// lld dp[1<<18];

vector<lld> G[lim];
// string S[lim];
lld A[lim], Lis[lim], Ans[lim];
lld lisLen = 0;

void findAns(lld x, lld par) {
    //find lis
    bool isLenIncreased = false;
    lld ind = lower_bound(Lis, Lis + lisLen, A[x]) - Lis;
    lld lastValue;
    if(ind == lisLen) {
        lisLen++;
        isLenIncreased = true;
    }
    else lastValue = Lis[ind];
    Lis[ind] = A[x];

    Ans[x] = lisLen;
    for(auto c : G[x]) {
        if(c != par) findAns(c, x);
    }

    //revert
    if(isLenIncreased) lisLen--;
    else Lis[ind] = lastValue;
}


int main(){
    lld n = sc();
    rep(i,1,n) A[i] = sc();
    rep(i,1,n-1) {
        lld a = sc(), b = sc();
        G[a].push_back(b);
        G[b].push_back(a);
    }
    findAns(1, -1);
    rep(i,1,n) prL(Ans[i]);
    return 0;
}


Measured memory_bytes: 34560
import math
from functools import reduce


def gcd(*numbers):
    return reduce(math.gcd, numbers)


k = int(input())
s = 0

# a = b = c -> gcd(a,a,a) -> a
for a in range(1, k+1):
    s += a

# a = b, a < c -> gcd(a, c)と同じ -> gcd(c, a)も同じ 6倍
for a in range(1, k+1):
    for b in range(a+1, k+1):
        s += gcd(a, a, b) * 6

# a < b < c -> gcd(a, b, c)と同じ -> 6通り

for a in range(1, k+1):
    for b in range(a+1, k+1):
        for c in range(b+1, k+1):
            s += gcd(a, b, c) * 6

print(s)


Measured memory_bytes: 9532
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define FOR(i, first, last) for (int i = (first); i < (last); ++i)
#define REP(i, n) FOR(i, 0, n)
#define CLR(a) memset((a), 0, sizeof(a))
#define DUMP(x) std::cerr << #x << " = " << (x) << std::endl;

inline int to_int(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T> inline string to_string(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

typedef unsigned long long ull;
typedef unsigned long ul;

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

  int n = s.length()-2;
  string ans = s.substr(0,1) + to_string(n) + s.substr(s.size()-1,1);
  cout<<ans<<endl;
 
  return 0;
}


Measured memory_bytes: 256
// O O O O O O O O O O O O O O O OO O OO O OO O O O TTCH O TTTCH O TTTCH O O O O
#pragma GCC optimize("Ofast")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx")
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
// #include <unordered_set>
// #include <unordered_map>
#include <stdio.h>
#include <cstdio>
#include <math.h>
#include <cmath>
#include <cstring>
#include <queue>
#include <deque>
#include <random>
#include <iomanip>
#include <bitset>
#include <cassert>

using namespace std;

#define int long long
#define y1 y1228
#define left left228
#define right right228
#define list list228
#define all(v) v.begin(), v.end()
#define tm tm228
#define free free228
#define app push_back



template<typename T> void uin(T &a, T b) {
    if (b < a) a = b;
}
template<typename T> void uax(T &a, T b) {
    if (b > a) a = b;
}
const int N = 2007;
int a[N][N];
int ver[N][N], edg1[N][N], edg2[N][N];

int getv(int x1, int y1, int x2, int y2) {
    return ver[x2][y2] - ver[x1 - 1][y2] - ver[x2][y1 - 1] + ver[x1 - 1][y1 - 1];
}
int gete1(int x1, int y1, int x2, int y2) {
    return edg1[x2][y2] - edg1[x1 - 1][y2] - edg1[x2][y1 - 1] + edg1[x1 - 1][y1 - 1];
}
int gete2(int x1, int y1, int x2, int y2) {
    return edg2[x2][y2] - edg2[x1 - 1][y2] - edg2[x2][y1 - 1] + edg2[x1 - 1][y1 - 1];
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, m, q;
    cin >> n >> m >> q;
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= m; ++j) {
            char c;
            cin >> c;
            a[i][j] = c - '0';
        }
    }
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= m; ++j) {
            if (a[i][j] && a[i + 1][j]) ++edg1[i][j];
            if (a[i][j] && a[i][j + 1]) ++edg2[i][j];
        }
    }
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= m; ++j) {
            ver[i][j] = a[i][j] + ver[i - 1][j] + ver[i][j - 1] - ver[i - 1][j - 1];
            edg1[i][j] = edg1[i][j] + edg1[i - 1][j] + edg1[i][j - 1] - edg1[i - 1][j - 1];
            edg2[i][j] = edg2[i][j] + edg2[i - 1][j] + edg2[i][j - 1] - edg2[i - 1][j - 1];
        }
    }
    while(q--) {
        int x1, y1, x2, y2;
        cin >> x1 >> y1 >> x2 >> y2;
        cout << getv(x1, y1, x2, y2) - gete1(x1, y1, x2 - 1, y2) - gete2(x1, y1, x2, y2 - 1) << '\n';
    }
    return 0;
}

// RU_023
 
/*
4 3
0
0
1

3 1000
0
0

*/









Measured memory_bytes: 127616
import math
import fractions
a,b,c,d = map(int, input().split())
e = a-1
gcd = fractions.gcd(c,d)
less_than_e = e - (e//c) - (e//d) + (e//(c*d//gcd))
less_than_b = b - (b//c) - (b//d) + (b//(c*d//gcd))
print(less_than_b - less_than_e)

Measured memory_bytes: 5048
#include <cstdio>
#include <algorithm>
using namespace std;
#define ll long long
int main(){
	ll n, k, s = 0;
	scanf("%lld %lld", &n, &k);
	ll a[n];
	for (ll i = 0; i < n; i++) scanf("%lld", &a[i]);
	sort(a, a + n);
	if (k >= n){
		printf("0\n");
		return 0;
	}
	for (ll i = 0; i < n - k; i++){
		s += a[i];
	}
	printf("%lld\n", s);
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

int main(void){
  ll n;
  cin >> n;

  ll ans = false;
  ll count = 0;
  REP(i, n){
    ll a, b;
    cin >> a >> b;
    if(a == b) count++;
    else count = 0;
    if(count == 3) ans = true;
  }
  if(ans) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

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

int main() {
	int n,maxi = 0;
	string name;
	map<string, int>poll;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> name;
		if (poll.count(name))poll.at(name)++;
		else poll[name] = 1;
	}
	for (pair<string, int>p : poll) {
		maxi = max(p.second, maxi);
	}
	for (pair<string, int>p : poll) {
		if (p.second == maxi)cout << p.first << endl;
	}

}


Measured memory_bytes: 25216
#include <algorithm>
#include <bitset>
#include <iomanip>
#include <ios>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>

using namespace std;

int main()
{
    int x;
    cin >> x;
    if (x < 1200) {
        cout << "ABC\n";
    } else {
        cout << "ARC\n";
    }
}

Measured memory_bytes: 256
n=gets.chomp.to_s
a=0
v=n.length
v=v.div(2)
b=n
while b.length>=2
    b=b.chop
    
for i in 0..b.length
      if b[0..i]==b[i+1..2*i+1] then
        if b[0..i].length>=a
            a=b[0..i].length*2
        end
      end
  
end
 end
p a

Measured memory_bytes: 1916
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main() {
  int n, i, j;
  ll ans = 0;
  cin >> n;
  vector<string> str(n);
  for(int i = 0; i < n; i++) {
    cin >> str.at(i);
    sort(str[i].begin(), str[i].end());
  }
  sort(str.begin(), str.end());
  for(i = 0; i < n;) {
    ll count = 0;
    for(j = i; j < n; j++) {
      if(str[i] != str[j]) break;
      count++;
    }
    ans += (count*(count-1))/2;
    i = j;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 7296
# ROT N

# libraries
from string import ascii_uppercase as ALP

# input
N = int(input())
S = input()

# solve
ALPALP = ALP + ALP

def f(s, N = N):
    return ALPALP[ALPALP.index(s) + N]

res = ''.join([f(s) for s in S])

# output
print(res)

Measured memory_bytes: 3772
#include<bits/stdc++.h>
using namespace std;
typedef long long int  ll;
const ll mod = 1e9+7;
#define rep(i,a,b) for(ll i=a;i<b;i++)

void swap(ll &a , ll &b){
    ll t = a;
    a = b;
    b = t;
}

ll min(ll a, ll b){
    if(a<b)return a;
    return b;
}

ll max(ll a, ll b){
    if(a>b)return a;
    return b;
}

 ll pow(ll a, ll b) {
    a %= mod;
    ll ans = 1;
    while (b > 0) {
        if (b & 1)
            ans = ans * a % mod;
        a = a * a % mod;
        b /= 2;
    }
    return ans;
}
const int MAX = 1e3+3;

ll a[MAX][MAX];
ll dp[MAX][MAX];

int main(){


   ios_base :: sync_with_stdio(0);
   cin.tie(0);
   ll h,w;
   cin>>h>>w;

   rep(i , 0 , h){
        rep(j ,  0 , w){
            char c;
            cin>>c;
            if(c == '.')a[i][j] = 1;
            else
                a[i][j] = 0;
        }
   }
   dp[0][0] = a[0][0];
   for(int i = 1 ; i < w;i++){
        dp[0][i] = (dp[0][i-1] == 0 || a[0][i] == 0)?0:dp[0][i-1];
   }
   for(int i = 1; i<h;i++){
    dp[i][0] = (dp[i-1][0] == 0 || a[i][0] == 0)?0:dp[i-1][0];
   }
   for(int i =1 ; i<h;i++){
    for(int j = 1;j<w;j++){
        if(a[i][j] == 0){dp[i][j] = 0;continue;}

        dp[i][j] = (a[i-1][j]== 0)?0:dp[i-1][j];
        dp[i][j] %= mod;
        dp[i][j] += (a[i][j-1]== 0)?0:dp[i][j-1];
        dp[i][j] %= mod;
    }
   }
   cout<<dp[h-1][w-1];


}


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

int main(void) {
  int N, K;
  cin >> N >> K;
  vector<int> h(N);
  for (int i = 0; i < N; i++) {
    cin >> h[i];
  }
  sort(h.begin(), h.end());
  int ans = INT_MAX;
  for (int i = 0; i + K - 1 < N; i++) {
    ans = min(ans, h[i + K - 1] - h[i]);
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define rep(i,N) for(ll i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

string a,b;

ll stringtoi(string s){
    ll res = 0;
    rep(i,s.size()){
        res *= 10;
        res += (s[i] - '0');
    }
    return res;
}

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

Measured memory_bytes: 256
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
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;
}
//setprecision(15)有効数字15桁
//-std=c++14
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll n, m;
vector<ll> a, b;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> m;
    for (int i = 0; i < n; i++)
    {
        ll temp;
        cin >> temp;
        a.push_back(temp);
    }
    for (int i = 0; i < m; i++)
    {
        ll temp;
        cin >> temp;
        b.push_back(temp);
    }
    a.push_back(0);
    b.push_back(0);
    sort(ALL(a), greater<ll>());
    sort(ALL(b), greater<ll>());
    ll ans = 1;
    ll x = 0;
    ll y = 0; //ぴったりの数を探しているところ
    //else埋められるのはxyの前の数まで
    //i==a[x]||i==b[y]を満たすときは初めて入るため必ずその行or列は空
    for (ll i = n * m; i >= 1; i--)
    {
        if (a[x] > i || b[y] > i)
            return cout << 0 << "\n", 0;
        if (i == a[x] && i == b[y])
        {
            x++;
            y++;
        }
        else if (i == a[x])
        {
            x++;
            ans *= y;
            ans %= MOD;
        }
        else if (i == b[y])
        {
            y++;
            ans *= x;
            ans %= MOD;
        }
        else
        {
            ans *= x * y - (m * n - i);
            if (ans < 0)
                return cout << 0 << "\n", 0;
            ans %= MOD;
        }
    }
    cout << ans << "\n";
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <vector>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iomanip>
#include <vector>
#include <cstdio>
#include <float.h>
#include <queue>
#include <set>
#include <map>
#include <fstream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <stack>
#include <functional>
 
using namespace std;
 
#define endl '\n'
#define MOD 1000000007
#define INF 1ll<<30
#define MAX 100010
#define eps 1e-11
#define bit_max 1ll<<32
#define _USE_MATH_DEFINES

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
  //  freopen("input.txt","r",stdin);
  //  freopen("output.txt","w",stdout);
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    sort(a,a+n);
    int mn = a[0];
    vector<int> factors;
    for (int i=1; i<=(int)(sqrt(mn)); i++) 
    { 
        if (mn%i == 0) 
        { 
            if (mn/i == i) 
                factors.push_back(i);
            else
            {
                factors.push_back(i);
                factors.push_back(mn/i);
            }
        } 
    } 
    int ans = 0;
    sort(factors.begin(),factors.end());
    for(int i=factors.size()-1;i>=0;i--)
    {
        // cout<<factors[i]<<endl;
        int ctr = 0;
        for(int j=0;j<n;j++)
        {
            if(a[j]%factors[i]==0)
            {
                ctr++;
            }
        }
        if(ctr>=n-1)
        {
            ans = max(ans,factors[i]);
        }
    }
    mn = a[1];
    vector<int> fac;
    for (int i=1; i<=(int)(sqrt(mn)); i++) 
    { 
        if (mn%i == 0) 
        { 
            if (mn/i == i) 
                fac.push_back(i);
            else
            {
                fac.push_back(i);
                fac.push_back(mn/i);
            }
        } 
    } 
    sort(fac.begin(),fac.end());
    for(int i=fac.size()-1;i>=0;i--)
    {
        // cout<<fac[i]<<endl;
        int ctrr = 0;
        for(int j=0;j<n;j++)
        {
            if(a[j]%fac[i]==0)
            {
                ctrr++;
            }
        }
        if(ctrr>=n-1)
        {
           ans = max(ans,fac[i]);
        }
    }
    cout<<max(1,ans);
    return 0;
}

Measured memory_bytes: 640
n = int(input())
s = str(input())

max = -1

for i in range(1,n):
	syu = []
	x = s[0:i]
	y = s[i:]
	
	for moji in x:
		if moji not in syu and moji in y:
			syu.append(moji)
	
	if max < len(syu):
		max = len(syu)
	
print(max)

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

typedef long long LL;

const int N=100005;

int n,q,f[N],s[N];
LL m;
struct data{int x,y,z;}a[N];

int find(int x)
{
	if (f[x]==x) return x;
	else return f[x]=find(f[x]);
}

int main()
{
	scanf("%d%lld%d",&n,&m,&q);
	for (int i=1;i<=n;i++) f[i]=i;
	int k=n,flag=0;
	for (int i=1;i<=q;i++)
	{
		scanf("%d%d%d",&a[i].x,&a[i].y,&a[i].z);
		a[i].x++;a[i].y++;
		if (!a[i].z)
		{
			int x=find(a[i].x),y=find(a[i].y);
			if (x!=y) f[x]=y,k--;
		}
		else flag=1;
	}
	for (int i=1;i<=q;i++)
		if (a[i].z==1&&find(a[i].x)==find(a[i].y)) {puts("No");return 0;}
	if (!flag&&m==n-1||m>=n&&m<=(LL)n-(LL)k+(LL)k*(k-1)/2) puts("Yes");
	else puts("No");
	return 0;
}

Measured memory_bytes: 1920
#include<stdio.h>
int main(){
  int a,b,c;
  scanf("%d",&a);
  scanf("%d",&b);
  scanf("%d",&c);
  if(a==5&&b==7&&c==5){
    printf("YES");
  }
  else if(a==5&&b==5&&c==7){
    printf("YES");
  }
  else if(a==7&&b==5&&c==5){
    printf("YES");
  }
  else{
    printf("NO");
  }
  return 0;
}


Measured memory_bytes: 128
#include <algorithm>
//#include <cstdio>
//#include <functional>
#include <iostream>
//#include <cfloat>
//#include <climits>
//#include <cstdlib>
//#include <cstring>
//#include <cmath>
#include <map>
//#include <queue>
//#include <set>
//#include <sstream>
//#include <stack>
//#include <string>
//#include <time.h>
#include <vector>
//#include <random>
//#include <unordered_set>
//#include <complex>
#define rt0 return 0
#define rep(i,n) for(int i=0;i<n;i++)
#define LL long long
using namespace std;
int main()
{
	int n;
	cin>>n;
	vector <int> a(n),b(n);
	map <int,int> mp;
	rep(i,n) 
	{
		cin>>a[i];
		b[i]=a[i];
	}	
	sort(a.begin(),a.end());
	rep(i,n)
	{
		if(i+1<=(n/2)) mp[a[i]]=a[n/2];
		else mp[a[i]]=a[n/2-1];
	}
	rep(i,n) cout<<mp[b[i]]<<endl;
    rt0;
}

Measured memory_bytes: 12928