akhauriyash/Code-Regression huggingface dataset:
a, b = map(int, input().split(" "))

c = [list(input()) for i in range(a)]

d = [False, 0]

for i in range(a):
    if d[0]:
        i -= d[1]
    if c[i] == ['.' for i in range(b)]:
        del c[i]
        d[0] = True
        d[1] += 1
a -= d[1]
c = list(map(list, zip(*c)))
d = [False, 0]

for i in range(b):
    if d[0]:
        i -= d[1]
    if c[i] == ['.' for i in range(a)]:
        del c[i]
        d[0] = True
        d[1] += 1
b -= d[1]

if len(c) == 1:
    print("#")
else:
    for i in list(map(list, zip(*c))):
        for j in range(b):
            print(i[j], end="")
        print()


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

int main() {
  int64_t N;
  cin >> N;
   vector<int64_t> vec(N+1);
   vec.at(0) = 2;
   vec.at(1) = 1;
  int64_t i;

  for (i = 2; i < N+1; i++) {
    vec.at(i) = vec.at(i - 1) + vec.at(i - 2);
  }
  
  cout << vec.at(N) << endl;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define DEBUG 0
#define nl          '\n'
#define fori(n)			for(int i = 0; i < n; ++i) 
#define forj(n)			for(int j = 0; j < n; ++j)
#define fork(n)			for(int k = 0; k < n; ++k)
#define forl(n)			for(int l = 0; l < n; ++l)
#define pq priority_queue
#define umap unordered_map
#define uset unordered_set
#define ppb push_back
typedef long long ll;typedef pair<int,int> pii;typedef vector<bool> vbool;
typedef vector<int> vint;typedef vector<ll> vll;typedef long double ld;
typedef vector<vector<int>> vvi; typedef vector<vbool> vvb;

const ll N = 200000;
const ll MOD = 1e9 + 7;

ll fact[N+1], inv[N+1]; //factorial and inverse factorial

ll power(ll b, ll e) {
	if (b == 0) return 0;
	if (b == 1 || e == 0) return 1;
	if (e%2) return (b * power(b, e-1))%MOD;
	else {
		ll ans = power(b, e/2);
		return (ans*ans)%MOD;
	}
}

void init() {
	fact[0] = 1;
	for(ll i = 1; i <= N; i++)
		fact[i] = (fact[i-1] * i) % MOD;
	inv[N] = power(fact[N], MOD-2);
	for(ll i = N-1; i >= 0; i--) 
		inv[i] = (i+1) * inv[i+1] % MOD; 
}

ll choose(ll n, ll k) {   
	ll ans = fact[n] * inv[k] % MOD * inv[n-k] % MOD;
	return ans;
}

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	init();
	ll n, k; cin >> n >> k;
	ll ans = 0;
	for(int m = 0; m <= min(n-1, k); m++) {
		ans += (choose(n-1, n-m-1) * choose(n, m) % MOD);
		ans %= MOD;
	}
	cout << ans << nl;
	#if DEBUG
	cerr << "Time: " << (ld)clock() / CLOCKS_PER_SEC << " s" << nl;
	#endif
	return 0;
}


Measured memory_bytes: 3328
k, n = map(int, input().split())
a = list(map(int, input().split()))

max_dist = 0
for i in range(n):
    nxt = (i+1) % n
    distance = a[nxt] - a[i]
    if distance < 0:
        distance += k
    max_dist = max(max_dist, distance)

print(k-max_dist)

Measured memory_bytes: 26444
#include <cstdio>
#include <cstring>

int main() {
    int n;
    char s[110], t[110];
    while (scanf("%d", &n) == 1) {
        scanf("%s%s", s, t);
        int ans = n * 2;
        for (int i = 0; i < n; ++i) {
            bool yes = 1;
            for (int j = i; j < n; ++j)
                if (s[j] != t[j-i]) {
                    yes = 0;
                    break;
                }
            if (yes) {
                ans = i + n;
                break;
            }
        }
        printf("%d\n", ans);
    }
    return 0;
}


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

using namespace std;

// MACROS

#define ll long long
#define ull unsigned long long
#define ld long double

#define vi vector<int>
#define vll vector<ll>
#define vld vector<ld>
#define u_s unordered_set

#define pii pair<int,int>
#define pll pair<ll,ll>

#define FOR(i, n) for (ll (i) = 0; i < n; i++)
#define FORN(i, a, b) for (ll (i) = a; i < b; i++)
#define FORE(i, l) for (auto (i) : l)

#define pb push_back
#define pob pop_back
#define emp emplace
#define fi first
#define se second

#define all(n) (n).begin(), (n).end()
#define in(n) cin >> (n);
#define debug(n) cout << #n << ": " << n << '\n';

// FUNCTIONS

template< typename T >
inline T gcd(T a, T b) { if (b) return gcd(b, a % b); return a; }

template< typename T >
inline T ext_gcd(T a, T b, T & x, T & y) { if (a == 0) { x = 0; y = 1; return b; } T x1, y1; T g = ext_gcd(b % a, a, x1, y1); x = y1 - (b / a) * x1; y = x1; return g; }

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);	
    //cout << setprecision(15);
    ll n;
    cin >> n;
    bool works = true;
    FOR(i, n)
    {
        ll x;
        cin >> x;
        works &= (x % 2 == 1 || x % 3 == 0 || x % 5 == 0);
    }
    if (works) cout << "APPROVED\n";
    else cout << "DENIED\n";
}



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

using ll = long long;
#define ALL(c) (c).begin(), (c).end()
const int MOD = 1000000007;

int main() {
    int r, d, x;
    cin >> r >> d >> x;

    for (int i = 0; i < 10; i++) {
        x = r * x - d;
        cout << x << endl;
    }
}


