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

using namespace std;

#define DUMP(x) std::cerr << (#x) << " = " << (x) << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP(i, k, n) for (int i = (k); i < (int)(n); ++i)
#define ALL(r) r.begin(), r.end()
#define YES puts("YES")
#define Yes puts("Yes")
#define NO puts("NO")
#define No puts("No")
#define IMP puts("IMPOSSIBLE")
#define Imp puts("Impossible")
#define imp puts("impossible")
#define M1 puts("-1")
#define pb push_back

template <typename T>
ostream &operator<<(ostream &os, vector<T> &v)
{
    os << "{";
    rep(i, v.size()) os << v[i] << (i == (int)v.size() - 1 ? "" : ", ");
    os << "}";
    return os;
}
template <typename T>
T dup(T x, T y)
{
    return (x + y - 1) / y;
};
template <typename A, size_t N, typename T>
inline void arrayFill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); }
struct in
{
    const size_t n = 0;
    in() = default;
    in(size_t n) : n(n){};
    template <typename T>
    operator T()
    {
        T ret;
        cin >> ret;
        return ret;
    }
    template <typename T>
    operator vector<T>()
    {
        assert(n != 0);
        vector<T> ret(n);
        for (auto &x : ret)
            cin >> x;
        return ret;
    }
};

using ll = int64_t;
using vint = vector<int32_t>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pint = pair<int32_t, int32_t>;
using pll = pair<ll, ll>;
using setint = set<int32_t>;
using setstr = set<string>;
using qint = queue<int32_t>;
using qpint = queue<pint>;

constexpr std::int32_t INF = 1001001001;
constexpr std::int64_t LINF = 1001001001001001001;

void Main()
{
    ll n = in(), m = in();
    vll a = in(n);
    vector<pll> cb(m);
    rep(i, m)
    {
        ll b = in(), c = in();
        cb[i] = make_pair(c, b);
    }

    sort(ALL(a));
    sort(ALL(cb), greater<pll>());

    vll d(n, 0);
    ll cnt = 0;
    bool is_end = false;
    rep(i, m)
    {
        rep(j, cb[i].second)
        {
            if (cnt >= n)
            {
                is_end = true;
                break;
            }
            d[cnt] = cb[i].first;
            ++cnt;
        }
        if (is_end)
            break;
    }

    rep(i, n)
    {
        if (a[i] < d[i])
            a[i] = d[i];
    }
    cout << accumulate(ALL(a), (ll)0) << endl;
}

