akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<functional>
#include<cmath>
#include<set>
#include<random>
#include<stdio.h>
#include<map>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
const long long mod = 1000000007;
const long long inf = 11451419198109311;
const long double pi = 3.1415926535897932384626433;
typedef pair<int, int> P;
struct edge { int to, cost; };

signed main() {
	int h, w, x, y; cin >> h >> w >> x >> y;
	if (1 & (h*w) && 1 & (x + y))puts("No");
	else puts("Yes");
}


Measured memory_bytes: 3092
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(a);i>(b);--i)
#define eper(i,a,b) for(int i=((int)(a));i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF (1<<30)-1
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
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; }
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

int n;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
    cin >> n;
    vector<ll> a(n), sum(n+1);
    rep(i, 0, n) cin >> a[i];
    sort(all(a));
    sum[0] = 0;
    rep(i, 0, n) sum[i+1] = sum[i] + a[i];
    ll ans = 1;
    per(i, n-1, 0) {
        if (2 * sum[i] < a[i]) break;
        else ans++;
    }
    cout << ans << endl;
    return 0;
}


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

int main(){
    string str, ans = "hon";
    cin >> str;
    int s =str.size() - 1;
    if(str.at(s) == '3') ans ="bon";
    if(str.at(s) == '0' || str.at(s) == '1' || str.at(s) == '6' || str.at(s) == '8') ans ="pon";
    cout << ans << endl;
}

Measured memory_bytes: 3600
import sys
input = sys.stdin.buffer.readline

n,k = map(int,input().split())
p = list(map(int,input().split()))

for i in range(n):
    p[i] -= 1

c = list(map(int,input().split()))
used = [False]*n

edge = []

for i in range(n):
    if used[i]:
        continue
    now = i
    edge.append([])

    while True:
        if used[now]:
            break
        used[now] = True
        edge[-1].append(c[now])
        now = p[now]