Measured memory_bytes: 256
from itertools import accumulate
def main():
    n,k = map(int, input().split())
    s = list(input())
    ls = []

    cnt = 0
    buf = '1'
    for ele in s:
        if ele != buf:
            ls.append(cnt)
            cnt = 1
            buf = ele
        else:
            cnt += 1
    ls.append(cnt)

    if buf == '0':
          ls.append(0)

    w = 2*k+1
    if w >= len(ls):
          print(n)
    else:
          acc = [0] + list(accumulate(ls))
          ans = 0
          for i in range(0,len(ls)-w+1,2):
               ans = max(ans,acc[i+w]-acc[i])
          print(ans)

main()

Measured memory_bytes: 9380
#include <bits/stdc++.h>
#define ll long long
#define For(i,a,b) for (int i=a;i<=b;i++)
#define fi first
#define se second
#define pb push_back
#define dscan(x) scanf("%d", &x)
#define lldscan(x) scanf("%lld", &x)
#define task "A"
using namespace std;

/*~~~~~~~~~~~~~~~~~~~~SET YOUR MAXIMUM N VALUE HERE~~~~~~~~~~~~~~~~~~~~*/

const ll maxn = 1000007;
const ll inf = 1000000007;

/*~~~~~~~~~~~~~~~~~~~~VARIABLES~~~~~~~~~~~~~~~~~~~~*/

ll a, b;
ll ans;

/*~~~~~~~~~~~~~~~~~~~~FUNCTIONS & PROCEDURES~~~~~~~~~~~~~~~~~~~~*/

void open() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen(task".inp","r",stdin);
    //freopen(task".out","w",stdout);
}

void read() {
    open();
    lldscan(a); lldscan(b);
}

void solve() {
    if ((a+b)%2==0) printf("%lld\n", abs((a+b)/2)); else printf("IMPOSSIBLE\n");
}

/*~~~~~~~~~~~~~~~~~~~~MAIN~~~~~~~~~~~~~~~~~~~~*/

int main()
{
    read();
    solve();
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,count=0,sum,m,dip;
  cin>>a>>b>>c;
  for(int i=1;i<=a;++i){
    sum=0,m=i;
    while(m>0){
      dip=m%10;
      sum+=dip;
      m=m/10;
    }
    if(sum>=b&&c>=sum){
      count+=i;
    }
  }
  cout<<count<<endl;
}

Measured memory_bytes: 384
#include <stdio.h>

int main(void){
  int x, y, z,cnt=0;
  scanf("%d %d %d",&x, &y, &z);
  x -= z;
  while(x>=0){
    x -=  z;
    x -= y;
    cnt++;
  }
  printf("%d\n",cnt-1);
  return 0;
}

Measured memory_bytes: 128
#define _USE_MATH_DEFINES
#include<stdio.h>
#include<string>
#include<iostream>
#include<cctype>
#include<cstdio>
#include<vector>
#include<stack>
#include <algorithm>
#include<math.h>
#include<set>
#include<map>
#include<iomanip>

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



using namespace std;




int main() {
	
	set<int>p;
	int a,b,c;
	cin>>a>>b>>c;
	p.insert(a);
	p.insert(b);
	p.insert(c);
	cout<<p.size()<<endl;

    return 0;
}

	
	


	

Measured memory_bytes: 256
class BIT(object):
    def __init__(self, n):
        self.n = n
        self.bit = [0] * (n + 1)

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

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


def main():
    n = int(input())
    *a, = map(int, input().split())
    small, large = 0, max(a)
    criteria = n * (n + 1) // 4

    while large - small > 1:
        mid = (small + large) // 2
        num = 0
        b = BIT(2 * n + 1)
        suma = 0
        b.add(suma + n + 1, 1)
        for aa in a:
            suma += 1 if aa <= mid else -1
            num += b.sum(suma + n)
            b.add(suma + n + 1, 1)

        if num > criteria:
            large = mid
        else:
            small = mid
    print(large)


main()


Measured memory_bytes: 108960
//It doesn't matter how slow you go, Unless you don't stop.
#include<iostream>
#include<algorithm>
#include<bitset>
 
#include<cmath>
#include<cstring>
#include<climits>
 
#include<deque>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
 
#include<fstream>
#include<chrono>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
using namespace std;
 
typedef long long LL;
typedef pair<LL,LL> p64;
typedef vector<LL> v64;
typedef map<LL,LL> mp64;
 
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define rep(i,s,e) for(long long i=s;i<=e;i++)
#define brep(i,s,e) for(long long i=s;i>=e;i--)
#define all(x) x.begin(),x.end()
#define mem(x,y) memset(x,y,sizeof(x))
#define DANGER std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
 
void solve()
{
     string s;
     vector<char> v;
     cin>>s;
     int len = s.length();
     int queries;cin>>queries;
     int j=0;
     int x = 0;
     while(queries--)
     {
         int type;cin>>type;
         if(type==1)//reverse
         {
             if(j==0)
             {
                 j = len-1;
             }
             else
             {
                 j = 0;
             }
             x = !x;             
         }
         else
         {
             int type2;cin>>type2;
             char c;cin>>c;
             if(type2 == 1)//start me add
             {
                 if(x==1)
                 {
                     s += c;
                 }
                 else
                 {
                     v.pb(c);
                 }
                 
             }
             else//end m add
             {
                 if(x==1)
                 {
                     v.pb(c);
                 }
                 else
                 {
                     s += c;
                 }
                 
             }
             
         }         
     }
     if(x==1)
     {
         reverse(s.begin(),s.end());
         for(auto it:v)
         {
             s += it;
         }
         cout<<s<<endl;
     }
     else
     {
         string new_s="";
         for(auto it:v)
         {
             new_s += it;
         }
         reverse(new_s.begin(),new_s.end());
         new_s += s;
         cout<<new_s<<endl;
     }
     //cout<<s<<endl;
     
}
 
int main()
{
    DANGER;
    ofstream out("output.txt");
 
    auto start = chrono::high_resolution_clock::now();
    
    LL t = 1;
    // cin>>t;
    rep(test,1,t)
    {
        solve();
    }
    
    auto stop = chrono::high_resolution_clock::now();
     auto duration = chrono::duration_cast<chrono::milliseconds>(stop - start); 
    // cout << "Time taken by function: " << duration.count() << " milliseconds" << endl;
}

