akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

const int mod = 1e9 + 7;
int dp[2][301][301];

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	int h, w; cin >> h >> w;
	rep(i, h) rep(j, w){
		string s; cin >> s;
		if(s == "snuke"){
			cout << char('A' + j) << i + 1 << endl;
			return 0;
		}
	}
	return 0;
}

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

memo = [0 for _ in range(M + 1)]
for i in range(N):
    A = list(map(int, input().split()))[1:]
    for a in A:
        memo[a] += 1

ans = len(list(filter(lambda x: x == N, memo)))
print(ans)

Measured memory_bytes: 3060
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
# include <bitset>
# include <random>
# include <chrono>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
typedef pair<LL, LL> P;
constexpr int INF = 2000000000;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
# define ALL(x)      (x).begin(),(x).end()
# define UNIQ(c)     (c).erase(unique(ALL((c))),(c).end())
# define mp          make_pair
# define eb          emplace_back
# 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 INIT        std::ios::sync_with_stdio(false);std::cin.tie(0)

list<int> li;

int n, num;
string s;

int main() {
	cin >> n;
	REP(i, n) {
		cin >> s;
		if (s == "insert")cin>>num,li.push_front(num);
		else if (s == "delete") {
			cin >> num;
			for (auto t = li.begin(); t != li.end(); t++) {
				if (*t == num) {
					li.erase(t);
					break;
				}
			}
		}
		else if (s == "deleteFirst")li.pop_front();
		else if (s == "deleteLast")li.pop_back();
	}
	int i = 0;
	for (auto t = li.begin(); t != li.end(); t++) {
		if (i++)cout << " ";
		cout << *t;
	}
	cout << endl;
}



Measured memory_bytes: 34420
wordsparser::String ->Bool
wordsparser [] = True
wordsparser cs
      | take 5 cs == "maerd" = wordsparser (drop 5 cs)
      | take 5 cs == "esare" = wordsparser (drop 5 cs)
      | take 6 cs == "resare" = wordsparser (drop 6 cs)
      | take 7 cs == "remaerd" = wordsparser (drop 7 cs)
      | otherwise = False

main::IO()
main =do
  dat<-getLine
  putStr ((if wordsparser (reverse dat) then "YES" else "NO")++"\n")


Measured memory_bytes: 7548
#include <iostream>

using namespace std;

int main()
{
   long number, x, i=1, max, min, sum=0;
    
    cin>> number >> x;
    max=x;
    min=x;
    for (i=1;i<=number;i++)
    {
        sum=sum+x;
        if (x<min)
        {
        min=x;
        }
        if (x>max)
        {
            max=x;
        }
        cin >> x;
    }
     cout << min << " " << max  << " " << sum<< endl;
   return 0;
}


Measured memory_bytes: 3112
k,a,b = gets.split.map(&:to_i)

n = 1

t = [k, a-n].min
n += t
k -= t

t = k.even? ? 0 : 1
n += t
k -= t

t = [k, (b-a)*(k/2)].max
n += t
k -= t

puts n


Measured memory_bytes: 1788
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp94 {
    class Program {
        static void Main(string[] args) {
            string s = Console.ReadLine();

            int A = int.Parse(s[0].ToString());
            int B = int.Parse(s[1].ToString());
            int C = int.Parse(s[2].ToString());
            int D = int.Parse(s[3].ToString());

            int[] num = new int[4] { A, B, C, D };

            for (int t = 0; t < (1 << 4); t++) {
                string kari = "";
                int ans = A;

                for (int i = 0; i < 4; i++) {
                    if ((t & (1 << i)) != 0) {
                        kari = "+" + kari;
                    } else {
                        kari = "-" + kari;
                    }
                }

                for (int i = 0; i < 3; i++) {
                    if (kari[i] == '+') {
                        ans += num[i + 1];
                    } else {
                        ans -= num[i + 1];
                    }


                }

                //Console.WriteLine(kari + ans.ToString());

                if (ans == 7) {
                    string finalAnswer = A.ToString();

                    for (int i = 0; i < 3; i++) {
                        if (kari[i] == '+') {
                            finalAnswer += "+";
                            finalAnswer += num[i + 1].ToString();
                        } else {
                            finalAnswer += "-";
                            finalAnswer += num[i + 1].ToString();
                        }
                    }

                    finalAnswer += "=7";

                    Console.WriteLine(finalAnswer);
                    return;
                }
            }

        }
    }
}


Measured memory_bytes: 13140
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			int n = scanner.nextInt();
			if (n == 0)
				break;
			int max = 0;
			int[][] map = new int[n + 1][n + 1];
			for (int i = 1; i < n + 1; i++) {
				String line = scanner.next();
				for (int j = 1; j < n + 1; j++) {
					if (line.charAt(j - 1) == '*') {
						map[i][j] = 0;
					} else {
						int num = Integer.MAX_VALUE;
						num = Math
								.min(num, Math.min(map[i - 1][j - 1],
										Math.min(map[i - 1][j], map[i][j - 1])));
						map[i][j] = num + 1;
						max = Math.max(max, map[i][j]);
					}
				}
			}
			System.out.println(max);
		}
	}

}

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

const int INF = (int)1.01e9;

mt19937 rnd;

