akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
int main()
{
    int n,m,vis[200001];
    while(scanf("%d%d",&n,&m)!=EOF)
    {
        int u,v;
        bool flag=false;
        for(int i=1;i<=n;i++)
            vis[i]=false;
        for(int i=1;i<=m;i++)
        {
            scanf("%d%d",&u,&v);
            if(flag) continue;
            if(u==1)
            {
                if(vis[v])
                {
                    flag=true;
                }
                vis[v]=true;
            }else if(v==n)
            {
                if(vis[u])
                {
                    flag=true;
                }
                vis[u]=true;
            }
        }
        if(flag) printf("POSSIBLE\n");
        else printf("IMPOSSIBLE\n");
        break;
    }
    return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <vector>
#include <map>
#include <cstring>
#include <string>
#include <stack>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <sstream>
#include <set>
using namespace std;

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define repp(i,k,n) for(int i=k;i<(int)n;i++)
#define rei(n) for(int i=0;i<(int)n;i++)
#define rel(n) for(int l=0;l<(int)n;l++)
#define all(s) s.begin(),s.end()
#define INT_MAX 2147483647
#define debug(x) cout<<#x<<": "<<x<<endl;
#define PI 2*acos(0,0)
#define pb push_back
#define inin(x) int x; cin>>x;
#define ll long long
#define pb push_back

typedef pair<int, int> pii;
typedef pair<int, pii> pipii;

int main()
{
	int m;
	while (cin >> m&&m != 0)
	{
		vector<pii> a, b;
		map < pii, int> s;
		rep(i, m)
		{
			pii x;
			cin >> x.first >> x.second;
			a.push_back(x);
		}
		inin(n);
		rep(i, n)
		{
			pii x;
			cin >> x.first >> x.second;
			s[x] = 1;
			b.pb(x);
		}

		for (int i = 0; i < b.size(); i++)
		{
			int x, y;
			x = b[i].first - a[0].first;
			y = b[i].second - a[0].second;
			for (int k = 0; k < a.size(); k++)
			{
				pii now(x + a[k].first, y + a[k].second);
				if (s.find(now) == s.end())break;
				if (k == a.size() - 1)
				{
					cout << x << " " << y << endl;
				}

			}
		}
	}


}

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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const int MOD = 1000000007;

int main() {
  int L, R;
  cin >> L >> R;

  int ans = 10000000;
  for (int i = L; i <= min(R, L + 2019 * 3); i++) {
    for (int j = i + 1; j <= min(R, L + 2019 * 3); j++) {
      ans = min(ans, ((i % 2019) * (j % 2019)) % 2019);
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//F6編譯，右上三角形執行，ctrl+c強制停止執行  F5開啟exe
#define ll long long
#define maxn 200005
#define mod 998244353
using namespace std;

typedef pair<int, int> P;

int n;
int a[maxn];
bool ans[maxn];
vector<int> v;

int main()
{
    cin >> n;
    bool ok = 1;
    for (int i = 1; i <= n; i++)
        scanf("%d", &a[i]);

    for (int i = n; i >= 1; i--)
    {
        int cnt = 0;
        for (int j = 2; j * i <= n; j++)
            if (ans[i * j])
                cnt++;
        if (cnt % 2 == a[i] % 2)
            ans[i] = 0;
        else if (cnt % 2 == (a[i] + 1) % 2)
        {
            ans[i] = 1;
            v.push_back(i);
        }
        else
            ok = 0;
    }

    if (!ok)
    {
        printf("-1\n");
        return 0;
    }
    printf("%d\n", v.size());
    for (int i = 0; i < v.size(); i++)
        printf("%d ", v[i]);
    return 0;
}


Measured memory_bytes: 2552
n, y = map(int, input().split())
y /= 1000
def calc(a, b, c):
    li = [10, 5, 1]
    return a * li[0] + b * li[1] + c * li[2]
res1 = -1
res2 = -1
res3 = -1
for a in range(0,n+1):
    for b in range(0,n-a+1):
        c = n - a - b
        if y == calc(a, b, c):
            res1 = a
            res2 = b
            res3 = c
print(res1,res2,res3)

Measured memory_bytes: 3064
use proconio::{input, fastout};
use proconio::marker::Usize1;
#[fastout]
fn main() {
    input! {
        n: usize,
        m: usize,
        xy: [(Usize1, Usize1); m],
    }

    let mut prob = vec![false; n];
    prob[0] = true;

    let mut count = vec![1; n];

    for &(x, y) in xy.iter() {
        if prob[x] {
            prob[y] = true;
        }

        count[x] -= 1;
        if count[x] == 0 {
            prob[x] = false;
        }

        count[y] += 1;
    }

    let ans = prob.into_iter().filter(|&x| x).count();

    println!("{}", ans);
}

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

int min(int a, int b)
{
    if (a > b){
        return (b);
    }
    return (a);
}

int main(void)
{
    int map[50][50];
    char c;
    int dp[50][50];
    int x, y;
    int i, j;
    
    scanf("%d%d", &y, &x);
    
    getchar();
    for (i = 0; i < y; i++){
        for (j = 0; j < x; j++){
            scanf("%c", &c);
            map[i][j] = c - '0';
        }
        getchar();
    }
    
    memset(dp, 0, sizeof(dp));
    
    for (i = 0; i < y; i++){
        dp[i][0] = map[i][0] + (i - 1 >= 0 ? dp[i - 1][0] : 0);
    }
    for (i = 0; i < x; i++){
        dp[0][i] = map[0][i] + (i - 1 >= 0 ? dp[0][i - 1] : 0);
    }
    
    for (i = 1; i < y; i++){
        for (j = 1; j < x; j++){
            dp[i][j] = min(dp[i - 1][j] + map[i][j], dp[i][j - 1] + map[i][j]);
        }
    }
    
    printf("%d\n", dp[y - 1][x - 1]);
    return (0);
}

Measured memory_bytes: 0
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
	int N;
	cin>>N;

	int i;

	int odd=1;
	int num=1;
	int A;
	for (i=0;i<N;i++){
		cin>>A;
		if (A%2==0){
			odd*=2;
		}
		num*=3;
	}
	cout<<num-odd<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include "unistd.h"
using namespace std;
#define WA cout<<"char134217728";exit(0)
#define RE throw
#define TLE sleep(1000)
#define FOR(i,a,b) for(int i=(a),i##formax=(b);i<i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formax=(b);i>=i##formax;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)
#define show(x) cout<<#x<<" = "<<x<<endl;
#define all(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))
#define uniq(v) sort(all(v));v.erase(unique(all(v)), v.end());
#define bit(n) (1LL<<(n))
#define randInt(l,r) (uniform_int_distribution<ll>(l,r)(rnd))
#define randDouble(l,r) (uniform_real_distribution<double>(l,r)(rnd))
#define dout(d) printf("%.12f\n",d)

typedef long long ll;
typedef __int128_t lll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>ostream& operator<<(ostream& o,const pair<T,Y>& p){return o<<"("<<p.fi<<", "<<p.se<<")";}
template<typename A,size_t N,typename T>void Fill(A (&array)[N],const T&v){fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0;return gcd(a,b,x,y);}
ll modPow(lll a,lll n,ll m){if(!a)return a;lll p=1;for(;n>0;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
bool isPrime(ll n){if(n<2||n%2==0)return n==2;lll t=n-1,d=t/(t&-t);for(lll a:{2,325,9375,28178,450775,9780504,1795265022})if(a%n){for(t=d,a=modPow(a,t,n);t!=n-1&&a!=1&&a!=n-1;a=a*a%n,t=t*2%n);if(a!=n-1&&t%2==0)return 0;}return 1;}
const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7;
const double PI = acos(-1);
const double EPS = 1e-10;
static random_device rd;
static mt19937 rnd(rd());

const int N = 1e5;
int a, b;
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> a >> b;
  if(b%a){
    cout << b-a << endl;
  }else{
    cout << a+b << endl;
  }
}

Measured memory_bytes: 256
/*
          ,     \    /      ,
         / \    )\__/(     / \
        /   \  (_\  /_)   /   \
   ____/_____\__\@  @/___/_____\____
  |             |\../|              |
  |              \VV/               |
  |        ------hoi-------         |
  |_________________________________|
   |    /\ /      \\       \ /\    |
   |  /   V        ))       V   \  |
   |/     `       //        '     \|
   `              V                '
*/

#include <bits/stdc++.h>

#define ull unsigned long long
#define ll long long
#define pb push_back
#define f first
#define se second
#define mp make_pair
#define Speedforce boost();

using namespace std;

void boost(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

const int N = 1e6;
const int inf = 1e9 + 7;

int n, m, cnt[N];
bool can[N];

int main() {
    Speedforce
    cin >> n >> m;
    for(int i = 1;i <= n;i ++){
        cnt[i] = 1;
        can[i] = i == 1;
    }
    while(m--){
        int x, y;
        cin >> x >> y;
        can[y] |= can[x];
        cnt[x] --;
        cnt[y] ++;
        can[x] &= cnt[x] != 0;
    }
    int ans = 0;
    for(int i = 1;i <= n;i ++){
        ans += can[i];
    }
    cout << ans;
}

Measured memory_bytes: 768
#include<cstdio>
#include<cctype>
#include<cstring>
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define reg register
typedef long long ll;
const int maxe=1e6+10;
const int maxv=4005;
const int inf=0x3f3f3f3f;
struct edge{int t,nxt,c;}es[maxe<<2];
int h[maxv],cnt;
inline void ins(int s,int t,int c){es[cnt]=(edge){t,h[s],c};h[s]=cnt++;es[cnt]=(edge){s,h[t],0};h[t]=cnt++;}
int level[maxv],iter[maxv],q[maxv<<1],he,ta;
int S,T;
inline bool bfs(){
    memset(level,-1,sizeof(level));level[S]=he=ta=0;
    q[ta++]=S;
    while(he<ta){
        reg int v=q[he++];
        for(reg int i=h[v];i!=-1;i=es[i].nxt)
            if(es[i].c>0&&level[es[i].t]<0)
                level[es[i].t]=level[v]+1,q[ta++]=es[i].t;
    }
    return level[T]>=0;
}
inline int dfs(int v,int f){
    if(v==T)return f;
    reg int used=0;
    for(reg int& i=iter[v];i!=-1;i=es[i].nxt)
        if(es[i].c&&level[es[i].t]>level[v]){
            reg int w=dfs(es[i].t,min(f-used,es[i].c));
            if(w){
                es[i].c-=w;es[i^1].c+=w;used+=w;
                if(used==f)break;
            }
        }
    return used;
}
inline int Dinic(){
    reg int res=0;
    while(bfs()){
        memcpy(iter,h,sizeof(int)*(T+5));
        reg int f=0;
        while((f=dfs(S,inf))>0)res+=f;
    }
    return res;
}
int n,m;
char ch[105];
int main(){
	memset(h,-1,sizeof(h));scanf("%d%d",&n,&m);T=n+m+1;
	for(reg int i=1;i<=n;i++){
		scanf("%s",ch+1);
		for(reg int j=1;j<=m;j++)
			switch(ch[j]){
				case 'S':{ins(S,i,inf);ins(S,j+n,inf);break;}
				case 'T':{ins(i,T,inf);ins(j+n,T,inf);break;}
				case 'o':{ins(i,j+n,1);ins(j+n,i,1);break;}
				default:break;
			}
	}
	reg int ans=Dinic();
	if(ans>=inf)puts("-1");
	else printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;

class Main {
  public static void main(String... args) {
    Scanner sc = new Scanner(System.in);
    int size = sc.nextInt();
    int[] array = new int[size];
    for (int i = 0; i < size; i++) {
      array[i] = sc.nextInt();
    }

    int count = 0;
    for (int i = 0; i < size - 1; i++) {
      int min = i;
      for (int j = i; j < size; j++) {
        if (array[j] < array[min]) {
          min = j;
        }
      }
      if (min != i) {
        swap(array, min, i);
        count++;
      }
    }

    for (int i = 0; i < size - 1; i++) {
      System.out.print(array[i] + " ");
    }
    System.out.println(array[size - 1]);
    System.out.println(count);
  }

  public static void swap(int[] array, int min, int i) {
    int tmp = array[i];
    array[i] = array[min];
    array[min] = tmp;
  }
}



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

int main(){
	int k,n;
cin >> k >> n;
int a[n],b[n];
for(int i = 0;i<n;i++){
	cin >> a[i];
}
for(int i = 0;i<n;i++){
	b[i] = a[i+1] - a[i];
}
b[n-1] = k - a[n-1] + a[0];
int max = 0;
for(int i=0; i<n; i++){
if(max<b[i]){
max = b[i];
}

}

int ans = 0;
for(int i = 0;i<n;i++){
	ans += b[i];
}
ans = ans - max;
cout << ans << endl;

return 0;

}

Measured memory_bytes: 1920
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define PI 3.141592
#define LL_INF 9000000000000000000
#define LL_MINF -9000000000000000000
#define INT_INF 2000000000
#define INT_MINF -2000000000
#define all(a) (a).begin(), (a).end()
#define fi first
#define se second

int main(){
    char a;
    cin >> a;
    if('a' <= a and a <= 'z') puts("a");
    else puts("A");
}


Measured memory_bytes: 3588
#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 emplace_back
typedef long long ll;
typedef pair<int,int> pint;

template<typename T>
class ConvexHullTrick{
public:
    deque<pair<T,T> > dq;
    ConvexHullTrick(){};
    //min
    //x:monotonic
    T get(T x){
        while(dq.size()>=2){
            T l=dq[0].first*x+dq[0].second;
            T r=dq[1].first*x+dq[1].second;
            if(l<=r) break;
            dq.pop_front();
        }
        return dq[0].first*x+dq[0].second;
    }
    //x:other
    T getg(T x){
        int l=-1,r=dq.size()-1;
        while(r-l>1){
            int mid=(r+l)/2;
            T tl=dq[mid].first*x+dq[mid].second;
            T tr=dq[mid+1].first*x+dq[mid+1].second;
            if(tl<=tr) r=mid;
            else l=mid;
        }
        return dq[r].first*x+dq[r].second;
    }
    void add(pair<T,T> x){
        while(dq.size()>=2){
            pair<T,T> l=dq[dq.size()-1];
            pair<T,T> r=dq[dq.size()-2];
            if((x.second-l.second)*(r.first-l.first)>=(l.first-x.first)*(l.second-r.second)) break;
            dq.pop_back();
        }
        dq.pb(x);
    }
};
ll h[200001];
ll dp[200001];
int main(){
    ll n,c;
    cin>>n>>c;
    rep(i,n) cin>>h[i];
    ConvexHullTrick<ll> cht;
    dp[0]=0;
    cht.add({-h[0]*2,h[0]*h[0]});
    FOR(i,1,n){
        dp[i]=cht.getg(h[i])+h[i]*h[i]+c;
        cht.add({-h[i]*2,h[i]*h[i]+dp[i]});
    }
    cout<<dp[n-1]<<endl;
    return 0;
}


Measured memory_bytes: 6656
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[] A = new int[3];
        for (int i = 0; i < A.length; i++) {
            A[i] = sc.nextInt();
        }
        int[] abs = new int[3];
        int k = 0;
        for (int i = 0; i < A.length; i++) {
            for (int j = i + 1; j < A.length; j++) {
                abs[k] = Math.abs(A[j] - A[i]);
                k++;
            }
        }
        Arrays.sort(abs);
        System.out.println(abs[0] + abs[1]);
        sc.close();
    }
}

Measured memory_bytes: 23764
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    unsigned long long x = 0;
    int q;
    cin >> q;
    while(q--) {
        int t, i;
        cin >> t;
        switch(t) {
            case 0: cin >> i; cout << (x>>i&1ULL) << '\n'; break;
            case 1: cin >> i; x |= (1ULL<<i); break;
            case 2: cin >> i; x &= ~(1ULL<<i); break;
            case 3: cin >> i; x ^= (1ULL<<i); break;
            case 4: cout << (x == UINT64_MAX?1:0) << '\n'; break;
            case 5: cout << (x == 0ULL?0:1) << '\n'; break;
            case 6: cout << (x == 0ULL?1:0) << '\n'; break;
            case 7: cout << __builtin_popcountll(x) << '\n'; break;
            default: cout << x << '\n'; break;
        }
    }
}


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

using namespace std;

int main() {
	int h, w;
	cin >> h >> w;

	vector<string> image(h);
	for (int i = 0; i < h; i++) {
		cin >> image[i];
	}

	for (auto s: image) {
		cout << s << endl;
		cout << s << endl;
	}
	return 0;
}


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

#define FOR(a, b, c) for(int a = b; a <= c; ++a)
#define fi first
#define se second
#define pb push_back
#define int long long

typedef pair<int, int> ii;
typedef pair<int, ii> iii;

const int N = 2e5 + 10;
const int oo = 1e18;

int n, D, ans = 0;
int A[N], val[N], pr[N];
vector<iii> edge;

int nfind(int u)     { return (pr[u] == u) ? u : (pr[u] = nfind(pr[u])); }

void addeg(int u, int v)    {
    if(nfind(u) == nfind(v)) return;
    ans += D * abs(u - v) + A[u] + A[v];
    pr[nfind(u)] = nfind(v);
}

void solve(int lef, int rig)    {
    if(lef >= rig) return;

    int mid = (lef + rig) / 2;
    ii minl = {oo, 0}, minr = {oo, 0};
    FOR(i, lef, mid)    {
        val[i] = A[i] - i * D;
        minl = min(minl, {val[i], i});
    }
    FOR(i, mid + 1, rig) {
        val[i] = A[i] + i * D;
        minr = min(minr, {val[i], i});
    }
    FOR(i, lef, mid) edge.pb({val[i] + minr.fi, {i, minr.se}});
    FOR(i, mid + 1, rig) edge.pb({val[i] + minl.fi, {i, minl.se}});

    solve(lef, mid); solve(mid + 1, rig);
}
signed main()  {
//    freopen("test.inp", "r", stdin);
//    freopen("test.out", "w", stdout);
    ios_base::sync_with_stdio(false); cout.tie(0);

    cin >> n >> D;
    FOR(i, 1, n) pr[i] = i;
    FOR(i, 1, n) cin >> A[i];

    solve(1, n);

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

    for(auto i: edge)   addeg(i.se.fi, i.se.se);

    return cout << ans, 0;
}


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

def isOK(index,key):
    if S[index]>=key:
        return True
    else:
        return False


def binary_search(key):
    left=-1
    right=n

    while(right-left>1):
        mid = int(left+(right-left)/2)
        if isOK(mid,key):
            right = mid
        else:
            left = mid
    
    return right

ans=0
for x in T:
    index=binary_search(x)
    if x==S[index]:
        ans+=1
    

print(ans)


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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair 
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep1(i,n) for(ll i=1;i<=(n);i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
const ll MOD=1000000007;
const ll INF=1000000000000000;

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

int main(){
	//input
	ll N,K; cin>>N>>K;
	vector<ll> A;
    string s; cin>>s;

	//solve
	ll ans=0;
    ll l=0;
    char tmp=s[0];
    rep(i,sz(s)){
        if(tmp==s[i]) l++;
        else{
            A.pb(l);
            l=1;
            tmp=s[i];
        }
    }
    A.pb(l);

    rep(i,sz(A)){
        ans+=max(0ll,A[i]-1);
    }

    ll sub=1,SIZE=sz(A);
    while(sub<=K){
        if(SIZE==2){
            ans++;
            break;
        }
        else{
            if(SIZE>=3){
                SIZE-=2;
                ans+=2;
            }
            if(SIZE==1) break;
        }
        sub++;
    }

	//output
	cout<<ans;
}

Measured memory_bytes: 1528
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
#define P pair<int,int>
const int MOD=1e9+7;
const int INF=2e9;
 
 
int main() {
    ios_base::sync_with_stdio(false);
 
    string s;
    cin >> s;
    vector<int> alp(26);
    invrep(i,s.size()) ++alp[s[i]-'a'];
    bool flag=1;
    rep(i,26) {
        if (alp[i]%2==1) flag=0;
    }
    if (flag) cout << "Yes" << endl;
    else cout << "No" << endl;
 
    return 0;   
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Console;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(Get());
        }

        static int Get()
        {
            var sp = ReadLine().Split(' ');
            int a = int.Parse(sp[0]);
            int b = int.Parse(sp[1]);
            int c = int.Parse(sp[2]);
            int x = int.Parse(sp[3]);
            int y = int.Parse(sp[4]);
            if (a + b <= c * 2) return a * x + b * y;
            if (x == y) return c * x * 2;
            if (x < y)
            {
                if (c * 2 <= b) return c * y * 2;
                return c * x * 2 + b * (y - x);
            }
            if (c * 2 <= a) return c * x * 2;
            return c * y * 2 + a * (x - y);
        }
    }
}


Measured memory_bytes: 11092
#include<stdio.h>

#define MAX 36

struct Node{
  int value;
  char mark;
};

void BubbleSort(struct Node *C, int n){
  int i, j;
  struct Node buf;
  
  for(i = 0; i < n; i++){
    for(j = n - 1; j > i; j--){
      if(C[j].value < C[j - 1].value){
	buf = C[j];
	C[j] = C[j - 1];
	C[j - 1] = buf;
      }
    }
  }
}

void SelectionSort(struct Node *C, int n){
  int i,j,minj;
  struct Node buf;
  
  for(i = 0; i < n; i++){
    minj = i;
    for(j = i; j < n; j++){
      if(C[j].value < C[minj].value){
	minj = j;
      }
    }
    buf = C[i];
    C[i] = C[minj];
    C[minj] = buf;
  }

}

int main(){
  int i,j,n,f;
  struct Node c[MAX],d[MAX];
  int count[MAX] = {};
  char ex[MAX][4] = {};

  scanf("%d",&n);
  for(i = 0; i < n; i++){
    scanf("%c",&c[i].mark);
    if(c[i].mark == '\n' || c[i].mark == ' '){
      --i;
      continue;
    }  
    scanf("%d",&c[i].value);

    // ex[7][] = {'S','C'} 
    // count[] でその数が複数あったか確認させる
    ex[c[i].value][count[c[i].value]++] = c[i].mark;

    d[i].mark = c[i].mark;
    d[i].value = c[i].value;
  }

  BubbleSort(c,n);
  SelectionSort(d,n);

  for(i = 0; i < (n - 1); i++){
    printf("%c%d ",c[i].mark,c[i].value);
  }
  printf("%c%d\n",c[i].mark,c[i].value);
  
  f = 0;

  if(f == 0)
    printf("Stable\n");
  else
    printf("Not stable\n");
  
  for(i = 0; i < (n - 1); i++)
    printf("%c%d ",d[i].mark,d[i].value);
  printf("%c%d\n",d[i].mark,d[i].value);
  
  f = 0;
  for(i = 0; i < n; i++){
    if(count[d[i].value] > 1){
      // input: H2 H1 S2
      // H1 ここから->H2 S2
      for(j = 0; j < count[d[i].value]; j++){
	if(d[j + i].mark != ex[d[i].value][j]){
	  f = 1;
	  break;
	}
      }
      i += count[d[i].value];
    }
  }
  if(f == 0)
    printf("Stable\n");
  else
    printf("Not stable\n");
  

  return 0;
}



Measured memory_bytes: 2108
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
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;
}

using ll = long long;
using ull = unsigned long long;
const int INF = 2100100100;
const int MOD = 1e9 + 7;

ll N, M, K, Q;
string S;

int main() {
    long double a, b, c;
    cin >> a >> b >> c;

    if (sqrt(a) + sqrt(b) + 1.0e-14 < sqrt(c)) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <cmath>
using namespace std;
int F[1001];
int P[10010];

void init(int N) {
	for (int i=0; i<N; ++i) { P[i] = i; }
}

int root(int a) {
	if (P[a] == a) return a;
	return (P[a] = root(P[a]));
}

bool is_same_set(int a, int b) {
	return root(a) == root(b);
}

void unite(int a, int b) {
	P[root(a)] = root(b);
}

int main() {
	int V,D;
	int count;
	
	F[0] = 1, F[1] = 2;
	for (int i=0; i<1001; i++) {
		F[i+2] = (F[i] + F[i+1]) % 1001;
	}
	
	while(cin >> V >> D) {
		count = 0;
		init(V+1); //自分を設定
		for(int i=1; i<=V; ++i) {
			for(int j=i+1; j<=V; ++j) {
				if (abs(F[j] - F[i]) < D) {
					unite(i,j);
				}
			}
		}
		for(int i=1; i<=V; ++i) {
			if (root(i) == i) {
				count++;
			}
		}
		cout << count << endl;
	}
	return 0;
}

Measured memory_bytes: 1176
h, w = map(int, input().split())
s = [input() for _ in range(h)]
ans_field = []

direct_x = [1, 1, 0, -1, -1, -1, 0, 1]
direct_y = [0, 1, 1, 1, 0, -1, -1, -1]

for i in range(h):
    ans = ""
    for j in range(w):
        if s[i][j] == '.':
            count = 0
            for k in range(8):
                if 0 <= i+direct_y[k] < h and 0 <= j+direct_x[k] < w:
                    if s[i+direct_y[k]][j+direct_x[k]] == '#':
                        count += 1
            ans += str(count)
        else:
            ans += "#"
    ans_field.append(ans)

for i in range(h):
    print(ans_field[i])

Measured memory_bytes: 3064
# AOJ ITP2_6_A: Binary Search
# Python3 2018.6.24 bal4u

from bisect import bisect_left
n = int(input())
a = list(map(int, input().split()))
a.append(1000000001)  # > 1,000,000,000
q = int(input())
for i in range(q):
	k = int(input())
	p = bisect_left(a, k)
	print(1 if a[p] == k else 0)


Measured memory_bytes: 17220
import math
a, b = map(int, input().split())
minA = a*12.5
maxA = (a+1)*12.5
minB = b*10
maxB = (b+1)*10
if maxA <= minB or maxB <= minA:
    print(-1)
else:
    print(int(math.ceil(max(minA, minB))))

Measured memory_bytes: 3064
#include <iostream>
#include <queue>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <iomanip>

using namespace std;

#define REP(i,n) for(ll (i) = (0); (i) < (n); ++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define ALL(v) v.begin(),v.end()
#define INF 1100000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007
#define Decimal fixed << setpresicion(20)


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

int H, W;
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, -1, 0, 1};
int mp[500][500];
ll white[500][500];
pair<int, int> par[500][500];
int rnk[500][500];

int init(int h, int w) {
  REP(i, h) {
    REP(j, w) {
      par[i][j] = MP(i, j);
      white[i][j] = mp[i][j];
    }
  }
}

pair<int, int> find(pair<int, int> p)
{
  if (par[p.FI][p.SE] == p)
    return par[p.FI][p.SE];
  else
    return par[p.FI][p.SE] = find(par[p.FI][p.SE]);
}

void unite(pair<int, int> a, pair<int, int> b)
{
  a = find(a);
  b = find(b);
  if (a == b) return;
  if (rnk[a.FI][a.SE] > rnk[b.FI][b.SE]) {
    par[b.FI][b.SE] = a;
    white[a.FI][a.SE] += white[b.FI][b.SE];
  } else {
    par[a.FI][a.SE] = b;
    white[b.FI][b.SE] += white[a.FI][a.SE];
  }
  if (rnk[a.FI][a.SE] == rnk[b.FI][b.SE]) rnk[b.FI][b.SE]++;
}

int main()
{
  cin >> H >> W;
  vector<pair<int, int>> vb;
  REP(i, H) {
    REP(j, W) {
      char c; cin >> c;
      if (c == '#') {
        vb.PB(MP(i, j));
        mp[i][j] = 0;
      } else {
        mp[i][j] = 1;
      }
    }
  }
  init(H, W);
  REP(y, H) {
    REP(x, W) {
      REP(k, 4) {
        int ny = y + dy[k];
        int nx = x + dx[k];
        if (ny < 0 || H <= ny || nx < 0 || W <= nx) continue;
        if (mp[ny][nx] ^ mp[y][x] == 0) continue;
        unite(MP(y, x), MP(ny, nx));
      }
    }
  }

  ll ans = 0;
  for (auto pos : vb) {
    pair<int, int> tmp = find(pos);
    ans += white[tmp.FI][tmp.SE];
  }
  cout << ans << endl;

  return 0;
}

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

int main() {
	int n, m;
	cin >> n >> m;
	vector<pair<long long, long long>> v(n);
	for (int i = 0; i < n; i++) {
		cin >> v[i].first >> v[i].second;
	}
	sort(v.begin(), v.end());
	multiset<long long, greater<long long>> ms;
	int j = 0;
	long long ans = 0;
	for (int i = 1; i <= m; i++) {
		for (; j < n && v[j].first == i; j++) {
			ms.insert(v[j].second);
		}
		if (ms.size()) {
			ans += *ms.begin();
			ms.erase(ms.begin());
		}
	}
	cout << ans;

}



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

int main(){
    long long h , w;
    cin >> h >> w;
    long long ans;
    if (h % 2 == 1 && w % 2 == 1){
        ans = (h * w + 1) / 2;
    }
    else{
        ans = h * w / 2;
    }
    if (h == 1 || w == 1){
        ans = 1;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <numeric>
#include <algorithm>
#include <string>
#include <complex>
 
#include <cassert>
#include <cstdlib>
#include <cmath>
#include <cstdio>
#include <cstring>
 
#define REP(i,e) for(int i=0;i<(int)(e);i++)
#define FOR(i,b,e) for(int i=(int)(b);i<(int)(e);i++)
#define ALL(c) (c).begin(), (c).end()
#define EACH(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define RALL(c) (c).rbegin(), (c).rend()
#define ALLA(a,n) ((a)+0), ((a)+n)
 
using namespace std;
 
typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef vector<string> vstring;
typedef vector<double> vdouble;
 
template<class T>void pp(T v,int n){ REP(i,n)cout<<v[i]<< ' ' ; cout << endl; }
template<class T>void pp(T v){ EACH(it,v) cout << *it << ' ' ; cout << endl;  }
template<class T>T& ls(T& a,T b){ if(b<a) a=b; return a; }
template<class T>T& gs(T& a,T b){ if(b>a) a=b; return a; }
inline ll to_i(const string& s){ll n;sscanf(s.c_str(),"%lld",&n);return n;}
inline string to_s(ll n){char buf[32];sprintf(buf,"%lld",n);return string(buf);}

int main() {
  int n;
  while (cin >> n) {
    cout << (n - 2) * 180 << endl;
  }
}


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

ll C[2010][2010];
void init()
{
  for(int i=0;i<=2005;i++)
    {
      C[i][0]=C[i][i]=(ll)1;
      for(int j=1;j<i;j++) C[i][j]=(C[i-1][j-1]+C[i-1][j])%1000000007;
    }
}

int main() {
  init();
  int n,k;
  cin>>n>>k;
  for (int i=1; i<=k; i++) {
    if (n-k+1<i) cout<<0<<endl;
    else cout<<(C[k-1][i-1]*C[n-k+1][i])%1000000007<<endl;
  }
  
  return 0;
}

Measured memory_bytes: 30336
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define Would
#define you
#define please

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

	int N, M;
	string S[100], T[100];
	cin >> N;
	rep(i, N) cin >> S[i];
	cin >> M;
	rep(i, M) cin >> T[i];

	int saidai = 0;
	rep(i, N) {
		string S0 = S[i];
		int kari = 0;
		rep(i, N) {
			if (S[i] == S0) kari++;
		}

		rep(i, M) {
			if (T[i] == S0) kari--;
		}
		saidai = max(saidai, kari);
	}
	co(saidai);

	Would you please return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,M;cin>>N>>M;
  vector<int> c(N,0);
  for(int i=0; i<M; i++){
    int a,b;cin>>a>>b;
    c[a-1]++;c[b-1]++;
  }
  for(int i=0; i<N; i++){
    cout<<c[i]<<endl;
  }
}

Measured memory_bytes: 256
import java.awt.geom.*;
import java.io.*;
import java.util.*;

public class Main{
	
	class C implements Comparable<C>{
		int name;
		int score;

		public C(int name, int score) {
			this.name = name;
			this.score = score;
		}

		@Override
		public int compareTo(C o) {
			if(this.score - o.score != 0) return o.score - this.score;
			return this.name - o.name;
		}
	}
	
	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(true){
			int n = sc.nextInt();
			if(n == 0) break;
			sc.nextLine();
			C [] data = new C[n];
			for(int i = 0; i < n; i++){
				String [] input = sc.nextLine().split(" ");
				int score = calc(input);
				data[i] = new C(Integer.parseInt(input[0]), score);
			}
			Arrays.sort(data);
			for(C now: data){
				System.out.println(now.name + " " + now.score);
			}
		}
	}

	private int calc(String[] input) {
		int [] data = new int[input.length-1];
		for(int i = 0; i < input.length-1; i++){
			data[i] = Integer.parseInt(input[i+1]);
		}
		int sum = 0;
		int ind = 0;
		for(int i = 1; i <= 10; i++){
			if(i == 10){
				int a = data[ind];
				if(a == 10){
					int b = data[ind+1];
					int c = data[ind+2];
					sum += a + b + c;
				}
				else{
					int b = data[ind + 1];
					int c = 0;
					if(a + b == 10){
						c = data[ind + 2];
					}
					sum += a + b + c;
				}
			}
			else{
				int a = data[ind];
				if(a == 10){
					sum += data[ind+1] + data[ind + 2] + 10;
					ind++;
				}
				else{
					int b = data[ind + 1];
					if(a + b == 10){
						sum += 10 + data[ind + 2];
					}
					else{
						sum += a + b;
					}
					ind += 2;
				}
			}
		}
		return sum;
	}

	private void debug(Object... o) { System.out.println("debug = " + Arrays.deepToString(o)); }

	public static void main(String[] args) {
		new Main().doit();
	}
}

Measured memory_bytes: 21528
#include <iostream>
#include <vector>
#include <cstring>
#include <algorithm> // sort

#define REP(i, n) for (long long i = 0; i < (n); i++) 
typedef long long ll;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;
using namespace std;

int main(){
    int W,a,b;
    cin >> W >> a >> b;

    //(a < b) b - (a + W)  (a > b)a - (b + W)
    int res, higher,lower;
    //ternary operator
    higher = (a>b? a:b);
    lower = (a<b? a:b);

    res = higher - (lower + W);
    
    if(res < 0) res = 0;
    
    cout << res << endl;
    return 0;    

}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<cmath>
#include<iomanip>
#include<map>
#include<cstring>

using namespace std;

typedef long long int ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define vi vector<int>
#define vivi vector<vi>
const int INF = 1e9;
const ll LLINF = 1LL<<60;
/* -- template -- */

const int MAX_N = 101;
const int MAX_V = 100001;
ll weight[MAX_N];
int value[MAX_N];

ll dp[MAX_N][MAX_V]; //dp[i][value] : iまでのものを使って，valueを達成する最低のweight
int main(){
    int N, W; cin >> N >> W;
    rep(i, N)cin >> weight[i] >> value[i];
    for(int i = 0;i < MAX_N;++i){
        for(int v = 0;v < MAX_V;++v){
            dp[i][v] = LLINF;
        }
    }
    dp[0][0] = 0;
    for(int i = 0;i < N;++i){
        for(int v = 0;v < MAX_V;++v){
            if(value[i] >= v){
                dp[i + 1][v] = min(dp[i][v], weight[i]);
            }else if(value[i] < v){
                dp[i + 1][v] = min(dp[i][v], dp[i][v - value[i]] + weight[i]);
            }
            dp[i + 1][v] = min(dp[i + 1][v], dp[i][v]);
        }
    }
    for(int v = 0;v < MAX_V;++v){
        if(dp[N][v] > W){
            cout << (v - 1) << endl;return 0;
        }
    }
    cout << MAX_V - 1;
}


Measured memory_bytes: 79104
import sys
input = lambda: sys.stdin.readline().rstrip()
input_nums = lambda: list(map(int, input().split()))
sys.setrecursionlimit(10**6)

N, M = input_nums()

G = {}
for i in range(N):
    G[i] = []

for i in range(M):
    x, y = input_nums()
    x -= 1
    y -= 1
    G[x].append(y)

dp = [-1 for _ in range(N+1)]

def rec(v: int):
    if dp[v] != -1:
        return dp[v]
    res = 0
    for nv in G[v]:
        res = max(res, rec(nv) + 1)
    dp[v] = res
    return res

res = 0
for v in range(N):
    res = max(res, rec(v))
print(res)

Measured memory_bytes: 73784
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main()
{
     string s[200005];
     long long n,i,t=1;
     cin>>n;
     for(i=1;i<=n;i++)
     {
         cin>>s[i];
     }
     sort(s+1,s+1+n);
     for(i=1;i<n;i++)
     {
         if(s[i]!=s[i+1])
         {
             t++;
         }
     }
     cout<<t<<endl;
     return 0;
}

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

using namespace std;

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& (a) : (x))
#define all(x) (x).begin (), (x).end ()
#define sz(x) (int) (x).size ()
#define FASTIO cin.sync_with_stdio (0); cin.tie (0); cin.exceptions (cin.failbit);

typedef long long ll;

typedef pair<int, int> pii;
#define fi first
#define se second
#define mkp(x) make_pair ((x))

typedef vector<int> vi;
#define pb(x) push_back ((x))

#define DEBUG 1
#define ddcout if (DEBUG) cout
#define ddprintf(fmt, ...) if (DEBUG) printf (fmt, ##__VA_ARGS__)

int main ()
{
    int i, j;
    scanf ("%d", &i);
    printf ("%d\n", i*i);
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()

#include <algorithm>
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	string s;
	int k;
	vector<string> a;
	cin >> s >> k;
	for(int i = 0; i < s.size(); i++) {
		for(int j = 1; j <= k; j++){
			string tmp = s.substr(i,j);
			a.pb(tmp);
		}
	}
	sort(ALL(a));
	a.erase(unique(ALL(a)),a.end());
	cout << a[k - 1] << endl;
	return 0;
}

Measured memory_bytes: 1660
import sys
from typing import List

class UnionFind:
    """
    自身が親であれば、その集合に属する頂点数に-1をかけた物
    そうでなければ、親のid
    """
    def __init__(self, r: int):
        self.r : List[int] = [-1] * r

    def root(self, x: int):
        if self.r[x] < 0: return x
        self.r[x] = self.root(self.r[x])
        return self.r[x]

    def unite(self, x: int, y: int)->bool:
        x = self.root(x)
        y = self.root(y)
        if x == y:
            return False
        if self.r[x] > self.r[y]:
            x, y = y, x
        self.r[x] += self.r[y]
        self.r[y] = x
        return True

    def size(self, x: int)->int:
        return -self.r[self.root(x)]

def main():
    def input(): return sys.stdin.readline()[:-1]
    n, m = map(int, input().split())
    
    # 友達集合を作る
    uf = UnionFind(n)
    for i in range(m):
        a, b = map(int, input().split())
        a -= 1; b -= 1
        uf.unite(a, b)

    # 最大の友達集合をもとめる
    ans = 0
    for i in range(n):
        ans = max(ans, uf.size(i))

    print(ans)

if __name__ == "__main__":
    main()

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

#define ll = long long;

using vi = vector<int>;
#define pb push_back
#define rsz resize
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()

using pi = pair<int,int>;
#define f first
#define s second
#define mp make_pair


int main() {
     int n,x,t;
     cin>>n>>x>>t;
     int nt;
     if(n%x==0){
         nt=n/x;
     }else{
         nt=n/x+1;
     }
     long long int total=nt*t;
     cout<<total<<endl;
}


Measured memory_bytes: 3620
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<cstdio>
#include<vector>
#include<iostream>
#include<string>
#include<algorithm> 
using namespace std;
int h,w,ch[4]={-1,0,1,0},cw[4]={0,1,0,-1};
char c[55][55];
bool dfs(int i,int j){
	c[i][j]='@';
	int res=0;
	for(int k=0;k<4;k++){
		if(c[i+ch[k]][j+cw[k]]=='#'){
			res=1;
			int is=0;
			is=dfs(i+ch[k],j+cw[k]);
			if(is){
				c[i+ch[k]][j+cw[k]]='$';
			}
		}
	}
	if(res){
		c[i][j]='$';
	}
	return res==1;
}
int main(){
	cin>>h>>w;
	for(int hh=1;hh<=h;hh++){
		for(int ww=1;ww<=w;ww++){
			cin>>c[hh][ww];
		}
	}
	for(int hh=1;hh<=h;hh++){
		for(int ww=1;ww<=w;ww++){
			if(c[hh][ww]=='#'){
				int i=dfs(hh,ww);
				if(i)
					c[hh][ww]='$';
			}
		}
	}
	bool can=1;
	for(int hh=1;hh<=h;hh++){
		for(int ww=1;ww<=w;ww++){
			if(c[hh][ww]=='@'){
				int q=0;
				for(int k=0;k<4;k++){
					if(c[hh+ch[k]][ww+cw[k]]=='$'){
						
						q=1;
						break;
					}
				}
				if(!q){
					c[hh][ww]='#';
				}
			}
			if(c[hh][ww]=='#'){
				can=0;
				break;
			}
		}
	}
	if(!can){
		cout<<"No";
	}else{
		cout<<"Yes";
	}
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
using namespace std;
int main() {
    long long k, a, b; cin >> k >> a >> b;
    if (b - a <= 2) { cout << 1 + k << endl; return 0; }
    long long ans = a;
    k -= a - 1;
    ans += (b - a) * (k / 2);
    if (k % 2) ans++;
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define repr_inv(i,a,b) for(int i=(int)(a);i>=(int)(b);i--)
#define rep(i,n) repr(i,0,n)
#define INF 2000000000
#define INFLL 9000000000000000000
using namespace std;
int main(void)
{
	string s, t;

	char temp;

	cin>>s>>t;

	sort(s.begin(), s.end());
	sort(t.begin(), t.end());
	rep(i, t.size()/2){
		temp=t[i];
		t[i]=t[t.size()-i-1];
		t[t.size()-i-1]=temp;
	}
	if(s<t){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
}



Measured memory_bytes: 256
import sys
sys.setrecursionlimit(1 << 25)
readline = sys.stdin.buffer.readline
read = sys.stdin.readline  # 文字列読み込む時はこっち

import numpy as np
from functools import partial
array = partial(np.array, dtype=np.int64)
zeros = partial(np.zeros, dtype=np.int64)
full = partial(np.full, dtype=np.int64)

ra = range
enu = enumerate


def a_int(): return int(read())


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import


K = np.array(list(map(int, list(input()))))
D = a_int()

'''
ある数xにおいて総和がDの倍数であるかの判定
x[0]+x[1]...+x[n] ≡ 0 (mod D) 各桁の和にMODを取れば良い。つまり桁ごとに処理できる

dp[i,j,k] ... K[:i]以下の整数のうち、k=mod Dとなるような数字の個数。j==1は上位桁が一致している場合の通りの個数。j==0は上位桁が一致しなくなったときの個数。

遷移
for l in range(10):
    dp[i+1,0,(k+l)%D] += dp[i,0,k] #1~9を考慮可能
for l in range(K[i]):
    dp[i+1,0,(k+l)%D] += dp[i,1,k] #1~K[i]-1をつけるとぴったりにならないグループへ行く

dp[i+1,1,(k+K[i])%D] += dp[i,1,k]
'''
# print(K, D)

from numba import njit


@njit('(i8[:],i8)', cache=True)
def solve(K, D):
    N = K.shape[0]
    dp = np.zeros((N + 1, 2, D), dtype=np.int64)
    dp[0, 1, 0] = 1
    for i in range(N):  # 各桁について
        for k in range(D):  # 各あまりについて処理
            # for l in range(K[i]):
            #     # 1~K[i]-1をつけるとぴったりにならないグループへ行く
            #     dp[i + 1, 0, (k + l) % D] += dp[i, 1, k]
            # for l in range(10):  # 各数字について処理
            #     dp[i + 1, 0, (k + l) % D] += dp[i, 0, k]  # 1~9を考慮可能
            #     dp[i + 1, 0, (k + l) % D] %= MOD
            for l in range(10):
                m = (k + l) % D
                if l < K[i]:
                    dp[i + 1, 0, m] += dp[i, 0, k] + dp[i, 1, k]
                else:
                    dp[i + 1, 0, m] += dp[i, 0, k]  # 1~9を考慮可能
                dp[i + 1, 0, m] %= MOD

            # ぴったりグループ
            dp[i + 1, 1, (k + K[i]) % D] += dp[i, 1, k]
            # dp[i + 1, 1, (k + K[i]) % D] %= MOD

    print((dp[-1, :, 0].sum() - 1) % MOD)  # -1は0の分


solve(K, D)


Measured memory_bytes: 131312
import sys

n, m, *ab = map(int, sys.stdin.read().split())
ab = sorted(zip(*[iter(ab)] * 2))

def main():
    r = -1
    cnt = 0
    for a, b in ab:
        if a < r:
            if b < r:
                r = b
            continue
        else:
            cnt += 1
            r = b
    return cnt

if __name__ == '__main__':
    ans = main()
    print(ans)

Measured memory_bytes: 25132
#include <iostream>
#include <fstream>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <sstream>
#include <string>
#include <vector>
using namespace std;

#define EPS 1e-9
#define INF MOD
#define MOD 1000000007LL
#define fir first
#define iss istringstream
#define sst stringstream
#define ite iterator
#define ll long long
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<n;i++)
#define pi pair<int,int>
#define pb push_back
#define sec second
#define sh(i) (1LL<<i)
#define sz size()
#define vi vector<int>
#define vc vector
#define vl vector<ll>
#define vs vector<string>

int n,s;
typedef pair<pi,int> T;
map<T,int> M;

int f(int n,int s,int S){
	if(!n)return !s;
	if(M.find(T(pi(n,s),S))!=M.end())return M[T(pi(n,s),S)];
	int& r=M[T(pi(n,s),S)];
	rep(i,10)if(!(S&1<<i)&&s>=n*i)r+=f(n-1,s-n*i,S|1<<i);
	return r;
}

int main(){
	while(cin>>n>>s){
		cout<<f(n,s,0)<<endl;
	}
}

Measured memory_bytes: 14000
# from math import inf
inf = 10**50

N, M = map(int, input().split())
edges = []
for j in range(M):
    edges.append(list(map(int, input().split())))

d = [0] + ([-inf]*(N-1))
pred = [None] * N

for i in range(N-1):
    for j in range(M):
        u = edges[j][0]-1
        v = edges[j][1]-1
        w = edges[j][2]
        if (d[v] < d[u] + w) and (d[u] != -inf):
            d[v] = d[u] + w
            pred[v] = u

positive_loop = False
for i in range(N):
    for j in range(M):
        u = edges[j][0]-1
        v = edges[j][1]-1
        w = edges[j][2]
        if (d[u] + w > d[v]) and (d[u] != -inf):
            d[v] = d[u] + w
            if v == N-1:
                positive_loop = True
                break
    if positive_loop:
        break

if positive_loop:
    print("inf")
else:
    print(d[N-1])


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

int main(){
    int n;
    string s1, s2;
    int a=0, b=0;
    cin>>n;
    
    for(int i=0; i<n; i++){
        cin >> s1 >> s2;
        if(s1>s2) a+=3;
        else if(s1<s2)b+=3;
        else{
            a++; b++;
        
        }
    }
    
    cout << a << " " << b << endl;
    return 0;    
}


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



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

    int N;
    cin >> N;
    int maxh = 1000000000;
    int A = maxh;
    int cnt = -1, maxc = 0;
    for (int i = 0; i < N; i++) {
        int H;
        cin >> H;
        if (H <= A) {
            A = H;
            cnt++;
        } else {
            maxc = max(cnt, maxc);
            cnt = 0;
            A = H;
        }
    }
    maxc = max(cnt, maxc);
    cout << maxc << endl;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<math.h>
int main(void)
{
	int a,s[41],d[41][22],f[41],g,h[41],i,j,z,x;
	while(1){
		scanf("%d",&a);
		if(a==0) break;
		for(i=0;i<a;i++){
			scanf("%d",&s[i]);
			f[i]=0;
			g=1;
			h[i]=0;
			while(1){
				scanf("%d",&d[i][f[i]]);
				h[i]+=d[i][f[i]];
				if(d[i][f[i]]==10&&g%2==1){
					g++;
				}
				g++;
				f[i]++;
				if(g==19) break;
			}
			scanf("%d %d",&d[i][f[i]],&d[i][f[i]+1]);
			h[i]+=d[i][f[i]]+d[i][f[i]+1];
			if(d[i][f[i]]+d[i][f[i]+1]>=10){
				scanf("%d",&d[i][f[i]+2]);
				h[i]+=d[i][f[i]+2];
			}
			z=0;
			for(j=0;j<f[i];j++){
				if(d[i][j]==10&&z==0){
					h[i]+=d[i][j+1]+d[i][j+2];
				}
				else if(z==0) z=1;
				else if(d[i][j-1]+d[i][j]==10&&z==1){
					h[i]+=d[i][j+1];
					z=0;
				}
				else if(z==1) z=0;
			}
		}
		x=0;
		for(i=0;i<a-1;i++){
			for(j=i+1;j<a;j++){
				if(h[i]<h[j]){
					x=h[i];
					h[i]=h[j];
					h[j]=x;
					x=s[i];
					s[i]=s[j];
					s[j]=x;
				}
				if(h[i]==h[j]){
					if(s[i]>s[j]){
						x=h[i];
						h[i]=h[j];
						h[j]=x;
						x=s[i];
						s[i]=s[j];
						s[j]=x;
					}
				}
			}
		}
		for(i=0;i<a;i++) printf("%d %d\n",s[i],h[i]);
	}
	return 0;
}

Measured memory_bytes: 2740