akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <algorithm>
#define MP make_pair
using ll = long long;
using namespace std;

ll gcd(ll x, ll y)
{
  if (x < y){
    ll tmp = x;
    x = y;
    y = tmp;
  }
  while(y > 0){
    ll r = x % y;
    x = y;
    y = r;
  }
  return x;
}

int main()
{
  ll N,K;
  cin >> N >> K;
  vector<ll>A(N);
  for(int i=0; i < N; i++)
    cin >> A[i];
  sort(A.begin(),A.end());
  ll x = gcd(A[0], A[1]);
  for(int i=2; i < N; i++){
    x = gcd(x, A[i]);
  }
  //cout << mine << endl;
  //cout << w << endl;
  if(K > A[N-1])
    cout << "IMPOSSIBLE" << endl;
  else if(K%x != 0)
    cout << "IMPOSSIBLE" << endl;
  else if (N == 1 && A[0] != K)
    cout << "IMPOSSIBLE" << endl;
  else
    cout << "POSSIBLE" << endl;

  return 0;
}


Measured memory_bytes: 1024
H,W = map(int,input().split())

lis = [[0] * W for i in range(H)]

mod = 10**9+7

a = []

for i in range(H):
    A = list(input())
    a.append(A)

lis[0][0] = 1
for i in range(H):

    for j in range(W):

        if a[i][j] == "#":
            continue

        if i > 0:
            lis[i][j] += lis[i-1][j]
        if j > 0:
            lis[i][j] += lis[i][j-1]

        lis[i][j] %= mod

print (lis[-1][-1])


Measured memory_bytes: 87792
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define MAX 2000000
#define INFTY (1 << 30)
int H, A[MAX + 1];

void maxHeapify(int i)
{
  int l, r, largest;
  l = 2 * i;
  r = 2 * i + 1;

  if (l <= H && A[l] > A[i])
    largest = l;
  else
    largest = i;
  if (r <= H && A[r] > A[largest])
    largest = r;

  if (largest != i)
  {
    swap(A[i], A[largest]);
    maxHeapify(largest);
  }
}

int extract()
{
  int maxv;
  if (H < 1)
    return -INFTY;
  maxv = A[1];
  A[1] = A[H--];
  maxHeapify(1);
  return maxv;
}

void increaseKey(int i, int key)
{
  if (key < A[i])
    return;
  A[i] = key;
  while (i > 1 && A[i / 2] < A[i])
  {
    swap(A[i], A[i / 2]);
    i = i / 2;
  }
}

void insert(int key)
{
  H++;
  A[H] = -INFTY;
  increaseKey(H, key);
}

int main()
{
  int key;
  char com[10];

  while (1)
  {
    scanf("%s", com);
    if (com[0] == 'e' && com[1] == 'n')
      break;
    if (com[0] == 'i')
    {
      scanf("%d", &key);
      insert(key);
    }
    else
    {
      printf("%d\n", extract());
    }
  }
  return 0;
}


Measured memory_bytes: 6596
s=input()
ans=0
ans_list=[]
n=len(s)


for i in range(0,n):
    if s[i] not in {'A','T','C','G',' '}:
        ans_list.append(ans)
        ans=0
#        print(str(ans)+'!')
    else:
        ans+=1
        if i == n-1:
           ans_list.append(ans) 
 #       print(str(ans)+'z')

#print(ans_list)
if max(ans_list)==0:
    print(0)
else:
    print(max(ans_list))

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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

int main() {
	std::string s;
	std::cin >> s;
	int n = s.size();
	int dp[n + 1][2];
	bool from[n + 1][2];
	for (auto &i : dp) for (auto &j : i) j = -1000000000;
	dp[0][0] = 0;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 2; j++) {
			if (dp[i][j] == -1000000000) continue;
			if (s[i] == 'P' || s[i] == '?') { // 1
				if (dp[i + 1][1] < dp[i][j]) {
					dp[i + 1][1] = dp[i][j];
					from[i + 1][1] = j;
				}
			}
			if (s[i] == 'D' || s[i] == '?') { // 1
				if (dp[i + 1][0] < dp[i][j] + j + 1) {
					dp[i + 1][0] = dp[i][j] + j + 1;
					from[i + 1][0] = j;
				}
			}
		}
	}
	std::string tmp;
	int cur = dp[n][0] < dp[n][1] ? 1 : 0;
	for (int i = n; i; i--) {
		tmp.push_back(cur ? 'P' : 'D');
		cur = from[i][cur];
	}
	std::reverse(tmp.begin(), tmp.end());
	printf("%s\n", tmp.c_str());
	return 0;
}


Measured memory_bytes: 5748
using System;
using System.Linq;

class A_BPro
{
    static void Main()
    {
            string str;
            {
                str = Console.ReadLine();
                long a = int.Parse(str.Split(' ')[0]);
                long b = int.Parse(str.Split(' ')[1]);
                    Console.WriteLine("{0} {1} {2:f8}",a/b,a%b,(double)a/b);
            }
    }
}

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