int main()
{
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 3456
import java.util.*;
class Main
{
	public static void main(String []args)
	{
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		int a = s.nextInt();
		int p = n/500;
		int q = (n - 500*p);
		if(q <=  a ) 
		System.out.println("Yes");
		else
		System.out.println("No");	

	}
}

Measured memory_bytes: 23380
#include <bits/stdc++.h>
 
using namespace std;
 
int main(){
    string S;
    cin >> S;
    long long int now = 0,ans = 0;
    for(int i=0;i<S.size();i++){
        if(S[i]=='W'){
            ans += i-now;
            now++;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const double EPS = 1e-8;

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

int main(){
    map<int, int> mp;
    rep(i, 3) {
        int a;
        cin >> a;
        mp[a]++;
    }
    if(mp.size() == 2) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

int main(void) {
    
    int n;
    cin >> n;
    
    int s = 0;
    for (int i = 1; i <= n; ++i) {
        int x;
        cin >> x;
        
        s = (s + x) & 1;
    }
    
    if (s & 1)
        cout << "NO";
    else
        cout << "YES";
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1e18
#define PI 3.14159265358979

using namespace std;

ll gcd(ll a, ll b);
ll power(ll n, ll k);
ll inv(ll n);
ll genfact(ll n, ll k);
ll fact(ll n);
ll nck(ll n, ll k);

int main(void){
  int n, t;
  cin >> n >> t;
  int m = 1e9;
  int a, b;
  for (int i = 0; i < n; i++){
    cin >> a >> b;
    if (b <= t)
      m = min(m, a);
  }

  if (m == 1e9)
    cout << "TLE" << endl;
  else
    cout << m << endl;

  return 0;
}

ll gcd(ll a, ll b){
  if (a < b)
    return gcd(b, a);
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}

ll power(ll n, ll k){
  ll res = 1;
  while(k > 0){
    if (k & 1) 
      res = res * n % MOD;
    n = n * n % MOD;
    k >>= 1;
  }
  return res;
}

ll genfact(ll n, ll k){

  ll res = 1;
  while (k >= 0){
    res = (res * (n - k)) % MOD;
    k--;
  }

  return res;
}

ll inv(ll n){
  return power(n, MOD - 2);
}

ll fact(ll n){
  return genfact(n, n - 1);
}

ll nck(ll n, ll k){
  if (k == 0)
    return 1;
  if (n <= 0)
    return 0;

  return ((genfact(n, k) % MOD) * inv(fact(k))) % MOD;
}


Measured memory_bytes: 256
N=int(input())
ans=N
def func1():
    global ans
    for i in range(N+1):
        cnt=0
        t=i
        while(t>0):
            cnt+=t%6
            t/=6
            t=int(t)
        t=N-i
        while(t>0):
            cnt+=t%9
            t/=9
            t=int(t)
        if(ans>cnt):
            ans=cnt
    return ans

func1()
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

using pi = pair<int,int>;

const int INF = 1010101;
const int dx[4]={1,-1,0,0}, dy[4]={0,0,1,-1};

bool is_edge(int x, char c){
    if(x<2) return c=='-';
    return c=='|';
}

int main(){
    int h,w;
    char s,t;
    cin >>h >>w >>s >>t;

    vector<string> f(h);
    rep(i,h) cin >>f[i];

    pi start,goal;
    rep(i,h)rep(j,w){
        if(f[i][j] == s) start = {i,j};
        if(f[i][j] == t) goal = {i,j};
    }

    auto IN = [&](int y, int x){ return 0<=y && y<h && 0<=x && x<w; };

    vector<vector<int>> d(h,vector<int>(w,INF));
    queue<pi> que;
    d[start.fi][start.se] = 0;
    que.push(start);
    while(!que.empty()){
        pi now = que.front();
        que.pop();

        rep(i,4){
            int xx = now.se+2*dx[i], yy = now.fi+2*dy[i];
            if(IN(yy,xx) && is_edge(i,f[yy][xx])){
                while( !('A'<=f[yy][xx] && f[yy][xx]<='Z') ){
                    yy += dy[i];
                    xx += dx[i];
                }

                if(('A'<=f[yy][xx] && f[yy][xx]<='Z')){
                    if(d[yy][xx] > d[now.fi][now.se]+1){
                        d[yy][xx] = d[now.fi][now.se]+1;
                        que.push({yy,xx});
                    }
                }
            }
        }
    }

    cout << d[goal.fi][goal.se] << endl;
    return 0;
}



Measured memory_bytes: 3184
#include <cstdio>
#include <cstring>
// #include <queue>
#include <algorithm>
#include <list>
#include <iostream>
using namespace std;

int main(int argc, char const *argv[])
{
	int q, x;
	char com[20];

	list<int> v;
	scanf("%d", &q);

	for(int i = 0; i < q; ++i) {
		scanf("%s", com);
		if (com[0] == 'i') {
			scanf("%d", &x);
			v.push_front(x);
		}
		else if(com[0] == 'd' && strlen(com) < 7) {
			scanf("%d", &x);
			for(list<int>::iterator it = v.begin(); it != v.end(); ++it) {
				if(*it == x) {
					v.erase(it);
					break;
				}
			}
		}
		else if(com[6] == 'L') {
			v.pop_back();
		}
		else if(com[6] == 'F') {
			v.pop_front();
		}
	}

	int i = 0;
	for(list<int>::iterator beg = v.begin(); beg != v.end(); ++beg) {
	    if(i++) printf(" ");
	    printf("%d", *beg);
	}
	printf("\n");
	return 0;
}


Measured memory_bytes: 34388
#include <stdio.h>
#include <string.h>
int main()
{
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    if (a==b && b!=c){
        printf("Yes\n");
    }
    else if (a==c && b!=a){
        printf("Yes\n");
    }
    else if (b==c && a!=b){
        printf("Yes\n");
    }
    else{
        printf("No\n");
    }

    return 0;
}

Measured memory_bytes: 1608
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;
const ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef vector<int> vecint;
typedef vector<ll> vecll;
typedef vector<string> svec;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a-1;i>=b;i--)

int main() {
	ll a, b, c;
	cin >> a >> b >> c;
	cout << min({ a + b,b + c,c + a }) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n); for(int i = 0;i < (n);i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
long double pi = acos(-1);
const int INF = 1001001001;


// 最小公倍数を求める
int euqlid (int a, int b){
  int temp;
  temp = a % b;
  if(temp == 0)return b;
  return euqlid(b,temp);
}
ll conbination(ll a,ll b){
  ll u = 1;
  ll d = 1;
  while(b != 0){
    u *= a;
    d *= b;
    a--;
    b--;
  }
  return u / d;
}
int strtoint(char s){
  return (int(s-'0'));
}
int fact(int n){
  if(n == 1)return 1;
  return n * fact(n-1);
  }


int main(){
  int x,y;
  cin >> x >> y;
  int group[12] = {1,3,1,2,1,2,1,1,2,1,2,1};
  cout << (group[x-1] == group[y-1]?"Yes":"No") << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>


#define int  long long
#define rep(i,begin,end) for(__typeof(end)i=(begin)-((begin)>(end));i!=(end)-((begin)>(end));i+=1-2*((begin)>(end)))
// rep(i,1,10) is from 1 to 9 and rep(I,10,1) is from 9 to 1
#define F first
#define S second
#define sz(x) ((int)x.size())
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
#define pf push_front
#define eb emplace_back
#define all(v) (v).begin(), (v).end()
#define mod 1000000007
#define mi multiset<int>
#define mii multiset<pii>
#define what_is(x) cerr << #x << " is " << x <<"\n";
#define sortA(v) sort(v.begin(), v.end())
#define sortD(v) sort(v.rbegin(), v.rend())
#define PI 3.14159265358979323846
#define vout(a) for(auto x:a) cout<<x<<" ";

// #define ordered_set tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>


// using namespace __gnu_pbds;
using namespace std;

int lcm(int a,int b) {return (a*(b/__gcd(a,b)));}

int modp(int a,int n)
{
    if(n==0) return 1;
    if(n==1) return a;
    int res=modp(a,n/2);
    if(n%2==0) return (res*res);
    else return (a*res*res);
}

vi adj[1000005],ans;
vector<bool> vis(1000005,false);
map<pii,int> problem,elected;
int check=0;

bool dfs(int s)
{
    bool y=0;
    vis[s]=true;
    for(int u:adj[s])
    {
        if(!vis[u])
        {
            vis[u]=true;
            if(problem[{u,s}]||problem[{s,u}])
            {
                y=1;
                if(!dfs(u))
                {
                    ans.pb(u);
                }
            }
            else
            {
                if(dfs(u))
                {
                    y=1;
                }
            }
        }
    }
    return y;
}

void solve()
{
    int t,n,m,i,k,r,l,u,v,w,j,s,sum=0,pos,flag=0,count=0;
    string S,T,U;
    int a,b,c;
    cin>>n;
    // vi a(n),b(n),c(n);
    vi dp1(n,0),dp2(n,0),dp3(n,0);
    cin>>a>>b>>c;
    dp1[0]=a;
    dp2[0]=b;
    dp3[0]=c;
    rep(i,1,n)
    {
        cin>>a>>b>>c;
        dp1[i]=a+max(dp2[i-1],dp3[i-1]);
        dp2[i]=b+max(dp1[i-1],dp3[i-1]);
        dp3[i]=c+max(dp1[i-1],dp2[i-1]);
    }
    cout<<max({dp1[n-1],dp2[n-1],dp3[n-1]});
}


signed main()
{
 //   #ifndef ONLINE_JUDGE 
   //    freopen("input.txt","r",stdin);
     //  freopen("output.txt","w",stdout);
   // #endif
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--)
    {
        solve();
        cout<<"\n";
    }
    return 0;
}


Measured memory_bytes: 26112
#include <stdio.h>
int main()
{
  int num,arr[100],i,minj,tmp,cnt=0;
  scanf("%d",&num);
  for(i = 0; i < num; i++){
    scanf("%d",&arr[i]);
  }
  for( i = 0; i < num; i++){
    minj = i;
    for(int j = i; j < num; j++){
      if(arr[j] < arr[minj]) minj =j;
    }
      if(arr[i] != arr[minj]){
	tmp = arr[i];
	arr[i] = arr[minj];
	arr[minj] = tmp;
	cnt++;
      }
  }
  for(i = 0; i < num - 1; i++){
    printf("%d ",arr[i]);
  }
  printf("%d\n%d\n",arr[num - 1],cnt);
  return 0;
}



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

using namespace std;
#define  ll long long
#define ld long double
#define f first
#define s second

string s;
char lst = '0';
ll ans;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    cin >> s;

    for(int i=0; i<(int)s.size(); i++)
    {
        if (s[i] != lst)
        {
            lst=s[i];
            ans++;
        }
        else
        {
            if (i < (int)s.size()-1)
            {
                ans++ , i++;
                lst='0';
            }
            else break;
        }
    }

    cout << ans << '\n';
  //

    return 0;
}

Measured memory_bytes: 3756
import sys
input = sys.stdin.readline
from itertools import combinations
from collections import Counter
def main():
    N = int(input())
    s = Counter()
    for _ in range(N):
        s[input().rstrip("\r\n")[0]] += 1
    print(sum([s[a]*s[b]*s[c] for a,b,c in combinations("MARCH",3)]))
if __name__ == "__main__":
    main()

Measured memory_bytes: 40044
n=gets.chomp.to_i
s=[]
t=[]
for i in 0..n-1
  s[i],t[i]=gets.chomp.split(" ")
  t[i]=t[i].to_i
end
x=gets.chomp

for i in 0..n-1
  if s[i]==x
    ans=t[i+1..n-1].inject(:+)
  end
end
p ans unless ans.nil?
p 0 if ans.nil?

Measured memory_bytes: 1788
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}

void main()
{
  int n; readV(n);

  auto dp1 = new int[](n+1), dp2 = new int[](n+1);
  dp1[] = n;

  foreach (i; 0..6) dp1[i] = i;

  foreach (i; 1..8) {
    dp2[] = dp1[];
    auto m = 6^^i;
    foreach (j; 0..n+1)
      foreach (k; 0..6)
        if (j >= m*k)
          dp1[j] = min(dp1[j], dp2[j-m*k]+k);
  }

  foreach (i; 1..7) {
    dp2[] = dp1[];
    auto m = 9^^i;
    foreach (j; 0..n+1)
      foreach (k; 0..9)
        if (j >= m*k)
          dp1[j] = min(dp1[j], dp2[j-m*k]+k);
  }

  writeln(dp1[n]);
}


Measured memory_bytes: 2556
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define pai 3.14159265358979323846
const int INF = 1001001001;
typedef long long ll;
int A[3][3], N;
bool punched[3][3];
bool ok[3][3];
int a[3][3],n;
using Graph = vector<vector<int>>;
vector<vector<int>> field;
vector<bool> seen;

const int MOD = 1000000007;
typedef pair<int,int> P;

int gcd(int a,int b){
	if (a%b == 0){
		return b;
	}
	else{
		return gcd(b,a%b);
	}

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










int main() {

	string s;
  cin >> s;
  vector <char> ans;

  rep (i,s.size()){

    if (s[i]=='0'){
      ans.push_back('0');
    }
    if (s[i]=='1'){
      ans.push_back('1');
    }
    if (s[i]=='B'&&ans.size()>0){
      ans.pop_back();
    }
  }
  for (auto x:ans){
    cout << x;
  }
  cout << endl;
}



Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
from collections import Counter
INF = float("inf")


def solve(N: int, A: "List[int]"):
    c = Counter(A)
    daburi = 0
    for k in c:
        if c[k] % 2 == 1:
            c[k] = 1
        elif c[k] % 2 == 0:
            c[k] = 2
            daburi += 1
    if daburi % 2 == 1:
        print(len(c)-1)
    else:
        print(len(c))

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)


if __name__ == '__main__':
    main()


Measured memory_bytes: 24032
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll n,k;
	double a[200010];
	cin>>n>>k;
	for(ll i=0;i<n;i++){
		double x;
		cin>>x;
		a[i]=(1+x)/double(2);
	}
	for(ll i=1;i<n;i++){
		a[i]=a[i-1]+a[i];
	}
	double ans=a[k-1];
	for(ll i=k;i<n;i++){
		
		double now=a[i]-a[i-k];
		ans=max(now,ans);
	}
	printf("%.9f",ans);
	// your code goes here
	return 0;
}

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

using vi = vector<int>;
using vvi = vector<vi>;

int main()
{
    ios_base::sync_with_stdio(0);

    int n, m; cin >> n >> m;

    vvi g(n + 1);

    for(int i = 0; i < m; i++)
    {
        int a, b; cin >> a >> b;

        g[a].push_back(b);
        g[b].push_back(a);
    }

    for(int i = 1; i <= n; i++) cout << g[i].size() << '\n';

    return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;

namespace abc141_c
{
    static class Program
    {
        static void Main(string[] args)
        {
            var items = Console.ReadLine().ToIntArray();
            // 参加者の人数
            var n = items[0];
            // 開始時に持っていた点数
            var k = items[1];
            // 終了したクイズ数
            var q = items[2];
            // クイズの正答者一覧
            var a = new int[q];
            for (int i = 0; i < q; i++)
            {
                a[i] = Console.ReadLine().ToInteger();
            }

            // クイズで正答した回数 
            var ans = new int[n];
            for (int i = 0; i < a.Length; i++)
            {
                ans[a[i] - 1]++;
            }

            // 点数 = 初期値 - クイズに正答しなかった数
            // 点数 = 初期値 - (クイズ数 - 正答数)
            // 点数 = 初期値 - クイズ数 + 正答数
            var kk = k - q;
            for (int i = 0; i < ans.Length; i++)
            {
                var ok = kk + ans[i] > 0;
                Console.WriteLine($"{(ok ? "Yes" : "No")}");
            }
        }

        static int ToInteger(this string s)
        {
            return int.Parse(s);
        }

        static int[] ToIntArray(this string s, char separator = ' ')
        {
            return s.Split(separator).Select(m => m.ToInteger()).ToArray();
        }
    }
}


Measured memory_bytes: 18264
S = gets.chomp
T = gets.chomp

s_nums = []
t_nums = []

('a'..'z').to_a.each do |i|
  
  if s_nums[S.count(i)]
    s_nums[S.count(i)] += 1
  else
    s_nums[S.count(i)] = 1
  end
 
   
  if t_nums[T.count(i)]
    t_nums[T.count(i)] += 1
  else
    t_nums[T.count(i)] = 1
  end
end

S.length.times do |i|
  if s_nums[i] != t_nums[i]
    puts 'No'
    exit
  end
end

puts 'Yes'


Measured memory_bytes: 4288
#include<stdio.h>
int main(){
  int n,a,i,ans=0,k=1;
  scanf("%d\n",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a);
    if(a==k){
      k++;
    }
    else{
      ans++;
    }
  }
  if(ans==n){
    printf("-1\n");
  }
  else{
  printf("%d\n",ans);
  }
  return 0;
}

Measured memory_bytes: 128
using System;

namespace ABC167B
{
    class Program
    {
        static void Main(string[] args)
        {
            var target = Console.ReadLine().Split(' ');
            long A = long.Parse(target[0]);
            long B = long.Parse(target[1]);
            long C = long.Parse(target[2]);
            long K = long.Parse(target[3]);
            long max = 0;
            if(K <= A) max = K;
            else if(K <= A+B) max = A;
            else max = A-(K-(A+B));
            Console.WriteLine(max);
        }
    }
}


Measured memory_bytes: 27548
#include<bits/stdc++.h>
using namespace std;
 
#define int long long
typedef long long ll;  
typedef vector<ll> vi; 
typedef pair<int, int> ii; 
typedef vector<ii> vii; 
typedef vector<vi> vvi;
#define F first
#define S second
#define pb emplace_back
#define M 1000000007
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define fr(i,a,b) for(int i = a; i<= b; i++)
#define ws " "
#define all(c) c.begin(), c.end()
#define ln "\n" 
 
void printarray(int ar[], int n) {
    for (int i = 0; i < n; i++) {
        cout << ar[i] << ws;
    }
    cout << ln;
}

int ar[101];
int sum[101][100001];
int dp[101][100001];

main() {
    IOS;
    // candies

    int n, k;
    cin >> n >> k;
    for (int i = 1; i <= n; i++) {
        cin >> ar[i];
    }
    for (int i = 0; i <= n; i++) {
        for (int c = 0; c <= k; c++) {
            if (i == 0) {
                sum[i][c] = 1;
                continue;
            }
            if (c == 0) {
                sum[i][0] = 1;
                continue;
            }
            int ans = 0;
            int pos = max(0LL, c - ar[i]);
            ans = sum[i - 1][c] % M;
            if (pos != 0) {
                ans = (ans - sum[i - 1][pos - 1] + M) % M;
            }
            sum[i][c] = ans + sum[i][c - 1];
            sum[i][c] %= M;
        }
    }
    
    int val = (k == 0) ? 0: sum[n][k - 1];
    cout << (sum[n][k] - val + M) % M;
}
 
/*  Check for base cases such as n == 1
    and cases like it where code can fail */

Measured memory_bytes: 80256
L, R = map(int, input().split())
MOD = 10 ** 9 + 7
l = '{:060b}'.format(L)[::-1]
r = '{:060b}'.format(R)[::-1]
 
memo = [[[[-1 for l in range(2)] for k in range(2)] for j in range(2)] for i in range(60)]
 
def f(pos, flagX, flagY, flagZ):
    if pos == -1:
        return 1
    if memo[pos][flagX][flagY][flagZ] != -1:
        return memo[pos][flagX][flagY][flagZ]
    ret = 0
    # x 0 y 0
    if l[pos] == '0' or flagX:
      ret += f(pos - 1, flagX, 1 if flagY or r[pos] == '1' else 0, flagZ)
    # x 0 y 1
    if (l[pos] == '0' or flagX) and (r[pos] == '1' or flagY) and flagZ:
      ret += f(pos - 1, flagX, flagY, flagZ)
    # x 1 y 1
    if r[pos] == '1' or flagY:
      ret += f(pos - 1, 1 if l[pos] == '0' or flagX else 0, flagY, 1)
    ret %= MOD
    memo[pos][flagX][flagY][flagZ] = ret
    return ret
 
ans = f(59, 0, 0, 0)
print(ans)

Measured memory_bytes: 3064
//#include "pch.h"
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <tuple>
#include <cctype>
#include <ctype.h>
#include <set>
#include <sstream>
#include <time.h>
#include <numeric>
using namespace std;
//#define int long long
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define l1 list[index]
#define l2 list[index - 1]
#define l3 list[index + 1]
#define iif(i,j) ((i<0 && j<0) || (i>0 && j>0)) ? true : false 
typedef long long ll;
typedef pair<int, int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
typedef pair<pint, int> P1;
typedef pair<int, pint> P2;
typedef pair<pint, pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD = 1000000007;
const ll INF = 1e18;
const double PI = 3.14159265359;
int ca[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };



signed main() {
	ll a, b, k;

	cin >> a >> b >> k;

	a -= k;

	if (a < 0) {
		b -= abs(a);
		a = 0;
	}

	if (b < 0) {
		b = 0;
	}
	cout << a << " " << b << endl;



	return 0;
}

Measured memory_bytes: 256
# ABC104B - AcCepted
s = input().rstrip()
if (
    s[0] == "A"
    and s[2:-1].count("C") == 1
    and s.translate(str.maketrans({"A": None, "C": None})).islower()
):
    print("AC")
else:
    print("WA")

Measured memory_bytes: 2940
#include <iostream>
using namespace std;
int main() {
    int N, A, B, acnt = 0, bcnt = 0;
    cin >> N >> A >> B;
    char c;
    for (int i = 0; i < N; i++) {
        bool yes = false;
        cin >> c;
        if (acnt + bcnt < A + B) {
            if (c == 'a') {
                acnt++;
                yes = true;
            }
            else if (c == 'b' && bcnt < B) {
                bcnt++;
                yes = true;
            }
        }
        cout << (yes ? "Yes" : "No") << endl;
    }
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

long long res,n,m,i;

int main() {
	cin>>n;
	for(i=1;i*i<=n;i++){
		if(n%i==0){
			m = n/i;
			m--;
			if(m!=0) { if(n/m==n%m) res += m; }
		}
	}
	cout<<res;
	return 0;
}


Measured memory_bytes: 256
K, N = (int(i) for i in input().split())
A = [int(i) for i in input().split()]


distance = []

for i in range(1,N):
    difference = A[i] - A[i-1]
    distance.append(difference)
    
distance.append(K-A[N-1] + A[0])

print(K-max(distance))

Measured memory_bytes: 26444
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define N 2020
inline int read(){
	int x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-')f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=(x<<1)+(x<<3)+c-'0';
		c=getchar();
	}
	return x*f;
}
const int n=read()*3,mod=read(),base=6000;
int dp[3*N][6*N],ans;
int main(){
	dp[0][base]=1;
	for(int i=1;i<=n;++i){
		for(int j=1;j<=(base<<1);++j){
			dp[i][j]=(dp[i][j]+dp[i-1][j-1])%mod;
			if(i>=2)dp[i][j]=(dp[i][j]+1LL*dp[i-2][j+1]*(i-1))%mod;
			if(i>=3)dp[i][j]=(dp[i][j]+1LL*dp[i-3][j]*(i-2)%mod*(i-1))%mod;
		}
	}
	for(int i=base;i<=(base<<1);++i){
		ans=(ans+dp[n][i])%mod;
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 287784
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 1e9;
#define sz              300005
#define Fast            ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

int par[sz];
bool vis[sz];
vector < int > V[sz];

void bfs(int src){

    memset(vis,0,sizeof(vis));
    memset(par,0,sizeof(par));
    queue< int > q;
    q.push(1);
    vis[1]=0;

    while(!q.empty()){
        int u=q.front();
        q.pop();

        for(int i=0; i<V[u].size(); i++){
            int v=V[u][i];
            if(vis[v]==0){
                par[v]=u;
                vis[v]=1;
                q.push(v);
            }
        }
    }
}

int main(){
    Fast;
    int a,b,c, i,j, n,m,t, cs=1;

    cin>>n>>m;
    for(i=0; i<m; i++){
        cin>>a>>b;
        V[a].push_back(b);
        V[b].push_back(a);
    }
    bfs(1);

    bool flag=true;
    vector < int > pp;
    for(i=2; i<=n; i++){
        if(par[i]==0){
            flag=false;break;
        }
        pp.push_back(par[i]);
    }
    if(!flag){
        cout<<"No"<<endl;
    }
    else{
        cout<<"Yes"<<endl;
        for(i=0; i<n-1; i++){
            cout<<pp[i]<<endl;
        }
    }


    return 0;
}

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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  while(x->left != NIL)
    x = x->left;
  
  return x;
}

Node treeMaximum(Node x){
  while(x->right != NIL)
    x = x->right;
  
  return x;
}

Node treeSearch(Node x, int k){
  if(x == NIL || k == x->key)
    return x;
  if(k < x->key)
    return treeSearch(x->left,k);
  else
    return treeSearch(x->right,k);

}

Node treeSuccessor(Node x){
  Node y;
  
  if(x->right != NIL)
    return treeMinimum(x->right);

  y = x->parent;
  
  while(y != NIL && x == y->right){
    x = y;
    y = y->parent;
  }

  return y;
}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y

  if(z->left == NIL || z->right == NIL)
    y = z;
  else
    y = treeSuccessor(z);

  if(y->left != NIL)
    x = y->left;
  else
    x = y->right;

  if(x != NIL)
    x->parent = y->parent;

  if(y->parent == NIL)
    root = x;
  else if(y == y->parent->left)
    y->parent->left = x;
  else
    y->parent->right = x;

  if(y != z)
    z->key = y->key;
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
  
  while(x!=NIL){
    y = x;
    if(z->key < x->key)
      x=x->left;
    else
      x=x->right;
  }
  
  z->parent = y;
  
  if(y==NIL)
    root=z;
  else
    if(z->key < y->key)
      y->left=z;
    else
      y->right=z; 
}

void inorder(Node x){
  if(x != NIL){
    inorder(x->left);
    printf(" %d",x->key);
    inorder(x->right);
  }
}
  
void preorder(Node x){
  if(x != NIL){
    printf(" %d",x->key);
    preorder(x->left);
    preorder(x->right);
  }
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}



Measured memory_bytes: 20424
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for (ll i = 0; i < (ll)n; i++)
#define all(x) (x).begin(), (x).end()
#define unique(x) x.erase(unique(x.begin(), x.end()), x.end());
const long long INF = 1LL << 60;
// map<int,int> mp;

int main() {
  int i;
  cin >> i ;
  if (i==0){
    cout << 1 << endl;
  }else{
    cout << 0 << endl;
  }

}

Measured memory_bytes: 3512
#include <stdio.h>
int main(void){
 
    double r;
    double are,circ,M_PI;
     
    M_PI=3.141592653589;
     
    scanf("%lf", &r);
     
    are=r*r*M_PI;
    circ=2*r*M_PI;
     
    printf("%f %f\n", are,circ);
    return 0;
     
}


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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

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

	int m,n; cin >> m >> n;

	ll p[10005];
	ll sum[10005];
	for (int i = 0;i < m;i++){
		cin >> p[i];
	}

	sort(p,p+m);
	reverse(p,p+m);
	
	sum[0] = 0;
	sum[1] = p[0];
	for (int i = 1;i < m;i++){
		sum[i+1] = sum[i]+p[i];
	}

	pair<ll,ll> box[505];

	for (int i = 0;i < n;i++){
		cin >> box[i].first >> box[i].second;
	}

	sort(p,p+m);
	sort(box, box+n);

	ll dp[n+5][m+5];
	for (int i = 0;i <= n;i++){
		for (int j = 0;j <= m;j++){
			dp[i][j] = LLONG_MAX;
		}
	}

	dp[0][0] = 0;

	for (int i = 0;i < n;i++){
		for (int j = 0;j <= m;j++){
			if(dp[i][j] == LLONG_MAX) continue;
			dp[i+1][j] = min(dp[i+1][j], dp[i][j]);
			int next = j+box[i].first;
			if(next <= m){
				dp[i+1][next] = min(dp[i+1][next],dp[i][j]+box[i].second);
			} else {
				dp[i+1][m] = min(dp[i+1][m], dp[i][j]+box[i].second);
			}
		}
	}

	/*for (int i = 0;i < n;i++){
		for (int j = 0;j <= m;j++){
			if(dp[i][j] == LLONG_MAX) cout << "**** ";
			else cout << setfill('0') << setw(4) << dp[i][j] << " ";
		}
		cout << endl;
	}*/


	ll ans = 0;

	ll memo = -1;
	for (int i = m;i >= 0;i--){
		ll prof;
		if(dp[n][i] == LLONG_MAX){
			if(memo == -1) continue;
			else{
				prof = sum[i] - memo;
			}
		} else {
			prof = sum[i] - dp[n][i];
			memo = dp[n][i];
		}

		ans = max(ans, prof);
	}

	cout << ans << endl;

	return 0;

}



Measured memory_bytes: 42496
#include <stdio.h>
#include <string.h>
//prototype
int main(void);

int main(void){
  int time;
  char TARO_CARDs[100];
  char HANAKO_CARDs[100];
  int taro_point = 0, hanako_point = 0;
  int judge_len, loop_len;

  scanf("%d", &time);

  for (int j = 0; j < time; j++) {
    scanf("%s %s", TARO_CARDs, HANAKO_CARDs);
    int t_len = strlen(TARO_CARDs);
    int h_len = strlen(HANAKO_CARDs);

    //Length check
    if(t_len <= h_len){
      if(t_len == h_len){
        judge_len = -1;
      }
      else {
        judge_len = 0;
      }
      loop_len = t_len;
    }
    else {
      loop_len = h_len;
      judge_len = 1;
    }

    //Judge process
    for (int i = 0; i < loop_len; i++) {
      if ((int)TARO_CARDs[i] > (int)HANAKO_CARDs[i]) {
        taro_point += 3;
        break;
      }
      else if ((int)HANAKO_CARDs[i] > (int)TARO_CARDs[i]){
        hanako_point += 3;
        break;
      }

      if(i == loop_len - 1){
        if (judge_len == 1) {
          taro_point += 3;
        }
        else if (judge_len == 0) {
          hanako_point += 3;
        }
        else {
          taro_point++;
          hanako_point++;
        }
      }
    }
  }

  //Show points
  printf("%d %d\n", taro_point, hanako_point);

  return 0;
}



Measured memory_bytes: 2044
#include<stdio.h>
int main(void){
    int H,W;
    while(1){
        scanf("%d %d",&H,&W);
        if(H==0 && W==0){
            break;
        }
        int i,j;
        for(i=0;i<H;i++){
            if(i==0 || i==H-1){
                for(j=0;j<W;j++){
                printf("#");
                }
            }
            
            else{
                for(j=0;j<W;j++){
                if(j==0 || j==W-1){
                    printf("#");
                }
                else{
                    printf(".");
                }
                }
            }
           
        printf("\n");
        }
    printf("\n");
    }
    
    return 0;
}


Measured memory_bytes: 1912
#include <bits/stdc++.h>
using namespace std;
using ll = long long; using P = pair<int,int>;
using vl = vector<ll>; using vvl = vector<vl>;
#define mp make_pair
#define pb push_back
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,n) for (int i=(n-1);i >= 0;i--)
#define all(v) v.begin(),v.end()
#define sz(v) (int)((v).size())
#define MAX(v) *max_element(all(v))
#define MIN(v) *min_element(all(v))
#define Sort(v) sort(all(v))
#define Rev(v) reverse(all(v))
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);in(name)
#define vv(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define VV(type,name,h,w) vector<vector<type>>name(h,vector<type>(w));in(name)
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cout << H << " ";
    debug_out(T...);
}
#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
    for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
    return os;
}
inline void IN(void){return;}
template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){cin >> first;IN(rest...);return;}
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;}
const ll INF = 1LL << 60;
const ll mod = 1000000007;
const int dx[8] = {1,0,-1,0,1,1,-1,-1}; const int dy[8] = {0,1,0,-1,1,1,-1,-1};

