akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define ll long long int
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define all(x) x.begin(),x.end()
#define sz(x) (ll)x.size() 

int main()
{
    ios_base::sync_with_stdio(false);
	ll n,i,j,k,x,y,t,m;

	map<string,ll>M;
	M["AC"]=0,M["TLE"]=0,M["RE"]=0,M["WA"]=0;

	cin >> t;
	while(t--)
	{
		string s;
		cin >> s;
		M[s]++;
	}

	cout<<"AC x "<<M["AC"]<<endl;
	cout<<"WA x "<<M["WA"]<<endl;
	cout<<"TLE x "<<M["TLE"]<<endl;
	cout<<"RE x "<<M["RE"]<<endl;
}

Measured memory_bytes: 3664
#include <bits/stdc++.h>
#define INF 2000000000000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

//=============ford_fulkerson============================
ll MAX_V = 20100;
struct edge {ll to, cap, rev;};
vector<vector<edge>> G(MAX_V);
vector<bool> used(MAX_V, false);

void add_edge(ll from, ll to, ll cap) {
  G.at(from).push_back((edge){to, cap, (ll)G.at(to).size()});
  G.at(to).push_back((edge){from, 0ll, (ll)G.at(from).size() - 1});
}

ll dfs(ll v, ll t, ll f) {
  if (v == t) {
    return f;
  }
  used.at(v) = true;
  for (ll i = 0; i < G.at(v).size(); ++i) {
    edge &e = G.at(v).at(i);
    if (!used.at(e.to) && e.cap > 0) {
      ll d = dfs(e.to, t, min(f, e.cap));
      if (d > 0) {
        e.cap -= d;
        G.at(e.to).at(e.rev).cap += d;
        return d;
      }
    }
  }
  return 0;
}

ll max_flow(ll s, ll t) {
  ll flow = 0;
  while (true) {
    used = vector<bool>(MAX_V, false);
    ll f = dfs(s, t, INF);
    if (f == 0) {
      return flow;
    }
    flow += f;
  }
}
//=================================================

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll H, W;
  cin >> H >> W;
  ll s, t;
  // ll temp = H * W;
  ll temp = 10050;
  vector<vector<char>> A(H, vector<char>(W));
  vector<vector<ll>> num(H, vector<ll>(W));
  ll cnt = 0;
  for (ll i = 0; i < H; ++i) {
    for (ll j = 0; j < W; ++j) {
      num.at(i).at(j) = cnt;
      cnt += 1;
    }
  }
  for (ll i = 0; i < H; ++i) {
    for (ll j = 0; j < W; ++j) {
      cnt = num.at(i).at(j);
      char a;
      cin >> a;
      A.at(i).at(j) = a;
      if (a == 'S') {
        s = cnt;
        add_edge(cnt, cnt + temp, INF);
      }
      else if (a == 'T') {
        t = cnt;
        add_edge(cnt, cnt + temp, INF);
      }
      else if (a == 'o') {
        add_edge(cnt, cnt + temp, 1);
      }
    }
  }
  for (ll i = 0; i < H; ++i) {
    for (ll j = 0; j < W - 1; ++j) {
      for (ll k = j + 1; k < W; ++k) {
        if (A.at(i).at(j) != '.' && A.at(i).at(k) != '.') {
          add_edge(num.at(i).at(j) + temp, num.at(i).at(k), INF);
          add_edge(num.at(i).at(k) + temp, num.at(i).at(j), INF);
        }
      }
    }
  }
  for (ll i = 0; i < W; ++i) {
    for (ll j = 0; j < H - 1; ++j) {
      for (ll k = j + 1; k < H; ++k) {
        if (A.at(j).at(i) != '.' && A.at(k).at(i) != '.') {
          add_edge(num.at(j).at(i) + temp, num.at(k).at(i), INF);
          add_edge(num.at(k).at(i) + temp, num.at(j).at(i), INF);
        }
      }
    }
  }
  ll ans = max_flow(s, t + temp);
  if (ans == INF) {
    cout << -1 << "\n";
  }
  else {
    cout << ans << "\n";
  }
}


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

#define REP(i, x, n) for (int i = x; i < (int)(n); ++i)
#define RREP(i, x, n) for (int i = x - 1; i >= (int)(n); --i)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) RREP(i, n, 0)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define MAX 1e9 + 7

using namespace std;

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

int main(void)
{
    int a, b, x;
    cin >> a >> b >> x;
    if (a + b < x)
    {
        cout << "NO" << endl;
    }
    else if (a == x)
    {
        cout << "YES" << endl;
    }
    else if (a < x)
    {
        if (b - (a - x) > 0)
        {
            cout << "YES" << endl;
        }
    }
    else
    {
        cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) int((x).size())
#define OUT(x) cout << (x) << endl
typedef long long ll;
typedef vector<int> V;
typedef vector<vector<int>> VV;
typedef pair<int, int> P;
typedef map<string, int> M;
typedef unordered_map<int, int> HM;
typedef set<int> S;
typedef multiset<int> MS;
typedef queue<int> Q;

int main(){
    int h,w; cin>>h>>w;
    VV a(h,V(w));
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            cin>>a[i][j];
        }
    }
    vector<tuple<int,int,int,int>> ans;
    for(int i=0; i<h; i++){
        if(i&0){
            for(int j=0; j<w; j++){
                if(i==h-1 && j==w-1) break;
                if(a[i][j]&1){
                    if(j == w-1){
                        a[i+1][j]++;
                        ans.emplace_back(i+1,j+1,i+1+1,j+1);
                    }
                    else{
                        a[i][j+1]++;
                        ans.emplace_back(i+1,j+1,i+1,j+1+1);
                    }
                }
            }
        }
        else{
            for(int j=w-1; j>=0; j--){
                if(i==h-1 && j==0) break;
                if(a[i][j]&1){
                    if(j == 0){
                        a[i+1][j]++;
                        ans.emplace_back(i+1,j+1,i+1+1,j+1);
                    }
                    else{
                        a[i][j-1]++;
                        ans.emplace_back(i+1,j+1,i+1,j-1+1);
                    }
                }
            }
        }
    }
    OUT(ans.size());
    for(auto t : ans){
        cout << get<0>(t) << " " << get<1>(t) << " " << get<2>(t) << " " << get<3>(t) << endl; 
    }
}