Measured memory_bytes: 1320
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

# dijkstra -- START --
def dijkstra(n,s,edge):
  d=[inf]*n
  used=[False]*n
  d[s]=0
  used[s]=True
  pq=[]
  for e in edge[s]:
    heapq.heappush(pq,e)
  while pq:
    c,v=heapq.heappop(pq)
    if used[v]:
      continue
    d[v]=c
    used[v]=True
    for nc,nv in edge[v]:
      if not used[nv]:
        nd=nc+c
        if d[nv]>nd:
          heapq.heappush(pq,(nd,nv))
  return d
# dijkstra --- END ---

def main():
  n=I()
  e=[[] for _ in range(n)]
  for _ in range(n-1):
    a,b,c=LI()
    a-=1
    b-=1
    e[a].append((c,b))
    e[b].append((c,a))

  q,k=LI()
  d=dijkstra(n,k-1,e)

  ans=[]
  for _ in range(q):
    x,y=LI()
    x-=1
    y-=1
    dist=d[x]+d[y]
    ans.append(dist)

  for x in ans:
    print(x)

main()
# print(main())


Measured memory_bytes: 51240
#include<cstdio>
#include<cstring>
#include<vector>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
char s[2][60];
vector <int> k;
int main()
{
	ll n;
	cin>>n;
	cin>>s[0]>>s[1];
	for(int i=0;i<n;i++)
	{
		if(s[0][i]==s[1][i])
			k.push_back(0);
		else
		{
			k.push_back(1);
			i++;
		}
	}
	ll ans;
	if(k[0]==1)
		ans=6;
	else 
		ans=3;
	for(int i=1;i<k.size();i++)
	{
		if(k[i]==0&&k[i-1]==0)
			ans*=2;
		else if(k[i]==1&&k[i-1]==0)
			ans*=2;
		else if(k[i]==0&&k[i-1]==1)
			ans*=1;
		else if(k[i]==1&&k[i-1]==1)
			ans*=3;
		ans=ans%mod;
	}
	cout<<ans;
	cout<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  vector< int > time;
  for(int k = 0; k < 2; k++){
    scanf("%d", &N);
    while(N--){
      int h, m;
      scanf("%d %d", &h, &m);
      time.push_back(h * 60 + m);
    }
  }
  sort( time.begin(), time.end());
  time.erase( unique(time.begin(), time.end()), time.end());
  for(int i = 0; i < time.size(); i++){
    if(i > 0) putchar(' ');
    printf("%d:%02d", time[i] / 60, time[i] % 60);
  }
  putchar('\n');
}

Measured memory_bytes: 1228
n,k,*h=map(int,open(0).read().split())
a=[0]*n
for i in range(1,n):
    j=max(0,i-k)
    e=h[i]
    a[i]=min(A+abs(e-H) for A,H in zip(a[j:i],h[j:i]))
print(a[-1])

Measured memory_bytes: 13876
#include<stdio.h>

int main(){

    unsigned int n, x;
    unsigned int i, j, k;
    unsigned int counter = 0;

    while (1){

        scanf("%d%d", &n, &x);

        if( n == 0 && x == 0 ){
            break;
        }

        for( i = 1; i <= n; i++ ){
            for( j = 1; j < i; j++ ){
                for ( k = 1; k < j; k++ ){
                    if( i + j + k == x){
                        // printf("%d %d %d\n", i, j, k);
                        counter += 1;
                    }
                }
            }
        }

        printf("%d\n", counter);
        counter = 0;

    }

    return 0;
    
}


Measured memory_bytes: 2684
#include<bits/stdc++.h>
using namespace std;
string s[105];
int main()
{
    int n,l;
    cin>>n>>l;
    for(int i=1;i<=n;i++) cin>>s[i];
    sort(s+1,s+1+n);
    for(int i=1;i<=n;i++) cout<<s[i];
    cout<<endl;
}


Measured memory_bytes: 256
def is_integer_num(n):
    if isinstance(n, int):
        return True
    if isinstance(n, float):
        return n.is_integer()
    return False

A, B = map(int, input().split())
a = (A + B) / 2
if is_integer_num(a):
    print(int(a))
else:
    print("IMPOSSIBLE")

Measured memory_bytes: 2940
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
using namespace std;