bool solve(string s, vector<pair<int, int> > a) {
    int n = s.length();
    int m = a.size();

    int k = n / 2;
    for (int i = 0; i < m; i++) {
        if (a[i].first <= n - 1 - a[i].first && a[i].second >= n - 1 - a[i].second) {
            if (a[i].first <= n - 1 - a[i].second) {
                a[i].second = n - 1 - a[i].second - 1;
            } else {
                a[i].first = n - 1 - a[i].first + 1;
            }
        }
        if (a[i].first <= a[i].second && a[i].first >= n - 1 - a[i].first) {
            swap(a[i].first, a[i].second);
            a[i].first = n - 1 - a[i].first;
            a[i].second = n - 1 - a[i].second;
        }
        assert(a[i].first > a[i].second || a[i].second < k);
    }

    vector<int> b(k);
    for (int i = 0; i < k; i++) {
        b[i] = (s[i] - s[n - 1 - i] + 26) % 26;
    }
    vector<int> d(k);
    for (int i = 0; i < k; i++) {
        d[i] = i == 0 ? b[i] : (b[i] - b[i - 1] + 26) % 26;
    }

    vector<vector<int> > e(k + 1);
    for (int i = 0; i < m; i++) {
        if (a[i].first > a[i].second) continue;
        e[a[i].first].push_back(a[i].second + 1);
        e[a[i].second + 1].push_back(a[i].first);
    }
    vector<char> can(k + 1);
    vector<int> vct;
    function<void(int)> dfs1 = [&](int v) {
        if (can[v]) return;
        vct.push_back(v);
        can[v] = 1;
        for (int to : e[v]) dfs1(to);
    };
    dfs1(k);
    for (int i = k - 1; i >= 0; i--) {
        if (can[i]) continue;
        vct.clear();
        dfs1(i);
        int sum = 0;
        for (int v : vct) sum += d[v];
        if (sum % 26 != 0 || sum > 0 && vct.size() == 1) return 0;
    }
    return 1;
}

int main() {
#ifdef HOME
    freopen("in", "r", stdin);
#endif

    string s;
    while (cin >> s) {
        int m;
        cin >> m;
        vector<pair<int, int> > a(m);
        for (int i = 0; i < m; i++) {
            cin >> a[i].first >> a[i].second;
            a[i].first--;
            a[i].second--;
        }

        puts(solve(s, a) ? "YES" : "NO");
    }


#ifdef HOME
    cerr << clock() / (double)CLOCKS_PER_SEC << endl;
#endif
    return 0;
}

Measured memory_bytes: 7424
#include<bits/stdc++.h>
#define ll long long int
#define mod 1000000007
using namespace std;
int main()
{
  int n,i,j;
  cin>>n;
  ll arr[n];
  for(i=0;i<n;i++)
    cin>>arr[i];
  ll csum[n];
  csum[n-1]=arr[n-1];
  for(i=n-2;i>=0;i--)
    csum[i]=arr[i]+csum[i+1];
  ll ans=0,t;
  for(i=0;i<n-1;i++)
  {
      t=(arr[i]*(csum[i+1]%mod))%mod;
      ans+=t;
      ans=ans%mod;
  }
  cout<<ans;
  return 0;
}


Measured memory_bytes: 6752
#include <cstdio>
#include <vector>

using namespace std;

int main()
{
	for(int n;scanf("%d",&n),n;){
		vector<int> sums(1000);
		vector<int> begins(1000,-1);
		while(n--){
			int h,m,id; char t;
			scanf("%*d/%*d %d:%d %c %d",&h,&m,&t,&id);
			if(t=='I'){
				begins[id]=h*60+m;
				if(id==0){
					for(int i=1;i<1000;i++)
						if(begins[i]!=-1)
							begins[i]=h*60+m;
				}
			}
			if(t=='O'){
				if(id==0){
					for(int i=1;i<1000;i++)
						if(begins[i]!=-1)
							sums[i]+=h*60+m-begins[i];
				}
				else{
					if(begins[0]!=-1)
						sums[id]+=h*60+m-begins[id];
				}
				begins[id]=-1;
			}
		}
		int res=0;
		for(int i=0;i<1000;i++)
			res=res<sums[i]?sums[i]:res;
		printf("%d\n",res);
	}
}

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

#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int MN = 14, LN = 17, MOD = 1e9 + 7, INF = 0x3f3f3f3f, BSZ = 320;
int N, M, X, c[MN], a[MN][MN];

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    cin >> N >> M >> X;
    for (int i = 0; i < N; i++) {
        cin >> c[i];
        for (int j = 0; j < M; j++) cin >> a[i][j];
    }
    int mn = INT_MAX;
    for (int mask = 0; mask < (1 << N); mask++) {
        vector<int> temp(M, 0);
        int cost = 0;
        for (int i = 0; i < N; i++) {
            if (mask & (1 << i)) {
                cost += c[i];
                for (int j = 0; j < M; j++) temp[j] += a[i][j];
            }
        }
        bool flag = true;
        for (int j = 0; j < M; j++) {
            if (temp[j] < X) {
                flag = false;
                break;
            }
        }
        if (flag) {
            mn = min(mn, cost);
        }
    }
    cout << (mn == INT_MAX ? -1 : mn) << '\n';
    return 0;
}


Measured memory_bytes: 3628
#include<stdio.h>
#include <string.h>
#include <stdlib.h>

int main (){
  
 int ans[255];
 int a,b,k,i,j;
  scanf("%d %d %d",&a,&b,&k);
  
  for(i = 1;i < 101;i++){
    if(a % i == 0 && b % i == 0){
      ans[j] = i;
      j++;
    }
  }
  
  printf("%d",ans[j - k]);
    
  
      return 0;
  
}



Measured memory_bytes: 128
#include <bits/stdc++.h>
#define M0D 1000000007
using namespace std;

uint64_t modinv(uint64_t a, uint64_t m){
    uint64_t u = m-2;
    uint64_t v = a; 
    uint64_t ret = 1;
    while(u){
        if(u & 1) ret = ret * v % m;
        v = v * v % m;
        u >>= 1;
    }
    return ret;
}