Measured memory_bytes: 5232
#include <stdio.h>
int main(void){
    int n;
    scanf("%d",&n);
    int a[n];
    int kari;
    for(int i=0;i<n;i++){
        scanf("%d",&kari);
        if(n%2==0){
            if(i%2==0)a[n/2+i/2]=kari;
            if(i%2==1)a[n/2-(i+1)/2]=kari;
        }
        if(n%2==1){
            if(i%2==0)a[(n-1)/2-i/2]=kari;
            if(i%2==1)a[(n-1)/2+(i+1)/2]=kari;
        }
    }
    for(int i=0;i<n;i++)printf("%d ",a[i]);
    return 0;
}


Measured memory_bytes: 2816
def main():
    n = int(input())
    txy = [list(map(int, input().split())) for _ in range(n)]
    
    pre_x, pre_y, pre_t = 0, 0, 0
    for t, x, y in txy:
        d = abs(pre_x - x) + abs(pre_y - y)
        if not(t - pre_t >= d and (t - pre_t) % 2 == d % 2):
            print('No')
            break
        pre_x,  pre_y, pre_t = x, y, t
    else:
        print('Yes')
        
        
if __name__ == '__main__':
    main()

Measured memory_bytes: 27380
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <set>
#include <queue>
#include <deque>
#include <map>
#include <stack>
#include <cmath>
using namespace std;

#define mod 1000000007
#define ten5 100005
#define ten52 200005
#define ten53 300005
#define ten6 1000005
#define PI 3.1415926
#define pb(x) push_back(x)
#define all(x) x.begin(),x.end()
#define mkpr(x1,x2) make_pair(x1,x2)
typedef long long int ll;

//stack<char> stk;
//set<ll> sll;
//set<pair<ll,ll>> spll;
//map<string,ll> mp;
//map<ll,ll> mp;
//deque<ll> deq;
vector<ll> vll,v1,v2,v3;
ll num[ten52],num2[ten52];
//priority_queue<pair<ll,ll>> pq;          //decreasing

int main(void)
{
    ll m,n,i,j,k=0,a=1,b,ans=0;
    string s="";
    cin>>n;
    cout<<(n^1);
    return 0;
}





Measured memory_bytes: 3624
#include<stdio.h>

struct SI{int top;int west;int south;int east;int north;int back;};

struct SI E(struct SI P);
struct SI W(struct SI);
struct SI S(struct SI P);
struct SI N(struct SI P);


int main(){

struct SI P;
char q;

scanf("%d%d%d%d%d%d",&P.top, &P.south, &P.east, &P.west, &P.north, &P.back);
while(scanf("%c",&q)!=EOF){
if(q=='E')P=E(P);
if(q=='N')P=N(P);
if(q=='W')P=W(P);
if(q=='S')P=S(P);


}
printf("%d\n",P.top);

return 0;
}

struct SI N(struct SI P){
int t=P.top;
P.top=P.south;P.south=P.back;P.back=P.north;P.north=t;
return P;
}

struct SI S(struct SI P){
int t=P.top;
P.top=P.north;P.north=P.back;P.back=P.south;P.south=t;
return P;
}
struct SI E(struct SI P){
int t=P.top;
P.top=P.west;P.west=P.back;P.back=P.east;P.east=t;
return P;
}
struct SI W(struct SI P){
int t=P.top;
P.top=P.east;P.east=P.back;P.back=P.west;P.west=t;
return P;
}

Measured memory_bytes: 1028
import math
N,D = map(int,input().split())
X = []
for i in range(N):
    X.append(list(map(int,input().split())))
def check(x,y):
    s = 0
    for i in range(D):
        s += (x[i]-y[i])**2
    j = math.floor(math.sqrt(s))
    return j**2 == s
ans = 0
for i in range(N):
    for j in range(i+1, N):
        if check(X[i],X[j]):
            ans += 1
print(ans)

Measured memory_bytes: 3064
n,m=gets.chomp.split(" ").map{|s| s.to_i}
a=[]
for i in 0..m-1
  a[i]=gets.chomp.to_i
end

dp=[]
for i in 0..n
  dp[i]=0
end

dp[0]=1

if a[0]==1
  dp[1]=0
else
  dp[1]=1
end

u=[*2..n]-a

u.each do |i|
    dp[i]=dp[i-1]+dp[i-2]
end
puts dp[n]%1000000007

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

string s;
int sum1,sum2;

int Search2(int indx);


int Search1(int indx){


  while(indx < (int)s.size()){

    if(s[indx]==']'){
      return -1;
    }

    else if(s[indx]=='('){
      indx = Search1(indx+1);
      sum1++;
      if(indx==-1 ) return -1;
    }

    else if(s[indx]=='['){
      indx = Search2(indx+1);
      sum2++;
      if(indx == -1) return -1;
    }

    else if(s[indx]==')'){
      sum1--;
      return indx;
    }


    indx++;

  }

  return indx;

}

int Search2(int indx){

  while(indx < (int)s.size() ){
    
    if(s[indx]==')'){
      return -1;
    }
    
    else if(s[indx]=='['){
      indx = Search2(indx+1);
      sum2++;
      if(indx==-1) return -1;
    }

    else if(s[indx]=='('){
      indx = Search1(indx+1);
      sum1++;
      if(indx==-1) return -1;
    }

    else if(s[indx] == ']'){
      sum2--;
      return indx;
    }

    indx++;
  }

  return indx;
}





int main(){

  while(getline(cin,s)){

    if(s=="."){ break; }

    sum1= sum2= 0;

    if( Search1(0) == -1 || (sum1!=0 || sum2!=0) )
      cout << "no" << endl;
    else
      cout << "yes" << endl;

  }
  

  return 0;
}