int main(){
    int c[3][3];
    for(int i=0; i<3; i++){
        for(int j=0; j<3; j++){
            cin>>c[i][j];
        }
    }
    
    int correct=0;
    for(int a1=0; a1<=100; a1++){
        for(int a2=0; a2<=100; a2++){
            for(int a3=0; a3<=100; a3++){
                if(c[0][0]-a1==c[1][0]-a2 && c[1][0]-a2==c[2][0]-a3){
                    if(c[0][1]-a1==c[1][1]-a2 && c[1][1]-a2==c[2][1]-a3){
                        if(c[0][2]-a1==c[1][2]-a2 && c[1][2]-a2==c[2][2]-a3){
                            correct=1;
                        
                        }
                    }
                }
                
                
            }
        }
    }
    
    if(correct){cout<<"Yes"<<endl;}
    else{cout<<"No"<<endl;}
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <vector>
using namespace std;
#define N (200010)
typedef long long LL;
#define PB push_back
int n, m;
int f[N][2], lx[N], ly[N];
vector <int> v[N];
int main(){
    scanf("%d%d", &n, &m);
    for (int i = 1, a, b; i <= m; ++i){
        scanf("%d%d", &a, &b);
        v[a].PB(b);
        v[b].PB(a);
    }
    f[1][0] = 1;
    lx[0] = 1;
    ly[0] = 0;
    for (int op = 0, cl = 1; op < cl; op++){
        int x = lx[op], y = ly[op], z;
      
        for (auto it = v[x].begin(); it != v[x].end(); ++it){
            if (!f[z = *it][!y]){
                f[z][!y] = 1;
                lx[cl] = z;
                ly[cl++] = !y;
            }
        }
    }
    int od = 0;
    for (int i = 1; i <= n; ++i){
        od += f[i][1];
    }
    LL ans = 0, al = 0;
    for (int i = 1; i <= n; ++i){
        if (f[i][0]){
            if (f[i][1]){
                ans += (od - 1);
                al++;
            }
            else {
                ans += od;
            }
        }
    }
    printf("%lld\n", ans-m - al*(al-1)/2);
}

Measured memory_bytes: 10496
#include <stdio.h>
#include <stdlib.h>

int main(){
  int *array;
  int n;
  int m;
  scanf("%d", &n);
  array = (int*)malloc(sizeof(int) * n);
  for(int i = 0; i < n; i++){
    array[i] = 0;
  };
  for(int i = 0; i < (n - 1); i++){
    scanf("%d", &m);
    array[m - 1] += 1;
  };
  for(int i = 0; i < n; i++){
    printf("%d\n", array[i]);
  };
  
  return 0;
  
}

Measured memory_bytes: 2512
import scala.io.StdIn.{readInt, readLine}

object Main extends App {

  val n = readInt()
  val in = readLine().split(' ')
  val a = Array.fill(n)(0)
  val b = Array.fill(n + 1)(0L)
  val mod = 1000000007

  for (i <- 0 until n) {
    a(i) = in(i).toInt
    b(i + 1) = b(i) + a(i)
  }

  var ans = 0L

  for (i <- 0 until n) {
    val sum = (b(n) - b(i + 1)) % mod

    ans += a(i) * sum
    ans %= mod
  }
  println(ans)
}


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

int main(){
    int x = 0;
    int max = 0;
    int n;
    string s;    
    cin >> n >> s;
    for(int i = 0; i < n; i++){
        if(s[i] == 'I') x++;
        else x--;
        
        if(max < x) max = x;
    }
    cout << max << endl;
}

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

int main(){
	int N;
	cin >> N;
	int ans=0;
	if(N==10 || N==100 || N==1000 || N==10000 || N==100000)ans=10;
	else{
		while(N>0){
			ans+=N%10;
			N/=10;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <functional>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <sstream> //stringstream
#include <cstring> // getline
#include <cmath>
#include <unordered_set>
#include <limits>
#include <unordered_map>

#define _CRT_SECURE_NO_WARNINGS
#define ll 				long long int
#define FOR(i, b, e)    for (ll i =(b)-((b)>(e));i!=(e)-((b)>(e));i += 1-2*((b)>(e)))
#define EPS  			1e-9
#define all(v) 			v.begin(),v.end()
#define X 				first 
#define Y 				second
#define IO 				std::ios_base::sync_with_stdio(0);cin.tie(NULL);
#define MAXI 			100005
#define endl 			'\n'
#define re   			return
#define mp				make_pair
#define NumofDigits(n)  ((int)log10(n)+1)
#define fixedpre(n)     fixed<<setprecision(n);

using namespace std;

ll pw(ll b, ll p) { if (!p) re 1; ll sq = pw(b, p / 2); sq *= sq; if (p % 2) sq *= b; re sq; }
ll gcd(ll a, ll b) { re(b == 0 ? a : gcd(b, a % b)); }
ll lcm(ll a, ll b) { re((a*b) / gcd(a, b)); }
bool cmp(double a, double b) { re abs(a - b)<EPS; }
bool isint(double a) { re cmp(a, round(a)); }

const double PI = acos(-1);
ll OO = 1e18 + 8;
int oo = 1e9 + 9;

//freopen("input.txt", "r", stdin);
//freopen ("output.txt","w",stdout);

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

int n, m;
vector<vector<int>> adj(MAXI);
ll dp[MAXI];

ll maxPath(int node)
{
	if (adj[node].size() == 0) re 0;

	ll &ret = dp[node];
	if (~ret) re ret;
	ret = 0;

	for (auto i : adj[node])
		ret = max(ret, maxPath(i) + 1);

	re ret;
}

int main()
{
	IO;
	cin >> n >> m;
	int f, t;
	FOR(i, 0, m)
		cin >> f >> t,
		adj[f].push_back(t);

	memset(dp, -1, sizeof dp);
	ll maxi = 0;
	FOR(i, 1, n + 1)
		maxi = max(maxi, maxPath(i));

	cout << maxi << endl;
	re 0;
}

Measured memory_bytes: 7936
#include<bits/stdc++.h>
using namespace std;
#define maxn 810
#define INF 0x3f3f3f3f
char s[maxn][maxn];
int dx[]={0,0,1,-1};
int dy[]={1,-1,0,0};
int n,m,k;
int dis[maxn][maxn];
int get_dis(int x,int y)
{
    int tmp=min(min(x,n-1-x),min(y,m-1-y));
    if(tmp==0) return 0;
    return (tmp+k-1)/k;
}
#define P pair<int,int>
void bfs()
{
    queue<P>Q;
    while(!Q.empty()) Q.pop();
    for(int i=0;i<n;++i)
    {
        for(int j=0;j<m;++j)
        {
            if(s[i][j]=='S')
            {
                Q.push(P(i,j));
                dis[i][j]=0;
            }
            else dis[i][j]=INF;
        }
    }
    while(!Q.empty())
    {
        P tmp=Q.front(); Q.pop();
        int x=tmp.first,y=tmp.second;
        for(int i=0;i<4;++i)
        {
            int nx=x+dx[i],ny=y+dy[i];
            if(nx<0||nx>=n||ny<0||ny>=m||s[nx][ny]=='#'||dis[nx][ny]!=INF) continue;
            dis[nx][ny]=dis[x][y]+1;
            if(dis[nx][ny]<k) Q.push(P(nx,ny));
        }
    }
}
int main()
{
    scanf("%d%d%d",&n,&m,&k);
    for(int i=0;i<n;++i) scanf("%s",s[i]);
    bfs();
    int ans=INF;
    for(int i=0;i<n;++i)
        for(int j=0;j<m;++j)
        {
            if(dis[i][j]>=INF) continue;
            ans=min(ans,1+get_dis(i,j));
        }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 3456
#include <iostream>
#include <vector>
#include <limits>
#include <boost/range/irange.hpp>
#include <boost/range/adaptors.hpp>
#include <array>
using namespace std;
using namespace boost;
using uint = unsigned int;
using ll = long long int;
using ull = unsigned long long int;

int main() {
    array<bool, 100> alice;
    array<bool, 100> bob;
    alice.fill(false);
    bob.fill(false);
    uint A, B, C, D;
    cin >> A >> B >> C >> D;
    for (auto &&i: irange(A, B)){
        alice.at(i) = true;
    }
    for (auto &&i: irange(C, D)){
        bob.at(i) = true;
    }
    uint count{0};
    for (auto &&i: irange(0U, 100U)){
        if (alice.at(i) && bob.at(i))count++;
    }
    cout << count;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

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

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}
int sgn(const double&r){return (r>EPS)-(r<-EPS);} // a>0  : sgn(a)>0
int sgn(const double&a,const double&b){return sgn(a-b);} // b<=c : sgn(b,c)<=0

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,m;
	cin>>n>>m;
	vl o(m);
	vs s(m);
	vb ac(n,false);
	vl pe(n);
	rep(i,m){
		cin>>o[i]>>s[i];
		o[i]--;
		if(s[i]=="AC"){
			ac[o[i]]=true;
		}
		else{
			if(!ac[o[i]])pe[o[i]]++;
		}
	}
	ll a=0,p=0;
	rep(i,n){
		if(ac[i]){
			a++;
			p+=pe[i];
		}
	}
	puta(a,p);

}


Measured memory_bytes: 7296
import java.math.*;
import java.util.*;


public class Main {

    public static void main(String args[]){
        Scanner scan =new Scanner(System.in);
        int Th =scan.nextInt();
        int Ts=scan.nextInt();
        int Ah =scan.nextInt();
        int As=scan.nextInt();
        int i=0;
        while(Th>0 && Ah>0){
            
            if(i%2==0){
                Ah=Ah-Ts;
            }
            else if(i%2==1){
                Th=Th-As;
            }
           
            i++;
        }
        if(Ah<=0){
            System.out.print("Yes");
        }
        else if(Th<=0){
            System.out.println("No");
        }
    }

}


Measured memory_bytes: 35820
A = int(input())
B = int(input())
C = int(input())
D = int(input())

# 電車とバスを乗り継いで旅行をする計画を立てた。
# 電車は旅程に沿って通常のきっぷを買うと A円、乗り放題きっぷを買うと B円 かかる。
# バスは旅程に沿って通常のきっぷを買うと C円、乗り放題きっぷを買うと D円 かかる。
# 電車およびバスについて通常の切符を買うか乗り放題きっぷを買うかをうまく選んだときの、運賃の合計の最小値を求めてください。

a = A + C
b = A + D
c = B + C
d = B + D
print(min(a, b, c, d))

Measured memory_bytes: 8988
#include<bits/stdc++.h>
using namespace std;
signed main(){
  int n;
  while(cin>>n,n){
    char c[150];
    int sum=0,a,ans[810]={};
    cin>>c;
    a=n-1;
    n=0;
    for(int i=0;i<=100;i++){
      if(c[i]=='M'){
	ans[n]++;
      }
      if(c[i]=='S'){
	ans[n]++;
	sum+=ans[n];
	ans[n]=0;
      }
      if(c[i]=='L'){
	ans[n]++;
	ans[n]+=sum;
	sum=0;
      }
      n++;
      if(n>a){
	n=0;
      }
    }
    sort(ans,ans+a+1);
    for(int i=0;i<=a;i++){
      cout<<ans[i]<<' ';
    }
    cout<<sum<<'\n';
  }
  return(0);
}
	
	
      



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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)
#define PI 3.14159265358979323846

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

//-----------------------------------------------------------------------------

#define INIT INF
typedef int Weight;
typedef pair<Weight,int> P;

typedef pair<P,int> PP;

int c,n,m,s,g;

struct Edge {
	int to;
	Weight cost;
	Edge(int to,Weight cost):to(to),cost(cost) {}
};

typedef vector< vector<Edge> > Graph;

bool operator<(const Edge &e,const Edge &f) {
	return e.cost!=f.cost?e.cost>f.cost:e.to<f.to;
}

void dijkstra(const Graph &G,int s,vector< vector<Weight> > &dist) {
	int n=(int)G.size();
	dist.assign(n,vector<Weight>(c+1,INIT));
	dist[s][0]=0;
	priority_queue< PP,vector<PP>,greater<PP> > Q;
	Q.push(PP(P(0,s),0));
	while(!Q.empty()) {
		PP p=Q.top();Q.pop();
		int v=p.first.second,times=p.second;
		if(dist[v][times]<p.first.first) continue;
		for(auto e:G[v]) {
			if(dist[e.to][times]>dist[v][times]+e.cost) {
				dist[e.to][times]=dist[v][times]+e.cost;
				Q.push(PP(P(dist[e.to][times],e.to),times));
			}
			if(times+1<=c&&dist[e.to][times+1]>dist[v][times]+e.cost/2) {
				dist[e.to][times+1]=dist[v][times]+e.cost/2;
				Q.push(PP(P(dist[e.to][times+1],e.to),times+1));
			}
		}
	}
}

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

	while(true) {
	cin>>c>>n>>m>>s>>g;
	if(c==0&&n==0&&m==0&&s==0&&g==0) break;
	s--,g--;
	Graph G(n);
	vector< vector<Weight> > dist(n,vector<Weight>(c+1));
	REP(i,m) {
		int a,b;Weight c;
		cin>>a>>b>>c;
		a--,b--;
		G[a].emplace_back(b,c);
		G[b].emplace_back(a,c);
	}
	dijkstra(G,s,dist);
	Weight ans=INIT;
	REP(i,c+1) ans=min(ans,dist[g][i]);
	cout<<ans<<endl;
	}

	return 0;
}



Measured memory_bytes: 3200
//! ----------------------------------------------
//! Framework <https://github.com/vain0x/procon>
//!
//! See the bottom of file for solution.
//! ----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

/// Print values to standard error if debug mode.
#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

/// Read from standard input and parse each word.
/// - `read!(T, U, ..)` parses a line as a tuple of words.
/// - `read![[T]]` parses a line as an array of words.
/// - `read![..; N]` parses `N` lines, using `read!(..)` repeatedly.
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

/// Read a line from standard input.
#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();

    #[allow(deprecated)]
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

fn main() {
    let (N, Q) = read!(usize, usize);
    let S = rl();

    // acc[i] = (S[..i] に部分文字列として出現する AC の個数)
    let mut acc = vec![0; N + 1];
    for i in 0..N {
        acc[i + 1] = acc[i];

        if S[..i + 1].ends_with("AC") {
            acc[i + 1] += 1_usize;
        }
    }

    for (l, r) in read![usize, usize; Q] {
        let count = acc[r] - acc[l];
        println!("{}", count);
    }
}


Measured memory_bytes: 6908
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc  __builtin_popcountl
#define m_p make_pair
#define inf 1000000000000000000ll
#define MAXN 1000001
#define eps 0.0000000001
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>//usage rand<long long>()
T rand() {
    return uniform_int_distribution<T>()(rng);
}

// string to integer stuuu()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();

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

#define S second
#define F first
#define int long long  
///////

long long powerm(long long x, unsigned long long y, long long p) 
{ 
    long long res = 1;
    x = x % p;
    while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x) % p; 
        y = y>>1;
        x = (x*x) % p;   
    } 
    return res; 
} 

