akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

typedef ostringstream OSS;
typedef istringstream ISS;

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

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef vector<VS> VVS;
typedef vector<bool> VB;
typedef vector<VB> VVB;
typedef vector<PII> VPII;

#define Y first
#define X second
#define MP make_pair
#define PB push_back
#define EB emplace_back 
#define ALL(x) (x).begin(),(x).end()
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl

template < typename T > inline T fromString(const string &s) { T res; ISS iss(s); iss >> res; return res; };
template < typename T > inline string toString(const T &a) { OSS oss; oss << a; return oss.str(); };

const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};

int H, W;
VB as;
map<char, VPII> poss;
VS ts;

bool dire(PII a1, PII a2) {
	int dx = a1.X - a2.X;
	int dy = a1.Y - a2.Y;

	return (dx < 0 && dy < 0) ||
		   (dx > 0 && dy > 0);
}

bool can_erase(char c0) {
	PII a1 = poss[c0][0];
	PII a2 = poss[c0][1];

	if ((abs(a1.X - a2.X) + abs(a1.Y - a2.Y)) == 1) {
		return false;
	}

	int min_x = min(a1.X, a2.X);
	int max_x = max(a1.X, a2.X);
	int min_y = min(a1.Y, a2.Y);
	int max_y = max(a1.Y, a2.Y);
	bool rev = dire(a1, a2);

	for (int i = 0; i < 2; i++) {
		bool ans = [&]()->bool{
			{
				int y = i ? min_y : max_y;
				for (int x = min_x; x <= max_x; x++) {
					char c = ts[y][x];
					if (c == '.') continue;
					if (c == c0) continue;
					if (as[c - 'A']) {
						return false;
					}
				}
			}

			{
				int x = (!!i ^ rev) ? min_x : max_x;
				for (int y = min_y; y <= max_y; y++) {
					char c = ts[y][x];
					if (c == '.') continue;
					if (c == c0) continue;
					if (as[c - 'A']) {
						return false;
					}
				}
			}

			return true;
		}();

		if (ans) return true;
	}

	return false;
}

bool erase(char c) {
	if (!as[c - 'A']) return false;
	if (!can_erase(c)) return false;
	as[c - 'A'] = false;

	return true;
}

int main(void) {
	cin >> H >> W;
	as.resize(26);
	ts.resize(H);

	for (int y = 0; y < H; y++) {
		cin >> ts[y];
		for (int x = 0; x < W; x++) {
			char c = ts[y][x];
			if (c == '.') continue;

			as[c - 'A'] = true;
			poss[c].EB(y, x);
		}
	}

	//////

	int cnt = 0;

	for (int ti = 0; ti < 26; ti++) {
		for (int i = 0; i < 26; i++) {
			char c = 'A' + i;
			cnt += (erase(c) ? 2 : 0);
		}
	}

	////

	cout << cnt << endl;

	return 0;
}

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