Measured memory_bytes: 1172
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>

using namespace std;

int main(void)
{
    uint64_t K, A, B;
    cin >> K >> A >> B;

    uint64_t ans = 1;
    if(A > B)
    {
        ans = K + ans;
    }
    else
    {
        uint64_t y = 0;
        while(K--)
        {
            if(y)
            {
                ans += B;
                y = 0;
            }
            else if(ans >= A && K && (B - A > 2))
            {
                ans -= A;
                y = 1;
            }
            else
            {
                ans++;
            }
        }
    }

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

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

using namespace std;
using ll = long long;
#define int ll
using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define PB push_back

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')';
  return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'[';
  REP(i, a.size()) {out<<a[i];if(i!=a.size()-1)out<<',';}
  out<<']';
  return out;
}

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

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

  string s;
  cin >> s;
  int k;
  cin >> k;

  vector<string> vs;
  REP(i, s.size()) {
    string t = "";
    FOR(j, i, i+5) {
      if(j < s.size()) t += s[j];
      vs.PB(t);
    }
  }

  sort(ALL(vs));
  vs.erase(unique(ALL(vs)), vs.end());

  cout << vs[k-1] << endl;

  return 0;
}


Measured memory_bytes: 1660
#include <iostream>
#include <cstdio>

using namespace std;

#define rep(i,n) for(int i=0; i<n; i++)
int main(){
    int l[10];
    int v1,v2;
    while(scanf("%d,",&l[0])!=EOF){
        int sum=l[0];
        for(int i=1; i<10; i++){
            scanf("%d,",&l[i]);
            sum+=l[i];
        }
        scanf("%d,%d",&v1,&v2);
        double inter=1.0*sum*v1/(v1+v2);
        int sub=0;
        int i=0;
        while(sub<inter)sub+=l[i++];
        cout<<i<<endl;
    }
}

Measured memory_bytes: 1200
import sys
#sys.setrecursionlimit(1000000)

class UnionFind():
    def __init__(self,n):
        self.parent = [-1 for _ in range(n)]

    def size(self,x):
        return -self.parent[self.find(x)]

    def find(self,x):
        if(self.parent[x]<0):
            return x
        else:
            self.parent[x]=self.find(self.parent[x])
            return self.parent[x]

    def unite(self,x,y):
        x = self.find(x)
        y = self.find(y)
        if(x == y):
            return False
        if(self.size(x)<self.size(y)):
            self.parent[y]+=self.parent[x]
            self.parent[x]=y
        else:
            self.parent[x]+=self.parent[y]
            self.parent[y]=x
        return True

    def same(self,x,y):
        return self.find(x)==self.find(y)

N,M = [int(x) for x in input().split()]
A = [0]*M
B = [0]*M
ans = [0]*M
for i in range(M):
    A[i],B[i] = [int(x) for x in input().split()]
ans[M-1] = int(N*(N-1)/2)
uni = UnionFind(N)
for i in range(M-1,0,-1):
    ans[i-1]=ans[i]
    if(not uni.same(A[i]-1,B[i]-1)):
        ans[i-1]-=uni.size(A[i]-1)*uni.size(B[i]-1)
        uni.unite(A[i]-1,B[i]-1)
for i in ans:
    print(i)