long long modPow(long long x, long long a) {
  if (a == 1) return x;
  if (a % 2) return (x * modPow(x, a - 1)) % mod;
  long long t = modPow(x, a / 2);
  return (t * t) % mod;
}

long long modInv(long long x) {
  return modPow(x, mod - 2);
}

long long modFact(long long x) {
  long long ret = 1;
  for (long long i = 1; i <= x; i++) {
    ret = (ret * i) % mod;
  }
  return ret;
}

long long modComb(long long n, long long k) {
  long long a, b, c, d;
  a = modFact(n);
  b = modFact(k);
  c = modFact(n - k);
  d = (b * c) % mod;
  return (a * modInv(d)) % mod;
}

ll solve(ll n){
    cin.tie(0); ios::sync_with_stdio(false);
    ll ans = 0;
    ll k = 1;
    while(n-3*k >= 0) {
        ans += modComb(n-2*k-1, k-1);
        ans %= mod;
        k++;
    }
    return ans % mod;
}

int main() {
    ll n; cin >> n;
    cout << solve(n) << endl;
}

Measured memory_bytes: 3584
#include <iomanip>
#include <random>
#include <time.h>
#include <vector>
#include <queue>
#include <functional>
#include <map>
#include <string>
#include <cstdlib>
#include <typeinfo>
#include <math.h>
#include <algorithm>
#include <iostream>
#include <list>
#include <stack>
#include <set>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
using namespace std;
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin >> s;
	ll a, b, cnt = 0, yan = 0, ud[5000] = {}, lr[5000] = {};
	ll A, B, S = s.size();
	cin >> a >> b;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == 'F')cnt++;
		else {
			if (yan % 2) ud[yan / 2 + 1] += cnt;
			else lr[yan / 2 + 1] += cnt;
			cnt = 0; yan++;
		}
	}
	if (cnt) {
		if (yan % 2) ud[yan / 2 + 1] += cnt;
		else lr[yan / 2 + 1] += cnt;
		yan++;
	}
	if (lr[1] == S && a == S && !b) {
		cout << "Yes" << endl;
		return 0;
	}
	bool dpa[4010][18010] = {}, dpb[4010][18010] = {};
	A = (yan + 1) / 2;
	B = yan / 2;
	dpa[1][lr[1]] = 1;
	for (int i = 2; i <= A; i++) {
		for (int j = -9000; j <= 9000; j++) {
			if (dpa[i - 1][j + lr[i]] || dpa[i - 1][j - lr[i]]) {
				dpa[i][j] = 1;
			}
		}
	}
	if (!dpa[A][a]) {
		cout << "No" << endl;
		return 0;
	}
	dpb[1][ud[1]] = dpb[1][-ud[1]] = 1;
	for (int i = 2; i <= B; i++) {
		for (int j = -9000; j <= 9000; j++) {
			if (dpb[i - 1][j + ud[i]] || dpb[i - 1][j - ud[i]]) {
				dpb[i][j] = 1;
			}
		}
	}
	if (dpb[B][b])cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 141440