int main(void){
	int a,b,c,d,e,f;
	int ans1=0, ans2=0;
	cin >> a >> b >> c >> d >> e >> f;
	a*=100; b*=100;
	for(int A=0; a*A<=f; A++){
		for(int B=0; b*B+a*A<=f; B++){
			for(int C=0; a*A+b*B+c*C<=f; C++){
				for(int D=0; a*A+b*B+c*C+d*D<=f; D++){
					int suger=c*C+d*D, water=a*A+b*B;
					if(suger > water/100*e)break;
					if(ans2*(water+suger)<=ans1*suger){
						ans1=water+suger;
						ans2=suger;
					}
				}
			}
		}
	}
	cout << ans1 << " " << ans2 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define all(x) (x).begin(), (x).end()
#define getsize(x) ((long long)(x).size())
#define srt(x) sort((x).begin(), (x).end())
#define rsrt(x) sort((x).rbegin(), (x).rend())
#define g(a, b) __gcd((a), (b))
#define l(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<long long>;
using vllvll = vector<vll>;
using vc = vector<char>;
using vs = vector<string>;
using um = unordered_map<long long, long long>;
template<class T>void print(T x) { cout << '\n' << "== " << x << " ==" << '\n'; }
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T>void precise(T x) { cout << setprecision(21) << x << '\n'; }
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<class T, class U>T rem(T a, U b) { return a - b*floor(a/b); }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
const long double pi = M_PI;
const long double doublepi = M_PI * 2.0;
const long double halfpi = M_PI / 2.0;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long MOD = 1e9 + 7;



int main()
{
    ll N, M;
    cin >> N >> M;
    vll s(M), c(M);
    rep(i, 0, M) cin >> s[i] >> c[i];
    ll ans = -1;
    rep(i, 0, (ll)round(pow(10, N))) {
        string digits = to_string(i);
        if (getsize(digits) != N) continue;
        bool flg = true;
        rep(i, 0, M) {
            if (digits[s[i]-1]-'0' != c[i]) {
                flg = false;
                break;
            }
        }
        if (flg) {
            ans = i;
            break;
        }
    }
    cout << ans << endl;
}

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

const int mod = 1000000007;
struct mint {
  ll x;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
};

int main(){
  long long n, k;
  cin >> n >> k;
  mint ans=0;
  
  for(long long i=k;i<=n+1;i++){
    ll mx = (n+n-i+1)*i/2;
    ll mn = (i-1)*i/2;
    ll tmp = mx-mn+1;
    //cout << "[" << tmp << "]";
    ans += tmp;
  }

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


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

using namespace std;

typedef long long ll;

const double pi = 3.14159265358979323846;

#define rep(i, n) for (ll i = 0; i < n; i++)
#define mod 1000000007LL
#define PS(p) cout << setprecision(15) << fixed << p << endl;
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
#define ALL(c) c.begin(), c.end()

bool isClear(int h[], int r[], int N) {
  for (int i = 0; i < N; i++) {
    if (h[i] != r[i])
      return false;
  }

  return true;
}

void print(int h[], int N) {
  for (int i = 0; i < N; i++) {
    cout << h[i] << " ";
  }

  cout << endl;
}

void setCurrent(int h[], int l, int r, int setV) {
  for (int i = l; i < r; i++) {
    h[i] = setV;
  }
}

int h[101];
int current[101];

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

  int minH = INT_MAX;

  for (int i = 0; i < N; i++) {
    cin >> h[i];
    minH = min(h[i], minH);
  }

  h[N + 1] = INT_MAX;
  current[N + 1] = INT_MAX;

  // 全部最小値に埋める
  int count = minH;
  for (int i = 0; i < N; i++) {
    current[i] = minH;
  }

  while (!isClear(h, current, N)) {
    int push = 0;
    int r = 0;

    for (int l = 0; l < N; l++) {
      minH = INT_MAX;
      // 一緒
      if (current[l] == h[l]) {
        // cout << "same l => " << l << " current => " << current[l] << endl;
        continue;
      }
      // cout << "l => " << l << " current => " << current[l] << endl;

      for (r = l; r < N + 1; r++) {

        if (current[r] == h[r]) {
          // cout << "same current r => " << r << " current => " << current[r] << endl;
          // cout << minH << " c " << current[l] << " count " << minH - current[l] << endl;
          count += minH - current[l];
          setCurrent(current, l, r, minH);

          break;
        } else {
          minH = min(minH, h[r]);
        }
      }

      break;
    }
  }

  cout << count << endl;

  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}


signed main() {
    int A, B, C;
    cin >> A >> B >> C;

    if(A==B) cout << C;
    else if(B==C) cout << A;
    else cout << B;
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
const int MOD = 1000000007;
int main(){
    int n;string s;
    cin>>n>>s;
    ll all=0,r=0,g=0,b=0;
    for (auto c:s)
    {
        /* code */
        if (c=='R')
        {
            /* code */
            r++;
        }
        else if (c=='G')
        {
            /* code */
            g++;
        }
        else
        {
            b++;
        } 
    }
    all=r*g*b;
    ll sub=0;
    for (int i = 0; i < n; i++)
    {
        /* code */
        for (int j = i+1; j < n; j++)
        {
            if(s[i]==s[j])continue;
            int k=2*j-i;
            if(k>=n||s[k] == s[i] || s[k] == s[j])continue;
            sub++;
        }
        
    }
    
    cout<<all-sub<<endl;
    
}

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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;

#define REP(k, n) for (ll k = 0; k < (ll)(n); ++k)
#define REPREV(k, n) for (ll k = (ll)(n)-1; k >= 0; --k)
#define FOR(k, a, b) for (ll k = (ll)(a); k < (ll)(b); ++k)
#define FORREV(k, a, b) for (ll k = (ll)(b)-1; k >= (ll)(a); --k)
#define FOREACH(e, v) for (auto e : v)

#define TGET(t, i) get<i>(t)
#define TSET(t, i, a) get<i>(t) = a
// MinHeap - priority_queue<ll, vll, greater<ll>> pq;

#define EVEN(n) ((n)&1) == 0
#define ODD(n) ((n)&1) == 1
#define MOD(x, m) ((x) % (m) + (m)) % (m)

#define SORT(v) sort(v.begin(), v.end())
#define SORTREV(v) sort(v.rbegin(), v.rend())
#define SHUFFLE(v) random_shuffle(v.begin(), v.end())
//srand(unsigned(time(0)));

#define REMOVEAT(v, i) v.erase(v.begin() + i)
#define REVERSE(v) reverse(v.begin(), v.end())

template <typename T>
void join(vector<T>& arr, string sep) {
    bool first = true;
    for (auto t : arr) {
        if (first) {
            first = false;
            cout << t;
        } else {
            cout << sep << t;
        }
    }
    cout << "\n";
}

#define POS "POSSIBLE"
#define IMPOS "IMPOSSIBLE"

// #define INF LLONG_MAX
// #define MINF LLONG_MIN
#define INF 9e18
#define MINF -INF

const ll m = 1e9+7;

ll power(ll a, ll b, ll m) {
    ll res = 1;
    while (b > 0) {
        if (b % 2 == 1)
            res = (res * a) % m;
        a = (a * a) % m;
        b /= 2;
    }
    return res;
}

void solve() {
    ll n, k;
    cin >> n >> k;

    ll res = 0;
    vll dp(k+1);
    FORREV(i, 1, k+1) {
        dp[i] = k / i;
        dp[i] = power(dp[i], n, m);
        FOR(j, 2, k+1) {
            if (j * i > k)
                break;
            dp[i] = MOD(dp[i] - dp[j*i], m);
        }
        res = MOD(res + MOD(dp[i] * i, m), m);
    }
    cout << res << "\n";
}

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

    return 0;
}

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

using namespace std;

using ll = long long;

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

    string s;
    cin >> s;

    bool win_fst = true;
    if ((s.size() & 1) && (s.front() == s.back())) win_fst = false;
    if (!(s.size() & 1) && (s.front() != s.back())) win_fst = false;

    if (win_fst) cout << "First\n";
    else cout << "Second\n";

    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define int long long
#define INF 1000000000000000000
using namespace std;

typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int, int> Pii;

template<typename T>
void readv(vector<T> &a){ REP(i, a.size()) cin >> a[i]; }
void readi(vector<int> &a){ REP(i, a.size()){cin >> a[i]; a[i]--;} }



signed main(){

    int N; cin >> N;
    vec A(N); readv(A);

    int ans = 0;
    vec p(0);
    REP(i, N){
        int tmp = max(0LL, (A[i] - 2) / 2);
        ans += tmp;
        A[i] -= 2 * tmp;
        REP(k, A[i]) p.push_back(i);
    }
    
    int i = 0;
    while(i < (int)p.size() - 1){
        if(p[i + 1] - p[i] <= 1){
            ans++;
            i += 2;
        }else i++;
    }
    cout << ans;
    
    return 0;
}

Measured memory_bytes: 6896
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define start_routine() int begtime = clock();
#define end_routine() int endtime = clock(); \
                      cerr << "\n\n" << "Time elapsed: " << \
                      (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n"; \
                      return 0
#define ll long long int
#define ull unsigned long long int
#define db long double
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound 
#define pii pair<int , int>
#define pdd pair<db , db>
#define pll pair<ll , ll>
#define vpl vector<pll >
#define vll vector<ll >
#define mod 1000000007
#define mod1 998244353 
#define inf 1000000000000000007
#define eps 0.000001
#define stp fixed<<setprecision(20)
#define endl '\n'



int main()
{
    fastio;
    #ifdef APNA_IO
        start_routine();
        freopen("input.txt", "rt", stdin);
        freopen("output.txt", "wt", stdout);    
    #endif

    string s;cin>>s;
    ll f=0,n=s.size();
    for(ll i=0;i<s.size();i++)
        if(s[i]=='o')
            f++;

    if((f+(15-n))>=8) cout<<"YES";
    else cout<<"NO";

    #ifdef APNA_IO
        end_routine();
    #endif
}

Measured memory_bytes: 256
n, a, b = list(map(int, input().split()))

if (b - a) % 2 == 0:
    print((b - a) // 2)
    exit()

result = 10 ** 19

result = min(result, n - a)
result = min(result, b - 1)
result = min(result, a + ((b - a) -1 )//2)
result = min(result, (n - b) + 1 + ((n - ((n - b) + 1 + a)) // 2))

print(result)

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

int main() {
    ll n;
    cin >> n;
    vector<ll> a(n, 0);
    vector<ll> cnt(n+10, 0);
    for (int i = 0; i < n; i++){
        cin >> a.at(i);
        cnt.at(a.at(i))++;
    }
    
    ll sum = 0;
    for (ll c : cnt)
    {
        sum += (c-1)*c/2;
    }


    for (int i = 0; i < n; i++)
    {
        cout << sum - (ll)(cnt.at(a.at(i)) - 1) << endl;
    }

    return 0;
}

Measured memory_bytes: 6372
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
int main() {
  string s;
  cin >> s;
  vector<int> a(s.size(),0);
  int f=0;
  int g=0;
  bool ex=true;
  rep(i,s.size()-1){
    if(s.at(i)=='L'&&s.at(i+1)=='R'){
      g=i;
      ex=false;
      break;
    }
  }
  if(ex){
    g=s.size()-1;
  }
  while(g<s.size()-1){
    ex=true;
    rep2(i,f,g){
      if(s.at(i)=='R'&&s.at(i+1)=='L'){
        a.at(i)=(i-f)/2+(g-i+2)/2;
        a.at(i+1)=(i+1-f)/2+(g-i+1)/2;
      }
    }
    f=g+1;
    rep2(i,f,s.size()-1){
      if(s.at(i)=='L'&&s.at(i+1)=='R'){
        g=i;
        ex=false;
        break;
      }
    }
    if(ex){
      g=s.size()-1;
    }
  }
  rep2(i,f,g){
    if(s.at(i)=='R'&&s.at(i+1)=='L'){
      a.at(i)=(i-f)/2+(g-i+2)/2;
      a.at(i+1)=(i+1-f)/2+(g+1-i)/2;
    }
  }
  rep(i,s.size()) {
    cout<<a.at(i)<<" ";   
  }
  cout<<endl;
}

Measured memory_bytes: 1024
h,w = map(int,input().split())
a = [[(i == "#")*1 for i in list(input())] for _ in range(h)]
dp = [[float("inf")]*w for _ in range(h)]
dp[0][0] = a[0][0]
def cnt(i0,j0,i1,j1):
  if a[i0][j0] == 0 and a[i1][j1] == 1:
    return 1
  return 0

for s in range(h+w):
  for i in range(s+1):
    j = s - i
    if i >= h or j >= w:
      continue
    if i < h-1:
      dp[i+1][j] = min(dp[i+1][j],dp[i][j]+cnt(i,j,i+1,j))
    if j < w-1:
      dp[i][j+1] = min(dp[i][j+1],dp[i][j]+cnt(i,j,i,j+1))
print(dp[-1][-1])

Measured memory_bytes: 3188
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;

vector <P> ans;
string str;

int main(){
  ll anssum=0,anssize=0;
  ll maxH,nowH,cnt,maxW;
  cin>>str;
  maxH=nowH=20000LL;
  cnt=0;

  for(int i=0;i<(int)str.size();i++){

    if(str[i]=='/'){
      nowH++;
      if(maxH==nowH){
	cnt++;
	ans.push_back(P(i,cnt/2));
	cnt=0;
      }else if(maxH<nowH){
	maxH=nowH;
      }else{
	cnt+=(maxH-nowH)*2+1;
      }
      
    }else if(str[i]=='_'){

      if(maxH>nowH){
	cnt+=(maxH-nowH)*2;

      }
    }else{

      nowH--;
      if(maxH>nowH){
	cnt+=(maxH-nowH)*2-1;
      }

    }
  }
  
  maxH=nowH=20000LL;
  maxW=(int)str.size()-1;

  cnt=0;

  for(int i=(int)str.size()-1;i>=0;i--){
    if(str[i]=='\\'){
      nowH++;
      if(maxH==nowH){
	cnt++;
	ans.push_back(P(maxW,cnt/2));
	cnt=0;
      }else if(maxH<nowH){
	maxH=nowH;
	maxW=i;
      }else{
	cnt+=(maxH-nowH)*2+1;
      }
    }else if(str[i]=='_'){
      if(maxH>nowH){
	cnt+=(maxH-nowH)*2;
	
      }else if(maxH==nowH){
	maxW=i;
      }
    }else{
      if(nowH==maxH)maxW=i;
      nowH--;
      if(maxH>nowH){
	cnt+=(maxH-nowH)*2-1;
      }
    }
  }

  sort(ans.begin(),ans.end());
  anssum=anssize=0;
  for(int i=0;i<(int)ans.size();i++){
    if(i>0&&ans[i-1]==ans[i])continue;
    anssum+=ans[i].second;
    anssize++;
  }
  
  cout<<anssum<<endl;
  cout<<anssize;
  for(int i=0;i<(int)ans.size();i++){
    if(i>0&&ans[i-1]==ans[i])continue;
    cout<<' '<<ans[i].second;
  }
  cout<<endl;
}

Measured memory_bytes: 1304
#include <stdio.h>

int main() {
  int N, A, B;
  scanf("%d", &N);
  
  if (N == 1)
    printf("Hello World");
  else if (N == 2) {
  	scanf("%d", &A);
    scanf("%d", &B);
    printf("%d", A+B);
  }
  return 0;
}

Measured memory_bytes: 128
from itertools import product

def main():
    n = int(input())
    a = []
    ls = []
    ans = 0
    for _ in range(n):
        ai = int(input())
        a.append(ai)
        ls.append([tuple(map(int, input().split())) for i in range(ai)])
    ptns = list(product([0,1], repeat=n))
    for ptn in ptns:
        flag = 0
        lsls = list(ptn)
        for j in range(n):
            if ptn[j] == 1:
                for i in range(a[j]):
                    if ls[j][i][1] == 1 and lsls[ls[j][i][0]-1] == 1:
                        lsls[ls[j][i][0]-1] *= ls[j][i][1]
                    elif ls[j][i][1] == 0 and lsls[ls[j][i][0]-1] == 0:
                        lsls[ls[j][i][0]-1] *= ls[j][i][1]
                    else:
                        flag = 1
        if flag == 0:
            if list(ptn) == lsls:
                if ans < sum(ptn):
                    ans = sum(ptn)
    print(ans)

if __name__ == "__main__":
    main()

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

#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define RFOR(i, a, b) for(int i=(a); i>=(b); i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define CEIL(n, m) ceil(n/pow(10.0, m))*pow(10.0, m)
#define FLOOR(n, m) floor(n/pow(10.0, m))*pow(10.0, m)
#define ROUND(n, m) round(n/pow(10.0, m))*pow(10.0, m)
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define RSORT(x) sort((x).begin(),(x).end(),greater<int>())
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) " (L" << __LINE__ << ") " << __FILE__ << endl;

typedef long long ll;
const int mod = 1e9+7;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;

void solve()
{
  ll ans=0;

  ll x,y; cin>>x>>y;
  while (x <= y) {
    ans++;
    x*=2;
  }

  cout << ans << endl;
}

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


Measured memory_bytes: 256
#include <iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<limits>
#include<string.h>
#include<vector>
#include<stack>
#include<queue>
using namespace std;

int main()
{
    string a;
    cin>>a;
    int b=a.size();
    char c=a[b-1];
    if (c=='s')
    {
        a+="es";
    }else
    {
        a+="s";
    }
    
    cout<<a<<endl;
    

    return 0;
}

Measured memory_bytes: 3136
#include <iostream>
using namespace std;
int n, s, sum = 0;
void f(int*,int);

int main() {
	while (1) {
		cin >> n >> s;
		if (n == 0 && s == 0)
			break;
		int *a;
		a = new int[n];
		f(a, 0);
		cout << sum << endl;
		sum = 0;
		delete[] a;
	}
	return 0;
}

void f(int *a, int x) {
	if (x == 0)
		a[0] = 0;
	else
		a[x] = a[x - 1] + 1;
	if (x == n - 1) {
		for (; a[x] < 10; a[x]++) {
			int y = 0;
			for (int i = 0; i < n; i++) {
				y += a[i];
				//cout << a[i] << " ";
			}
		//	cout << endl;
			if (y == s)
				sum++;
		}
		return;
	}
	for (; a[x] <= 10 - n + x; a[x]++)
		f(a, x + 1);
	return;
}



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

int N;
int a[200001];

signed main() {
  cin >> N; 
  for(int i=1; i<=N; i++) cin >> a[i];

  vector<int> b(N+1, 0);
  int M = 0;
  set<int> bi;

  for(int i=N; i>0; i--) {
    if(i*2>N) {
      b[i] = a[i];
      M += b[i];
      if(b[i]) bi.insert(i);
      continue;
    }

    int sum = 0;
    for(int j=i*2; j<=N; j+=i) sum += b[j];
    sum %= 2;
    b[i] = a[i] ^ sum;
    if(b[i]) bi.insert(i);
    M += b[i];
  }

  cout << M << endl;
  for(auto i : bi) {
    cout << i << " ";
  }
  cout << endl;
}


Measured memory_bytes: 8576
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define mod 1000000007
#define pb emplace_back
#define mp make_pair
#define fi first
#define sec second
typedef long long ll;
typedef long double  ld;
#define pii pair<ll,ll> 
#define vi vector< ll > 
#define vvi vector< vi > 
#define vpi vector< pii > 
#define vvpi vector< vpi > 
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define test(t) ll t;cin>>t;while(t--)
#define mem(a,b) memset(a,b,sizeof(a))
#define inn freopen("input.txt", "r", stdin)
#define outt freopen("output.txt", "w", stdout)
#define all(arr) arr.begin(),arr.end()
#define fr(i,n) for(ll i=0;i<(n);++i)
#define rep(i,a,b) for(ll i=a;i<=b;++i)
#define per(i,a,b) for(ll i=a;i>=b;i--)
#define remin(a,b) (a=min((a),(b)))
#define remax(a,b) (a=max((a),(b)))
#ifndef ONLINE_JUDGE
#define debarr(a,n)cerr<<#a<<":";for(int i=0;i<n;i++)cerr<<a[i]<<" ";cerr<<endl;
#define debmat(mat,row,col)cerr<<#mat<<":\n";for(int i=0;i<row;i++){for(int j=0;j<col;j++)cerr<<mat[i][j]<<" ";cerr<<endl;}
#define pr(...)dbs(#__VA_ARGS__,__VA_ARGS__)
template<class S,class T>ostream &operator<<(ostream &os,const pair<S,T> &p){return os<<"("<<p.first<<","<<p.second<<")";}
template<class T>ostream &operator<<(ostream &os,const vector<T> &p){os<<"[";for(auto&it:p)os<<it<<" ";return os<<"]";}
template<class T>ostream &operator<<(ostream &os,const set<T>&p){os<<"[";for(auto&it:p)os<<it<<" ";return os<<"]";}
template<class T>ostream &operator<<(ostream &os,const multiset<T>&p){os<<"[";for(auto&it:p)os<<it<<" ";return os<<"]";}
template<class S,class T>ostream &operator<<(ostream &os,const map<S,T>&p){os<<"[";for(auto&it:p)os<<it<<" ";return os<<"]";}
template<class T>void dbs(string str,T t){cerr<<str<<":"<<t<<"\n";}
template<class T,class...S>void dbs(string str,T t,S... s){int idx=str.find(',');cerr<<str.substr(0,idx)<<":"<<t<<",";dbs(str.substr(idx+1),s...);}
#else
#define pr(...){}
#define debarr(a,n){}
#define debmat(mat,row,col){}
#endif
ll power(ll x,ll y){ll res = 1;while(y){if(y&1) res = (res*x)%mod;y=y/2,x=(x*x)%mod;}return res%mod;}
signed main()
{
    fast;
    ll n;
    cin>>n;
    ll arr[n];
    ll i;
    for(i=0;i<n;i++)
        cin>>arr[i];
    sort(arr,arr+n);
    ll ans = 0;
    for(i=1;i<=n;i++)
    {
        ll temp = power(2,n-1)+(n-i)*power(2,n-2)%mod;
        temp%=mod;
        temp = temp*arr[i-1]%mod;
        ans = ans+temp;
        ans%=mod;
    }
    ans = ans*power(2,n)%mod;
    cout<<ans;
    
}


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


void solve(long long N, std::vector<long long> A){
  sort(A.begin(), A.end());

  cout << abs(*A.begin() - *(A.end()-1)) << endl;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
  scanf("%lld",&N);
  std::vector<long long> A(N);
  for(int i = 0 ; i < N ; i++){
    scanf("%lld",&A[i]);
  }
    solve(N, std::move(A));
    return 0;
}


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

using namespace std;

const int mxn = 1e6;

bool flag[mxn + 11];

int main(){
	int k;
	scanf("%d", &k);
	int cur = 0;
	for (int i = 1; i; i++){
		cur *= 10;
		cur += 7;
		if (cur % k == 0){
			printf("%d\n", i);
			return 0;
		}
		cur %= k;
		if (flag[cur]){
			puts("-1");
			return 0;
		}
		flag[cur] = true;
	}
}


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

using namespace std;

typedef long long ll;

const int MAXN = 1e5 + 5;

int N, M;

vector<int> adj[MAXN];

set<int> s0, s1;

bool vis[MAXN][2];
void dfs(int pos, int st){
    vis[pos][st] = true;

    if(st) {
        //cout << "Find " << pos << "\n";
        s1.insert(pos);
    } else {
        s0.insert(pos);
    }
    for(int i : adj[pos]){
        if(!vis[i][!st]){
            dfs(i, !st);
        }
    }
}

int main(){
    cin.tie(0);
    cin.sync_with_stdio(0);

    cin >> N >> M;
    for(int a = 0; a < M; a++){
        int u, v;
        cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }

    ll ans = 0;
    for(int a = 1; a <= N; a++){
        if(!vis[a][0]){
            // cout << "Start " << a << "\n";
            s0.clear();
            s1.clear();

            dfs(a, 0);
            
            ans += (ll)s0.size() * s1.size();
            for(int i : s0){
                if(s1.count(i)){
                    ans--;
                }
                ans -= adj[i].size();
            }
        }
    }
    cout << ans / 2 << "\n";
}

Measured memory_bytes: 17024
from collections import deque

N = int(input())
A = [deque([ a-1 for a in map(int, input().split())]) for _ in range (N)]
cnt = 0
cur = [-1 for _ in range(N+1)]
day = [0 for _ in range(N+1)]
que = deque( range(N) )

while que:
    x = que.popleft()
    if not A[x]:
        continue
    y = A[x].popleft()
    if cur[y] == x:
        cnt += 1
        day[x] = day[y] = max(day[x], day[y]) + 1
        cur[x] = cur[y] = -1
        que.append(x), que.append(y)
    else:
        cur[x] = y

flag = ( cnt == N*(N-1)/2 )
print( max(day) if flag else -1 )

Measured memory_bytes: 36016
//ALDS1_6_B_Partition

#include<bits/stdc++.h>
using namespace std;
const int INF=2E9;
typedef pair<int,int> Pair;
typedef long long LL;
int cnt=0;

int partition(int A[],int p,int r){
    int x=A[r];
    int i=p-1;
    int tmp;
    for(int j=p;j<r;j++){
        if(A[j]<=x){
            i++;
            tmp=A[i];
            A[i]=A[j];
            A[j]=tmp;
        }
    }
    tmp=A[i+1];
    A[i+1]=A[r];
    A[r]=tmp;
    return i+1;
}

int main(){
    int n;
    cin >> n;
    int A[100010];
    for(int i=0;i<n;i++){
        cin >> A[i];
    }
    int q=partition(A,0,n-1);
    for(int i=0;i<n;i++){
        if(i) cout << " ";
        if(i==q) cout << "[";
        cout << A[i];
        if(i==q) cout <<"]"; 
    }
    cout << endl;
    return 0;
}



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

int N; //頂点の数
vector<vector<int>> G; //グラフ
vector<int> h; //入次数
vector<int> l_depth; //最大経路長
vector<int> ans; //トポロジカルソート結果を格納

void input(){
  int n;
  cin>>n;
  vector<vector<int>> IDs(n, vector<int>(n, -1));
  N = n*(n-1)/2;
  G.resize(N);
  h.resize(N, 0);
  l_depth.resize(N, -1);

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

  int t, bufid, vsid;
  for(int i=0; i<n; i++){
    bufid = -1;
    for(int j=0; j<n-1; j++){
      cin>>t;t--;
      vsid = IDs[i][t];

      if(bufid != -1){
        G[bufid].push_back(vsid);
        h[vsid]++;
      }

      bufid = vsid;
    }
  }
}

void topoBFS(){   
  queue<int> unchecked;
  for(int i=0; i<N; i++){
    if(h[i]==0){
      unchecked.push(i); //入次数が0の頂点をキューに入れる
      l_depth[i] = 0; //そのような頂点は深さが0
    }
  }
  while(!unchecked.empty()){
    int current = unchecked.front();
    unchecked.pop();
    ans.push_back(current); //キューから取り出したらすぐソート後のリストに加える

    for(int next: G[current]){ //「行ける」頂点について
      h[next]--; //入次数を減らす
      l_depth[next] = max(l_depth[next], l_depth[current]+1); //最長経路
      if(h[next]==0){ //入次数0になったらキューに追加
        unchecked.push(next);
      }
    }
  }
}

int main(){
  input();
  
  topoBFS();

  bool isDAG = ans.size()==N;
  if(isDAG){
    int l_max = *max_element(l_depth.begin(), l_depth.end()); //l_depthの最大値をとる
    cout<<l_max+1<<endl;
  }else{
    cout<<-1<<endl;
  }
}

Measured memory_bytes: 40404
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) rep(i,v.size())cout<<" "<<v[i];cout<<endl<<endl;
#define show2d(v) rep(i,v.size()){rep(j,v[i].size())cout<<" "<<v[i][j];cout<<endl;}cout<<endl;
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};//RDLU

int d[1010][1010][4];
signed main(){
	int n,m,q;
	while(cin>>n>>m>>q,n){
		string s;
		cin>>s;
		vs in(n);
		rep(i,n)cin>>in[i];
		int sx,sy,gx,gy;
		rep(i,n)rep(j,m)if(in[i][j]=='S'){
			sx=i,sy=j;
		}else if(in[i][j]=='G'){
			gx=i,gy=j;
		}
		vvi ne(s.size()+1,vi(4,inf));
		for(int i=s.size()-1;i>=0;i--){
			int t=1;
			if(s[i]=='R')t=-1;
			rep(j,4)ne[i][j]=ne[i+1][(j+4+t)%4];
			if(s[i]=='R')ne[i][1]=i+1;
			if(s[i]=='L')ne[i][3]=i+1;
		}
		// show2d(ne);
		
		rep(i,1010)rep(j,1010)rep(k,4)
			d[i][j][k]=inf;
		d[sx][sy][3]=0;
		priority_queue<tp>q;
		q.push(tp(0,sx,sy,3));
		while(!q.empty()){
			Def cost,x,y,to;
			tie(cost,x,y,to)=q.top();
			cost*=-1;
			q.pop();
			if(cost>d[x][y][to])continue;
			rep(k,4){
				int nx=x+dx[k];
				int ny=y+dy[k];
				if(nx<0||ny<0||nx>=n||ny>=m)continue;
				if(in[nx][ny]=='#')continue;
				int nto=k;
				int ncost=ne[cost][(k-to+4)%4];
				if(k==to)ncost=cost;
				if(ncost==inf)continue;
				if(ncost<d[nx][ny][nto]){
					d[nx][ny][nto]=ncost;
					q.push(tp(-ncost,nx,ny,nto));
				}
			}
		}
		rep(i,4)if(d[gx][gy][i]-inf){
			cout<<"Yes"<<endl;
			goto end;
		}
		cout<<"No"<<endl;
		end:;
	}
}








Measured memory_bytes: 40092
//#pragma comment(linker, "/STACK:102400000,102400000") 
#pragma warning(disable:4996)
#include <fstream>
#include <iostream>
#include <functional>
#include <algorithm>
#include <cstring>
#include <vector>
#include <string>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <deque>
#include <ctime>
#include <list>
#include <set>
#include <map>
using namespace std;

typedef long long ll;
#define eps 1e-10
#define LL_INF 0x33ffffffffffffff
#define INF 0x3f3f3f3f
#define mem(a, b) memset(a, b, sizeof(a))
#define pper(i,n,m) for(int i = n;i >= m; i--)
#define repp(i, n, m) for (int i = n; i <= m; i++)
#define rep(i, n, m) for (int i = n; i < m; i++)
#define sa(n) scanf("%d", &(n))
#define mp make_pair
#define ff first
#define ss second
#define pb push_back

const int maxn = 1e5 + 5;
const ll mod = 1e9 + 7;
const double PI = acos(-1.0);
ll po(ll a, ll b, ll mod) { ll res = 1; a %= mod; for (; b; b >>= 1) { if (b & 1)res = res*a%mod; a = a*a%mod; }return res; }
ll gcd(ll a, ll b) { if (a == 0) { return b; } else { return gcd(b%a, a); } }

int n, k, res;
int val[maxn], dep[maxn], vis[maxn];
vector<int>edge[maxn];

int dfs(int x, int fa)
{
	int ans = 0;
	vis[x] = 1;
	int sz = edge[x].size();
	for (int i = 0; i<sz; i++)
	{
		int y = edge[x][i];
		if (vis[y])continue;
		ans = max(ans, dfs(y, x));
	}
	ans++;
	if (ans >= k&&val[x] != 1)
	{
		ans = 0;
		res++;
	}
	return ans;
}

void solve()
{
	scanf("%d%d", &n, &k);
	scanf("%d", &val[1]);
	res = 0;
	if (val[1] != 1)
	{
		res++;
		val[1] = 1;
	}
	for (int i = 2; i <= n; i++)
	{
		scanf("%d", &val[i]);
		edge[val[i]].push_back(i);
	}
	dfs(1, 1);
	printf("%d", res);
}

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



Measured memory_bytes: 12800
N, A = [int(_) for _ in input().split()]
X = [int(_) for _ in input().split()]

xs = {0: 1}

for n in X:
    #print(xs)
    kv = list(xs.items())
    for k, v in kv:
        nk = k + n - A
        xs[nk] = xs.get(nk, 0) + v

#print(xs)

result = xs[0] - 1

print(result)

Measured memory_bytes: 3188
# coding: utf-8
# Your code here!

def Bellman_Ford(g,start):
    n = len(g)    
    dist = [float("inf")]*n
    dist[start] = 0
    a0 = float("inf")
    
    for i in range(n<<1):
        updated = False
        for v in range(n):
            for to, cost in g[v]:
                if dist[to] <= dist[v] + cost: continue
                dist[to] = dist[v] + cost
                updated = True
        if not updated: break
        if i <= n: a0 = dist[-1]
    if a0 != dist[-1]: return None, False
    return dist, True


import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline #文字列入力のときは注意

n,m,p = [int(i) for i in readline().split()]
g = [[] for _ in range(n)]
for i in range(m):
    a,b,c = [int(i) for i in readline().split()]
    g[a-1].append((b-1,-c+p))
#    g[b-1].append((a-1,c))

dist, TF = Bellman_Ford(g, 0)

if TF: print(max(-dist[-1],0))
else: print(-1)




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

string s;
vector<int> cnt(3, 0);

int main() {
  cin >> s;
  bool ch = 1;
  for (auto c : s) ++cnt[c - 'a'];
  int x = min({cnt[0], cnt[1], cnt[2]});
  for (int i = 0; i < 3; ++i)
    if (x != cnt[i] && x + 1 != cnt[i]) ch = 0;
  if (ch)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}


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

int main(){
	int p[10], d, v1, v2, x1, x2, i, sum;
	double t;
	while(~scanf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",&p[0],&p[1],&p[2],&p[3],&p[4],&p[5],&p[6],&p[7],&p[8],&p[9],&v1,&v2)){
		d = 0;
		for (i = 0; i < 10; i++) {
			d += p[i];
		}
		t = (double)d / (double)(v1+v2);
		
		sum = 0;
		for (i = 0; i < 10; i++) {
			sum += p[i];
			if((double)v1*t <= sum){
				i++;
				break;
			}
		}
		cout << i << endl;

	}
	return 0;
}

Measured memory_bytes: 0
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <math.h>

double pi(double ang){
    double rag;
    rag=acos(-1)*ang/180;
    return rag;
}
int main(void){
    double a, b, c, ang_C, rag_C, S, L, h, PI;
    scanf("%lf %lf %lf", &a, &b, &ang_C);
    
    rag_C=pi(ang_C);
    c=sqrt(a*a+b*b-2*a*b*cos(rag_C));
    L=a+b+c;
    
    S=a*b*sin(rag_C)/2;
    
    h=2*S/a;
    printf("%lf\n%lf\n%lf\n", S, L, h);
    return 0;
}



Measured memory_bytes: 2072
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#define F first
#define S second
using namespace std;
typedef pair<int,int> P;
vector<P> info;//position,time

//再帰で全てのパターンをためす
//といっても本当に全てのパターンやったら終わらないので
//現在の距離が答えの距離より大きくなったら最短にはなりえないのでおわらせる


bool iscan;
int ans;
int failedPosition;

void rec(int time,int k,int distance,int position){
  if(distance >= ans)return;

  if(position >= info.size()-1){
    ans = min(ans,distance+info[position].F);
    //cout << "ans = " << ans << endl;
    return;
  }


  int time1,time2;//time1 -> そのまま次へ, time2 -> 一旦家に帰る
  time1 = time+(k+1)*abs(info[position+1].F-info[position].F);
  time2 = time+(k+1)*abs(info[position].F-info[0].F)+info[position+1].F;
  
  if(k == 3){//vechicle can carry at most three balloons at a time. <- importance
    if(time2 <= info[position+1].S){
      rec(info[position+1].S,1,distance+abs(info[position].F-info[0].F)+info[position+1].F,position+1);
      return; // <- dont forget
    }
    else{
      iscan = false;
      failedPosition = position+1;
      return;
    }
   
  }



 
  if(time1 <=info[position+1].S && time2 <=info[position+1].S ){
    rec(info[position+1].S,k+1,distance+abs(info[position+1].F-info[position].F),position+1);
    if(position!=0)rec(info[position+1].S,1,distance+abs(info[position].F-info[0].F)+info[position+1].F,position+1);
  }
  else if(time1<=info[position+1].S){
    rec(info[position+1].S,k+1,distance+abs(info[position+1].F-info[position].F),position+1);
  }
  else if(time2<=info[position+1].S){
    rec(info[position+1].S,1,distance+abs(info[position].F-info[0].F)+info[position+1].F,position+1);
  }
  else {
    iscan = false;
    failedPosition = position+1;
    return;
  } 



}


int main(){
  int n,p,t;
  const int INF=999999999;

  while(cin >> n && n){
    ans = INF;
    info.clear();
    iscan = true;

    info.push_back(P(0,0));//Home 
    for(int i=0;i<n;i++){
      cin >> p >> t;
      info.push_back(P(p,t)); // t_i < t_(i+1)
    }
   
    rec(0,0,0,0);

    if(!iscan && ans == INF){
      cout << "NG " << failedPosition << endl;
    }
    else{
      cout << "OK " << ans << endl;
    }

  }
  return 0;
}

Measured memory_bytes: 1204
#include <stdio.h>
int main(){
    int n,z;
    scanf("%d",&n);
    int a[n];
    for (int i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    for (int i=1;i<n;i++){
      while (1){
        if (a[i-1]<a[i]){
          a[i]%=a[i-1];
          	if (a[i]==0){
              a[i]=a[i-1];
              break;
          	}
        }
        else{
          a[i-1]%=a[i];
          	if (a[i-1]==0){
              break;
          	}
        }
      }
    } 
    printf("%d",a[n-1]);
    return 0;
}


Measured memory_bytes: 512
#include <stdio.h>
#include <limits.h>

int main(void){
    int n, m, city[32767] = {0};
    int i, a, b;
    
    scanf("%d%d", &n, &m);
    
    for(i = 0; i < m; i++){
        scanf("%d%d", &a, &b);
        city[a - 1]++; city[b - 1]++;
    }
    
    for(i = 0; i < n; i++){
        printf("%d\n", city[i]);
    }
    return 0;
}


Measured memory_bytes: 256
def dfs(s, t, links):
    visited = set()
    q = [(s, 0)]
    while q:
        v, used = q.pop()
        if v == t:
            return used
        visited.add(v)
        for lb, u in links[v]:
            if u in visited:
                continue
            q.append((u, used | lb))


n = int(input())
links = [set() for _ in range(n)]
for i in range(n - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    lb = 1 << i
    links[a].add((lb, b))
    links[b].add((lb, a))
conditions = []
m = int(input())
for i in range(m):
    u, v = map(int, input().split())
    u -= 1
    v -= 1
    conditions.append(dfs(u, v, links))

ans = 0
for i in range(1 << m):
    cnd_cnt = bin(i).count('1')
    bit = 0
    k = i
    while k:
        b = k & -k
        j = b.bit_length() - 1
        bit |= conditions[j]
        k ^= b
    free_link_cnt = n - 1 - bin(bit).count('1')
    val = 2 ** free_link_cnt
    if cnd_cnt % 2:
        ans -= val
    else:
        ans += val
print(ans)


Measured memory_bytes: 43832
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int main(void){
  int n;
  cin >> n;
  
  vector<int>a(n-1);
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  
  int ans = a[0];;
  
  for(int i=0;i<n-2;i++){
    ans += min(a[i],a[i+1]);
  }
  
  ans += a[n-2];
  
  cout << ans << endl;
  
  return 0;
}

    

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define INF 0x3f3f3f3
#define LINF 0x3f3f3f3f3f3f3f
#define MAXN int(10e3+3)
#define fim '\n'
#define ll long long
#define f first
#define s second
#define debug(x) cout << "DEBUG " << x << endl
using namespace std;
typedef pair<int, int> pii;

char m[MAXN][MAXN];
ll dp[MAXN][MAXN];
int l, c;
const ll MOD = 1e9+7;

int main(){
    cin.tie(NULL);
    cout.tie(NULL);
    ios::sync_with_stdio(false);
    cin >> l >> c;
    
    for(int i = 1; i <= l; i++)
        for(int j = 1; j <= c; j++)
            cin >> m[i][j];
    
    dp[1][1] = 1;
    for(int i = 1; i <= l; i++)
        for(int j = 1; j<= c; j++) {
            if( (i == 1 && j == 1) or m[i][j] == '#') continue;
            dp[i][j] = (dp[i-1][j]%MOD+dp[i][j-1]%MOD)%MOD;
        }
        
    cout << dp[l][c]%MOD << fim;
}

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

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

	if (s[2] == s[3] && s[4] == s[5])
	{
		cout << "Yes";
	}
	else
	{
		cout << "No";
	}
	return 0;
}

Measured memory_bytes: 3624
#include <string>
#include <algorithm>
#define maxx 100
#include <iostream>
int main()
{
    int n, L;
    std::string s[maxx+1];
    std::cin >> n >> L;
    for(int i = 1; i <= n; i++) {
        std::cin >> s[i];
    }
    std::sort(s+1, s+n+1);
    for(int i = 1; i <= n; i++) {
        std::cout << s[i];
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using lint=long long;
using namespace std;

int main()
{
	string s,t;
	int dp[3010][3010]={};
	string ans="";
	
	cin >> s >> t;
	
	for(int i=1;i<=s.size();i++)
	{
		for(int j=1;j<=t.size();j++)
		{
			if(s[i-1]==t[j-1])
				dp[i][j]=max({dp[i-1][j-1]+1,dp[i][j-1],dp[i-1][j]});
			else 
				dp[i][j]=max({dp[i-1][j-1],dp[i][j-1],dp[i-1][j]});
		}
	}
	
	for(int i=s.size(),j=t.size(),k=0;k<dp[s.size()][t.size()];k++)
	{
		while(dp[i-1][j]==dp[i][j])i--;
		while(dp[i][j-1]==dp[i][j])j--;
		ans=s[i-1]+ans;
		i--;
		j--;
	}
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 35712
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

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

const ll INF = 1LL << 50;

const ll mod = 1000000007;

int main() {
  char c;
  cin >> c;

  char ans = c + 1;
 
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
/**********************
    Vikas Kumar Jha
    vkjha1010
**********************/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional> 
using namespace std;
using namespace __gnu_pbds;


#define ll          long long int 
#define ld          long double
#define mod         1000000007
#define fi          first
#define se          second
#define pb          push_back
#define mp          make_pair
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define vb          vector<bool>
#define mii         map<ll,ll>
#define pqb         priority_queue<ll>
#define pqs         priority_queue<ll, vi, greater<ll> >
#define ps(x,y)     fixed << setprecision(y) << x
#define fast        ios_base::sync_with_stdio(0);   cin.tie(0); cout.tie(0);
#define w(t)        ll t; cin >> t; while(t--)  
#define fr(be,en)   for(ll i = be; i < en; i++)
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbd;
ll powy(ll x,ll y)
{ if(y==0) return 1; 
    ll a=(powy(x,y/2))%mod;
    if(y%2==1) return ((((a*a)%mod)*x)%mod);
     else return (a*a)%mod;
 }
vb prime;   vi spf; 
void sieve(ll n) 
{   prime.resize(n+1,true); prime[0]=prime[1]=false;
    spf.resize(n+1,1); 
    for(ll i=0;i<=n;++i)
        spf[i]=i;
     spf[2]=2;
    for(ll i=4;i<=n;i+=2){ prime[i]=false; spf[i]=2; } 
    for (ll p=3; p*p<=n; p+=2) 
    {   if (prime[p] == true) 
        {   spf[p]=p;
            for (ll i=p*p; i<=n; i += p) 
            {   if(prime[i]==true)
                {   spf[i]=p;
                    prime[i] = false;
                }
            } 
        } 
    } 
}


int main()
{
    ll x,n,ans=-1;
    // fr(1,101)
    //     cout << i << " ";
    // cout << "\n";
    cin >> x >> n;
    vi vec(n);
    vi num(102);
    fr(0,n)
    {
        cin >> vec[i];
        num[vec[i]]++;
    }
    ll j=x,k=0;
    while(true)
    {
        if(j-k>=0 && num[j-k]==0)
        {
            ans=j-k;
            break;
        }
        if(j+k<=100 && num[j+k]==0)
        {
            ans=j+k;
            break;
        }
        if(j-k<0)
        {
            ans=j-k;
            break;  
        }
        if(j+k>100)
        {
            ans=j+k;
            break;
        }
        ++k;
    }
    cout << ans ;
}
























Measured memory_bytes: 3524
#include<bits/stdc++.h>
//cervello|Phoenix
using namespace std;
#define ll long long int
#define eb emplace_back
#define mk make_pair
#define all(x) x.begin(),x.end()
#define mod 1000000007

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int t; cin>>t;
  map<string,int> mp;
  while(t--){
    string s; cin>>s;
    mp[s]++;
  }
  cout<<"AC"<<" x "<<mp["AC"]<<"\n";
  cout<<"WA"<<" x "<<mp["WA"]<<"\n";
  cout<<"TLE"<<" x "<<mp["TLE"]<<"\n";
  cout<<"RE"<<" x "<<mp["RE"]<<"\n";
  return 0;
}

Measured memory_bytes: 3660