signed main()
{
	fastio;
	#ifdef ANIKET_GOYAL
		freopen("inputf.in","r",stdin);
		freopen("outputf.in","w",stdout);
	#endif
	string s;
	cin>>s;
	int mo=1000000007;
	int n=s.length();
	int ans=0;
	int c=0;
	for(int i=0;i<n;++i)
	{
		if(s[i]=='1')
		{
			ans+=(powerm(3,n-i-1,mo)*powerm(2,c,mo))%mo;
			++c;
			ans%=mo;
		}
	}
	ans+=powerm(2,c,mo);
	ans%=mo;
	cout<<ans;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define ll unsigned long long int
using namespace std;
int main()
{
    ll n,a,b,i,j,ans;
    while(cin>>a>>b>>n)
    {
       /*if(a==0)
        {
            cout<<b/n +1<<endl;
        }*/
         if(a%n==0||b%n==0)
            cout<<(b-a)/n +1<<endl;
        else
            cout<<(b/n)-(a/n)<<endl;

    }
    return 0;

}


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

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


X = max(max(x), A)

dp = [[0 for i in range(2*N*X+1)] for j in range(N+1)]

dp[0][N*X] = 1

y = []

for i in range(N):
    tmp = x[i]-A
    y.append(tmp)

for i in range(N):
    for j in range(2*N*X+1):
        if j-y[i]<0 or j-y[i]>2*N*X:
            dp[i+1][j] = dp[i][j]
        else:
            dp[i+1][j] = dp[i][j] + dp[i][j-y[i]]
            
print(dp[N][N*X]-1)


Measured memory_bytes: 5744
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i)
#define all(x) (x).begin(),(x).end()
const int INF = 1000000007;
typedef long long ll;
using namespace std;
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; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
ll fac(ll a) { return a > 1 ? fac(a - 1) * a : 1; }
int solve(){
  int n;
  cin >> n;
  long double tmp = 0;
  vector<int>v(n);
  rep(i,n){
    cin >> v[i];
    tmp += v[i];
  }
  tmp /= (long double)n;
  int ans;
  long double ansn = INF;
  rep(i,n){
    if(abs(tmp - v[i]) < ansn){
      ansn = abs(tmp - v[i]);
      ans = i;
    }
  }
  cout << ans << endl;
  return 0;
}
int main(){
  ios::sync_with_stdio(false);cin.tie(nullptr);
  solve();
  return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var N, K, uc, oc int
	fmt.Scan(&N, &K)
	var r float64
	for i := 1; i <= N; i++ {
		if i < K {
			uc++
		} else {
			oc++
		}
	}
	r += float64(oc) / float64(N)
	for i := 1; i <= N; i++ {
		if i >= K {
			break
		}
		r += 1 / (float64(N) * float64(calc(i, K)))
	}
	fmt.Println(r)
}
func calc(n, k int) int {
	w := n
	r := 0
	if w >= k {
		return 1
	}
	for w < k {
		w *= 2
		r++
	}
	return Pow(2, r)
}
func Pow(x int, n int) int {
	r := 1
	for n > 0 {
		if (n & 1) == 1 {
			r *= x
		}
		x *= x
		n = n >> uint(1)
	}
	return r
}