#include<stdio.h>
#include<math.h>
#include<stdlib.h>

//D日目時点のスコアを計算
int score(int D, int c[], int s[][26], int t[]){
    int pen_day[26]={1};
    for(int i=0; i<26; i++){
        pen_day[i]=1;
    }
    int score=0;
    
    for(int i=0; i<D; i++){
        int type=t[i]-1;
        pen_day[type]=0;
        //満足度増加
        score+=s[i][type];
        //満足度低下
        for(int j=0; j<26; j++){
            int dec=c[j]*pen_day[j];
            score-=dec;
        }
        //日数追加
        for(int j=0; j<26; j++){
            pen_day[j]++;
        }        
    }
    return score;
}

void Greedy(int D, int c[], int s[][26]){
    int t[D], max_type=0, max_score=0;

    for(int i=0; i<D; i++){
        max_score=0;
        for(int j=0; j<26; j++){
            t[i]=j+1;
            int S=score(i+1, c, s, t);
            if(max_score < S){
                max_score = S;
                max_type=j+1;
            }
        }
        t[i]=max_type;
    }

    //局所探索
    int new=0;
    int roop_num=0;
    int MAX=max_score;
    while(1){
        int a=rand()%D;
        int b=rand()%D;

        //a,bを入れ替え
        int tmp;
        tmp=t[a];
        t[a]=t[b];
        t[b]=tmp;

        //scoreを計算
        int now_score=score(D, c, s, t);
        if(MAX<now_score) MAX=now_score;
        else{
            tmp=t[a];
            t[a]=t[b];
            t[b]=tmp;  
        }
        new++;
        roop_num++;
        if(roop_num==D*50) break;
    }

    for(int i=0; i<D; i++){
        printf("%d\n", t[i]);
    }
}