Measured memory_bytes: 18168
def f(n):
 if(m:=s.get(n))is None:s[n]=m=min([d*n]+[abs(p*k-n)*d+c+f(k)for p,c in zip(a,b)for k in(n//p,0--n//p)])
 return m
exec("n,*b,d=map(int,input().split());a=2,3,5;s={0:0,1:d};print(f(n));"*int(input()))

Measured memory_bytes: 11172
S = str(input())

#list_S_even =  [ c for c in S  if S.index(c)%2==1 ]
#list_S_odd =  [ c for c in S  if S.index(c)%2==0 ]

list_S_even = [c for c in S[1::2]]
list_S_odd =  [c for c in S[::2]]

#print(list_S_even)
#print(list_S_odd)

judge_aaa = True

for i in list_S_even:
    if i == "L" or i == "U" or i == "D":
        pass
    else:
        judge_aaa = False

for i in list_S_odd:
    if i == "R" or i == "U" or i == "D":
        pass
    else:
        judge_aaa = False

if judge_aaa:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int min=1001,max=-1,n;
	cin>>n;
	int a;
	for(int i=0;i<n;i++){
		cin>>a;
		if(max<a)max=a;
		if(min>a)min=a;
	}
	cout<<max-min<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>

using namespace std;

long long sum[2] = {0};

// long long calcSum(int i, long long na[]) {
//     long long sum = 0;
//     for (int j = 0; j <= i; j++) {
//         sum += na[j];
//     }
//     return sum;
// }

long long check(int n, int s, long long a[]) {
    long long cnt = 0;
    long long na[n];

    for (int i = 0; i < n; i++) {
        na[i] = a[i];
        // sum += na[i];

        if (s == 0) {
            sum[s] += na[i];
            // 偶数番目のsumが負の場合
            if (i % 2 == 0 && sum[s] <= 0) {
                // 変更する差分
                long long dx = 1 - sum[s];
                na[i] += dx;
                cnt += abs(dx);
                sum[s] += dx;

                // cout << "dx: " << dx << endl;
                // cout << "cnt: " << cnt << endl;

            } else if (i % 2 != 0 && sum[s] >= 0) {
                // 変更する差分
                long long dx = -1 - sum[s];
                na[i] += dx;
                cnt += abs(dx);
                sum[s] += dx;

                // cout << "dx: " << dx << endl;
                // cout << "cnt: " << cnt << endl;

            }
        }

        if (s == 1) {
            sum[s] += na[i];
            // 奇数番目のsumが負の場合
            if (i % 2 != 0 && sum[s] <= 0) {
                // 変更する差分
                long long dx = 1 - sum[s];
                na[i] += dx;
                cnt += abs(dx);
                sum[s] += dx;

                // cout << "dx: " << dx << endl;
                // cout << "cnt: " << cnt << endl;

            } else if (i % 2 == 0 && sum[s] >= 0) {
                // 変更する差分
                long long dx = -1 - sum[s];
                na[i] += dx;
                cnt += abs(dx);
                sum[s] += dx;

                // cout << "dx: " << dx << endl;
                // cout << "cnt: " << cnt << endl;
            }
        }
    }

    return cnt;
}

int main()
{
    int n; cin >> n;
    long long a[100001];

    for (int i = 0; i < n; i++) cin >> a[i];

    cout <<min(check(n, 0, a), check(n, 1, a)) << endl;

    return 0;
}


Measured memory_bytes: 1024
n, k = gets.split.map(&:to_i)

hash = Hash.new 0
n.times do
  a, b = gets.split.map(&:to_i)
  hash[a] += b
end

hash.sort.each do |a, b|
  k -= b
  if k <= 0
    puts a
    break
  end
end

Measured memory_bytes: 10120
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
 
typedef pair<int,int> P;
struct edge{int to, id;};
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define mod 1000000007

using graph = vector<vector<ll>>;

int main(){
    int n;
    cin >> n;
    int a[n];
    rep(i,n){
        int temp;
        cin >> temp;
        a[i] = temp;
    }
    ll ans;
    ans = 1000;
    ll kosuu = 0;
    for(int i = 0; i < n; i++){
        if(- a[i] * (ans / a[i]) + (ans / a[i]) * a[i+1] > 0){
            int hoge = i+1;
            while(a[hoge] > a[hoge-1] && hoge < n){
                hoge++;
            }
            hoge--;
            ans = ans - a[i] * (ans / a[i]) + (ans / a[i]) * a[hoge];
            i = hoge;
        }
    }
    cout << ans << endl; 
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

#include <vector>
#include <numeric>
#include <utility>
#include <cassert>

struct UnionFind {
public:
	using size_type = std::size_t;
	
	UnionFind(size_type n) : n(n), size_(n, 1) {
		par.resize(n);
		std::iota(par.begin(), par.end(), 0);
	}
	
	size_type size(size_type x) { return size_[find(x)]; }
	
	size_type find(size_type x) {
		assert(x < n);
		while (par[x] != x) {
			par[x] = par[par[x]];
			x = par[x];
		}
		return x;
	}
	
	void unite(size_type x, size_type y) {
		x = find(x);
		y = find(y);
		if (x == y) return;
		if (size(x) > size(y)) std::swap(x, y);
		par[x] = y;
		size_[y] += size_[x];
	}
	
	bool issame(size_type x, size_type y) { return find(x) == find(y); }
	
private:
	size_type n;
	std::vector<size_type> size_, par;
};

int main() {
	int N, M;
	cin >> N >> M;
	UnionFind uf(N);
	
	REP(i, M) {
		int a, b;
		scanf("%d %d", &a, &b);
		--a; --b;
		uf.unite(a, b);
	}
	
	int ans = N - 1;
	REP(i, N) if (uf.find(i) == i) ans -= uf.size(i) - 1;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 4840
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

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

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

void yes() {
  cout << "Yes" << endl;
  exit(0);
}

void no() {
  cout << "No" << endl;
  exit(0);
}

int main() {
  ll n;
  cin >> n;
  vector<string> s(n);
  vector<ll> mini(n,0), last(n);
  ll sum = 0;
  REP(i, n) {
    cin >> s[i];
    ll t = 0;
    REP(j, SZ(s[i])) {
      t += (s[i][j] == '(' ? 1 : -1);
      chmin(mini[i], t);
    }
    last[i] = t;
    sum += t;
  }

  if (sum != 0) {
    no();
  }

  vector<ll> ord(n);
  iota(ALL(ord), 0);
  sort(ALL(ord), [&](ll i, ll j) {
    return min(mini[i], last[i]+mini[j]) > min(mini[j],last[j]+mini[i]); 
  });

  ll c = 0;
  REP(i, n) {
    ll j = ord[i];
    if (c + mini[j] < 0) {
      no();
    }
    c += last[j];
  }

  yes();
}

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

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

    k = ((a*a)-(b*b))/(2*(a-b));

    if(int(k) == double(k)) {
        printf("%10.0Lf\n", k);
    }else{
        cout << "IMPOSSIBLE" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h> 
using namespace std;
typedef long long ll;
const int INF=0x3f3f3f3f;
const int N=5e5+5;
struct Edge{
	int to,w,next;
}edge[N];

struct node{
	int id,d;
	node(int x,int y){id=x;d=y;}
	bool operator <(const node &a)const{
		return d>a.d;
	}
};

int head[N];
int n,m,cnt;
void addedge(int u,int v,int w){
	edge[cnt].to=v;
	edge[cnt].w=w;
	edge[cnt].next=head[u];
	head[u]=cnt++;
}
int dis[N],pre[N];
bool done[N];
void init(){
	for(int i=0;i<N;i++){
		edge[i].next=-1;
		head[i]=-1;
	}
	cnt=0;
}


void dijkstra(){
	int s=1;
	for(int i=1;i<=n;i++){
		dis[i]=INF;
		done[i]=false;
	}
	dis[s]=0;
	priority_queue<node>q;
	q.push(node(s,0));
	while(!q.empty()){
		node u=q.top();
		q.pop();
		if(done[u.id])continue;
		done[u.id]=true;
		for(int i=head[u.id];~i;i=edge[i].next){
			int v=edge[i].to,w=edge[i].w;
			if(done[v])continue;
			if(dis[v]>u.d+w){
				dis[v]=u.d+w;
				q.push(node(v,dis[v]));
				pre[v]=u.id;
			}
		}
	}
	int f=1;
	for(int i=2;i<=n;i++){
		if(dis[i]==INF){
			puts("No\n");
			f=0;
		}	
	}
	if(f==1){
		printf("Yes\n");
		for(int i=2;i<=n;i++){
			printf("%d\n",pre[i]);
		}
	}
}

int main(){
		scanf("%d%d",&n,&m);
		init();
		while(m--){
			int a,b,c;
			scanf("%d%d",&a,&b);
			addedge(a,b,1);
			addedge(b,a,1);
		}
		dijkstra();
	
	return 0;
}

Measured memory_bytes: 13020
n = int(input())
a = 0
b = 0
c = 0
for i in range(n):
    t,x,y = map(int,input().split())
    if (t - a) >= (abs(x - b) + abs(y - c)):
        if ((t - a)%2 != (abs(x-b) + abs(y-c))%2):
            print("No")
            exit()
    else:
        print("No")
        exit()
    a,b,c = t,x,y       
print("Yes")


Measured memory_bytes: 3060
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {
	static double rec(int parent , int cur , double memo[] , List<Integer> ordering, int adj[][] , int idx[][]){
		ordering.add(cur);
		int P = 0;
		double S = 0.0;
		for(int i = 0 ; i < adj[cur].length ; ++i){
			int dst = adj[cur][i];
			if(dst == parent){
				continue;
			}
			int id = idx[cur][i];
			if(memo[id] < 0.0){
				double p = rec(cur , dst , memo , ordering , adj , idx) + 1.0;
				memo[id] = p;
			}
			S += memo[id];
			P = P + 1;
		}
		if(P == 0){
			return 0.0;
		}
		return S / P;
	}
	public static void main(String[] args) throws Exception{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int N = Integer.parseInt(br.readLine());
		int srcs[] = new int[N - 1];
		int dsts[] = new int[N - 1];
		int vsize[] = new int[N];
		for(int i = 0 ; i < N - 1 ; ++i){
			String line = br.readLine();
			int i0 = line.indexOf(' ');			
			int u = Integer.parseInt(line.substring(0, i0)) - 1;
			int v = Integer.parseInt(line.substring(i0 + 1)) - 1;
			srcs[i] = u;
			dsts[i] = v;
			vsize[u]++;
			vsize[v]++;
		}
		int adj[][] = new int[N][];
		int idx[][] = new int[N][];
		for(int i = 0 ; i < N ; ++i){
			adj[i] = new int[vsize[i]];
			idx[i] = new int[vsize[i]];	
		}
		int pointer[] = new int[N];
		for(int i = 0 ; i < N  - 1 ; ++i){
			int s = srcs[i];
			int d = dsts[i];
			adj[s][pointer[s]] = d;
			idx[s][pointer[s]++] = i * 2;
			adj[d][pointer[d]] = s;
			idx[d][pointer[d]++] = i * 2 + 1;

		}
		List<Integer> ordering = new ArrayList<Integer>();
		double memo[] = new double[(N - 1) * 2];
		Arrays.fill(memo, -1);
		double ans[] = new double[N];
		rec(0, 0, memo, ordering, adj , idx);
		for(int cur : ordering){
			double S = 0.0;
			for(int i = 0 ; i < adj[cur].length ; ++i){
				S += memo[idx[cur][i]];
			}
			int size = adj[cur].length;
			ans[cur] = S / size;
			for(int i = 0 ; i < adj[cur].length ; ++i){
				int id = idx[cur][i];
				int redge = id % 2 == 0 ? id + 1 : id - 1;
				if(size == 1){
					memo[redge] = 1.0;
				}else{
					double v = S - memo[id];
					memo[redge] = 1.0 + v / (size - 1);
				}
			}
		}
		StringBuilder sb = new StringBuilder();
		for(double v : ans){
			sb.append(v);
			sb.append('\n');
		}
		System.out.println(sb.toString());
	}
}

Measured memory_bytes: 73556
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
using namespace std;
///////////////////library zone!!!!!!!!!!!!!!!!!!!!!!!!!!!!
typedef long long ll;
typedef long double ld;
#define all(a) (a).begin(),(a).end()
#define EPS (1e-5)
#define bit(n,k) ((n>>k)&1)
const ll Mod = 1000000007;
const ll mod = 998244353;
struct H {
	ll x, y;
	bool operator<(const H &b) const {
		if (x != b.x) return x < b.x;
		return y < b.y;
	}
	bool operator>(const H &b) const {
		if (x != b.x) return x > b.x;
		return y > b.y;
	}
	bool operator==(const H &b) const { return x == b.x&&y == b.y; }
	bool operator!=(const H &b) const { return (*this) != b; }
};
struct P {
	ll pos, cost;
	bool operator<(const P &b) const { return cost < b.cost; }
	bool operator>(const P &b) const { return cost > b.cost; }
};
struct B {
	ll to, cost;
};
struct E {
	ll from, to, cost;
	bool operator<(const E &b) const { return cost < b.cost; }
	bool operator>(const E &b) const { return cost > b.cost; }
};
template<typename T, typename U>
void chmin(T &a, U b) {
	if (a > b) a = b;
}
template<typename T, typename U>
void chmax(T &a, U b) {
	if (a < b) a = b;
}
template<typename T>
T max_0(T a) {
	if (a < 0) return 0;
	return a;
}
template<typename T>
T min_0(T a) {
	if (a > 0) return 0;
	return a;
}
ll read() {
	ll u;
	ll k = scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j%i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}//x^n%p
vector<string>split(string s, char c = ' ') {
	vector<string>vec;
	string h = "";
	for (int i = 0; i < s.size();) {
		int j = i;
		while (j < s.size() && s[j] != ' ') {
			h += s[j++];
		}
		if (h.size() > 0) vec.push_back(h);
		h = "";
		i = j + 1;
	}
	return vec;
}
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int long long
//----------------------------------------------------
int n, a[3];
int d[20];
int solve(int i, int t) {
	if (i == 3) {
		return 0;
	}
	int res = Inf;
	for (int j = 1; j < (1ll << n); j++) {
		if (j & t) continue;
		int sum = 0, k = 0;
		for (int z = 0; z < n; z++) {
			if ((1ll << z) & j) {
				sum += d[z];
				k++;
			}
		}
		res = min(res, (k - 1) * 10 + abs(sum - a[i]) + solve(i + 1, t | j));
	}
	return res;
}
signed main() {
	cin >> n >> a[0] >> a[1] >> a[2];
	for (int i = 0; i < n; i++) cin >> d[i];
	cout << solve(0, 0) << endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
from scipy import ndimage
s = sys.stdin.readlines()
N, W = map(int, s[0].split())
W_matrix = [list(line.strip()) for line in s[1:N + 1]]
matrix_like_list = [[1 if x == "." else 0 for x in W_list] for W_list in W_matrix]
dist = ndimage.distance_transform_cdt(matrix_like_list, metric="taxicab")
print(dist.max())

Measured memory_bytes: 56828
#include<stdio.h>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
 
 
using namespace std;
 
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
 
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//pair sort
bool compare_by_b(pair<LL, LL> a, pair<LL, LL> b) {
    if(a.second != b.second) return a.second < b.second;
    else return a.first < b.first;
}
std::uint32_t euclidean_gcd(std::uint32_t a, std::uint32_t b){return b != 0 ? euclidean_gcd(b, a % b) : a;}


void solve(long long N, long long K, std::vector<long long> t, std::vector<long long> d){
    
}

bool check(string str){
    char c = str[0];
    REP(i, str.size())if(c!=str[i])return false;
    return true;
}

int main(){
    int N, K;
    cin>>N>>K;
    VI A(N);
    REP(_, N)cin>>A[_];
    // int minim = 10000;
    // int idx = 0;
    // REP(i, N){
    //     if(A[i]<minim){
    //         idx=i;minim=A[i];
    //     }
    // }
    // int l = idx+1;
    // int r = N - idx-1;
    int cnt=1;
    N-=K;
    cnt+=ceil(N/(float)(K-1));
    cout<<cnt<<endl;
    return 0;
}

/*
123456


jackal
aacaa


whbrjpjyhsrywlqjxdbrbaomnw 26 (=13*2)

*/

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

ll N;

int main(){
  cin >> N;
  vector<ll> a(N+1);
  for(ll i = 1; i <= N; i++){
    cin >> a[i];
  }
  
  ll now = 1;
  for(ll i = 1; i <= N+1; i++){
    now = a[now];
    if(now == 2) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}

Measured memory_bytes: 1024
#define TST 0
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <cctype>
#include <bits/stdc++.h>
#include <queue>

using namespace std;
// for loop
#define F(i, L, R) for(long i = L; i < R; i++)
#define FE(i, L, R) for(long i = L; i <= R; i++)
// for (reversed)
#define FR(i, L, R) for(long i = L; i > R; i--)
#define FRE(i, L, R) for(long i = L; i >= R; i--)

// data types
#define Int long
#define ul unsigned long
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define us unsigned shoft

// vectors
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
#define ALL(c) (c).begin(),(c).end()
#define last(vec) vec.size()-1
#define lastEle(vec) vec[last(vec)]
#define pb push_back
#define InputV(a, n) F(i,0,n){long l; cin >> l; a.pb(l);}

// debug
#define DBG(vari) cerr<<#vari<<" = "<<(vari)<<endl;
#define printA(a, L, R) FE(i, L, R) cout << a[i] << (i==R?'\n':' ')
#define printAF(a, L) printA(a, 0, L-1)
#define printV(a) printA(a, 0, a.size()-1)
#define printM(a, n, m) F(i, 0, n){ FE(j, 0, m) cout << a[i][j] << (i==m?'\n':' ');}

// utils
#define char2int(c) (c-'0')
#define bit(x, i) (x&(1<<i))
#define space ' '
#define PI 3.14159265358979323

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

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

#define printMatrix(mat,n,m){ \
    F(i, 0, n){               \
        F(j, 0, m){           \
            cout << mat[i][j] << space;\
        }\
        cout << endl;\
    }\
}
struct Proc {
    string name;
    long time;
};

int main() {
#if TST==1
    ifstream in ("input.txt");
    cin.rdbuf(in.rdbuf());
#endif
    queue<Proc> procs;
    long n;
    long q;
    cin >> n;
    cin >> q;
    F(i, 0, n){
        string name;
        long time;
        cin >> name >> time;
        Proc proc = {name, time};
        procs.push(proc);
    }
    long totaltime = 0;
    while(!procs.empty()){
        Proc proc = procs.front();
        procs.pop();
        if(proc.time <= q){
            cout << proc.name << space <<  totaltime+proc.time << endl;
            totaltime += proc.time;
            continue;
        }
        proc.time -= q;
        totaltime += q;
        procs.push(proc);
    }
    
#if TST==1
#endif
    //cout << ans << endl;
}



Measured memory_bytes: 6400
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <set>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int n, m, k, x, y;
    pii a[300005] = {}, b[300005] = {};
    cin >> n >> m >> k;
    set<pii> s;
    while (k--) cin >> x >> y, a[x].first++, b[y].first++, s.insert({x, y});
    for (int i = 1; i <= n; i++) a[i].second = i;
    for (int i = 1; i <= m; i++) b[i].second = i;
    sort(a + 1, a + n + 1); sort(b + 1, b + m + 1);
    for (int i = n; i; i--) {
        for (int j = m; j; j--) {
            if (s.find({a[i].second, b[j].second}) == s.end()) {
                cout << a[n].first + b[m].first;
                return 0;
            }
            if (b[j].first != b[j - 1].first) break;
        }
        if (a[i].first != a[i - 1].first) break;
    }
    cout << a[n].first + b[m].first - 1;
}


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

using namespace std;

#define int long long

struct node {
    int to[26];
    int term;
    node () {
        for (int i = 0; i < 26; ++i) to[i] = -1;
        term = 0;
    }
};

int ans = 0;
string ts;
int last[26];

vector <node> bor;

bool cmp(string &a, string &b) {
    return a.size() < b.size();
}

void add(int id, int v) {
    if (id == ts.size()) {
        ++bor[v].term;
        return;
    }
    for (int i = 0; i < 26; ++i) {
        if (bor[v].to[i] == -1) continue;
        if (last[i] < id) continue;
        ans += bor[bor[v].to[i]].term;
    }
    if (bor[v].to[ts[id] - 'a'] == -1) {
        while (id < ts.size()) {
            int tv = bor.size();
            bor[v].to[ts[id] - 'a'] = tv;
            bor.push_back(node());
            ++id;
            v = tv;
        }
        ++bor[v].term;
        return;
    }
    add(id + 1, bor[v].to[ts[id] - 'a']);
}

void solve() {
    int n;
    cin >> n;
    vector <string> kek(n);
    for (int i = 0; i < n; ++i) cin >> kek[i];
    sort(kek.begin(), kek.end(), cmp);
    node root = node();
    bor.push_back(root);
    for (int i = 0; i < n; ++i) {
        ts = kek[i];
        reverse(ts.begin(), ts.end());
        for (int j = 0; j < 26; ++j) last[j] = -1;
        for (int id = 0; id < ts.size(); ++id) last[ts[id] - 'a'] = id;
        add(0, 0);
    }
    /*for (int i = 0; i < bor.size(); ++i) {
        cout << i << ":\n";
        for (int j = 0; j < 26; ++j) {
            if (bor[i].to[j] == -1) continue;
            cout << (char) ('a' + j) << ' ' << bor[i].to[j] << '\n';
        }
    }*/
    cout << ans;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}


Measured memory_bytes: 228452
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        int H = sc.nextInt();
        int W = sc.nextInt();
        
        String[] line = new String[H];

        for(int i = 0; i < H; i++) {
            line[i] = sc.next();
        }
        
        for(int i = 0; i < H; i++) {
            System.out.println(line[i]);

            System.out.println(line[i]);
        }
    }
}

Measured memory_bytes: 23040
import java.util.*;

class Main
{
    public static void main (String[] args)
    {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a = sc.nextInt();
        String ans = "No";

        if( (n % 500) <= a){
            ans = "Yes";
        } 
        System.out.println(ans);
    }
}

Measured memory_bytes: 23124
N, M = map(int, input().split())
odd_l = 1
odd_r = M
even_l = M + 1
even_r = 2 * M + 1
i = 0
while i < M:
    print(even_l, even_r)
    i += 1
    if i == M:
        break
    print(odd_l, odd_r)
    i += 1
    odd_l += 1
    odd_r -= 1
    even_l += 1
    even_r -= 1


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

int main() {
  string S;
  cin >> S;
  for (int i = 0; i < S.size(); i++) {
    if (S.at(i) == '7') return cout << "Yes" << "\n", 0;
  }
  cout << "No" << "\n";
}

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

int main()
{
    int n, k, sum = 0;
    cin >> n >> k;

    vector<int> a(n, 0);
    for (int i = 0; i < n; i++)
        cin >> a[i];

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

    for (int i = 0; i < k; i++)
        sum += a[i];

    cout << sum  << endl;
    return 0;
}


Measured memory_bytes: 3196
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(;;){
        int n;
        cin >> n;
        if(n == 0)
            return 0;

        int ret = INT_MIN/2;
        int tmp = INT_MIN/2;
        for(int i=0; i<n; ++i){
            int a;
            cin >> a;
            tmp = max(tmp + a, a);
            ret = max(ret, tmp);
        }
        cout << ret << endl;
    }
}

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

int main() {
  string X;
  string Y;
  cin >> X >> Y;
  
  if (X > Y) {
    cout << ">" << endl;
  }
  if (X < Y) {
    cout << "<" << endl;
  }
  if (X == Y) {
    cout << "=" << endl;
  }
}

Measured memory_bytes: 256
#pragma region header
#include <bits/stdc++.h>
using namespace std;
#define int long long
#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 rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define resort(v) sort((v).rbegin(), (v).rend())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
using ll = long long;
using P = pair<int, int>;
/* ----------------よく使う数字や配列----------------- */
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
constexpr ll mod = 1e9+7;
constexpr ll inf = INT32_MAX/2;
constexpr ll INF = LLONG_MAX/2;
constexpr long double eps = DBL_EPSILON;
constexpr long double pi = 3.141592653589793238462643383279;
/* ----------------------end----------------------- */

/* --------------------テンプレート------------------ */
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
/* ----------------------end----------------------- */

/* --------------------ライブラリ-------------------- */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i % mod;
}
ll gcd(ll a, ll b) {        //最大公約数
    if(b == 0) return a;
    return gcd(b, a % b); 
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a * b / gcd(a, b);
}
int keta(ll n) {        //桁数を求める
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
/* ----------------------end----------------------- */
#pragma endregion
signed main() { 
    int h,w;cin >> h >> w;
    vvb bo(h,vb(w));
    vector<P> v;
    rep(i, h) {
        rep(j, w) {
            char c;cin >> c;
            if(c=='#') {
                bo[i][j]=true;
                v.pb({i,j});
            }
            else bo[i][j]=false;
        }
    }
    bool ok = true;
    rep(i, v.size()) {
        rep(j, 4) {
            int x=v[i].first+dx[j],y=v[i].second+dy[j];
            if(x<0||x>=h||y<0||y>=w||!bo[x][y]) {
                // cout << i << endl;
                if(j==3) {
                    cout << "No" << endl;
                    return 0;
                }
                continue;
            }
            break;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 3640
#include<stdio.h>

#define ll long long

class FIO
{
public:
    template<typename T>FIO& operator >>(T& x){ _R(x);return *this; }
    template<typename T>FIO& operator <<(T x){ _W(x);return *this; }
private:
    char f,c,a[25],i;
    template<typename T>inline void _R(T& x)
    {
        for(f=0;(c=getchar())<48;c==45&&(f=1));
        for(x=c^48;(c=getchar())>47;x=(x<<3)+(x<<1)+(c^48));
        if(f)x=-x;
    }
    template<typename T>inline void _W(T x)
    {
        if(sizeof(x)==1){ putchar(x);return; }
        if(x<0)putchar(45),x=-x;
        if(x>99) {
            for(i=0;x;x/=10)a[i++]=x%10;
            while(i--)putchar(a[i]+48);
        } else if(x>9) putchar(x/10+48),putchar(x%10+48);
        else putchar(x+48);
    }
}io;

int main()
{
    ll n;
    io>>n;
    ll ans=0;
    for(register int i=1;i<=n;++i) {
        if(i%3==0||i%5==0)continue;
        ans+=i;
    }
    io<<ans;
    return 0;
}

Measured memory_bytes: 1492
s = input()
n = len(s)
t = s.replace("x","")
rt = t[::-1]
m = len(t)
if t != rt:
    print(-1)
    exit()

kouho = [0 for i in range(m+1)]
cou = 0
for i in range(n):
    if s[i] == "x":
        kouho[cou] += 1
    else:
        cou += 1

ans = 0
for j in range(-(-m//2)):
    ans += abs(kouho[j]-kouho[m-j])
    
print(ans)

Measured memory_bytes: 4060
n,q = map(int,input().split())
s = input()
l = [list(map(int,input().split())) for i in range(q)]
#print(n,q,s,l)

ac = []
for i in range(n-1):
    if s[i] == "A" and s[i+1] == "C":
        ac.append(i)
#print(ac)
cum = [0]*n
for i in range(1,n):
    if s[i-1] == "A" and s[i] == "C":
        cum[i] = cum[i-1] + 1
    else:
        cum[i] = cum[i-1]
#print(cum)
ans = 0 
for i in range(q):
    left = l[i][0]-1
    right = l[i][1]-1
    ans = cum[right] - cum[left]
    print(ans)

Measured memory_bytes: 69464
/**
*   @Author : MeGA
*   @InitTime :01/25/20 11:11:36
*   @Idea : 
*
*
*
*
*
*
*
**/
#include <bits/stdc++.h>
using namespace std;
string s;
int n;

const int MOD=1e9+7;
int dp[(int)1e5+7][15];
int solve(int idx,int rem){
    if(idx==n){
       return rem==5?1:0;
    }
    int &ret=dp[idx][rem];
    if(ret!=-1){
    	return  ret;
    }
    ret=0;
    if(s[idx] != '?')
    return ret=solve(idx+1,(rem*10+(s[idx]-'0'))%13);
    for(int i=0;i<=9;i++){
       ret=(1ll*ret+1ll*solve(idx+1,(rem*10+i)%13))%MOD;
    }
    return ret;
}
int main(){
#ifndef ONLINE_JUDGE
  // freopen("in","r",stdin);
  // freopen("out","w",stdout);
#endif
     cin>>s;
     n=s.size();
     memset(dp,-1,sizeof(dp));
     printf("%d",solve(0,0));


}

Measured memory_bytes: 14108
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define INF 999999999
#define rep(i,n) for(int i=0;i<n;i++)
const int mod = 1000000007;
ll cnt = 0;

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

   s.at(k-1) = s.at(k-1)+32;
   cout << s << endl;
}

Measured memory_bytes: 256
#include <string>
#include <cctype>
#include <iostream>
using namespace std;
#define loop(i,a,b) for(int i=a; i<(int)(b); i++)
#define rep(i,n) loop(i,0,n)

int Num(const string & s, int & i){
    int res = 0;
    while (isdigit(s[i])){
        res *= 10;
        res += s[i++] - '0';
    }
    return res;
}

int main(){
    int n = 0; string s;
    while (cin >> s){
        rep(i, s.size())
            if (isdigit(s[i]))
                n += Num(s, i);
    }
    cout << n << endl;
}

Measured memory_bytes: 1188
N=int(input())

ba=0
_a=0
b_=0

ans=0
for i in range(N):
    s=input()
    ans+=s.count("AB")
    if s[0]=="B" and s[-1]=="A":
        ba+=1
    elif s[-1]=="A":
        _a+=1
    elif s[0]=="B":
        b_+=1

#print(ans)

if ba>0:
    ans+=(ba-1)
    if _a>0:
        _a-=1
        ans+=1
    if b_>0:
        b_-=1
        ans+=1

ans+=min(_a,b_)

print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define init ios::sync_with_stdio(0); cin.tie(NULL);cout.tie(NULL);
using namespace std;
//  =========     /\       /|    |====/|
//      |        /  \       |    |   / |
//      |       /____\      |    |  /  |
//      |      /      \     |    | /   |
//  ========= /        \  =====  |/====|  
//  code

int main(){
    init;
    int n,m,i,j,k,l;
    string s,t;
    cin>>s>>t;
    n = s.length();
    m = t.length();
    int dp[n+1][m+1];
    memset(dp,0,sizeof(dp));
    dp[0][0] = 0;
    for(i=0;i<n;i++){
        for(j=0;j<m;j++){
            if(s[i] == t[j])
                dp[i+1][j+1] = 1 + dp[i][j];
            else dp[i+1][j+1] = max(dp[i+1][j] , dp[i][j+1]);
        }
    }
    string p;
    p.resize(dp[n][m]);
    k = dp[n][m] - 1;
    i = n-1,j = m-1;
    while(k >= 0){
        if(s[i] == t[j]){
            p[k] = s[i];
            k--;
            i--;
            j--;
        }
        else if(dp[i+1][j] > dp[i][j+1]){
            j--;
        }
        else i--;
    }
    cout<<p<<endl;
    return 0;
}

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

int main()
{
  long X, A, B;
  cin >> X >> A >> B;

  string ans;
  if (A >= B)
    ans = "delicious";
  else if (X >= B - A)
    ans = "safe";
  else
    ans = "dangerous";

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256