Measured memory_bytes: 512
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner scanner= new Scanner(System.in);
		String[] str = scanner.nextLine().split(" ");
		Deque<Integer> stack = new LinkedList<Integer>();

		for (int i=0; i<str.length; i++) {
			char c = str[i].charAt(0);
			if(c>='0' && c<='9'){
				stack.add(Integer.parseInt(str[i]));
			}else {
				int x = stack.pollLast();
				int y = stack.pollLast();
				switch(c){
					case '+':stack.add(x+y); break;
					case '-':stack.add(y-x); break;
					case '*':stack.add(x*y); break;
				}
			}
		}

		System.out.println(stack.poll());
	}
}



Measured memory_bytes: 26140
A = []
for _ in range(3):
    A.extend([int(x) for x in input().rstrip().split()])
N = int(input().rstrip())
for i in range(N):
    tmp = int(input().rstrip())
    for j, x in enumerate(A):
        if A[j] == tmp:
            A[j] = 'o'
if A[0] == 'o' and A[1] == 'o' and A[2] == 'o':
    print('Yes')
elif A[3] == 'o' and A[4] == 'o' and A[5] == 'o':
    print('Yes')
elif A[6] == 'o' and A[7] == 'o' and A[8] == 'o':
    print('Yes')
elif A[0] == 'o' and A[3] == 'o' and A[6] == 'o':
    print('Yes')