int main(void){
    int D, c[26], s[365][26], t[365];

    //入力
    scanf("%d", &D);
    for(int i=0; i<26; i++){
        scanf("%d", &c[i]);
    }
    for(int i=0; i<D; i++){
        for(int j=0; j<26; j++){
            scanf("%d", &s[i][j]);
        }
    }
    /*
    for(int i=0; i<D; i++){
        scanf("%d", &t[i]);
    }
    */

   /*ここから処理*/
   /*
    int num=1;
    for(int i=0; i<D; i++){
        printf("%d\n", num);
        num++;
        if(num>26) num=1;
    }
    */

   Greedy(D, c, s);


    return 0;
}

Measured memory_bytes: 1772
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] A = new int[N];
        for (int i = 0; i < N; i++) {
            A[i] = sc.nextInt();
        }

        long sum = 0;
        HashMap<Long, Long> map = new HashMap<>();
        map.put(0L, 1L);
        for (int i = 0; i < N; i++) {
            sum += A[i];
            if (map.containsKey(sum)) {
                map.put(sum, map.get(sum) + 1);
            } else {
                map.put(sum, 1L);
            }
        }

        long ret = 0;
        for (long value : map.values()) {
            ret += (value * (value - 1)) / 2;
        }

        System.out.println(ret);
    }
}

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