int main(){

  long X,Y;
  uint64_t ans=1,numA,numB;
  uint64_t mod, tes=1;
  cin >> X >> Y;
  bool divi = true;
  if((2*Y-X)%3!=0 || (2*Y-X)<0) divi = false;
  if((2*X-Y)%3!=0 || (2*X-Y)<0) divi = false;
  if(!divi) cout << "0" << endl;
  else {
     numA = (2*Y-X)/3;
    numB = (2*X-Y)/3;
    long numC=numA+numB;
    for(int i=1; i<=numA; i++) ans *= modinv(i, M0D), ans %= M0D;
    for(int i=numC-numA+1; i<=numC; i++) ans *= i, ans %= M0D;
  cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#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 fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n;
    cin>>n;
    vector<ll> v;
    for(int i=0;i<n;i++){
        ll k;
        cin>>k;
        v.pb(k);
    }
    sort(v.begin(),v.end());
    ll ans=1;
    if((n&1)==0){
        for(int i=0;i<=n-2;i+=2){
            if(v[i]!=i+1){
                ans=0;
                break;
            }
            if(v[i+1]!=i+1){
                ans=0;
                break;
            }
        }
        if(ans==1){
            for(int i=0;i<(n>>1);i++){
                ans<<=1;
                ans=ans%1000000007;
            }
        }
        cout<<ans<<endl;
    }
    else{
        if(v[0]!=0)
            ans=0;
        for(int i=1;i<=n-2;i+=2){
            if(v[i]!=i+1){
                ans=0;
                break;
            }
            if(v[i+1]!=i+1){
                ans=0;
                break;
            }
        }
        if(ans==1){
            for(int i=0;i<(n>>1);i++){
                ans<<=1;
                ans=ans%1000000007;
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}


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

int a[3000000],n;

int main(){

  a[0] = 1;
  a[1] = 1;

  for(int i=2;i*i<3000000;i++){
    if(!a[i]){
      for(int j=i+i;j<3000000;j+=i) a[j] = 1;
    }
  }


  while(cin >> n, n){

    int ans = 0;

    for(int i=n+1;i<=2*n;i++){
      if(!a[i]) ans++;
    }

    cout << ans << endl;
  }
}

Measured memory_bytes: 12876
import java.util.Scanner;

public class Main {
  public static void main(String args[]){
      Scanner sc = new Scanner(System.in);
      int N = sc.nextInt();
    int sum = 0;
 
    
    int v[] = new int[N];
    int c[] = new int[N];
    
    
    for (int i = 1; i <= N; i++) {
  		v[i-1] = sc.nextInt();
	}
    
    for (int i = 1; i <= N; i++) {
  		c[i-1] = sc.nextInt();
	}
    
    for (int i = 1; i <= N; i++) {
      int rev = v[i-1] - c[i-1];
      if(rev > 0){
        sum = sum + rev;
      } else {
        sum = sum + 0;
      }
	}
    
      System.out.println(sum);

  }
}

Measured memory_bytes: 21844
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#define nmax_def 110000
#define Cmax_def 2200
#define mod 1000000007
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

int main() {
	int N, M;
	string S;
	cin >> N >> M;
	cin >> S;
	vi anslist;
	int i = N;
	bool can = 1;
	while (1) {
		if (i == 0)
			break;
		int inext = i - M;
		inext = max(inext, 0);
		while (1) {
			if (S[inext] == '0')
				break;
			if (inext >= i) {
				can = 0;
				break;
			}
			inext++;
		}
		if (!can) {
			break;
		}
		int len = i - inext;
		if (len == 0) {
			can = 0;
			break;
		}
		anslist.push_back(len);
		i = inext;
	}
	if (!can) {
		cout << "-1" << endl;
	}
	else {
		reverse(anslist.begin(), anslist.end());
		int ansnum = anslist.size();
		rep(i, ansnum) {
			cout << anslist[i] << " ";
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 1144
#include <iostream>
using namespace std;
int main(){
  int h, n;
  cin >> h >> n;
  int a[n];
  int sum = 0;
  for(int i = 0; i < n; i++){
    cin >> a[i];
    sum+= a[i];
  }
  if(sum>=h)cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;

using ll = long long;

int H[10000];
int N;
int ans = 0;
int maxh = 0;

int main() {
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> H[i];
		if (H[i] >= maxh) {
			ans++;
			maxh = H[i];
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= (b); i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
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 hr() {
   cerr << "--------------" << endl;
}
const int INF = 1001001001;
const int MOD = 1000000007;

struct unionFind {
   vector<int> d;
   unionFind(int n) {
      d.resize(n);
      rep(i, 0, n) d[i] = -1;
   }
   int find(int x) {
      if (d[x] < 0) return x;
      return d[x] = find(d[x]);
   }
   bool unite(int x, int y) {
      x = find(x);
      y = find(y);
      if (x == y) return false;
      if (d[x] > d[y]) swap(x, y);
      d[x] += d[y];
      d[y] = x;
      return true;
   }
   bool same(int x, int y) {
      if (find(x) == find(y)) return true;
      return false;
   }
};
int main() {
   cin.tie(0);
   ios_base::sync_with_stdio(0);

   int n;
   cin >> n;

   unionFind un(n);
   int q;
   cin >> q;
   rep(i, 0, q) {
      int com, x, y;
      cin >> com >> x >> y;
      if (!com)
         un.unite(x, y);
      else {
         if (un.same(x, y))
            cout << 1 << endl;
         else
            cout << 0 << endl;
      }
   }
   return 0;
}


Measured memory_bytes: 3260
num = int(input())
val = [int(x) for x in input().split()]
val_bk = val
kind = int(input())
array = []
for i in range(kind):
    array.append([int(x) for x in input().split()])

for j in array:
    bk = val[j[0]-1]
    val[j[0]-1] = j[1]
    print(sum(val))
    val[j[0] - 1] = bk

Measured memory_bytes: 3064
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <set>
#include <iostream>
#include <stack>
#include <vector>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <random>
#include <chrono>
using namespace std;

typedef long long LL;
const LL INF = 1e18;

struct Edge {
    int from, to, index;
    LL cap, flow;
    Edge(int from, int to, LL cap, LL flow, int index) :
    from(from), to(to), cap(cap), flow(flow), index(index) {}
};

struct Dinic {
    int N;
    vector < vector < Edge > > G;
    vector < Edge * > dad;
    vector < int > Q;

    Dinic(int N) : N(N), G(N), dad(N), Q(N) {}

    void AddEdge(int from, int to, LL cap) {
        G[from].push_back(Edge(from, to, cap, 0, G[to].size()));
        if (from == to) G[from].back().index++;
        G[to].push_back(Edge(to, from, 0, 0, G[from].size() - 1));
    }

    long long BlockingFlow(int s, int t) {
        fill(dad.begin(), dad.end(), (Edge *) NULL);
        dad[s] = &G[0][0] - 1;

        int head = 0, tail = 0;
        Q[tail++] = s;

        while(head < tail){
            int x = Q[head++];
            for (int i = 0; i < G[x].size(); i++){
                Edge &e = G[x][i];
                if(!dad[e.to] && e.cap - e.flow > 0){
                    dad[e.to] = &G[x][i];
                    Q[tail++] = e.to;
                }
            }
        }
        if (!dad[t]) return 0;

        long long totflow = 0;
        for (int i = 0; i < G[t].size(); i++){
            Edge *start = &G[G[t][i].to][G[t][i].index];
            LL amt = INF;
            for (Edge *e = start; amt && e != dad[s]; e = dad[e->from]){
                if (!e) { amt = 0; break; }
                amt = min(amt, e->cap - e->flow);
            }
            if (amt == 0) continue;
            for (Edge *e = start; amt && e != dad[s]; e = dad[e->from]) {
                e->flow += amt;
                G[e->to][e->index].flow -= amt;
            }
            totflow += amt;
        }
        return totflow;
    }

    long long GetMaxFlow(int s, int t) {
        long long totflow = 0;
        while (long long flow = BlockingFlow(s, t)) totflow += flow;
        return totflow;
    }
};

int n;
LL a[105];

int main(){
    cin >> n;
    LL sum = 0;
    for(int i = 1;i <= n;i++){
        scanf("%lld", &a[i]);
        a[i] = -a[i];
        sum += a[i];
    } 
    Dinic dinic(105);
    LL p = 0;
    for(int i = 1;i <= n;i++){
        if(a[i] > 0){
            dinic.AddEdge(0, i, a[i]);
            p += a[i];
        }
        if(a[i] < 0)
            dinic.AddEdge(i, n + 1, -a[i]);
    }
    for(int i = 1;i <= n;i++){
        for(int j = 2 * i;j <= n;j += i){
            dinic.AddEdge(i, j, INF);
        }
    }
    LL tmp = dinic.GetMaxFlow(0, n + 1);
    tmp = p - tmp;
    cout << -(sum - tmp) << endl;
    return 0;
}


Measured memory_bytes: 256
N = gets.to_i
s = gets.chomp.split('').map{|c| c == 'x' ? 1 : 0}

[[0, 0], [1, 0], [0, 1], [1, 1]].each do |arr|
    (2...(N+2)).each do |i|
        arr[i] = arr[i-1] ^ arr[i-2] ^ s[(i-1)%N]
    end
    if arr[0] == arr[N] && arr[1] == arr[N+1]
        puts arr[0, N].map{|n| n == 1 ? 'W' : 'S'}.join
        exit
    end
end

puts -1

Measured memory_bytes: 16324
#include <bits/stdc++.h>
#include <chrono>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repl(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define rep2l(i, s, n) for (ll i = (ll)(s); i < (ll)n; i++)

int main() {
    int N, M, X;
    cin >> N >> M >> X;
    vector<int> C(N);
    vector<vector<int>> A(N, vector<int>(M));
    priority_queue<ll, vector<ll>, greater<ll>> ans;
    
    rep(i, N) {
        cin >> C[i];
        rep(j, M) {
            cin >> A[i][j];
        }
    }
    for (ll tmp = 0; tmp < (1 << 12); tmp++) {
        ll res = 0;
        vector<ll> check(M, 0);
        bitset<12> s(tmp);
        for (int i = 0; i < N; i++) {
            if (s.test(i)) {
                rep(j, M) {
                    check[j] += A[i][j];
                }
                res += C[i];
            }
        }
        bool frag = true;
        rep(j, M) {
            if (check[j] < X) {
                frag = false;;
            }
        }
        if (frag) {
            ans.push(res);
        }
    }
    
    if (ans.empty()) {
        cout << -1 << endl;
        return 0;
    }
    cout << ans.top() << endl;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#ifdef _DEBUG
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
#else
#define debug(x)
#endif
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using P = pair<ll, ll>;
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr double PI = 3.141592653589793238462643383279;
ll getDigit(ll x) {
  return x == 0 ? 1 : log10(x) + 1;
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

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

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

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;
}

signed main() {
  ll N;
  cin >> N;

  ll m = INF;
  // rep(i, sqrtl(N)) {
  for (ll i = 1; i * i <= N; ++i) {
    if (i == 0) {
      continue;
    }
    if (N % i != 0) {
      continue;
    }
    ll j = N / i;
    m = min(m, i + j - 2);
  }
  COUT(m);
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string S;
  cin >> S;
  if(S=="SUN"){
    cout << 7 << endl;
  }
  if(S=="MON"){
    cout << 6 << endl;
  }
  if(S=="TUE"){
    cout << 5 << endl;
  }
  if(S=="WED"){
    cout << 4 << endl;
  }
  if(S=="THU"){
    cout << 3 << endl;
  }
  if(S=="FRI"){
    cout << 2 << endl;
  }
  if(S=="SAT"){
    cout << 1 << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
  string str,s;
  int cnt=0;
  cin >> s;
  for(int i=0,l=s.size();i<l;i++)
    if(s[i]>='A'&&s[i]<='Z')s[i]+=('a'-'A');
  while(cin >> str){
    if(str=="END_OF_TEXT")break;
    for(int i=0,l=str.size();i<l;i++)
      if(str[i]>='A'&&str[i]<='Z') str[i]+=('a'-'A');
    if(s==str) cnt++;
  }
  cout << cnt << endl;
}


Measured memory_bytes: 3160
#include <bits/stdc++.h>
#define pb push_back
#define int long long int
#define mod 1000000007
#define inf (1LL<<60)
#define f(i,a,b) for (int i= a; i <b; ++i)
using namespace std;
int dp[3005][3005];
void solve(string s,int n)
{
    dp[n][0]=(s[n-2]=='<')?0:1;
    dp[n][1]=(s[n-2]=='<')?1:0;
    for(int i=n-1;i>=2;i--)
    {
        int total=n-i+1;
        for(int j=0;j<=total;j++)
        {
            if(j==0)
            {
                if(s[i-2]=='>')
                {
                     for(int k=0;k<=total;k++)
                        dp[i][j]=(dp[i][j]+dp[i+1][k])%mod;
                }
            }
            else
            {
                if(s[i-2]=='<')
                    dp[i][j]=(dp[i][j-1]+dp[i+1][j-1])%mod;
                else
                    dp[i][j]=(mod+dp[i][j-1]-dp[i+1][j-1])%mod;
            }
        }
    }
}
signed main()
{
	ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    string s;
    cin>>n;
    cin>>s;
    solve(s,n);
    int ans=0;
    for(int i=0;i<=n-1;i++)
        ans=(ans+dp[2][i])%mod;
    cout<<ans;
}



Measured memory_bytes: 70016
// https://atcoder.jp/contests/abc154/tasks/abc154_d

#include <bits/stdc++.h>

using namespace std;

#define REP(i,n)   for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)
#define DUMP(a, n) REP(_i, n) printf("%d%c", a[_i], _i + 1 == n ? '\n' : ' ')
#define DUMP2D(a, n, m) REP(_i, n) REP(_j, m) printf("%d%c", a[_i][_j], _j + 1 == m ? '\n' : ' '); puts("")

const int N_MAX = 200000;
const int P_I_MAX = 1000;

int N, K;
int p[N_MAX];

int acc[N_MAX + 1];

void solve() {
  REP(i, N) acc[i + 1] = acc[i] + p[i];
  int ans = 0;
  FOR(i, K, N) ans = max(ans, acc[i] - acc[i - K]);
  printf("%.12lf\n", ((double) ans + K) / 2);
}

void input() {
  scanf("%d%d", &N, &K);
  REP(i, N) scanf("%d", p + i);
}

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


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

#define MAX 100
#define WHITE 0
#define GRAY 1
#define BLACK 2
int INF = (1<<21);

void dijkstra(void);

int n;
int M[MAX][MAX];

int main(){
  int i,j;
  int c,k,u,v;
  cin >> n;
  for( i = 0; i < n; i++){
    for(j = 0; j < n; j++){
      //M[i][j] = INFINITY;
      M[i][j] = INF;
    }
  }
  for(i = 0; i < n; i++){
    cin >> u;
    cin >> k;
    for(j = 0; j < k; j++){
      cin >> v;
      cin >> c;
      M[u][v] = c;
    }
  }
  dijkstra();
  return 0;
}

void dijkstra(){
  int minV;
  int d[MAX],color[MAX];
  int u,v;
  int i;
  for(i = 0; i < n; i++){
    //d[i] = INFINITY;
    d[i] = INF;
    color[i] = WHITE;
  }
  d[0] = 0;
  color[0] = GRAY;
  while(1){
    //minV = INFINITY;
    minV = INF;
    u = -1;
    for(i = 0; i < n; i++){
      if(minV > d[i] && color[i] != BLACK){
        u = i;
        minV = d[i];
      }
    }
    if(u == -1){
      break;
    }
    color[u] = BLACK;
    for(v = 0; v < n; v++){
      //if(color[v] != BLACK && M[u][v] != INFINITY){
      if(color[v] != BLACK && M[u][v] != INF){
        if(d[v] > d[u] + M[u][v]){
          d[v] = d[u] + M[u][v];
          color[v] = GRAY;
        }
      }
    }
  }
  for(i = 0; i < n; i++){
    //cout << i << " " << (d[i] == INFINITY ? -1 : d[i]) << endl;
    cout << i << " " << (d[i] == INF ? -1 : d[i]) << endl;
  }
}

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

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

  int d = N / 1000;
  if (N % 1000 == 0) {
    cout << 0 << endl;
  } else {
    cout << ((d + 1) * 1000 - N) << endl;
  }
}

Measured memory_bytes: 3620
#!/usr/bin/env python3
import sys


def solve(A: int, B: int):
    print(A * B if A <= 9 and B <= 9 else -1)


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(A, B)

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <cassert>
#include <memory>
#include <stack>
#include <set>

#define MAX_SIZE 100000000
typedef unsigned long long ull;
using namespace std;

int main() {
  int A,B,K; cin >> A >> B >> K;
  set<int> ans;
  for(int i = A; i <= B; i++) {
    if(i < A + K || i > B - K) {
      ans.insert(i);
    }
  }

  for(auto v : ans) {
    cout << v << endl;
  }
}


Measured memory_bytes: 256
using System;
public class Program{
    public static void Main(){
        int kusi = int.Parse(Console.ReadLine());
        string[] leng = Console.ReadLine().Split(' ');
        Array.Sort(leng);
        int x = 0;
        int[] len = new int[kusi*2];
        for(int i=0;i<kusi*2;i++){
            len[i] = int.Parse(leng[i]);
        }
        for(int j=0;j<kusi*2;j++){
            for(int i=0;i<kusi*2-1;i++){
                if(len[i]>len[i+1]){
                    int temp = len[i];
                    len[i] = len[i+1];
                    len[i+1] = temp;
                }
            }
        }
        for(int i=0;i<kusi;i++){
            x += len[i*2];
        }
        Console.WriteLine(x);
    }
}

Measured memory_bytes: 13664
Mod = 10**9+7
f3 = ["AGC", "GAC", "ACG"]
f4 = ["AGAC","AGGC","AGCC","AGTC"] + ["AAGC","AGGC","ACGC","ATGC"]
q = ["A", "G", "C", "T"]

d = {}
e = {}
for x in q:
  for y in q:
    for z in q:
      s = x+y+z
      if not s in f3:
        d[s] = 1
        e[s] = 0
      
n = int(input())
for i in range(n-3):
  for s in e.keys():
    for c in q:
      t = s+c
      if t[1:] in f3 or t in f4:
        continue
      e[t[1:]] = (e[t[1:]]+d[s])%Mod
  for s in e.keys():
    d[s] = e[s]
    e[s] = 0
    
print(sum(d.values())%Mod)


Measured memory_bytes: 3064
// Copyright 2017 Parallelc
#include <bits/stdc++.h>
#include <ext/numeric>
using namespace std;  // NOLINT
using namespace __gnu_cxx;
using LL = int64_t;
const int INF = 0x3f3f3f3f;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    for (int i = 1; i < n; i++) {
        string t, k = "";
        cin >> t;
        sort(t.begin(), t.end());
        set_intersection(s.begin(), s.end(), t.begin(), t.end(), back_inserter(k));
        s = k;
    }
    cout << s << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <math.h>
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) > (b) ? (b) : (a))
#define REP(i, n) for(int i = 0; i < n; i++)
typedef long long ll;

int
main(int argc, char *argv[])
{
  int h, w, a[500][500];
  scanf("%d %d", &h, &w);
  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      scanf("%d", &a[i][j]);
    }
  }

  int c[250000][4]; int n = 0;

  for(int i = 0; i < h; i++){
    for(int j = 0; j < w - 1; j++){
      if((a[i][j] & 1) == 1){
	a[i][j + 1]++;
	c[n][0] = i + 1; c[n][1] = j + 1;
	c[n][2] = i + 1; c[n][3] = j + 2;
	n++;
      }
    }
  }

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

  printf("%d\n", n);
  for(int i = 0; i < n; i++) printf("%d %d %d %d\n", c[i][0], c[i][1], c[i][2], c[i][3]);

  return 0;
}


Measured memory_bytes: 6784
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#define ll long long
using namespace std;
int main() {
	int n;
	cin >> n;
	//vector<int>a(n),b(n),c(n);
	vector<vector<ll>>dp(n,vector<ll>(3,0));
	for (int i =0 ; i < n; i++) {
		cin >> dp[i][0]>>dp[i][1]>>dp[i][2];
		if (i != 0) {
			dp[i][0] += max(dp[i - 1][1], dp[i - 1][2]);
			dp[i][1] += max(dp[i - 1][2], dp[i - 1][0]);
			dp[i][2] += max(dp[i - 1][1], dp[i - 1][0]);

			
		}
			
	}
	cout << max({dp[n-1][0],dp[n-1][1],dp[n-1][2]}) << endl;

}

Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
#ifdef ENABLE_DEBUG_OUTPUT
#define DEBUG_LOG(s) cout << s << endl;
#else
#define DEBUG_LOG(s) void();
#endif

int main(){
    while(true) {
        int n, m;
        cin >> n >> m;

        if(n == 0 and m == 0) break;

        vector<int> c(m), x(n);
        for (auto i = 0; i < m; i++) cin >> c[i];
        for (auto i = 0; i < n; i++) cin >> x[i];

        vector<vector<int64_t>> dp(n + 1, vector<int64_t>(256, INT64_MAX));
        dp[0][128] = 0;
        for (auto i = 0; i < n; i++) {
            for (auto j = 0; j < 256; j++) {
                for (auto k = 0; k < m; k++) {
                    if(dp[i][j] == INT64_MAX) continue;
                    auto y = max(min(j + c[k], 255), 0);
                    auto sum = (y - x[i]) * (y - x[i]);
                    dp[i + 1][y] = min(dp[i + 1][y], sum + dp[i][j]);
                }
            }
        }

//        for (auto i = 0; i <= n; i++) {
//            cout << i << " ";
//            for (auto j = 0; j < 256; j++) {
//                if(dp[i][j] != INT64_MAX) cout << j << " " << dp[i][j] << " ";
//            }
//            cout << endl;
//        }

        int64_t ans = INT64_MAX;
        for (auto i = 0; i < 256; i++) ans = min(ans, dp[n][i]);

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


Measured memory_bytes: 43836
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long
#define ar array<int,2>
#define inf 1000000000000000000 
#define deb(x) cerr << "\n" << (#x) << " is " << (x) << endl
int mod=1e9+7;
int min(int a,int b){return (a<b)?a:b;}
int max(int a,int b){return (a>b)?a:b;}
int fp(int a,int b){if(b==0) return 1;int x=fp(a,b/2);x=(x*x)%mod;if(b&1) x=(x*a)%mod;return x;}
auto random_add = [] { char *p = new char; delete p; return uint64_t(p); };
const uint64_t SEED = chrono::steady_clock::now().time_since_epoch().count() * (random_add() | 1);
mt19937_64 rng(SEED);


const int N=1e6+5;
int a[N]={0};




void solve()
{
  int n,x,m;
  cin>>n>>x>>m;
  int ans=0;
  vector<int> v;
  map<int,int> mp;
  int ct=0,base=x,last,l=n;
  for(int i=1;i<=n;i++)
  {
    if(mp.find(x)!=mp.end())
    {
      last=mp[x];
      break;
    }
    mp[x]=i-1;
    l--;
    ans+=x;
   // cout<<x<<endl;
    v.push_back(x);
    x=(x*x)%m; 
  }

  int cycle=0;
  ct=0;
  for(int j=last;j<v.size();j++)
  {
    cycle+=v[j];
    ct++;
  }
  //cout<<cycle<<endl;

  ans+=(l/ct)*cycle;
  l%=ct;
  for(int j=last;j<v.size();j++)
  {
    if(l==0)
      break;
    l--;
    ans+=v[j];
  }
  cout<<ans<<endl;

}

signed main() {
 ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 
 srand(time(0));
 int t=1;
// cin>>t;
 for(int i=1;i<=t;i++)
 {
   solve();
 }
}


Measured memory_bytes: 6724
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t,n,k;
    cin>>n>>k;

    int *a = new int[n+1]{0};
    
    for(int i=1;i<=n;++i)
    {
        cin>>a[i];
    }       
    
    int *dp = new int[n+1]{0};
    
    dp[1] = 0;
    dp[2] = abs(a[2]-a[1]);
    
    for(int i=3;i<=n;++i)
    {
        int curAns = INT_MAX;
        for(int j=1;j<=k;++j)
        {
            if(i-j>0)
            {
                int x = dp[i-j] + abs(a[i] - a[i-j]);
                curAns = min(curAns,x);
            }
        }
        dp[i] = curAns;
    }
    // for(int i=1;i<=n;++i)
    // {
    //     cout<<dp[i]<<" ";
    // }
    cout<<dp[n]<<endl;
    return 0;
}

Measured memory_bytes: 1152
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const long double EPS = 1e-9;
const ll mod = 1e9 + 7;
const ll INF = 1e9;

#define rep(i, n) for(ll i = 0; i < n ; i++ )
#define For(i, a, b) for(ll i = (a); i < (b) ; i++ )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

const ll MAX_N = 100000;

int main(void){
    ll x1, x2, y1, y2;
    ll x3, x4, y3, y4;

    cin >> x1 >> y1 >> x2 >> y2;
    
    ll dx = x2 - x1;
    ll dy = y2 - y1;
    
    if (dx * dy >= 0){
        x3 = x2 - dy;
        y3 = y2 + dx;
        x4 = x1 - dy;
        y4 = y1 + dx;
    }else {
        x3 = x2 - dy;
        y3 = y2 + dx;
        x4 = x1 - dy;
        y4 = y1 + dx;
    }
    
    cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<int,int> P;
const LL mod=998244353;
const LL LINF=1LL<<62;
const LL INF=1<<17;


int main(){
    int T;
    cin >> T;
    while(T--){
        LL a,b,c,d;
        cin >> a >> b >> c >> d;
        if(b>a) puts("No");
        else if(b>d) puts("No");
        else if(c>=b) puts("Yes");
        else{
            LL g=__gcd(b,d);
            if(c%b<b-g+a%g) puts("No");
            else puts("Yes");
       }
    }
    return 0;
}


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

typedef pair<string,int> P;
typedef map<string,int> M;

int dfs(string str) {
     queue<P> s;
     s.push(P(str,0));
     int res = -1;
     M m;

     while (s.size()) {
	  P p = s.front(); s.pop();
	  str = p.first;
	  if (m[str]) continue;
	  int num = p.second;
	  m[str] = num;
	  bool f = true;
	  int count = 0;
	  for (int i = 0; i < str.size() - 1; i++) {
	       string tmp = str;
	       bool flag = false;
	       if (tmp[i] != tmp[i + 1]) {
		    flag = true;
		    f = false;
		    count++;
		    if (tmp[i] != 'b' && tmp[i + 1] != 'b')
			 tmp[i + 1] = tmp[i] = 'b';
		    else if (tmp[i] != 'r' && tmp[i + 1] != 'r')
			 tmp[i + 1] = tmp[i] = 'r';
		    else if (tmp[i] != 'g' && tmp[i + 1] != 'g')
			 tmp[i + 1] = tmp[i] = 'g';
		    if (tmp == str) flag = false;
	       }
	       if (flag) s.push(P(tmp, num + 1));
	  }
	  if (f) {
	       res = num;
	       break;
	  }

     }

     return res;
}

int main()
{
     string str;
     while (cin >> str) {
	  if (str == "0") break;
	  int res = dfs(str);
	  if (res < 0) cout << "NA" << endl;
	  else cout << res << endl;
     }


     return 0;
}

Measured memory_bytes: 3244
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};

int n;
double p,e,t;
const double eps = 1e-20;

double dfs(int k,double l,double r,double pp){
    double tt = (l + r) / 2;
    if(k==n){
        if(abs(tt - t) <= e + eps) return pp;
        else return 0.0;
    }
    if(t - e <= l + eps && r <= t + e + eps) return pp;
    else if(r + eps < t - e || t + e + eps < l) return 0.0;
    double ret = 0.0;
    if(tt <= t + eps){
        ret += dfs(k+1, tt, r, pp * (1 - p));
        ret += dfs(k+1, l, tt, pp * p);
    }
    else{
        ret += dfs(k+1, l, tt, pp * (1 - p));
        ret += dfs(k+1, tt, r, pp * p);
    }
    return ret;
}

int main(){
    cin >> n;
    double l,r;cin >> l >> r;
    cin >> p >> e >> t;
    cout << setprecision(30) << fixed << dfs(0,l,r,1.0) << endl;
    return 0;
}



Measured memory_bytes: 3264
#include <cstdio>
#include <algorithm>
using namespace std;

const int MAXH = 400;

int fa[MAXH + 5], ind[MAXH + 5], oud[MAXH + 5], N, H;
int find(int x) {return fa[x] = ((fa[x] == x) ? x : find(fa[x]));}
void unite(int u, int v) {
	int fu = find(u), fv = find(v);
	if( fu != fv ) fa[fu] = fv;
}
void adde(int u, int v) {ind[v + H]++, oud[u + H]++, unite(u + H, v + H);}

int a[MAXH + 5], b[MAXH + 5];
int main() {
	scanf("%d%d", &N, &H);
	for(int i=0;i<=2*H;i++) fa[i] = i;
	for(int i=1,A,B,C,D;i<=N;i++) {
		scanf("%d%d%d%d", &A, &B, &C, &D), D = -D;
		if( !C ) C = -A; if( !D ) D = B;
		adde(C, D);
	}
//	for(int i=0;i<=2*H;i++) printf("%d %d\n", ind[i], oud[i]);
	
	int deg = 0;
	for(int i=0;i<H;i++) {
		if( ind[i] > oud[i] ) {
			puts("NO");
			return 0;
		} else a[find(i)] += (oud[i] - ind[i]), deg += (oud[i] - ind[i]);
	}
	for(int i=H+1;i<=2*H;i++) {
		if( oud[i] > ind[i] ) {
			puts("NO");
			return 0;
		} else b[find(i)] += (ind[i] - oud[i]), deg += (oud[i] - ind[i]);
	}
	if( deg ) {
		puts("NO");
		return 0;
	}
	for(int i=0;i<=2*H;i++) {
		if( !ind[i] || !oud[i] ) continue;
		if( find(i) == i && (!a[i] || !b[i]) ) {
			puts("NO");
			return 0;
		}
	}
	puts("YES");
}

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

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    if (a + b + c > 21) cout << "bust" << endl;
    else cout << "win" << endl;
}


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

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

    vector<Int> A(N), B(N);
    rep(i,N) cin >> A[i] >> B[i];

    sort(A.begin(), A.end());
    sort(B.begin(), B.end());

    Int mA, mB;
    if(N % 2 == 1){
        mA = A[N/2], mB = B[N/2];
    } else {
        mA = A[N/2-1]+A[N/2], mB = B[N/2-1]+B[N/2];
    }
    cout << mB - mA + 1 << endl; 
}

Measured memory_bytes: 6328
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
#include <complex>
#define repi(i, x, n) for(int i = x; i < n; i++)
#define rep(i, n) repi(i, 0, n)
#define endl "\n"
#define ing long long
using namespace std;
const int INF = 1<<30;
const int MOD = (int)1e9 + 7;
const int MAX_N = (int)1e5 + 5;
#define debug(x) cout << #x << ": " << x << endl
signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    while(cin >> N >> M, N or M)
    {
        int times[M][1300] = {};
        int r; cin >> r;
        for(int i = 0; i < r; i++)
        {
            int t, n, m, s; cin >> t >> n >> m >> s;
            m--;
            if(s) times[m][t + 1]++;
            else times[m][t + 1]--;
        }
        for(int i = 0; i < M; i++)
        {
            for(int j = 540; j <= 1300; j++) times[i][j] += times[i][j - 1];
        }
        int q; cin >> q;
        while(q--)
        {
            int s, t, m; cin >> s >> t >> m;
            m--;
            int cnt = 0;
            for(int i = s + 1; i <= t; i++)
            {
                if(times[m][i]) cnt++;
            }
            cout << cnt << endl;
        }
    }
    return 0;
}



Measured memory_bytes: 52312
c = input()

list=['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
count=0

for i in list:
  if(count==1):
    print(i)
    break
  if(c==i):
    count=1
   

Measured memory_bytes: 3060
#include <iostream>

#include <vector>
#include <map>
#include <algorithm>
#include <fstream>
#include<cstdio>
#include<iomanip>
#include<stack>
#include<queue>
#include<string>
#include <cstdlib>
#include <typeinfo>

#define REP(i, n) for(int i=0;i<n;i++)
#define REP2(i, s, n) for(int i=s;i<n;i++)
#define REP_1(i, n) for(int i=1;i<n+1;i++)
#define bitSearch(bit, n) for(int bit = 0; bit < (1 << N); bit++)
using namespace std;

template<class T>
void print(const T &value) {
    std::cout << value << std::endl;
}

void yesno(bool a) { if (a)cout << "Yes" << endl; else cout << "No" << endl; }

void YESNO(bool a) { if (a)cout << "YES" << endl; else cout << "NO" << endl; }

typedef long long ll;
typedef unsigned long ul;
typedef long double ld;

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;
}

//ll INF = 10000000;
//ll mod = 1000000007;//10^9+7

//using Graph = vector<vector<pair<int, int>>>;
//Graph G(100100);

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

//番号ズレ注意！！
int main() {
    int A, B, K;
    cin >> A >> B >> K;
    vector<int> ans;
    REP_1(i, A) {
        if (A % i == 0 && B % i == 0)ans.push_back(i);
    }
    int N = ans.size();
    print(ans[N - K]);
}


Measured memory_bytes: 256