elif A[1] == 'o' and A[4] == 'o' and A[7] == 'o':
    print('Yes')
elif A[2] == 'o' and A[5] == 'o' and A[8] == 'o':
    print('Yes')
elif A[0] == 'o' and A[4] == 'o' and A[8] == 'o':
    print('Yes')
elif A[2] == 'o' and A[4] == 'o' and A[6] == 'o':
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3064
#include <iostream>
#include <stdlib.h>

using namespace std;

struct info{
	int t;
	int w;
};

void func(info *a, int n)
{
	info tm;
	for(int i = n; i >= 1; i--){
		for(int j = 2; j <= i; j++){
			if(a[j].w < a[j-1].w){
				tm = a[j];
				a[j] = a[j-1];
				a[j-1] = tm;
			}
		}
	}
	
	return ;
}

int main(int argc, char **argv)
{
	int n, t;
	info *a;
	
	while(1){
		cin >> n;
		if(n == 0){
			break;
		}
		a = (info *)calloc(n+1, sizeof(info));
		
		for(int i = 1; i <= n; i++){
			cin >> a[i].t >> a[i].w;
		}
		func(a, n);
		
		t = 0;
		for(int i = 1; i <= n; i++){
			t += a[i].t;
			if(t > a[i].w){
				n = 0;
				break;
			}
		}
		
		if(n == 0){
			cout << "No" << endl;
		} else {
			cout << "Yes" << endl;
		}
		
		free(a);
	}
	
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
using namespace std;
long long int a[100006];
int main () {
    int N;
    cin >> N;
    for (int i=0; i<N; i++) {
        int x;
        cin >> x;
        a[x]++;
    }
    long long int q, sum=0;
    cin >> q;
    for (int i=1; i<=100000; i++) {
            if (a[i]>0) {
                sum+=a[i]*i;
            }
        }
    for (int i=0; i<q; i++) {
        long long int b, c;
        cin >> b >> c;
        sum-=a[b]*b;
        sum+=a[b]*c;
        a[c]+=a[b];
        a[b]=0;
        cout << sum << endl;
    }
}

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

using namespace std;

int main()
{
    string s;
    cin >>s;
    bool flg=true;
    if(s[0]==s[1]&&s[0]==s[2])flg=false;
    if(flg)puts("Yes");
    else puts("No");
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)a;i<(int)b;++i)
int main(){
    while(1){
        int h,w;cin>>h>>w;
        if(h==0&&w==0)return 0;
        rep(i,h){
            rep(j,w){
                if((i%2==0&&j%2==0)||(i%2!=0&&j%2!=0))cout<<"#";
                else cout<<".";
            } 
            cout<<endl;
        }
        cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 3112
#include<bits/stdc++.h>
//g++ -std=c++11 

using namespace std;
typedef long long ll;

#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define DIV 1000000007 //10^9+7

ll memo[30];
ll memo2[200005][30];

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

	string ss = s + s;

	rep(i, 30) memo[i] = -1;

	for(ll i = ss.size() - 1; i >= 0; i--) {
		rep(j, 30) {
			if(memo[j] != -1) {
				memo2[i][j] = memo[j] - i;
			} else {
				memo2[i][j] = -1;
			}
		}
		ll ch = ss[i] - 'a';
		memo[ch] = i;
	}

	ll cur = -1;
	rep(i, s.size()) {
		if(t[0] == s[i]) {
			cur = i;
			break;
		}
	}
	if(cur == -1) {
		cout << "-1" << endl;
		return 0;
	}

	for(ll i = 1; i < t.size(); i++){
		ll ch = t[i] - 'a';
		if(memo2[cur%s.size()][ch] == -1) {
			cout << "-1" << endl;
			return 0;
		}
		cur += memo2[cur%s.size()][ch];
	}
	cout << cur + 1 << endl;
}



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

using namespace std;
#define lint long long

int main() {
    int N, W;
    cin >> N >> W;
    
    int w[N], v[N];
    
    for(int i = 0; i < N; ++i){
        cin >> w[i] >> v[i];
    }
    
    lint dp[W + 1];
    memset(dp, 0, sizeof(dp));
    
    for(int i = 0; i < N; ++i){
        for(int j = W - w[i]; j >= 0 ; --j){
            if(dp[j] > 0){
                dp[j + w[i]] = max(dp[j + w[i]], dp[j] + v[i]);
            }
        }
        dp[w[i]] = max(dp[w[i]],(lint)v[i]);
    }
    lint ans = 0;
    for(int i = 0; i < W + 1; ++i){
        ans = max(ans, dp[i]);
    }
    cout << ans << endl;
}
    


Measured memory_bytes: 1024
N = int(input())
W = list(map(int,input().split()))
sum_W = sum(W)

ans = float('inf')
for i in range(N):
  #print(W[:i+1])
  sum1 = sum(W[:i+1])
  sum2 = sum_W-sum1
  dif = abs(sum1-sum2)
  ans = min(ans,dif)
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
const int INF = 1e9+1;
 
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 D, G;
    cin >> D >> G;
    vector<int> p(D),c(D),comp(D);
    for (int i = 0; i < D; i++) {
        cin >> p[i] >> c[i];
    }
    for (int i = 0; i < D; i++) {
        comp[i] = 100 * (i+1) * p[i] + c[i]; //ボーナス付き総得点
    }

    int res = INF;

    for (int bit = 0; bit < (1 << D); bit++) {
        int point = 0;
        int count = 0;
        int k = 0;
        for (int i = 0; i < D; i++) {
            if (bit & 1 << i) { //フラグが立っていれば
                point += comp[i];
                count += p[i]; //全問解いた
            } else {
                k = i;  //kは大きいやつに変更されていく
            }
        }   
        if (point < G) {
            int j = 0;
            while (point < G) {
                if (j == p[k]-1) { //コンプリートしたらあかん       
                    break;
                }
                point += 100 * (k+1); //単価
                count++;
                j++;
            }
        }
        if (point >= G) {
            chmin(res,count); //resをcountに変換
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
/*---------------------DEBUGGING--------------------------------------------*/
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
/*-------------------------------------------------------------------------------------*/
//#define mp make_pair
#define pb push_back
#define ll long long
#define pii pair<int,int>
#define pcc pair<char,char>
#define F first
#define S second
#define int long long
#define pi 3.141592653589793238462643383279502
#define M  1000000007
#define rep(i,a,n) for(int i=a;i<n;i++)
#define INF 10000000000000
#define N 1000005
#define vi vector<int>
#define all(v) v.begin(),v.end()
//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

signed main()
{
   ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
   int n,m,q;
   cin>>n>>m>>q;
   int a[n+1][n+1];
   memset(a,0,sizeof(a));
   rep(i,0,m)
   {
       int u,v;
       cin>>u>>v;
       a[u][v]+=1;
   }
   int c[n+1][n+1];
   memset(c,0,sizeof(c));
   rep(i,1,n+1)
   {
       rep(j,1,n+1)
        c[i][j]=(c[i][j-1] + a[i][j]);
   }
   while(q--)
   {
       int l,r;
       cin>>l>>r;
       int sum=0;
       for(int i=l;i<=r;i++)
       {
           sum+=(c[i][r]-c[i][l-1]);
       }
       cout<<sum<<endl;
   }
}



Measured memory_bytes: 4864
import java.util.*;

class Main {

  public static void main(String args[]) {
    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();
    int k = sc.nextInt();

    for (int i = k-n+1; i < k+n; i++) {
      if (i != k-n+1) System.out.print(" ");
      System.out.print(i);
    }
    System.out.println();

  }
}


Measured memory_bytes: 21716
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x)(x).begin(), (x).end() // 昇順ソート
#define rall(v)(v).rbegin(), (v).rend() // 降順ソート
#define INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair < ll, ll >
#define F first
#define S second
const int MOD = 1000000007;
template < class T > bool chmax(T & a,const T & b) { if (a < b) { a = b; return true; } return false; }
template < class T > bool chmin(T & a,const T & b) { if (a > b) { a = b; return true; } return false; }
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main() {
    int A,B;cin >> A >> B;
    int ans = 0;
    rep(i,2){
        if(A > B){
            ans += A;
            A--;
        }   
        else{
            ans += B;
            B--;
        }
    }
    cout << ans << endl;

}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>

int main(){
    int n;
    int x[11000];
    int i,j,k;
    int ans = 0;
    int test = 0;

    scanf("%d", &n);

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

    for(i=0; i<n; i++){
        test = (int)sqrt(x[i]);
        for(j=test ; j>0; j--){
            if(x[i]%j == 0){
                break;
            }
        }
        if(j==1){
            ans += 1;
        }

    }

    printf("%d\n", ans);

    return 0;
}


Measured memory_bytes: 2044
#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)

int main() {
	int m, n;
	while (cin >> m, m) {
		cin >> n;
		int ans = 0;
		for (int i = 1; i <= n; i *= 2)
			for (int j = i; j <= n; j *= 3)
				for (int k = j; k <= n; k *= 5)
					if (k >= m) ans++;
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
using System;
using System.Collections.Generic;
using System.Text;

class Program
{
	static void Main(string[] args)
	{
		string[] inputs = Console.ReadLine().Split(new char[] {' '});
		Stack<int> stack = new Stack<int>();

		for (int i = 0; i < inputs.Length; i++)
		{
			switch (inputs[i])
			{
				case "+":
					stack.Push(stack.Pop() + stack.Pop());
					break;
				case "-":
					stack.Push((stack.Pop() - stack.Pop()) * -1);
					break;
				case "*":
					stack.Push(stack.Pop() * stack.Pop());
					break;
				default:
					stack.Push(int.Parse(inputs[i]));
					break;
			}
		}

		System.Console.WriteLine(stack.Pop());
	}
}



Measured memory_bytes: 10120
package main

import "fmt"

var triplet = []int{111, 222, 333, 444, 555, 666, 777, 888, 999}

func main() {
	var n int
	fmt.Scan(&n)

	switch {
	case n <= triplet[n/100-1]:
		fmt.Println(triplet[n/100-1])
	default:
		fmt.Println(triplet[n/100])
	}
}


Measured memory_bytes: 512
#include<stdio.h>

int main(void){

    int n;
    scanf("%d",&n);

    int a[n];

    int i;

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


    int c = 0;
    for(i = 0; i <= n-1 ; i = i + 2){
        if(a[i] % 2 == 1)c++;
    }

    printf("%d",c);



}

Measured memory_bytes: 1708
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define ll          long long
#define pb          push_back
#define eb 			emplace_back
#define mp 			make_pair
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define vii         vector<pii>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define all(a)      (a).begin(),(a).end()
#define fi          first
#define si          second
#define sz(x)       (ll)x.size()
#define endl        '\n'
#define checkbit(n, b) ((n >> b) & 1)
#define mod        1000000007
#define inf        1000000000000000000
#define puts(n)		cout<<n;
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define setbits(x) __builtin_popcount(x)
#define mset(m,v) memset(m,v,sizeof(m))
using namespace std;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll k,a,b;
	cin>>k>>a>>b;
	bool flag=false;
	ll val = ceil(a/(k*1.0)) *k;
	if(val<=b) cout<<"OK";
	else cout<<"NG";
	
	
	return 0;
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  string t;
  cin>>s>>t;
  int cnt=0;
  for(int i=0;i<s.size();i++){
    if(s.at(i)!=t.at(i))cnt++;
  }
  cout<<cnt<<endl;
}

Measured memory_bytes: 3928
#include <stdio.h>
#include <string.h>
int main(int argc, char* argv[]) {
    int n, a, b;
    int min, max;
    
    scanf("%d %d %d", &n, &a, &b);
    
    max = (a > b) ? b : a;
    
    min = -(n - (a + b));
    
    min = (min < 0) ? 0 : min;
    
    printf("%d %d\n", max, min);
    return 0;
}

Measured memory_bytes: 128