int dx[] = {-1,1,0,0};
int dy[] = {0,0,-1,1};
int h,w;
string m[100];
	
void check(int x, int y, char ch){
	m[y][x] = 'f';
	
	for(int i=0 ; i<4 ; i++){
		int mx = x + dx[i];
		int my = y + dy[i];
		if( 0<=mx && mx<w && 0<=my && my<h){
			if(m[my][mx]==ch) check( mx , my , ch );
		}
	}
}

int main(){
	int cnt;
	while( cin >> h >> w, h, w ){
		cnt = 0;
		for(int y=0 ; y<h ; y++){
			cin >> m[y];
		}
		for(int y=0 ; y<h ; y++){
			for(int x=0 ; x<w ; x++){
				if( m[y][x] == '#'){
					cnt++;
					check( x , y , '#' );
				}
				if( m[y][x] == '@'){
					cnt++;
					check( x , y , '@' );
				}
				if( m[y][x] == '*'){
					cnt++;
					check( x , y , '*' );
				}
			}
		}
		cout << cnt << endl;
	}
	
	return 0;
}

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

int main(){
  int a,b,c;
  cin>>a>>b>>c;
  vector<vector<int>> d(b,vector<int>(a,0));
  int e,f,g,h;
  h=0;
  for(int i=0;i<c;i++){
    h=0;
    cin>>e>>f>>g;
    if(g==1){
      for(int j=0;j<e;j=j){
        d.at(h).at(j)=1;
        h++;
        if(h==d.size()){
          h=0;
          j++;
        }
      }
    }
    if(g==2){
      for(int j=e;j<d.at(0).size();j=j){
        d.at(h).at(j)=1;
        h++;
        if(h==d.size()){
          h=0;
          j++;
        }
      }
    }
    if(g==3){
      for(int j=0;j<f;j=j){
        d.at(j).at(h)=1;
        h++;
        if(h==d.at(0).size()){
          h=0;
          j++;
        }
      }
    }
    if(g==4){
      for(int j=f;j<d.size();j=j){
        d.at(j).at(h)=1;
        h++;
        if(h==d.at(0).size()){
          h=0;
          j++;
        }
      }
    }
  }
  int count =0;
  for(int i=0;i<b;i++){
    for(int j=0;j<a;j++){
      if(d.at(i).at(j)==0)
        count++;
    }
  }
  cout<<count<<endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define each(a,x) for(auto a : (x))
#define all(a) (a).begin(),(a).end()
#define chmin(a,b) ((a) = min((a),(b)))
#define chmax(a,b) ((a) = max((a),(b)))
#define in_range(x,l,r) ((l)<=(x) && (x)<(r))
#define printvec(a) rep(i,a) cout << a[i] << " \n"[i+1==(a).size()];
#define fs first
#define sc second
#define em emplace
#define eb emplace_back
#define sz size()
#define MP make_pair
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<pll> vp;

const ll INF = 1e8;
const D EPS = 1e-8;
const ll MOD = 1e9+7;

class SegmentTree{
  int n;
  vp node;
  vl val;
public:
  SegmentTree(int n_, vl a){
    n=1;
    while(n<n_)n*=2;
    node = vp(2*n-1, pll(0,0));
    val = a;
  }

  void add(int k, ll v){
    int cur = k + n-1;
    node[cur].fs += v*val[k];
    node[cur].sc += v;
    while(cur>0){
      cur = (cur-1)/2;
      node[cur].fs = node[cur*2+1].fs + node[cur*2+2].fs;
      node[cur].sc = node[cur*2+1].sc + node[cur*2+2].sc;
    }
  }

  //return maximum value in [a,b). ( [l,r) is interval in which k is.)
  pll rangeSum(int a,int b,int k=0,int l=0,int r=0){
    if(l>=r)r = n;
    if(r<=a || b<=l) return pll(0,0);
    if(a<=l && r<=b) return node[k];
    pll vl = rangeSum(a,b,2*k+1,l,(l+r)/2);
    pll vr = rangeSum(a,b,2*k+2,(l+r)/2,r);
    return pll(vl.fs + vr.fs, vl.sc + vr.sc);
  }
};

int main(){
  ll n;
  cin >> n;
  vl a(n+1,0), partial_max(n+1,0), ans(n,0);
  rep(i,n){
    cin >> a[i+1];
    partial_max[i+1] = max(a[i+1], partial_max[i]);
  }

  vl id = a;
  sort(all(id));
  id.erase(unique(all(id)), id.end());

  SegmentTree st(n+1, id);
  ll sum = 0;

  rrep(i,n){
    ll val = lower_bound(all(id), a[i+1]) - id.begin();
    st.add(val, 1);

    ll val_max = lower_bound(all(id), partial_max[i]) - id.begin();
    pll p = st.rangeSum(val_max+1, n+1);
    ans[i] += p.fs - partial_max[i]*p.sc - sum;
    sum += ans[i];
  }

  rep(i,n) cout << ans[i] << endl;
}


Measured memory_bytes: 10008
#include <bits/stdc++.h>
#define ll long long
#define f(i, x, n) for(int i = x; i < n; i++)
#define dbg(x) cout << x << endl
#define dbg2(x, y) cout << x << "  " << y << endl
#define dbg3(x, y, z) cout << x << "  " << y << "  " << z << endl
#define mod 1000000007
using namespace std;

int main(){
    ios::sync_with_stdio(0);
    ll n;
    cin >> n;
    ll sum = (n*(n+1))/2;
    ll three = n/3;
    ll five = n/5;
    sum -= 3 * (three*(three+1))/2;
    sum -= 5 * (five*(five+1))/2;
    ll fifteen = n/15;
    sum += 15 * (fifteen*(fifteen+1))/2;
    cout << sum << endl;
}

Measured memory_bytes: 3644
from functools import reduce
from fractions import gcd

N = int(input())
*A, = map(int, input().split())

l_gcd = [0]*(N+2)
r_gcd = [0]*(N+2)

l_gcd[0] = A[0]
for i in range(1, N+1):
    l_gcd[i] = gcd(l_gcd[i-1], A[i-1])

r_gcd[N+1] = A[N-1]
for i in range(1, N+1)[::-1]:
    r_gcd[i] = gcd(r_gcd[i+1], A[i-1])

ans = 0
for i in range(1, N+1):
    if i==1:
        ans = max(ans, r_gcd[i+1])
    elif i==N:
        ans = max(ans, l_gcd[i-1])
    else:
        ans = max(ans, gcd(l_gcd[i-1], r_gcd[i+1]))

print(ans)

Measured memory_bytes: 16132