int main() {
	int n,k;
	cin>>n>>k;
	// dp[i] True if first player wins if there are i coins left
	vector<int> a(n);
	for(int i=0;i<n;i++){
	    cin>>a[i];
	}
	vector<bool>dp(k+1);
	for(int stones=0;stones<=k;stones++){
	    bool res=0;
	    for(int i=0;i<n;i++){
	        if(stones-a[i]>=0 && !dp[stones-a[i]])
	        dp[stones]=true;
	        
	    }
	}
	string ans= dp[k]?"First":"Second";
	cout<<ans;
	
	return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int maxn=1e6+5;
int pre[maxn];
int main() {
    string s;cin>>s;
    if(s[0]==s[1]) return cout<<1<<' '<<2<<endl,0;
    for(int i=2;i<s.length();i++) {
    	vector<char> V;
    	if(s[i]==s[i-1]) return cout<<i<<' '<<i+1<<endl,0;
    	for(int j=0;j<3;j++) V.push_back(s[i-j]);
    	sort(V.begin(),V.end());
    	if(V[0]==V[1]||V[1]==V[2]) 
    		return cout<<i-1<<' '<<i+1<<endl,0;
    }
    puts("-1 -1");
    return 0;
}

Measured memory_bytes: 3704
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<P>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class T> istream& operator>>(istream& is,vector<T>& v) { for(T& t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream& os,const vector<T>& v) { for(T t:v){os<<t<<" ";} os<<"\n"; return os; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YES(bool b) { cout << (b ? "YES" : "NO") << endl; }
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;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    int n;
    ll k;
    cin >> n >> k;
    vl a(n);
    cin >> a;
    vl mi,pl;
    ll zero = 0;
    rep(i,n) {
        if(a[i] < 0) mi.pb(-a[i]);
        else if(a[i] == 0) zero++;
        else pl.pb(a[i]);
    }
    sort(all(mi));
    sort(all(pl));
    ll ng = -linf,ok = linf;
    auto f = [&](ll x) {
        // Are there no less than k pairs ?
        ll sum = 0;
        if(x > 0) {
            if(pl.size() >= 2) {
                int l = 0,r = 0;
                while(r < pl.size()-1 && pl[0]*pl[r+1] <= x) r++;
                while(l < pl.size()-1) {
                    if(l >= r) break;
                    while(pl[l]*pl[r] > x && r > l) r--;
                    sum += r-l;
                    l++;
                }
            }
            if(mi.size() >= 2) {
                int l = 0,r = 0;
                while(r < mi.size()-1 && mi[0]*mi[r+1] <= x) r++;
                while(l < mi.size()-1) {
                    if(l >= r) break;
                    while(mi[l]*mi[r] > x && r > l) r--;
                    sum += r-l;
                    l++;
                }
            }
        }
        if(x >= 0) {
            sum += zero*(zero-1)/2;
            sum += zero*(n-zero);
            sum += (ll)mi.size()*pl.size();
        } else {
            if(pl.size() == 0 || mi.size() == 0) return sum >= k;
            x = -x;
            int fm = 0,fp = pl.size();
            while(fm < mi.size()) {
                while(fp > 0 && mi[fm]*pl[fp-1] >= x) fp--;
                sum += pl.size()-fp;
                fm++;
            }
        }
        return sum >= k;
    };
    while(abs(ok-ng) > 1) {
        ll mid = (ng+ok)/2;
        if(f(mid)) ok = mid;
        else ng = mid;
    }
    cout << ok << endl;
}

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


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

    char temp = 0;
    int ans = 0;

    rep(i, sz(s)){
        if(temp == 0){
            temp = s.at(i);
            ans++;
        }else if(temp==s.at(i)){
            continue;
        }else{
            temp = s.at(i);
            ans++;
        }
    }

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


Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
#define int long long

signed main() {
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int count = 0;
  for (int i = 0; i < n; i++) {
    while (a[i] % 2 == 0) {
      count++;
      a[i] /= 2;
    }
  }
  cout << count << endl;
  return 0;
}


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

int main() {
  int N;
  cin>>N;
  
  int ans=0;
  if(N%111==0)
    ans=N;
  else{
    for(int i=0;i<111;++i){
   	  ++N;
      if(N%111==0)
        ans=N;
    }
  }
  
  cout<<ans<<endl;
  
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 1000000000000000
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
void init(){
  cin.tie(0);
  ios::sync_with_stdio(false);
}


main(){
  int n,m;
  cin>>n>>m;
  vector<int> a(n);
  rep(i,n){
    cin>>a[i];
  }
  sort(all(a));

  vector<P> b(m);
  rep(i,m){
    int x,y;
    cin>>x>>y;
    b[i]=P(y,x);
  }
  sort(all(b));
  reverse(all(b));

  int j=0;
  rep(i,n){
    if(j==m) break;
    if(a[i]<b[j].F){
      a[i]=b[j].F;
      b[j].S--;
    }
    if(b[j].S==0) j++;
  }

  int ans=0;
  rep(i,n){
    ans+=a[i];
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> ve_vel;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#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 rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pub push_back
#define puf push_front
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
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 (a>b) { a=b; return 1; } return 0; }


typedef pair<int , int> P;//<最短距離, 頂点番号>
#define MAX_V 2005
struct edge {int to, cost; };
int V;//頂点数
vector<edge> G[MAX_V];
int d[MAX_V];//頂点sからの最短距離

//ABC073,ABC070D


void dijkstra(int s) {
    //greater<P>を指定し.fsを小さい順に取り出す
    priority_queue<P, vector<P>, greater<P> > que;
    fill(d, d+V, INF);
    d[s] = 0;
    que.push(P(0,s));

    while(!que.empty()) {
        P p = que.top(); que.pop();
        int v = p.sc;
        if(d[v] < p.fs) continue;
        rep(i,G[v].size()) {
            edge e = G[v][i];
            if(d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    } 
}

int main() {
    int N,X,Y; cin>>N>>X>>Y; X--;Y--;

    rep(i,N-1) {
        edge e = {i+1, 1};
        G[i].push_back(e);
		edge f = {i,1};
		G[i+1].push_back(f);
    }

	edge e = {X,1};
	G[Y].push_back(e);
	edge f = {Y,1};
	G[X].push_back(f);
	V = N;

    
	vector<int> ans(N,0);
    for (int i=0; i<V; ++i) {
		dijkstra(i);
		for(int j = i+1; j<N; j++){
        	if(d[j] != INF) ans[d[j]]++;
			//cout <<i+1 << " " << j+1 << " " <<  d[j] << endl;
		}
    }
	rep(i,N-1){
		cout << ans[i+1] << endl;
	}
}



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

typedef long long ll;
using namespace std;

const int INF=1e9;

int main(){
  int h,n;
  cin>>h>>n;
  vector<int> dp(h+1,INF);
  dp[0]=0;
  rep(i,n){
    int a,b;
    cin>>a>>b;
    rep(j,h){
      int nj=min(j+a,h);
      dp[nj]=min(dp[nj],dp[j]+b);
    }
  }
  cout<<dp[h]<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n,i,j,a[100],f=1,ct=0,b[100];
	cin>>n;
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
		b[i]=a[i];
	}
	sort(a,a+n);
	for(i=0;i<n;i++){
		if(a[i]!=b[i])
		ct++;
		if(ct>2){
			f=0;
			printf("NO");
			break;
		}
	}
	if(f==1)	printf("YES");
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	int a,b,c,i,count=0;
	
	scanf("%d %d %d",&a,&b,&c);
	
	for (i=a;i<b+1;i++){
		if (c%i==0) count++;
	}
	
	printf("%d\n",count);
	
	return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <string>
#include <algorithm>

using namespace std;

const int R = 700;
int n, q, L;
int x[500000];
int go1[500000];
int goroot[500000];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> x[i];
    }
    cin >> L;
    int i = 0, j = 0;
    for (; i < n; i++)
    {
        while (j + 1 < n && x[j + 1] - x[i] <= L)
        {
            j++;
        }
        go1[i] = j;
    }
    for (int i = 0; i < n; i++)
    {
        int g = go1[i];
        for (int j = 1; j < R; j++)
            g = go1[g];
        goroot[i] = g;
    }
    cin >> q;
    while (q--)
    {
        int a, b;
        cin >> a >> b;
        if (b < a)
            swap(a, b);
        a--;
        b--;
        int d = 0;
        while (goroot[a] < b)
        {
            a = goroot[a];
            d += R;
        }
        while (a < b)
        {
            a = go1[a];
            d++;
        }
        cout << d << "\n";
    }
}


Measured memory_bytes: 3584
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int K = sc.nextInt();
    int[] l = new int[N];
    int max = 0;
    for(int i = 0; i < N; i++) {
      l[i] = sc.nextInt();
    }
    Arrays.sort(l);
    for(int i = N - 1; i >= N - K; i--) {
      max += l[i];
    }
    System.out.println(max);
  }
}


Measured memory_bytes: 23764
int a[100];
main(i,j,m,n){
  for(;scanf("%d%d",&n,&m),n;){
    for(i=0;i<m;i++)a[i]=i+1;
    for(;n;n--)
      for(i=0;i<m;i++)
        scanf("%d",&j),a[i]+=j*10000;
    for(i=0;i<m-1;i++)
      for(j=0;j<m-1;j++)
        if(a[j]/10000<a[j+1]/10000)
          n=a[j],a[j]=a[j+1],a[j+1]=n;
    for(i=0;i<m;i++)
      printf("%d%c",a[i]%10000,i==m-1?'\n':' ');
  }
  return 0;
}

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

using namespace std;

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

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    string S;
    cin >> S;
    ll Q;
    cin >> Q;

    deque<char> ans;
    ll N = S.size();
    rep(i, N) {
        ans.push_back(S[i]);
    }
    bool front = true;
    rep(q, Q) {
        ll n;
        cin >> n;
        if (n == 1) {
            front ^= true;
        } else {
            ll f;
            cin >> f;
            char c;
            cin >> c;
            if (f == 1) {
                if (front) {
                    ans.push_front(c);
                } else {
                    ans.push_back(c);
                }
            } else {
                if (front) {
                    ans.push_back(c);
                } else {
                    ans.push_front(c);
                }
            }
        }
    }
    if (front) {
        rep(i, ans.size()) {
            cout << ans[i];
        }
    } else {
        rrep(i, ans.size() - 1, 0) {
            cout << ans[i];
        }
    }
    cout << '\n';
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 976
n = int(input())
A = list()
G = [1]
cnt = 0

for i in range(0, n):
    A.append(int(input()))


def insertion_sort(A, n, g):
    global cnt
    for i in range(g, n):
        v = A[i]
        j = i - g
        while j >= 0 and A[j] > v:
            A[j+g] = A[j]
            j -= g
            cnt += 1
        A[j+g] = v


# G[i] = 3*Gi-1 + 1
def shell_sort():
    for i in range(1, 101):
        h = 3 * G[0] + 1
        if h > n:  # h???n?¶???????????????§?????????4n+3*2n-1+1
            break
        else:
            G.insert(0, h)
    for g in G:
        insertion_sort(A, n, g)

shell_sort()
print(len(G))
print(" ".join(str(x) for x in G))
print(cnt)
print("\n".join(str(x) for x in A))

Measured memory_bytes: 127884
#include<cstdio> 
int n,m;
int main() 
{
	scanf("%d%d",&n,&m);
    if (n==1&&m>1)printf("%d\n",m-2);
   	else if (n>1&&m==1)printf("%d\n",n-2);
    else if (n==1&&m==1)puts("1");
    else printf("%lld\n",1ll*n*m-2*n-2*m+4);
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

int main(){
	int n;cin>>n;
	string s;cin>>s;
	ll ans=0;
	map<char,ll>mp;
	for(char c:s){
		mp[c]++;
	}
	ans=1;
	rep(i,26){
		(ans*=(mp[i+'a']+1))%=MOD;
	}
	cout<<ans-1<<endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <string>
#include <bits/stdc++.h>
#include <set>
#include <list> //list<???> a; a.push_back ,insert(追加したい要素),a.sort(),参照できない
#include <vector> //vector<???> a; a.push_back,sort(a.begin(),a.end());a[i]
//配列 int a[N];a[i]=追加したい要素;sort(a,a+N);a[i]
using namespace std;
typedef long  ll;
#define rep(i,n) for(int i=0;i<(n);i++)


//using namespace std;
//


int main(){
  int N;cin>>N;
  int a[N];

  for(int i=0;i<N;i++){
    int t;cin>>t;
    a[i]=t;
  }
  int ans=0;
  int M;cin>>M;
  for(int i=0;i<M;i++){
    int p,x;cin>>p>>x;
    for(int j=0;j<N;j++){
      if (j==p-1){
        ans+=x;
      }else{
        ans+=a[j];
      }
    }
    cout<<ans<<endl;
    ans=0;
  }

}

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


int main() {
    vector<vector<int>> c(3,vector<int>(3));
    for (int i=0;i<3;i++){
        for (int j=0;j<3;j++){
            cin >> c.at(i).at(j);
        }    
    }
    for (int i=0;i<3;i++){
        while(1){
            if (c.at(i).at(0)==0 || c.at(i).at(1)==0 || c.at(i).at(2)==0 ){
                break;
            }
            for (int j=0;j<3;j++){
                c.at(i).at(j)--;
            }
        }    
    }
    for (int i=0;i<3;i++){
        if (c.at(0).at(i)==c.at(1).at(i) && c.at(1).at(i)==c.at(2).at(i))
            continue;
        else {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
 
#define FOR(idx, begin, end) for(int idx = (begin); idx < (end); ++idx)
#define DMP(x) cerr << #x << ": " << x << "\n"
 
using namespace std;
typedef long long lint;
const int MOD = 1000000007;
 
int main() {
 
	cin.tie(0);
 
	int N, M;
	cin >> N >> M;
 
	vector<int> visited(N, 0);
 
	vector<int> a(M), b(M);
	FOR(i, 0, M) cin >> a[i] >> b[i];
 
	vector<vector<int>> path(N, vector<int>(N, 0));
	FOR(i, 0, M) {
		path[a[i] - 1][b[i] - 1] = true;
		path[b[i] - 1][a[i] - 1] = true;
	}
 
	int ans = 0;
 
	queue<pair<int, vector<int>>> node;
	node.push({0, visited});
 
	while (!node.empty()) {
		
		auto now = node.front();
		now.second[now.first] = 1;
		node.pop();
 
		FOR(i, 0, N) {
			if (now.second[i] == 0 && path[now.first][i] == 1) {
 
				node.push({i, now.second});
			}
		}
 
		FOR(i, 0, N) {
 
			if (now.second[i] == 0) break;
			if (i == N - 1) ans++;
		}
	
	}
 
	cout << ans;
 
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
#define fore(i,a,b) for(ll i=(a);i<=(b);++i)
#define rep(i,n) fore(i,0,(n)-1)
#define rfore(i,a,b) for(ll i=(b);i>=(a);--i)
#define rrep(i,n) rfore(i,0,(n)-1)
#define all(x) (x).begin(),(x).end()
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
template<class T>
bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>
bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
template<class T>
ll sum(const T& a){return accumulate(all(a),0LL);}
const string YES = "YES";
const string NO = "NO";

void solve(){
    int n;cin>>n;
    vl a(n);rep(i,n)cin>>a[i];

    set<ll> s;
    rep(i,n)s.insert(a[i]);
    cout<<(s.size()==n?"YES":"NO")<<endl;
}

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


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

using namespace std;

typedef long long ll;

const ll mod = 1e9 + 7;

struct matrix
{
    int n;
    vector<vector<ll>> m;

    matrix(int n) : n(n), m(n, vector<ll>(n)) {}

    matrix identity()
    {
        matrix id(n);

        for(int i = 0; i < n; i++)
            id.m[i][i] = 1;

        return id;    
    }

    vector<vector<ll>> multiply(vector<vector<ll>> a)
    {
        matrix tmp(n);

        for(int k = 0; k < n; k++)
        {
            for(int i = 0; i < n; i++)
            {
                for(int j = 0; j < n; j++)
                {
                    tmp.m[i][j] = (tmp.m[i][j] + (m[i][k] * a[k][j]) % mod) % mod;
                }
            }
        }

        return tmp.m;
    }

    vector<vector<ll>> pow_fast(ll k)
    {
        matrix id = identity();

        while(k > 0)
        {
            if(k & 1)
                id.m = multiply(id.m);

            m = multiply(m);
            k >>= 1;
        }

        return id.m;
    }

    void print()
    {
        for(int i = 0; i < n; i++)
        {
            for(int j = 0; j < n; j++)
                cout << m[i][j] << " ";
            cout << endl;
        }
    }    
};

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

    int n;
    ll k;

    cin >> n >> k;

    matrix adj(n);

    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < n; j++)
        {
            int a;
            cin >> a;

            adj.m[i][j] = a;
        }
    }

    auto walk = adj.pow_fast(k);

    ll ans = 0;
    for(int i = 0; i < n; i++)
        for(int j = 0; j < n; j++)
            ans = (ans + walk[i][j]) % mod;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 384
#include"bits/stdc++.h"
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
const int mod = 1000000007;
const int inf = 1ll << 61;
typedef pair<int, int> P;
typedef pair<int, P>PP;
int a[300006];

int modpow(int x, int n, int md) {
	if (!n)return 1;
	int res = modpow(x*x%md, n / 2, md);
	if (n & 1)res = res*x%md;
	return res;
}

signed main() {
	int n; cin >> n;
	rep(i, n)cin >> a[i];
	int ans = 0;
	rep(i, 61) {
		int cnt = 0;
		rep(j, n) {
			if (a[j] & (1ll << i))cnt++;
		}
		ans += cnt*(n - cnt) % mod*modpow(2, i, mod) % mod;
		ans %= mod;
	}
	cout << ans << endl;
}

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

int main(){
  
  string s;
  cin >>s;
  
  int a=(s[0]-'0')*10+s[1]-'0', b=(s[2]-'0')*10+s[3]-'0';
  
  if( (0<a&&a<13) && (0<b&&b<13)){
  	cout << "AMBIGUOUS" << endl;
  }
  
  else if( (a==0 || a>12) && (b==0 || b>12) ){
  	cout << "NA" << endl;
  }
  
  else if((0<a&&a<13)){
  	cout << "MMYY" << endl;
  }
  else cout << "YYMM" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
using namespace std;

#define GET_N(A) (int)(A) - (int)'0'

int N = 0;
int M = 0;
string s;
int main()
{
    cin >> N;
    s = to_string(N);
    for(char c : s)
    {
        M += GET_N(c);
    }
    cout << ((N % M == 0) ? "Yes" : "No")<< endl;
    return 0;
}

Measured memory_bytes: 256
def main():
    cnt = 0
    for _ in range(m):
        x, y = map(int, input().split())
        unite(x, y)
    for i in range(1, n+1):
        if same(i, p[i-1]):
            cnt += 1
    print(cnt)
        
def root(x):
    if par[x] == x:
        return x
    par[x] = root(par[x])
    return par[x]

def same(x, y):
    return root(x) == root(y)

def unite(x, y):
    x = root(x)
    y = root(y)
    if x != y:
        par[x] = y

if __name__ == "__main__":
    n, m = map(int, input().split())
    p = list(map(int, input().split()))
    par = [0] + [i for i in range(1, n+1)]
    main()

Measured memory_bytes: 125676
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
typedef long long ll;
typedef double dd;
#define For(i,j,k) for (int i=(int)j;i<=(int)k;++i)
#define Forr(i,j,k) for (int i=(int)j;i>=(int)k;--i)
#define Set(a,p) memset(a,p,sizeof(a))
using namespace std;

template<typename T>bool chkmax(T &a,T b) { return a<b?a=b,1:0; }
template<typename T>bool chkmin(T &a,T b) { return a>b?a=b,1:0; }

const int maxn=100+10;
int n,m;
int a[maxn];

inline void file() {
	freopen("AGC001D.in","r",stdin);
	freopen("AGC001D.out","w",stdout);
}

inline int read() {
	int x=0,p=1;
	char c=getchar();
	while (!isdigit(c)) { if (c=='-') p=-1; c=getchar();}
	while (isdigit(c)) { x=(x<<1)+(x<<3)+(c-'0'); c=getchar();}
	return x*p;
}

int main() {
//	file();
	n=read(); m=read();
	int cnt=0;
	For (i,1,m) {
		a[i]=read(); if (a[i]&1) ++cnt;
	}
	if (cnt>2) {
		puts("Impossible"); return 0;
	}
	cnt=0;
	For (i,1,m) if (a[i]&1) {
		++cnt;
		if (cnt==1) swap(a[1],a[i]);
		else if (cnt==2) swap(a[m],a[i]);
	}
	For (i,1,m) printf("%d ",a[i]); cout << endl;
	if (m==1) {
		if (a[1]==1) puts("1"),puts("1");
		else puts("2"),printf("1 %d\n",a[1]-1);
		return 0;
	}
	++a[1]; --a[m];
	if (!a[m]) --m;
	printf("%d\n",m);
	For (i,1,m) printf("%d ",a[i]);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define re register
#define inc(i,j,k) for(re int i=j;i<=k;i++)
#define dec(i,j,k) for(re int i=j;i>=k;i--)
#define ll long long
using namespace std;
const int N=305;
int n,k,mod;
ll c[N][N],dp[N][N],sum[N][N];
int main(){
	scanf("%d%d%d",&n,&k,&mod);
	inc(i,0,n){
		c[i][0]=1;
		inc(j,1,i) c[i][j]=(c[i-1][j]+c[i-1][j-1])%mod;
	}
	inc(j,0,k) dp[1][j]=1,sum[1][j]=k-j+1;
	inc(i,2,n+1){
		inc(j,0,k){
			inc(s,1,i-1) (dp[i][j]+=dp[i-s][j]*sum[s][j+1]%mod*c[i-2][s-1])%=mod;
		}
		dec(j,k,1) sum[i][j]=(sum[i][j+1]+dp[i][j])%mod;
	}
	printf("%lld",dp[n+1][0]);
}


Measured memory_bytes: 2432
import java.util.Scanner;
import java.util.Arrays;
// Arrays.toString(array) 配列arrayの中身を出力する

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = Integer.parseInt(sc.nextLine());
    int[] p = new int[N];
    int cnt = 0;
    int temp1 = 0;
    int temp2 = 0;
    for(int i = 1; i <= N; i++){
      p[i-1] = Integer.parseInt(sc.next());
      if(p[i-1] != i){
        cnt += 1;

        if(cnt == 1){
          temp1 = i-1;
        }else if(cnt == 2){
          temp2 = i-1;
        }else{
          break;
        }

      }
    }

    if(cnt == 0){
      System.out.println("YES");
    }else if(cnt == 2){
      if(p[temp2] == temp1+1 && p[temp1] == temp2+1){
        System.out.println("YES");
      }else{
        System.out.println("NO");
      }
    }else{
      System.out.println("NO");
    }
  }
}


Measured memory_bytes: 22612
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include<limits.h>
#include<iomanip>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define check(v) rep(i,v.size()) cout << v[i] << " ";\
cout << endl
#define INF 1e8
typedef long long ll;
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

int main() {
    int n, a, b; cin >> n >> a >> b;
    string s; cin >> s;
    int comp = 0;
    int foreign = 0;
    rep(i,n){
        if(s[i]=='c') cout << "No" << endl;
        else if(s[i]=='a'){
            if(comp<a+b){
                comp++;
                cout << "Yes" << endl;
            }else cout << "No" << endl;
        }else {
            foreign++;
            if(comp<a+b && foreign<=b){
                comp++;
                cout << "Yes" << endl;
            }else cout << "No" << endl;
        }
    }

    return 0;
}

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

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

    int ans = 1;

    for (int i = 0; i < N; i++) {
        if (ans < K)
            ans += ans;
        else
            ans += K;
        /* code */
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
unittest
{
	assert( [ "6", "9 1 4 4 6 7" ].parse.expand.solve == 2 );
	assert( [ "8", "9 1 14 5 5 4 4 14" ].parse.expand.solve == 0 );
	assert( [ "14", "99592 10342 29105 78532 83018 11639 92015 77204 30914 21912 34519 80835 100000 1" ].parse.expand.solve == 42685 );
}



import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	input.popFront;
	auto ds = input.front.split.to!( long[] );
	return tuple( ds );
}

auto solve( long[] ds )
{
	ds.sort();
	return ds[ $ / 2 ] - ds[ $ / 2 - 1 ];
}


Measured memory_bytes: 4164
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define PI acos(-1)
#define fs first
#define sc second
#define debug freopen("1.in", "r", stdin), freopen("1.out", "w", stdout);
#define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int MAX = 0x7fffffff;
const int MIN = 0x80000000;
const ll maxn = 1e6 + 10;

int n, cnt = 0;
string s;

int main() {
    ios;
    cin >> n >> s;
    for (int i = 0; i < n - 2; i ++){
        if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C'){
            cnt ++;
            i += 2;
        }
    }
    cout << cnt << '\n';
    return 0;
}

Measured memory_bytes: 3192
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
#include<complex>
#include<cassert>
using namespace std;
#include<atcoder/all>
using namespace atcoder;


#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 4000001;
const long double eps = 1E-14;

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

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

ll gcd(ll a, ll b) {
	if (b == 0) { return a; }
	if (a < b) { return gcd(b, a); }
	return gcd(b, a % b);
}

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% MOD + MOD) % MOD) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint& a) {
		if ((x += a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator-=(const mint& a) {
		if ((x += MOD - a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator*=(const  mint& a) {
		(x *= a.x) %= MOD;
		return *this;
	}
	mint operator+(const mint& a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint& a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint& a) const {
		mint res(*this);
		return res *= a;
	}

	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime MOD
	mint inv() const {
		return pow(MOD - 2);
	}
	mint& operator/=(const mint& a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint& a) const {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream& os, const mint& m) {
		os << m.x;
		return os;
	}
};

mint pw(mint a, ll b) {
	if (b == 0) { return 1; }
	mint ret = pw(a, b >> 1);
	ret *= ret;
	if (b & 1) { ret *= a; }
	return ret;
}

typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;

typedef vector<mint> vmint;
typedef vector<vector<mint>> vvmint;
typedef vector<vector<vector<mint>>> vvvmint;

/////////////////////////////////////


int main() {
	ll T;
	cin >> T;
	repn(t, T) {
		ll n, m, a, b;
		cin >> n >> m >> a >> b;
		cout << floor_sum(n, m, a, b) << endl;
	}
}


Measured memory_bytes: 3608
import kotlin.random.Random

//

fun main() {
    intro_heuristicsa()
}

fun intro_heuristicsa() {
    val d = readLine()!!.toInt()
    val c = readLine()!!.split(" ").map { it.toInt() }
    val s = MutableList(d) { listOf<Int>()}
    repeat(d) {
        s[it] = readLine()!!.split(" ").map { it.toInt() }
    }
    repeat(d) {
        println(Random.nextInt(26) + 1)
    }
}


Measured memory_bytes: 40120
using System;

class Program{
    public static void Main(){
        var s=Console.ReadLine().Split(' ');
        var n=int.Parse(s[0]);
        var k=int.Parse(s[1]);
        var ws=new int[n];
        for(var i=0; i<n; i++){
            ws[i]=int.Parse(Console.ReadLine());
        }

        var left=1;
        var right=10000*100000;
        var p=0;
        while(left<=right){
            var mid=(left+right)/2;
            var i=0;
            var changeLeft=true;
            for(var j=0; j<k; j++){
                var pp=0;
                while(i<n){
                    if(pp+ws[i]<=mid){
                        pp+=ws[i];
                        i++;
                    } else{
                        break;
                    }
                }
                if(i==n){
                    changeLeft=false;
                }
            }
            if(changeLeft){
                left=mid+1;
            } else{
                right=mid-1;
                p=mid;
            }
        }

        Console.WriteLine(p);
    }
}

Measured memory_bytes: 9952
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=3e5+7;
int a[maxn];
vector<int> ans;vector<int> vec;vector<int> rem;
long double f(int u,int k)
{
	long double right=(long double)rem[u-1]/(long double)(k-u);
	return right;
}
int SanFen(int l,int r,int k) //找凸点  
{  
    while(l < r-1)  
    {  
        int mid  = (l+r)/2;  
        int mmid = (mid+r)/2;  
        if( f(mid,k) > f(mmid,k) )  
            l = mid;  
        else  
            r = mmid;  
    }  
    return f(l,k) > f(r,k) ? l : r;  
}  

int main()
{
	int n;scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		int x;scanf("%d",&x);
		a[x]++;
	}
	for(int i=1;i<maxn;i++)if(a[i]) vec.push_back(a[i]);
	sort(vec.begin(),vec.end(),greater<int>());
	for(int i=vec.size();i<=n;i++) vec.push_back(0);
	rem.push_back(n-vec[0]);
	for(int i=1;i<n;i++)rem.push_back(rem[i-1]-vec[i]);
	ans.push_back(n);
	for(int kpl=2;kpl<=n;kpl++)
	{
		int k=kpl;
		int l=SanFen(1,k,k);
		if(l>=k) l=k-1;
		if(l<=0) l=1;
		int cnt=rem[l-1]/(k-l);
		if(l>=0&&k!=l+1)
		cnt=min(cnt,rem[l]/(k-l-1));
		if(l+1<k-1)
		cnt=min(cnt,rem[l+1]/(k-l-2));
		cnt=min(cnt,n/k);
		ans.push_back(cnt);
	}
	for(auto u:ans) cout<<u<<endl;
 } 

Measured memory_bytes: 6896
#include <stdio.h>

int main(void) {
  int m, d, ans;
  ans = 0;
  scanf("%d %d", &m, &d);
  for (int i = 1; i <= m; i++) for (int j = 1; j <= d; j++) {
    int a = j / 10, b = j % 10;
    if (a >= 2 && b >= 2 && a * b == i) ans++;
  }
  printf("%d\n", ans);
}

Measured memory_bytes: 128
#include <iostream>

int main(int argc, char const* argv[])
{
    uint_fast64_t a[200];
    int i;
    std::cin >> i;
    i = 0;
    while (std::cin >> a[i]) {
        i++;
    }

    int result = 0;;
    bool detectOdd = false;
    while (!detectOdd) {
        for (int j=0; j<i; j++) {
            if (a[j] & 0x1) {
                detectOdd = true;
                break;
            }
            a[j] >>= 1;
        }
        if (!detectOdd) {
            result += 1;
        }
    }
    std::cout << result << std::endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  vector<int> n;
  vector<int> x;
  bool flag = true;
  while(flag){
    int tmp1, tmp2;
    cin >> tmp1 >> tmp2;
    if(tmp1 == 0 && tmp2 == 0){
      flag = false;
      continue;
    }
    n.push_back(tmp1);
    x.push_back(tmp2);
  }
  int N = n.size();
  REP(i, N){
    int ans = 0;
    for(int j = 1; j <= n[i]-2; j++){
      for(int k = j+1; k <= n[i]-1; k++){
        if(k+1 <= x[i]-j-k  && x[i]-j-k <= n[i]) ans++;
      }
    }
    cout << ans << endl;
  }
}


Measured memory_bytes: 3116
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<cmath>
#include<tuple>
#include<string>
typedef unsigned long long ll;
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define repm(i,a,b) for(int i=(a);i>(b);i--)
#define F first
#define S second
using namespace std;
const ll INF = 1e12;
const int i_INF = 2147483647;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
  int a,b;
  cin>>a>>b;
  cout<<a-b+1<<endl;
}

Measured memory_bytes: 256
// 2014/07/07 Tazoe

#include <iostream>
#include <queue>
using namespace std;

const int INF = 100000000;

struct Point{
	int x;
	int y;
};

int main()
{
	int H, W, N;
	cin >> H >> W >> N;

	char M[1002][1002];
	for(int y=0; y<H+2; y++){
		for(int x=0; x<W+2; x++){
			M[y][x] = 'X';
		}
	}

	struct Point P[10];

	for(int y=1; y<=H; y++){
		for(int x=1; x<=W; x++){
			cin >> M[y][x];

			if(M[y][x]=='S'){
				P[0].x = x;
				P[0].y = y;
			}
			else if('0'<=M[y][x] && M[y][x]<='9'){
				P[M[y][x]-'0'].x = x;
				P[M[y][x]-'0'].y = y;
			}
		}
	}

	int sum = 0;

	for(int i=0; i<N; i++){
		int d[1002][1002];
		for(int y=1; y<=H; y++){
			for(int x=1; x<=W; x++){
				d[y][x] = INF;
			}
		}

		// BFS

		queue<struct Point> que;

		struct Point p;
		p.x = P[i].x;
		p.y = P[i].y;
		que.push(p);
		d[p.y][p.x] = 0;

		while(!que.empty()){
			p = que.front();
			que.pop();

			if(p.x==P[i+1].x && p.y==P[i+1].y){
				sum += d[p.y][p.x];
				break;
			}

			if(M[p.y][p.x+1]!='X' && d[p.y][p.x+1]==INF){	// 東
				struct Point q;
				q.x = p.x+1;
				q.y = p.y;
				que.push(q);
				d[q.y][q.x] = d[p.y][p.x]+1;
			}
			if(M[p.y][p.x-1]!='X' && d[p.y][p.x-1]==INF){	// 西
				struct Point q;
				q.x = p.x-1;
				q.y = p.y;
				que.push(q);
				d[q.y][q.x] = d[p.y][p.x]+1;
			}
			if(M[p.y+1][p.x]!='X' && d[p.y+1][p.x]==INF){	// 南
				struct Point q;
				q.x = p.x;
				q.y = p.y+1;
				que.push(q);
				d[q.y][q.x] = d[p.y][p.x]+1;
			}
			if(M[p.y-1][p.x]!='X' && d[p.y-1][p.x]==INF){	// 北
				struct Point q;
				q.x = p.x;
				q.y = p.y-1;
				que.push(q);
				d[q.y][q.x] = d[p.y][p.x]+1;
			}
		}
	}

	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 6116
loop do
  q1, b, c1, c2, q2 = gets.split.map(&:to_i)
  break if q1.zero?

  aca = q2
  nca = 0
  loop do
    if aca.zero?
      break
    elsif q1 <= nca + aca && aca*c1 + nca*c2 <= b
      break
    elsif aca*c1 + nca*c2 > b
      aca -= 1
      nca = 0
    else
      nca += 1
    end
  end

  nca += 1 while aca*c1 + nca*c2 <= b
  nca -= 1

  if aca.zero?
    puts "NA"
  else
    puts "#{aca} #{nca}"
  end
end

Measured memory_bytes: 6104
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef list<int> liint;
typedef pair<int, int> pint;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }



int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll A, B;
    cin >> A >> B;
    ll ans = 0;
    rep(x, 100000) {
        if (ll(x * 0.08) == A && ll(x * 0.10) == B) {
            cout << x << endl;
            return 0;
        }
    }

    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <climits>
#define MAX 101
#define INF LLONG_MAX
using namespace std;

//the minimum matrix chain multiplication of M_i...M_j
long long m[MAX][MAX];
//M_i is p[i-1]*p[i]
long long p[MAX];

int main(){
  int n; cin >> n;
  cin >> p[0];
  for(int i=1;i<=n-1;i++){
    cin >> p[i];
    int x; cin >> x;
  }
  cin >> p[n];
  for(int i=1;i<=n;i++) m[i][i]=0;
  for(int l=2;l<=n;l++){
    for(int i=1;i<=n-l+1;i++){
      int j=i+l-1;
      m[i][j]=INF;
      //find the minimum of M_i...M_j
      for(int k=i;k<=j-1;k++){
        m[i][j]=min(m[i][j],m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j]);
      }
    }
  }
  cout << m[1][n] << endl;
}

Measured memory_bytes: 3168
n, a, b = map(int, input().split())
p = 10 ** 9 + 7

total = (pow(2, n, p) - 1) % p

def cmb(n, r):
    x = 1
    y = 1
    for i in range(r):
        x = (x * (n - i)) % p
        y = (y * (r - i)) % p
    ret = x * pow(y, p - 2, p) % p
    return ret

total = (pow(2, n, p) - 1 - cmb(n, a) - cmb(n, b)) % p
print(total)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rt "\n"
#define sp " "
#define test(n) cout << "test" << n << endl;
#define fixsp(n) fixed << setprecision(n)
#define defsp(n) defaultfloat << setprecision(n)
#define kyopro ios::sync_with_stdio(false);cin.tie(NULL)
#define MOD 1000000007
#define iikae auto&
#define vector3D(K, N, M, DP) vector<vector<vector<ll>>> DP(K, vector<vector<ll>>(N, vector<ll>(M)));
#define vector4D(K, N, M, O, DP) vector<vector<vector<vector<ll>>>> DP(K, vector<vector<vector<ll>>>(N, vector<vector<ll>>(M, vector<ll>(O))));
#define zenbu(a) a.begin(), a.end()
#define rzenbu(a) a.rbegin(), a.rend()
#define rep(i, s, N) for(ll i{s}; i < N; i++)
#define rem(i, N, s) for(ll i{N}; i > s; i--)
using namespace std;using ll = long long;using ld = long double;using P = pair<ll,ll>;
template<typename T> T gcd(T a, T b){return b != 0 ? gcd(b, a % b) : a;}
template<typename T> struct UnionFind{vector<T> par;UnionFind(T n) : par(n, -1){}void init(T n){par.assign(n, -1);}T root(T x){if (par[x] < 0) return x;else return par[x] = root(par[x]);}bool issame(T x, T y){return root(x) == root(y);}bool merge(T x, T y){x = root(x); y = root(y);if(x == y) return false;if(par[x] > par[y]) swap(x, y);par[x] += par[y];par[y] = x;return true;}int size(int x) {return -par[root(x)];}};
template<typename T> ll combpm(T N_, T C_) {const int NUM_=400001;static ll fact[NUM_+1],factr[NUM_+1],inv[NUM_+1];if (fact[0]==0) {inv[1]=fact[0]=factr[0]=1;for (int i=2;i<=NUM_;++i) inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD;for (int i=1;i<=NUM_;++i) fact[i]=fact[i-1]*i%MOD, factr[i]=factr[i-1]*inv[i]%MOD;}if(C_<0 || C_>N_) return 0;return factr[C_]*fact[N_]%MOD*factr[N_-C_]%MOD;}

/* ここからコード開始 */

int main(){
  kyopro;
  string s;
  cin >> s;
  rep(i, 0, (ll)s.size()-1){
    if(s.substr(i, 2) == "BC"){
      s.replace(i, 2, "X");
    }
  }
  ll sum{}, bA{};
  rep(i, 0, (ll)s.size()){
    if(s[i] == 'A'){
      bA++;
    }
    else if(s[i] == 'X'){
      sum += bA;
    }
    else{
      bA = 0;
    }
  }
  cout << sum << rt;
}

Measured memory_bytes: 720
#include <bits/stdc++.h>
using std::cout;
using std::endl;
using std::cin;

int cost[2][2010][2010];

int main() {
	int n; cin >> n; std::vector<std::vector<int>> a(2, std::vector<int>(n));
	for(int i = 0; i < 2 * n; i++) {
		char x; int y; cin >> x >> y;
		
		a[x == 'W'][y - 1] = i;
	}
	
	for(int k = 0; k < 2; k++) {
		for(int i = 0; i < n; i++) {
			for(int j = i + 1; j < n; j++) {
				cost[k][i][n] += (a[k][j] < a[k][i]);
			}
			
			for(int j = n - 1; j >= 0; j--) {
				cost[k][i][j] = cost[k][i][j + 1] + (a[1 - k][j] < a[k][i]);
			}
		}
	}
	
	std::vector<std::vector<int>> dp(n + 1, std::vector<int>(n + 1, 1e9));
	dp[0][0] = 0;
	for(int i = 0; i <= n; i++) {
		for(int j = 0; j <= n; j++) {
			if(i < n) dp[i + 1][j] = std::min(dp[i + 1][j], dp[i][j] + cost[0][i][j]);
			if(j < n) dp[i][j + 1] = std::min(dp[i][j + 1], dp[i][j] + cost[1][j][i]);
		}
	}
	
	cout << dp[n][n] << endl;
	return 0;
}
	


Measured memory_bytes: 47488
import Data.List (sortBy)

main :: IO ()
main = do
    (_:ps) <- getParams
    print . solve $ sortDesc ps

getParams :: IO [Int]
getParams = map read . words <$> getContents

solve :: [Int] -> Int
solve (p:ps) = p `div` 2 + sum ps

sortDesc :: Ord a => [a] -> [a]
sortDesc = sortBy (flip compare)


Measured memory_bytes: 508
N = int(input())
A, B = [], []
for _ in range(N):
    a, b = tuple(map(int, input().split()))
    A.append(a)
    B.append(b)
count = 0
for i in range(N-1, -1, -1):
    if (A[i] + count) % B[i] == 0:
        continue
    count += (B[i] - ((A[i] + count) % B[i]))
print(count)

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

int dp[3010][3010];

int main(){
	
	char a[3010], b[3010], ans[3010];
	
	scanf("%s %s", &a, &b);
	
	int n = (int)strlen(a), m = (int)strlen(b), v = 0;
	
	for(int i = 0; i < n; i++){
		for(int j = 0; j < m; j++){
			if(a[i] == b[j]) dp[i][j] = ((i > 0 && j > 0) ? dp[i - 1][j - 1] : 0) + 1;
			else dp[i][j] = max(j > 0 ? dp[i][j - 1] : 0, i > 0 ? dp[i - 1][j] : 0);
		}
	}
	
	for(int i = n - 1, j = m - 1; i >= 0 && j >= 0; j--, i--){
		
		if(a[i] == b[j]) ans[v++] = a[i];
		else{
			
			if(j == 0) j++;
			else if(i == 0) i++;
			else if(dp[i][j - 1] > dp[i - 1][j]) i++;
			else j++;
		}
	}
	
	for(int i = dp[n - 1][m - 1] - 1; i >= 0; i--) printf("%c", ans[i]);
	if(v == 0) printf("");
	
}


Measured memory_bytes: 38956