res = -10**9
for i in range(len(edge)):
    s = sum(edge[i])
    m = len(edge[i])

    for j in range(m):
        tmp = 0
        ctr = 0
        for h in range(j+1,m):
            ctr += 1
            tmp += edge[i][h]
            if ctr <= k:
                res = max(res,tmp,tmp+((k-ctr)//m)*s)
        for h in range(j+1):
            ctr += 1
            tmp += edge[i][h]
            if ctr <= k:
                res = max(res,tmp,tmp+((k-ctr)//m)*s)
print(res)

Measured memory_bytes: 74656
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int r;
    cin >> r;
    cout << r*r << endl;
}

Measured memory_bytes: 256
def solve(inp):
    S = inp.readline().strip()

    w = ['Sunny', 'Cloudy', 'Rainy', 'Sunny']

    return w[w.index(S) + 1]


def test(s):
    from io import StringIO
    print(solve(StringIO(s)))


def main():
    import sys
    result = solve(sys.stdin)
    if result:
        print(result)


if __name__ == '__main__':
    # test('50\n' + '100 ' * 50)
    main()

Measured memory_bytes: 3060
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    n,m=map(int,input().split())
    N=n*m
    CA=[0]*(N+1)
    CB=[0]*(N+1)
    for a in map(int,input().split()):
        CA[a]+=1
    for b in map(int,input().split()):
        CB[b]+=1
    for i in range(N):
        CA[i+1]+=CA[i]
        CB[i+1]+=CB[i]

    ans=1
    for i in range(N,0,-1):
        # 双方に i の数字があるとき
        if(CA[i]-CA[i-1]==1 and CB[i]-CB[i-1]==1):
            continue # 1通りしかない
        # B にだけあるとき
        elif(CA[i]==CA[i-1] and CB[i]-CB[i-1]==1):
            ans*=CA[-1]-CA[i]
        # A にだけあるとき
        elif(CA[i]-CA[i-1]==1 and CB[i]==CB[i-1]):
            ans*=CB[-1]-CB[i]
        # 双方に i の数字がないとき
        elif(CA[i]==CA[i-1] and CB[i]==CB[i-1]):
            ans*=(CA[-1]-CA[i])*(CB[-1]-CB[i])-(N-i)
        else:
            print(0)
            return
        ans%=MOD

    print(ans)
resolve()

Measured memory_bytes: 55024
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = list(input())

from collections import deque
que = deque([])

ans = 0
for i in range(n):
    if i >= k:
        pre = que.popleft()
        if t[i] == 'r':
            if pre == 'p':  # k回前の手のせいで勝てないとき
                que.append('')  # k回後に勝てるような手を出す
            else:
                que.append('p')
                ans += p
        elif t[i] == 's':
            if pre == 'r':
                que.append('')
            else:
                que.append('r')
                ans += r
        elif t[i] == 'p':
            if pre == 's':
                que.append('')
            else:
                que.append('s')
                ans += s 
    else:
        if t[i] == 'r':
            que.append('p')
            ans += p
        elif t[i] == 's':
            que.append('r')
            ans += r
        elif t[i] == 'p':
            que.append('s')
            ans += s
print(ans)

Measured memory_bytes: 4772
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
s = input()
t = input()

S,T = len(s),len(t)
dp = [[0 for _ in range(T+1)] for _ in range(S+1)]
for i in range(S):
  for j in range(T):
    if s[i]==t[j]:
      dp[i+1][j+1] = max(dp[i][j]+1,dp[i+1][j],dp[i][j+1])
    else:
      dp[i+1][j+1] = max(dp[i+1][j],dp[i][j+1])
# dpの終点から文字列を復元していく
ans=''
while(S>=0 and T>=0):
  if dp[S][T] == dp[S-1][T]:
    S-=1
  elif dp[S][T] == dp[S][T-1]:
    T-=1
  else:
    ans = s[S-1] + ans
    S -=1
    T -=1
print(ans)

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

int main(){
    int N; cin >> N;
    vector<string> S;

    rep(i ,N){
        string s; cin >> s;
        S.push_back(s);
    }

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

    int ans=1;
    string now=S[0];
    rep(i, N){
        if(S[i] != now){
            ans++;
            now=S[i];
        }
    }

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

Measured memory_bytes: 11656
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    int a,b; cin>>a>>b;
    if((a+b)%3==0 || a*b%3==0) cout<<"Possible"<<endl;
    else cout<<"Impossible"<<endl;
}


Measured memory_bytes: 3664
import java.util.*

fun exp(d: Int): Long {
    var ans: Long = 1
    for (i in 1..d-1) {
        ans *= 2
    }
    return ans
}


fun main(args: Array<String>){
	val cin = Scanner(System.`in`)
    var a = cin.nextLong()
    var b = cin.nextLong()
    var at: Long = a
    var bt: Long = b
    var ad: Int = 0
    var bd: Int = 0
    while (b > 0) {
        at = a
        bt = b
        ad = 0
        bd = 0
        while (bt > 0) {
            if (at > 0) {
                ad += 1
            }
            at = (at shr 1)
            bt = (bt shr 1)
            bd += 1
        }
        if (ad != bd) {
            break
        }
        val top = exp(ad)
        a = a - top
        b = b - top
    }
    if (b == 0.toLong()) {
        println(1)
    } else {
        val e = exp(bd)
        var non_top = b - e
        var non_top_d: Int = 0
        while (non_top > 0) {
            non_top = (non_top shr 1)
            non_top_d += 1
        }
        val temp = exp(non_top_d+1) - 1
        val under = e - a
        if (temp + under > e - 1) {
            println(e*2 - a)
        } else {
            println(e + temp - a + 1 + under)
        }
    }
}

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N+1);
  for (int i = 1; i < N+1; i++) {
    A.at(i) = i;
  }
  
  // ここにプログラムを追記
  int ans=0,tmp=N-1;
  for (int i = 1; i <= N/2; i++) {
    for (int j = tmp; j >= N/2; j--) {
      if(A.at(i)+A.at(j)==N&A.at(i)!=A.at(j)){
        ans++;
        tmp=j;
        break;
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B;
  cin >> A >> B;
  
  if (A == 2){
    A = 2;
  }
  else if (A == 4 || A == 6 || A == 9 || A == 11){
    A = 1;
  }
  else {
    A = 0;
  }
  if (B == 2){
    B = 2;
  }
  else if (B == 4 || B == 6 || B == 9 || B == 11){
    B = 1;
  }
  else {
    B = 0;
  }
  
  if (A == B){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}
    
  

Measured memory_bytes: 3564
#include<iostream>
using namespace std;
#define ll long long
int main()
{
  ll a,b;
  cin>>a>>b;
  if(a==b){cout<<0;return 0;}
  else if((a+b)%2==0){cout<<(a+b)/2;return 0;}
  cout<<"IMPOSSIBLE";return 0;
}

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

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repr(i, n) for(int i = (n-1); i >= 0; --i)

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

const int MAX = 200005;
const int INF = 1001001001;
const int MOD = 1000000007;

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

    if (s[2] == s[3] && s[4] == s[5]) {
        puts("Yes");
    } else {
        puts("No");
    }
}

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

int M;
int a[7];
int s, g;
int N[301];

bool isChecked[301];
vector<int> milestone[301];  //そのマスで出せばゴールにたどり着ける目を格納する

int iabs(int x){ return x >= 0 ? x : -x; }

bool search(int now){
	if (isChecked[now]) return false;
	else if (now == g)  return true;

	isChecked[now] = true;
	for (int dice = 1; dice <= 6; dice++){
		if (now + a[dice] <= M && search(now + a[dice] + N[now + a[dice]])){
			milestone[now].push_back(a[dice]);
		}
		if (now - a[dice] >= 1 && search(now - a[dice] + N[now - a[dice]])){
			milestone[now].push_back(-a[dice]);
		}
	}

	return milestone[now].size() > 0 ? true : false;
}

int main(){
	cin >> M;
	for (int i = 1; i <= 6; i++){
		cin >> a[i];
	}
	cin >> s >> g;
	for (int i = 1; i <= M; i++){
		cin >> N[i];
	}
	bool canGoal = search(s);

	int now = s; //自分が今いるマスの番号
	for (;;){
		int dice;
		cin >> dice;
		int pip = a[dice];

		bool found = false;
		for (vector<int>::iterator it = milestone[now].begin(); it != milestone[now].end(); it++){
			if (iabs(*it) == pip){
				if (*it > 0){
					now = now + pip + N[now + pip];
					cout << 1 << endl;
				}
				else{
					now = now - pip + N[now - pip];
					cout << -1 << endl;
				}
				found = true;
				break;
			}
		}
		if(!found) cout << 0 << endl;
		cout.flush();

		if (now == g) return 0;
	}
	
	return 0;
}

Measured memory_bytes: 1304
import java.util.*;

class Main{

    long search(long x, long y){
        long x_min = 0;
        long y_min = 0;
        long x_max = 0;
        long y_max = 0;
        long f, f1 = 1, f2 = 0;
        long p;
        for (p = 0;; p++){
            if ( x_min <= x && x <= x_max &&
                 y_min <= y && y <= y_max  ) return p%3 + 1;
            f = f1 + f2;
            if ( p % 4 == 0 )  x_max += f; // east
            else if ( p % 4 == 1 ) y_max += f; // north
            else if ( p % 4 == 2 ) x_min -= f; // west
            else  y_min -= f; // south
            f2 = f1;
            f1 = f;
        }
    }

    void solve(){
        long x, y;
        Scanner sc = new Scanner(System.in);
        x = sc.nextLong();
        y = sc.nextLong();
        System.out.println(search(x, y));
    }

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




Measured memory_bytes: 26304
#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;

template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int d, g;
    cin >> d >> g;
    vector<lint> p(d), c(d);
    for (int i = 0; i < d; ++i) {
        cin >> p[i] >> c[i];
    }
    lint ret = inf;
    for (int i = 0; i < 1 << d; ++i) {
        lint score = 0;
        lint cnt   = 0;
        int mx     = 0;
        int mxidx  = -1;
        for (int j = 0; j < d; ++j) {
            if (i & 1 << j) {
                score += (1 + j) * 100 * p[j] + c[j];
                cnt += p[j];
            } else {
                if (chmax(mx, j + 1)) {
                    mxidx = j;
                }
            }
        }
        if (score >= g) {
            chmin(ret, cnt);
        } else {
            int need = (g - score + (1 + mxidx) * 100 - 1) / ((1 + mxidx) * 100);
            if (need >= p[mxidx])
                continue;
            else
                chmin(ret, cnt + need);
        }
    }
    cout << ret << "\n";
    return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val ws: List<Int> =
            readLine()!!.split(" ")
            .map { it.toInt() }

    val m1 = (1..(n / 2))
            .map { 2 * it }
            .map { ws[it] - ws[it - 1] }
            .sum() + ws[0]

    var mp = m1
    print(mp)
    for (i in 1 .. (n - 1)) {
        mp = 2 * ws[i - 1] - mp
        print(" ")
        print(mp)
    }
}


Measured memory_bytes: 68648
/*
ID: alec3
LANG: C++14
PROG:
*/


#include <bits/stdc++.h>

#define check(x) cout<<(#x)<<": "<<x<<" ";
#define io ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ss second
#define ff first
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define ld long double
#define all(c) (c).begin(), (c).end()
#define FOR(i, a, b) for (int i = a; i < b; i++)

typedef long long ll;
typedef unsigned long long ull;

using namespace std;
unsigned nChoosek( unsigned n, unsigned k )
{
    if (k > n) return 0;
    if (k * 2 > n) k = n-k;
    if (k == 0) return 1;

    int result = n;
    for( int i = 2; i <= k; ++i ) {
        result *= (n-i+1);
        result /= i;
    }
    return result;
}

int main()
{
    io;
    int n;
    cin >> n;
    vector<ll> a(n);
    for(auto& it : a) cin >> it;

    sort(a.begin(), a.end());
    int ans = 0;
    for (int i = 2; i < a.size(); i++){
        for (int j = i -1; j >= 0; j--){
            for (int k = j -1; k >= 0; k--){
                if (a[i] + a[j] > a[k] && a[j] + a[k] > a[i] && a[k] + a[i] > a[j]){
                    if (a[i] != a[j] && a[i] != a[k] && a[k] != a[j])
                        ans ++;
                }
            }
        }
    }
    cout << ans << endl;



    //cout << abs() << endl;

    return 0;

}



Measured memory_bytes: 3648
#include<iostream>
#include<algorithm>

using namespace std;

int dp[2][10016][2];
int table[9999];
int n;
const int INF = 1000000000;

int main() {
	cin >> n;
	for (int i = 0; i < n - 1; i++)cin >> table[i];
	auto bef = dp[0], now = dp[1];
	
	for (int i = 0; i <= 10000; i++)now[i][0] = now[i][1] = bef[i][0] = bef[i][1] = INF;

	bef[1][0] = 0;
	bef[0][1] = 0;
	for (int i = 1; i < n; i++) {
		for (int j = 0; j <= i + 1; j++) {

			if(j != 0)now[j][0] = min(bef[j - 1][0], bef[j - 1][1] + table[i - 1]);

			if(j != i + 1)now[j][1] = min(bef[j][1], bef[j][0] + table[i - 1]);

		}
		swap(bef, now);
		for (int j = 0; j <= 10000; j++)now[j][0] = now[j][1] = INF;
	}
	cout << min(bef[n / 2][0], bef[n / 2][1]) << endl;
	return 0;
}

Measured memory_bytes: 3276
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define db double
#define pint pair<int,int>
#define mk(x,y) make_pair(x,y)
#define fir first
#define sec second
#define Rep(x,y,z) for(int x=y;x<=z;x++)
#define Red(x,y,z) for(int x=y;x>=z;x--)
using namespace std;
const int MAXN=2e3+5;
char buf[1<<12],*p1=buf,*p2=buf,nc;int ny;
inline char gc() {return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<12,stdin),p1==p2)?EOF:*p1++;}
//inline char gc(){return getchar();}
inline int read(){
	int x=0;for(ny=1;nc=gc(),(nc<48||nc>57)&&nc!=EOF;)if(nc==45)ny=-1;if(nc<0)return nc;
	for(x=nc-48;nc=gc(),47<nc&&nc<58&&nc!=EOF;x=(x<<3)+(x<<1)+(nc^48));return x*ny;
}int n,m,d[MAXN],dep[MAXN],fa[MAXN],Sum[MAXN],e[2][MAXN],ed[2][MAXN],vis[MAXN],p[MAXN],col[MAXN];vector<int>G[MAXN];
void dfs(int x,int f){fa[x]=f,dep[x]=dep[f]+1;for(int i=0,len=G[x].size(),y;i<len;i++)if((y=G[x][i])!=f)dfs(y,x);}
void dfs1(int x){for(int i=0,len=G[x].size(),y;i<len;i++)if((y=G[x][i])!=fa[x])dfs1(y),Sum[x]+=Sum[y];}
inline int lca(int x,int y){for(dep[x]<dep[y]?swap(x,y),0:0;dep[x]>dep[y];x=fa[x]);for(;x!=y;x=fa[x],y=fa[y]);return x;}
int main(){
	n=read(),m=read();
	Rep(i,1,n-1){int x=read(),y=read();G[x].push_back(y),G[y].push_back(x),d[x]++,d[y]++;}
	dfs(1,0);Rep(i,1,m)e[0][i]=ed[0][i]=read(),e[1][i]=ed[1][i]=read(),Sum[e[0][i]]++,Sum[e[1][i]]++,Sum[lca(e[0][i],e[1][i])]-=2;dfs1(1);
	int ans=0;Rep(i,2,n)ans+=min(Sum[i],2);cout<<ans<<'\n';
	Rep(i,1,n-1){
		int u=0,v=0;
		Rep(j,2,n)if(!vis[j]&&d[j]==1){u=j;break;}vis[u]=1;
		for(int j=0,len=G[u].size(),y;j<len;j++)if(!vis[y=G[u][j]]){v=y;break;}d[v]--;
		int id1=0,id2=0;
		Rep(j,1,m)if((ed[0][j]==u)^(ed[1][j]==u))
			if(!id1)id1=j;else if(!id2)id2=j;
		if(!id1&&!id2)continue;
		if(!id2){ed[ed[1][id1]==u][id1]=v;continue;}
		if(ed[0][id1]==u){if(ed[0][id2]==u)ed[0][id1]=ed[1][id2],col[id2]^=1;else ed[0][id1]=ed[0][id2];}
		else if(ed[1][id1]==u){if(ed[1][id2]==u)ed[1][id1]=ed[0][id2],col[id2]^=1;else ed[1][id1]=ed[1][id2];}
		ed[0][id2]=ed[1][id2],p[id2]=id1;
		Rep(j,1,m)if((ed[0][j]==u)^(ed[1][j]==u))ed[ed[1][j]==u][j]=v;
	}Rep(i,1,m)if(p[i])col[i]^=col[p[i]];
	Rep(i,1,m){
		if(col[i])swap(e[0][i],e[1][i]);
		cout<<e[0][i]<<" "<<e[1][i]<<'\n';
	}
	return 0;
}




Measured memory_bytes: 3900
#include<iostream>
#include<string>
using namespace std;
 
int main(void) {
  int A[3][3];
  bool TF[3][3];
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> A[i][j];
    }
  }
  
  int N;
  cin >> N;

    for (int i = 0; i < 3; i++) {
    	for (int j = 0; j < 3; j++) {
          	TF[i][j] = false;
        }
    }
  
  for (int k = 0; k < N; k++) {
    int num;
    cin >> num;
    for (int i = 0; i < 3; i++) {
    	for (int j = 0; j < 3; j++) {
          	
      		if (A[i][j] == num) TF[i][j] = true;
        }
    }
  }
  
  for (int i = 0; i < 3; i++) {
    bool sum = TF[i][0] && TF[i][1] && TF[i][2];
    if (sum){
      cout << "Yes" << endl;
      return 0;
    }
  }
  for (int j = 0; j < 3; j++) {
    bool sum = true;
    for (int i = 0; i < 3; i++) sum = sum && TF[i][j];
    if (sum){
      cout << "Yes" << endl;
      return 0;
    }
  }
  if (TF[0][0] && TF[1][1] && TF[2][2]) { cout << "Yes" << endl; return 0;}
  if (TF[0][2] && TF[1][1] && TF[2][0]) { cout << "Yes" << endl; return 0;}
  
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>      
#include <cstdio>    
#include <vector>    
    
int main() {    
    std::ios::sync_with_stdio(false);    
    std::cin.tie(nullptr);    
    std::string buf;    
    int l, r;    
    std::vector<long> v;    
    std::cin >> l >> r >> buf;    
    v.push_back(0);    
    int num = 0;    
    char prev = buf[0];                                                                                                                                       
    for (int i = 1; i < (int)buf.size(); i++) {    
        if (prev == 'A' && buf[i] == 'C') {    
            v.push_back(++num);    
            prev = buf[i];    
            continue;    
        }    
        prev = buf[i];    
        v.push_back(num);    
    }    
    while(std::cin >> l >> r) {    
        std::cout << v[r - 1] - v[l - 1] << std::endl;    
    }    
}       

Measured memory_bytes: 1860
#include <bits/stdc++.h>
#define endl '\n'
#define all(c) c.begin(), c.end()

using namespace std;

typedef long long int ll;
typedef long double ld;

const ll mod = 1e9 + 7;
const ld PI = 3.141592653589793;

void solve () {
	ll n;
	cin>>n;
	ll ans=0;
	for (int i=1; i<=n; i++) {
		string s=to_string(i);
		if (s.size()%2) ans++;
	}
	cout<<ans;
}
main(){
    ios_base::sync_with_stdio(false); cin.tie(0);
    
    solve();
    return 0;
    }


Measured memory_bytes: 256
n = int(input())
*arr, = map(int, input().split())

def pairwise_coprime(arr):
    mx = max(arr)
    data = [0] * (mx + 1)
    for v in arr:
        data[v] += 1
        if v > 1 and data[v] > 1:
            return False
    primes = [1] * (mx + 1)
    for v in range(2, mx + 1):
        if primes[v]:
            cnt = 0
            if data[v]:
                cnt += 1
            for nonprime in range(2 * v, mx + 1, v):
                primes[nonprime] = 0
                if data[nonprime]:
                    cnt += 1
            if cnt > 1:
                return False
    return True

def gcd(a, b):
    if a > b:
        a, b = b, a

    while a:
        # gcd(a, b) = gcd(b, a % b)
        b, a = a, b % a
    return b


def setwise_coprime(arr):
    common_gcd = arr[0]
    for i in range(1, len(arr)):
        common_gcd = gcd(common_gcd, arr[i])
    return common_gcd == 1


if pairwise_coprime(arr):
    print("pairwise coprime")
elif setwise_coprime(arr):
    print("setwise coprime")
else:
    print("not coprime")


Measured memory_bytes: 223540
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
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 (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=1000000007,MAX=300005,INF=1<<30;
int p[MAX],v[MAX],w[MAX];

vector<pair<int,int>> C[MAX];

vector<int> use[MAX];

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N;cin>>N;
    
    p[0]=-1;
    for(int i=2;i<=N;i++){
        p[i-1]=i/2-1;
    }
    
    for(int i=0;i<N;i++){
        cin>>v[i]>>w[i];
    }
    
    for(int i=0;i<(1<<10);i++){
        for(int j=0;j<10;j++){
            if(i&(1<<j)) use[i].push_back(j);
        }
    }
    
    int Q;cin>>Q;
    
    for(int u=0;u<min(N,1023);u++){
        vector<int> A,B;
        int save=u;
        while(u!=-1){
            A.push_back(v[u]);
            B.push_back(w[u]);
            u=p[u];
        }
        u=save;
        int M=si(A);
        C[u].push_back(mp(0,0));
        
        for(int bit=0;bit<(1<<M);bit++){
            int vsum=0,wsum=0;
            for(int i:use[bit]){
                vsum+=A[i];
                wsum+=B[i];
            }
            C[u].push_back(mp(wsum,vsum));
        }
        
        sort(all(C[u]));
    }
    
    vector<int> A,B;
    
    while(Q--){
        int u,L;cin>>u>>L;
        u--;
        
        if(u<min(N,1023)){
            int ans=0;
            for(int i=0;i<si(C[u]);i++){
                if(C[u][i].fi<=L) chmax(ans,C[u][i].se);
            }
            cout<<ans<<"\n";
            continue;
        }
        
        while(u>=1023){
            A.push_back(v[u]);
            B.push_back(w[u]);
            u=p[u];
        }
        
        int M=si(A);
        
        vector<pair<int,int>> D(1<<M);
        
        for(int bit=0;bit<(1<<M);bit++){
            int vsum=0,wsum=0;
            for(int i:use[bit]){
                vsum+=A[i];
                wsum+=B[i];
            }
            D[bit]=(mp(L-wsum,vsum));
        }
        
        D.push_back(mp(0,0));
        D.push_back(mp(L,0));
        
        sort(all(D));
        
        for(int i=si(D)-2;i>=0;i--) chmax(D[i].se,D[i+1].se);
        
        int ans=0;
        
        int id=0;
        
        for(int i=0;i<si(C[u]);i++){
            if(C[u][i].fi>L) break;
            while(id<si(D)&&C[u][i].fi>D[id].fi) id++;
            chmax(ans,C[u][i].se+D[id].se);
        }
        
        cout<<ans<<"\n";
        
        A.clear();
        B.clear();
    }
    
}



Measured memory_bytes: 29468
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef vector<int> vei;
typedef vector<string> ves;
typedef vector<vector<int>> ve_vei;
#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 fs first
#define sc second
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
 
int main() {
	//cout.precision(10);
	cin.tie(0);
	ios::sync_with_stdio(false);

    int N; cin >> N;
    vei p(N), q(N);
    rep(i,N) {
        cin >> p[i];
        q[i] = p[i];
    }
    sort(q.begin(),q.end());

    int cnt = 0;
    rep(i,N) if (q[i] != p[i]) cnt++;
    cout << ((cnt == 0 or cnt == 2) ? "YES" : "NO") << endl;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
hs = list(map(int, input().split()))
counter = [True] * n

for _ in range(m):
  # abs += list(map(int, input().split()))
  a, b = map(int, input().split())
  a -= 1
  b -= 1
  if hs[a] < hs[b]:
    counter[a] = False
  elif hs[a] > hs[b]:
    counter[b] = False
  else:
    counter[a], counter[b] = False, False
print(sum(counter))

Measured memory_bytes: 20112
#include "iostream"
#include "vector"
#include "string"
#include "algorithm"
#include "math.h"
#include "cstring"
#include "stack"
#include "queue"

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<vector<int> > mat;

const ll max_n = 1e5 + 1;

int main()
{
  ll h, w, n;
  cin >> h >> w >> n;
  ll a[max_n], b[max_n];
  for (ll i = 0; i < n; i++)
  {
    cin >> a[i] >> b[i];
    a[i]--;
    b[i]--;
  }
  vector<pll> p;
  for (ll i = 0; i < n; i++)
  {
    for (ll j = max(0LL, a[i] - 2); j <= min(a[i], h - 3); j++)
    {
      for (ll k = max(0LL, b[i] - 2); k <= min(b[i], w - 3); k++)
      {
        p.push_back(pll(j, k));
      }
    }
  }
  sort(p.begin(), p.end());
  ll size = p.size();
  int check = 1;
  ll ans[10];
  memset(ans, 0, sizeof(ans));
  if (size == 1)
  {
    a[1]++;
  }
  for (ll i = 1; i < size; i++)
  {
    if (p[i] == p[i - 1])
    {
      check++;
    }
    else
    {
      ans[check]++;
      check = 1;
    }
  }
  if (size != 0)
  {
    ans[check]++;
  }
  ll an = 0;
  for (int i = 1; i <= 9; i++)
  {
    an += ans[i];
  }
  ans[0] = (h - 2) * (w - 2) - an;
  for (int i = 0; i <= 9; i++)
  {
    cout << ans[i] << "\n";
  }
}

Measured memory_bytes: 20200
#include<stdio.h>

int main(void)
{
  int i,j,n,a[100];
  long long int dp[21][100];

  scanf("%d",&n);
  for(i=0;i<=n-1;i++)
    {
      scanf("%d",&a[i]);
    }
  for(i=0;i<=20;i++)
    {
      for(j=0;j<=n-1;j++)
	{
	  dp[i][j]=0;
	}
    }
  dp[a[0]][0]=1;
  for(i=1;i<=n-2;i++)
    {
      for(j=0;j<=20;j++)
	{
	  if(dp[j][i-1]!=0)
	    {
	      if(j-a[i]>=0) dp[j-a[i]][i]+=dp[j][i-1];
	      if(j+a[i]<=20) dp[j+a[i]][i]+=dp[j][i-1];
	    }
	 }
    }
  
  printf("%lld\n",dp[a[n-1]][n-2]);

  return 0;
}

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

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

    long long m = a + b;
    long long times = n / m;
    long long count = a * times;
    long long left = n % m;

    count += min(left, a);

    cout << count << endl;
    return 0;
}


Measured memory_bytes: 256
def check(x, y):
    for i in range(6):
        order = [0, 0, 0]
        for j in range(3):
            if {x[j], x[-j-1]} != {y[a[i][j]], y[-a[i][j]-1]}:
                break
            if x[j] == y[a[i][j]]:
                order[j] = 1
                if x[j] == x[-j-1]:
                    order[j] = 2
        else:
            if 2 in order or (i < 3) == sum(order) % 2:
                return True
    return False

a = [[0, 1, 2], [2, 0, 1], [1, 2, 0], [0, 2, 1], [2, 1, 0], [1, 0, 2]]
n = int(input())
x = [input().split() for i in range(n)]
for i in range(n):
    for j in range(i+1, n, 1):
        if check(x[i], x[j]):
            break
    else:
        continue
    print('No')
    break
else:
    print('Yes')

Measured memory_bytes: 7804
from itertools import product
n,m = map(int, input().split())

INF = float("inf")
dp = [[-INF]*8 for i in range(m+1)]
dp[0] = [0]*8
op = [i for i in product([-1,1], repeat=3)]

for i in range(n):
    x,y,z = map(int, input().split())
    nxt = [[-INF]*8 for i in range(m+1)]
    nxt[0] = [0]*8
    for j in range(m):
        for k in range(8):
            nxt[j+1][k] = max(dp[j+1][k], dp[j][k] + op[k][0]*x+op[k][1]*y+op[k][2]*z)
    dp = nxt
print(max(dp[-1]))

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

int main(){
  int N,K,count=0;
  cin >> N >> K;
  for(int i=1;i<N+1;i+=2){
    count++;
  }
  if(count>=K){
    cout << "YES" << endl;
  }
  else{
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define MODV 998244353
#define INFLL (1LL<<62) // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

// BinaryIndexedTree(Fenwick-Tree); フェニック木
// ：BIT<long long> bit(n);で初期化、bit.sum(n)で0~n番目までの累積和を計算
template<typename T> class BIT {
private:
    const long long n; vector<T> bit;
public:
    BIT(long long size) : n(size+1), bit(n, 0){}
    BIT(const vector<T>& v) : n((long long)v.size()+1), bit(n, 0){ for(long long i = 0; i < n-1; i++) add(i,v[i]); }
    T sum(long long i){ i++; T s = 0; while(i > 0){ s += bit[i], i -= i & -i; } return s; }
    void add(long long i, T x){ i++; while(i < n) bit[i] += x, i += i & -i; }
    void print(){ for(long long i = 0; i < n-1; i++) cout << sum(i)-sum(i-1) << (i != n-2 ? " " : "\n"); }
    void print_sum(){ for(long long i = 0; i < n; i++) cout << sum(i-1) << (i != n-1 ? " " : "\n"); }
};

int main(){
    Init();
    ll n, k;
    cin >> n >> k;
    vector<pair<ll, ll>> lr(k);

    // 区間は昇順にソートしておく
    rep(i, k) cin >> lr[i].first >> lr[i].second;
    sort(all(lr));

    // 動的計画法
    BIT<long long> dp(n+2);
    dp.add(1, 1);
    
    for(ll i=1; i<=n; i++){
        ll num = ((i == 1 ? dp.sum(i) : dp.sum(i) - dp.sum(1))%MODV+MODV)%MODV;
        for(ll j=0; j<k; j++){
            ll l = min(i+lr[j].first, n+1);
            ll r = min(i+lr[j].second+1, n+1);
            dp.add(l, num);
            dp.add(r, -num);
        }
    }
    cout << ((dp.sum(n)-dp.sum(1))%MODV+MODV)%MODV  << endl;
    return 0;
}

Measured memory_bytes: 4776
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<iomanip>
#include<map>
#include<utility>
#include<string>
#include<unordered_map>
#include<queue>

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

using namespace std;

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

int gcd(int a, int b){return b ? gcd(b, a%b) : a;}

int main(){
    int a, b;
    cin >> a >> b;
    string ans;

    if(a>0 && b>0) ans = "Positive";
    if(a<=0 && b>=0) ans = "Zero";
    if(a<0 && b<0){
        if((b-a)%2 == 0) ans = "Negative";
        else ans = "Positive";
    }

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


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

long long n, m, x[100004], y[100004];
const int mod = 1000000007;
long long mul(long long a, long long b){
	long long ret = a * b;
	return ret% mod;
}
long long sum(long long a, long long b){
	return (a+b)%mod;
}
int main() {
	ios_base :: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	cin>>n>>m;
	for(int i = 0;i<n;i++)	cin>>x[i];
	for(int i = 0;i<m;i++)	cin>>y[i];
	int ver = 0, hor = 0;
	for(int i = 1;i<n;i++)	ver = sum(ver,mul(mul(x[i]-x[i-1],i),n-i));
	
	for(int i = 1;i<m;i++)	hor = sum(hor,mul(mul(y[i]-y[i-1],i),m-i));
	cout<<mul(ver,hor);
	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl; 
#define n_max int(1e5+5)



int main(){
    int n;
    cin >>n;
    string s;
    cin >> s;
    int ans[n_max]={};
    bool flag = false;
    REP(i,2){
        if(flag) break;
        REP(j,2){
            ans[0]=i;
            ans[1]=j;
            FOR(k,1,n){
                if(ans[k]){
                    if(s[k]=='o') ans[k+1] = ans[k-1];
                    else ans[k+1] = 1 - ans[k-1];
                }
                else{
                    if(s[k]=='x') ans[k+1] = ans[k-1];
                    else ans[k+1] = 1 - ans[k-1];
                }
            }
            if(ans[0] != ans[n]){
                continue;
            }
            if(ans[0]){
                if(s[0] == 'o'){
                    if(ans[1] == ans[n-1]){
                        flag = true;
                        break;
                    }
                }
                else{
                    if(ans[1] != ans[n-1]){
                        flag = true;
                        break;
                    }
                }
            }
            else{
                if(s[0] == 'x'){
                    if(ans[1] == ans[n-1]){
                        flag = true;
                        break;
                    }
                }
                else{
                    if(ans[1] != ans[n-1]){
                        flag = true;
                        break;
                    }
                }                
            }
        }
    }

    if( not flag ){
       print(-1);
    }
    else{
        REP(i,n){
            if(ans[i]) cout << 'S';
            else cout << 'W';
        }
        cout << endl;
    }
}

Measured memory_bytes: 896
import collections

N=int(input())
L=list(map(int,input().split()))
L=sorted(L)
C=collections.Counter(L)
D=list(C.keys())
E=list(C.values())
K=len(C)
ans=0
for i in range(K):
	if D[i]==E[i]:
		ans+=0
	if D[i]>E[i]:
		ans+=E[i]
	if D[i]<E[i]:
		ans+=(E[i]-D[i])
print(ans)


Measured memory_bytes: 22236
#include <iostream>
#include <algorithm>
#include <vector>
#include <sstream>
#include <queue>
#include <cstring>
using namespace std;

struct NODE{
	int tx,ty,kx,ky,d;
	NODE(int tx,int ty,int kx,int ky,int d): tx(tx) , ty(ty) , kx(kx) , ky(ky) , d(d) {}
};

int c[53][53];
int memo[53][53][53][53]={0};

int main(){
	int W , H;
	while(cin >> W >> H && W){
		int tx,ty,kx,ky;
		cin >> tx >> ty >> kx >> ky;
		for(int i = 0 ; i < 53 ; i++)
			for(int j = 0 ; j < 53 ; j++)
				c[i][j] = 1;
		for(int i = 1 ; i <= H ; i++)
			for(int j = 1 ; j <= W ; j++)
				cin >> c[i][j];
		queue<NODE> Q;
		Q.push(NODE(tx,ty,kx,ky,0));
		memo[tx][ty][kx][ky] = 1;
		int dx[] = { -1 , 0 , 1 , 0 };
		int dy[] = { 0 , -1 , 0 , 1 };
		memset(memo,0,sizeof(memo));
		while(Q.size()){
			NODE q = Q.front(); Q.pop();
			if(q.d >= 100) break;
			
			if(q.kx == q.tx && q.ky == q.ty){
				cout << q.d << endl;
				goto exit;
			}
			for(int i = 0 ; i < 4 ; i++){
				NODE w = NODE(q.tx+dx[i],q.ty+dy[i],q.kx-dx[i],q.ky-dy[i],q.d+1);
				if(c[w.ty][w.tx]) w.ty = q.ty , w.tx = q.tx;
				if(c[w.ky][w.kx]) w.ky = q.ky , w.kx = q.kx;
				if(!memo[w.tx][w.ty][w.kx][w.ky]) Q.push(w) , memo[w.tx][w.ty][w.kx][w.ky] = true;
			}
		}
		cout << "NA" << endl;
		exit:;
	}
}

Measured memory_bytes: 0
#include <iostream>
using namespace std;
bool isPrime(int x){
    if(x == 1) return false;
    if(x == 2) return true;
    bool flag = true;
    for(int i = 2; i*i <= x; ++i){
        if(x%i == 0){
            flag = false;
            break;
        }
    }
    return flag;
}
int main(){
    int n; cin >> n;
    int ans = 0;
    for(int i = 0; i < n; ++i){
        int num; cin >> num;
        if(isPrime(num)) ans++;
    }
    cout << ans << endl;
    return 0;
}


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

//#pragma GCC optimize("O3")
//#pragma GCC target("sse4")

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define ITER(it, a) for(__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a, value) memset(a, value, sizeof(a))

#define SZ(a) (int)((a).size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = (LL)INF * INF;

const int MAX = 1 << 8;

int n;
string s[MAX];
int col[MAX];
bool bip = true;
int Q[MAX];
int d[MAX];

void dfs(int v)
{
	FOR(i, 0, n)
		if(s[v][i] == '1')
		{
			if(col[i] == 0)
			{
				col[i] = 3 - col[v];
				dfs(i);
			}
			bip &= col[i] != col[v];
		}
}

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> n;
	FOR(i, 0, n)
		cin >> s[i];
	col[0] = 1;
	dfs(0);
	if(!bip)
	{
		cout << -1 << "\n";
		return 0;
	}
	int ans = 0;
	FOR(i, 0, n)
	{
		FILL(d, -1);
		d[i] = 0;
		Q[0] = i;
		int qh = 0, qt = 1;
		while(qh != qt)
		{
			int v = Q[qh++];
			FOR(j, 0, n)
				if(s[v][j] == '1' && d[j] == -1)
				{
					d[j] = d[v] + 1;
					ans = max(ans, d[j]);
					Q[qt++] = j;
				}
		}
	}
	cout << ans + 1 << "\n";
	return 0;
}


Measured memory_bytes: 384
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int m[1010][1010];
string s[1010];

int main() {
	int n;
	while(n=in()){
		int i;
		for(i=0;i<n;i++){
			cin>>s[i];
		}
		for(i=0;i<n;i++){
			if(s[0][i]=='.')m[0][i]=1;
			else m[0][i]=0;
			if(s[i][0]=='.')m[i][0]=1;
			else m[i][0]=0;
		}
		int j;
		for(i=1;i<n;i++){
			for(j=1;j<n;j++){
				if(s[i][j]=='.')m[i][j]=min(min(m[i-1][j-1],m[i-1][j]),m[i][j-1])+1;
				else m[i][j]=0;
			}
		}
		int mx=0;
		for(i=0;i<n;i++){
			for(j=0;j<n;j++){
//cout<<m[i][j];
				chmax(mx,m[i][j]);
			}
//cout<<endl;
		}
		cout<<mx<<endl;
	}
	return 0;
}

Measured memory_bytes: 1952
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> p(N);
  for(int i=0;i<N;i++){
    cin >> p.at(i);
  }
  sort(p.begin(), p.end());
  cout << p.at(N/2) - p.at(N/2-1) <<endl;
}

Measured memory_bytes: 640
#include<stdio.h>
int main(void)
{
  int e,y,a;
scanf("%d",&e);
scanf("%d",&y);
if(e==0){
  if(y>=1989){
    a=y-1988;
    printf("H%d\n",a);
  }
  else if(y>=1926){
    a=y-1925;
    printf("S%d\n",a);
  }
      else if(y>=1912){
    a=y-1911;
    printf("T%d\n",a);
  }
        else{
    a=y-1867;
    printf("M%d\n",a);
  }
}
else{
  switch(e){
    case 1:
      a=y+1867;
      break;
    case 2:
      a=y+1911;
      break;
    case 3:
      a=y+1925;
      break;
    case 4:
      a=y+1988;
      break;
  }
printf("%d\n",a);
}
return 0;
}



Measured memory_bytes: 2724
N,M,C = map(int, input().split())
B = [int(i) for i in input().split()]

A = []
for i in range(N):
    A.append([int(i) for i in input().split()])
    
ans = 0
for i in range(N):
    check = 0
    for j in range(M):
        check += B[j] * A[i][j]
    if check + C > 0:
        ans += 1
print(ans)

Measured memory_bytes: 3064
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
 
#if DEBUG
    #include "debug.h"
#else
    #define debug(args...)
#endif    

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> ii;
typedef long long ll;


#define M 1000000 
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define fill(a,x) memset(a,x,sizeof(a))
#define F first
#define S second
#define FOR(i,a,b) for(int i = a; i<=b; ++i)
#define NFOR(i,a,b) for(int i = a; i>=b; --i)
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int INF = INT_MAX;
const int mod = 1e9+7;

const int N = 2e5 + 10;
inline int add(int x,int y){
  x += y;
  if(x >= mod) x -= mod;
  return x;
}
inline int mul(int x,int y){
  x = (1LL * x * y) % mod;
  return x;
}
clock_t time_p=clock();



int32_t main(){
  fast;

  //freopen("in.txt","r",stdin);
  //freopen("out.txt","w",stdout);

  int h,w,n;
  cin >> h >> w >> n;
  cout << (n + max(h,w) - 1)/max(h,w) << "\n";


  time_p=clock()-time_p;
  cerr<<"\nTime Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";

  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long LL;

LL q,h,s,d;
LL n;

int main()
{
	scanf("%lld%lld%lld%lld",&q,&h,&s,&d);
	scanf("%lld",&n);
	h=min(h,q*2ll);
	s=min(s,h*2ll);
	d=min(d,s*2ll);
	printf("%lld\n",n/2ll*d+n%2ll*s);
	return 0;
}

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

n, m = MAP()
ab = [LIST() for _ in range(n)]
ab.sort()
num = 0
ans = 0
for i in range(n):
    if num + ab[i][1] < m:
        num += ab[i][1]
        ans += ab[i][0] * ab[i][1]
    else:
        ans += ab[i][0] * (m - num)
        break
print(ans)


Measured memory_bytes: 29936
#include "bits/stdc++.h"

using namespace std;

int main (){
	int cnt;
	double max = 0;
	cin >> cnt;
	double s[1000];

	for(int i = 1;i <= cnt;i++){
	cin >> s[i - 1];
	}
	sort(s,s+cnt);
	reverse(s,s+cnt);
	
	for(int n = 0;n <=(cnt - 1);n++){
		for(int l = (n + 1);l <= (cnt - 1);l++){
			int maxone = 0;
			int maxtwo = 1;
			for(int m = 0;m <= 4;m++){
				if(maxone == n)maxone++;
				if(maxtwo == l)maxtwo++;
				if(maxone == l)maxone++;
				if(maxtwo == n)maxtwo++;
				if(maxone == maxtwo)maxtwo++;
			}
			if(n != l){
			double ma = ((s[maxone] + s[maxtwo])/(s[n] - s[l]));
			if(ma > max) max = ma;
			}
		}
	}

	cout << fixed << setprecision(5) <<max <<endl;

	return 0;
}

Measured memory_bytes: 3264
#include <bits/stdc++.h>
#define PI 3.1415926535897932
#define _GLIBCXX_DEBUG
#define MOD 1000000007;
using namespace std;
long long GCD(long long A,long long B){
  if(B==0){
    return A;
  }
  else{
    return GCD(B,A%B);
  }
}
int main() {
  
  int A,B;
  cin>>A>>B;
  
  
  for(int i=1;i<=10000;i++){
    if((i*8)/100==A&&i/10==B){
      cout<<i<<endl;
      return 0;
    }
  }
  cout<<-1<<endl;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define N 500005
#define int long long
using namespace std;
char s[N];int n,flag,c[N];
vector<int>G[27];bool vis[N];
inline int lowbit(int x){return x&-x;}
inline void add(int x,int y){for(int i=x;i<=n;i+=lowbit(i))c[i]+=y;}
inline int sum(int x){int ans=0;for(int i=x;i;i-=lowbit(i))ans+=c[i];return ans;}
signed main(){
	scanf("%s",s+1);n=strlen(s+1);
	for (int i=1;i<=n;i++){
		int x=s[i]-'a'+1;
		G[x].push_back(i);
	}
	int tot=0;
	for (int i=1;i<=26;i++) if (G[i].size()&1) tot++;
	if (tot>1) return puts("-1"),0;
	int ans=0;
	for (int i=1;i<=n;i++) add(i,1);
	for (int i=1;i<=n;i++){
		if (vis[i]) continue;
		int pos=G[s[i]-'a'+1].size();pos--;
		int last=G[s[i]-'a'+1][pos];
		if (i==last) ans=ans+(sum(n)-sum(i))/2;
		else ans=ans+sum(n)-sum(last);
		add(last,-1);add(i,-1);
		vis[i]=vis[last]=1;
		G[s[i]-'a'+1].pop_back();
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 6260
#include<bits/stdc++.h>
#define MAX 110
#define MAX_V 2016
#define inf 1<<29
#define linf 1e18
#define eps (1e-8)
#define mod 1000000007
#define pi M_PI
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define pd(a) printf("%.10f\n",(double)(a))
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define equals(a,b) (fabs((a)-(b))<eps)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<double,int> pdi;
typedef vector<int> vi;
typedef vector<pii> vpi;
const int dx[8]={1,0,-1,0,1,1,-1,-1};
const int dy[8]={0,1,0,-1,1,-1,1,-1};

struct edge{ int to,cap,rev; };

int n,m,l;
int dis[MAX][MAX];
vpi vp;
int V;
vector<edge> G[MAX_V];
bool used[MAX_V];

void add_edge(int from,int to,int cap){
  G[from].push_back((edge){to,cap,(int)G[to].size()});
  G[to].push_back((edge){from,0,(int)G[from].size()-1});
}
 
int dfs(int v,int t,int f){
  if(v==t)return f;
  used[v]=true;
  for(int i=0;i<G[v].size();i++){
    edge &e=G[v][i];
    if(!used[e.to] && e.cap>0){
      int d=dfs(e.to,t,min(f,e.cap));
      if(d>0){
    e.cap-=d;
    G[e.to][e.rev].cap+=d;
    return d;
      }
    }
  }
  return 0;
}
 
int max_flow(int s,int t){
  int flow=0;
  for(;;){
    fill(used,used+MAX_V,0);
    int f=dfs(s,t,inf);
    if(f==0)return flow;
    flow+=f;
  }
}

void init(){
  FOR(i,0,MAX){
    FOR(j,0,MAX){
      if(i==j)dis[i][j]=0;
      else dis[i][j]=inf;
    }
  }
  FOR(i,0,MAX_V)G[i].clear();
  vp.clear();
}

void wf(){
  FOR(k,0,n)
    FOR(i,0,n)
      FOR(j,0,n)
        dis[i][j]=min(dis[i][j],dis[i][k]+dis[k][j]);
}

void solve(){
  int s=2*l;
  int t=s+1;
  V=t+1;
  FOR(i,0,l){
    add_edge(s,i,1);
    add_edge(i+l,t,1);
  }
  FOR(i,0,l){
    FOR(j,0,l){
      if(i==j)continue;
      if(vp[j].s<vp[i].s)continue;
      if(dis[vp[i].f][vp[j].f]<=vp[j].s-vp[i].s)add_edge(i,j+l,1);
    }
  }
  cout<<l-max_flow(s,t)<<endl;
  return;
}

int main()
{
  while(1){
    cin>>n>>m>>l;
    if(n+m+l==0)break;
    init();
    FOR(i,0,m){
      int u,v,d;
      cin>>u>>v>>d;
      dis[u][v]=d;
      dis[v][u]=d;
    }
    FOR(i,0,l){
      int p,t;
      cin>>p>>t;
      vp.pb(mp(p,t));
    }
    wf();
    solve();
  }
  return 0;
}

Measured memory_bytes: 27888
#include <stdio.h>

int main()
{
    int X,A,B,Y;
   scanf("%d %d %d",&X,&A,&B);
    Y=X+A;
    if(Y<B) printf("dangerous");
    if(Y>=B&&B<=A) printf("delicious");
    if(Y>=B&&B>A) printf("safe");
   return 0;
}

Measured memory_bytes: 128