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

using namespace std;

    int a[100005];
    int b[100005];
    vector<int> v[100002];
    deque<int> d;
    int bio[100002];

int main (){

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

    for (int i = 0; i < m; i++){
        cin >> a[i] >> b[i];
        v[a[i]].push_back(b[i]);
        v[b[i]].push_back(a[i]);
    }

    d.push_back(1);

    bio[1] = 1;

    while (1){
        int e = 0;
        int prvi = d.front();
        for (int i = 0; i < v[prvi].size(); i++){
            if (bio[v[prvi][i]] == 0){
                d.push_front(v[prvi][i]);
                bio[v[prvi][i]] = 1;
                e = 1;
                break;
            }
        }
        int zadnji = d.back();
        for (int i = 0; i < v[zadnji].size(); i++){
            if (bio[v[zadnji][i]] == 0){
                d.push_back(v[zadnji][i]);
                bio[v[zadnji][i]] = 1;
                e = 1;
                break;
            }
        }
        if (e == 0)break;
    }

    cout << d.size() << "\n";

    for (int i = 0; i < d.size(); i++){
        cout << d[i] << " ";
    }

    return 0;
}


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

using namespace std;

#define int long long

const int mod = 1e9+7;

int p(int a, int b)
{
	if (b == 0)
		return 1;
	int tmp = p(a,b/2);
	if (b%2 == 0) return (tmp * tmp)%mod;
	return ((tmp * tmp)%mod * a)%mod;
}

int comb(int n,int k)
{
	int ans = 1;
	for (int i=n-k+1;i<=n;i++)
		ans = (ans * i)%mod;
	for (int i=1;i<=k;i++)
		ans = (ans * p(i,mod-2))%mod;
	return ans;	
}

int n,a,b;

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

	cin >> n >> a >> b;
	int ans = ((p(2,n) - 1)%mod + mod)%mod;
	ans = ((ans - comb(n,a))%mod + mod)%mod;
	ans = ((ans - comb(n,b))%mod + mod)%mod;
	cout << ans;
}

Measured memory_bytes: 384
/*
 * 2424.cc: Kakezan
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

/* typedef */

typedef set<int> si;

/* global variables */

/* subroutines */

/* main */

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

  while (qn--) {
    int n;
    cin >> n;

    int tm = 0;
    si ns;

    while (n >= 10) {
      //printf("%d: %d\n", tm, n);
      
      if (ns.find(n) != ns.end()) {
	tm = -1;
	break;
      }
      ns.insert(n);
      
      int maxm = 0;
      for (int t = 10; t <= n; t *= 10) {
	int m = (n / t) * (n % t);
	if (maxm < m) maxm = m;
      }

      tm++;
      n = maxm;
    }

    printf("%d\n", tm);
  }
  return 0;
}

Measured memory_bytes: 1176
#include<bits/stdc++.h>
using namespace std;
string s;
int len;
int main()
{
  cin>>s;
  len=s.size();
  for(int i=0;i<len-1;i++)
  {
    if(s[i]==s[i+1]){printf("%d %d\n",i+1,i+2);return 0;}
  }
  for(int i=0;i<len-2;i++)
  {
    if(s[i]==s[i+2]){printf("%d %d\n",i+1,i+3);return 0;}
  }
  printf("-1 -1\n");
  return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<unordered_map>
using namespace std;
//---------------------------------------------------
//ライブラリゾーン！！！！
#define int long long
#define str string
#define rep(i,j) for(int i=0;i<(int)(j);i++)
typedef long long ll;
typedef long double ld;
const ll inf = 4523372036854775807;
const ld pi = 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989;
struct P {
	ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {//隣接リスト表現
	ll to, cost;
};
struct S {//辺の情報を入れる変数
	int from, to, cost;
};
ll gcm(ll i, ll j) {//最大公約数
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcm(j%i, i);
}
//---------------------------------------------------
//+++++++++++++++++++++++++++++++++++++++++++++++++++
int n, a[100000], sum = 0;
signed main() {
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int i = 0; i < n-1; i++) {
		if (a[i] == i + 1) {
			int m = a[i];
			a[i] = a[i + 1];
			a[i + 1] = m;
			sum++;
		}
	}
	for (int i = n-1; i >= 0; i--) {
		if (a[i] == i + 1) {
			int m = a[i];
			a[i] = a[i + 1];
			a[i + 1] = m;
			sum++;
		}
	}

	cout<<sum<<endl;
	getchar(); getchar();
}

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

using namespace std;

#define ar array
#define ll long long

const ll INF=1e18;
const int mxV=1e5;

int main (){
	int n,W;
	cin >> n >> W;
	vector<ll> dp(mxV+1,INF);
	dp[0]=0;
	vector<ll> w(n);
	vector<ll> v(n);
	for(int i=0; i<n; ++i) cin >> w[i] >> v[i];
	for(int i=0; i<n; ++i){
		for(int j=mxV; j>=v[i]; --j){
			dp[j]=min(dp[j], dp[j-v[i]]+w[i]);
		}
	}
	ll ans=-1;
	for(int i=1; i<=mxV; ++i) if(W>=dp[i]) ans=i; 
	cout << ans;
	return 0;
}



Measured memory_bytes: 4048
#include<stdio.h>
#include<string.h>
#define rep(i,n) for(int i=0;(i)<(n);(i)++)
int main(void){
    char alp[53]="";
    rep(i,26){
        alp[i]='a'+i;
    }
    rep(i,26){
        alp[i+26]='A'+i;
    }
    //printf("%s\n",alp);
    while(1){
        int n; int list[100];
        scanf("%d",&n);
        if(n==0) break;
        rep(i,n) scanf("%d",&list[i]);
        getchar();
        char s[102]="";
        scanf("%s",s);
        //printf("%s len:%lu\n",s,strlen(s));
        int len=strlen(s);
        for(int i=0;i<len;i++){
            int key=list[i%n];
            if('A'<=s[i]&&s[i]<='Z'){
                char c=alp[(26+s[i]-'A'-key+52*2)%52];
                s[i]=c;
            }
            else{
                char c=alp[(s[i]-'a'-key+52*2)%52];
                s[i]=c;
            }
        }
        printf("%s\n",s);
    }
}



Measured memory_bytes: 2100
#include<bits/stdc++.h>
using namespace std;
unsigned long long N,ans=1ULL;
int main(){
    cin>>N;
    vector<long long>A(N);
    for(int i=0;i<N;i++)cin>>A[i];
    sort(A.begin(),A.end());
    if(A[0]==0LL){cout<<0<<endl;return 0;}
    for(int i=N-1;i>=0;i--){
        if(ans*A[i]>1000000000000000000ULL||ans*A[i]<ans){cout<<-1<<endl;return 0;}
        ans*=A[i];
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3996
#define _LIBCPP_DEBUG 0
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = 1e9 + 7;

int main(void) {

    int x[4],y[4];
    cin>>x[0]>>y[0]>>x[1]>>y[1];
    int xsa = x[1]-x[0];
    int ysa = y[1]-y[0];
    x[2] = x[0] + xsa - ysa;
    y[2] = y[0] + xsa + ysa;
    x[3] = x[1] - xsa - ysa;
    y[3] = y[1] + xsa - ysa;
    cout<<x[2]<<" "<<y[2]<<" "<<x[3]<<" "<<y[3]<<endl;
}

Measured memory_bytes: 256
N, L = input().split()
N,L = int(N),int(L)
apples = []
for i in range(N):
    apples.append(L+i)

error = abs(L)
num = 0

for i in range(N):
    if abs(apples[i]) < error:
        error = abs(apples[i])
        num = i
apples.pop(num)

print(sum(apples))

Measured memory_bytes: 3064
// NK
#include <bits/stdc++.h>
using namespace std;
#define ii pair<int,int>
#define ll long long
#define vi vector<int>
#define vii vector<ii>
#define vll vector<ll>
#define pb push_back
#define eb emplace_back
#define pob pop_back
#define psf push_front
#define pof pop_front
#define mkp make_pair
#define mkt make_tuple
#define all(x) x.begin(), x.end()

int main(){
	ios::sync_with_stdio(false), cin.tie(nullptr);
	int a[3];
	for (int i=0; i<3; i++) cin>>a[i];
	swap(a[0], a[1]);
	swap(a[0], a[2]);
	for (int i=0; i<3; i++) cout<<a[i]<<' ';
	
	return 0;
}


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

int main()
{
  string N;
  cin >> N;
  if (N[0] == N[1] && N[1] == N[2])
    cout << "Yes" << endl;
  else if (N[1] == N[2] && N[2] == N[3])
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


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

using namespace std;

int main()
{
  int N, A, B, C, X;
  while (scanf("%d %d %d %d %d", &N, &A, &B, &C, &X) == 5) {
    if (N == 0 && A == 0 && B == 0 &&  C == 0 && X == 0) break;
    int Y[N];
    for (int i = 0; i < N; i++) {
      scanf(" %d", &Y[i]);
    }
    int index = 0;
    bool flag = true;
    for (int i = 0; i <= 10000; i++, X = (A * X + B) % C) {
      if (X == Y[index]) index++;
      if (index == N) {
	cout << i << endl;
	flag = false;
	break;
      }
    }
    if (flag) {
      cout << -1 << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 0
import java.util.*;
import java.io.*;
import java.math.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true) {
			int n = sc.nextInt();
			
			int m = sc.nextInt();
			if(n == 0 && m == 0) break;
			char[][] N = new char[n][8];
			int[] M = new int[n];
			for(int i = 0; i < n; i++) {
				N[i] = sc.next().toCharArray();
				M[i] = sc.nextInt();
			}
			
			char[][] B = new char[m][8];
			for(int i = 0; i < m; i++) {
				B[i] = sc.next().toCharArray();
			}
			long ans = 0;
			for(int i = 0; i < n; i++) {
				IN:for(int j = 0; j < m; j++) {
					for(int k = 0; k < 8; k++) {
						if(N[i][k] == '*') continue;
						if(N[i][k] != B[j][k]) continue IN;
					}
					ans += M[i];
				}
			}
			System.out.println(ans);
			
			
			
		}
	}
}

Measured memory_bytes: 36712
n=int(input())
l=[int(i) for i in input().split()]
lcm=l[0]
def gcd(a,b): 
    if b==0: return a 
    return gcd(b,a%b)
for i in range(1,n):
    lcm=(lcm*l[i])//gcd(lcm,l[i])
m=lcm-1 
print(sum(m%i for i in l))

Measured memory_bytes: 3316
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define PI acos(-1)
#define fs first
#define sc second
#define debug freopen("1.in", "r", stdin), freopen("1.out", "w", stdout);
#define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int MAX = 0x7fffffff;
const int MIN = 0x80000000;
const ll maxn = 1e6 + 10;

int N, arr[10], a[10], b[10], cnt, k, m, bg, ed;

int main() {
    ios;
    cin >> N;
    for (int i = 1; i <= N; i ++){
        cin >> arr[i];
        a[i] = arr[i];
    }
    for (int i = 1; i <= N; i ++)cin >> b[i];
    sort(arr + 1, arr + 1 + N);
    cnt = 0;
    do{
        cnt++;
        k = 0;
        for (int i = 1; i <= N; i ++)
            if(arr[i] != a[i])
                break;
            else k = i;
       if (k == N) bg = cnt;
        m = 0;
        for (int i = 1; i <= N; i ++)
            if(arr[i] != b[i])
                break;
            else m = i;
        if(m == N) ed = cnt;
    }while(next_permutation(arr + 1, arr + 1 + N));
    cout << abs(bg - ed) << '\n';
    return 0;
}

Measured memory_bytes: 3196
#include<bits/stdc++.h>
using namespace std;
long long k,n,a[100005],ans1=1e18+19,ans2=-1;
long long bsl()
{
    long long low=0,high=1e18+18,mid;
    while(low<=high)
    {
        mid=(low+high)/2;
        long long temp=mid;
        for(int i=0;i<k;i++)
        {
            temp-=(temp%a[i]);
        }
        if(temp==2)
        {
            ans1=mid;
            high=mid-1;
        }
        else if(temp>2)
        {
            high=mid-1;
        }
        else
        {
            low=mid+1;
        }
    }
    return ans1;
}
long long bsh()
{
    long long low=0,high=1e18+18,mid;
    while(low<=high)
    {
       mid=(low+high)/2;
       long long temp=mid;
       for(int i=0;i<k;i++)
       {
           temp-=temp%a[i];
       }
       if(temp==2)
       {
           ans2=mid;
           low=mid+1;
       }
       else if(temp>2)
       {
           high=mid-1;
       }
       else
       {

            low=mid+1;
       }
    }
    return ans2;
}
int main()
{
    cin>>k;
    for(int i=0;i<k;i++)
    {
        cin>>a[i];
    }
    if(bsl()==1e18+18&&bsh()==-1)
    {
        cout<<-1<<"\n";
        return 0;
    }
    cout<<bsl()<<' '<<bsh()<<"\n";


    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<deque>
#include<tuple>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<cstdint>
#include<unordered_map>
#include<sstream>
#include<boost/multiprecision/cpp_int.hpp>

#define rep(i, n) for(int i = 0; i < ( int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define vi vector<int>
#define vll vector<ll>
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
#define pb push_back

namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

ll M = 1000000007;

typedef pair<int, int> P;

bool ps1(const P& element1, const P& element2)
{//first昇順
	return element1.first < element2.first;
}
bool ps2(const P& element1, const P& element2)
{//first降順
	return element1.first > element2.first;
}
bool ps3(const P& element1, const P& element2)
{//second昇順
	return element1.second < element2.second;
}
bool ps4(const P& element1, const P& element2)
{//second降順
	return element1.second > element2.second;
}


int main()
{
	int n;
	cin >> n;
	deque<int>plus, minus;
	vector<pair<int, int>>maneuver(n - 1);
	int i = 0;

	rep(i, n) {
		int x; cin >> x;
		if (x >= 0) {
			plus.push_back(x);
		}
		else {
			minus.push_back(x);
		}
	}
	bool flag = true;
	if (plus.size() > 0 && minus.size() > 0) {

	}
	else if (plus.size() == 0) {
		sort(all(minus));
		int Min = minus.front();
		int Max = minus.back();
		minus.pop_front();
		minus.pop_back();
		if (minus.size() == 0) {
			cout << Max - Min << endl;
			cout << Max << " " << Min << endl;
			flag = false;
		}
		maneuver[i].first = Max;
		maneuver[i].second = Min;
		i++;
		plus.push_back(Max - Min);
	}
	else if (minus.size() == 0) {
		sort(all(plus));
		int Min = plus.front();
		int Max = plus.back();
		plus.pop_front();
		plus.pop_back();
		if (plus.size() == 0) {
			cout << Max - Min << endl;
			cout << Max << " " << Min << endl;
			flag = false;
		}
		maneuver[i].first = Min;
		maneuver[i].second = Max;
		i++;
		minus.push_back(Min - Max);
	}
	if (flag) {
		sort(all(plus));
		sort(all(minus));
		while (minus.size() != 1) {
			maneuver[i].F = plus[0];
			plus[0] -= minus.front();
			maneuver[i].S = minus.front();
			i++;
			minus.pop_front();
		}
		while (plus.size() != 1) {
			maneuver[i].F = minus[0];
			minus[0] -= plus.front();
			maneuver[i].S = plus.front();
			i++;
			plus.pop_front();
		}
		cout << plus.front() - minus.front() << endl;

		maneuver[i].first = plus.front();
		maneuver[i].second = minus.front();

		rep(i, n - 1) {
			cout << maneuver[i].first << " " << maneuver[i].second << endl;
		}
	}
}


Measured memory_bytes: 3072
#include<bits/stdc++.h>
using namespace std;
const int N = 13;
const int siz = 55e4+100;
#define fr(i,a,b) for(int i = a;i <= b; ++i)
#define nfr(i,a,b) for(int i = a;i >= b; --i)

int d[N][siz],a[N][siz],w[N][siz];
int tag[N][siz];
int n,m;
char ch[siz];
int main(){
   scanf("%d",&n);
   scanf("%s",ch+1);
   m = strlen(ch+1);

   a[0][0] = 0;
   fr(i,0,m)w[0][i] = 0;

   int cur = 1;
   fr(i,1,n){
      cur *= 3;
      w[i][0] = cur-1;
      fr(j,0,cur-1)d[i][j] = j/(cur/3);

      int tg = 0;
      fr(j,1,m){
         if(ch[j] == 'S'){
            tg ^= 1;
            int p = w[i-1][j-1];
            fr(k,0,2){
               if(d[i][p+k*(cur/3)] == 0){
                  tag[i][p+k*(cur/3)] = tg;
                  continue ;
               }
               d[i][p+k*(cur/3)] ^= 3*(tag[i][p+k*(cur/3)]^tg);
               tag[i][p+k*(cur/3)] = tg;
            }
         } else {
            int p = w[i-1][j-1];
            fr(k,0,2){
               if(d[i][p+k*(cur/3)] != 0)
                  d[i][p+k*(cur/3)] ^= 3*(tag[i][p+k*(cur/3)]^tg);
               tag[i][p+k*(cur/3)] = tg;

               d[i][p+k*(cur/3)]++;
               d[i][p+k*(cur/3)] %= 3;
            }
         }
         
         int p = w[i-1][j];
         fr(k,0,2){
            if(d[i][p+k*(cur/3)] != 0)
               d[i][p+k*(cur/3)] ^= 3*(tag[i][p+k*(cur/3)]^tg);
            tag[i][p+k*(cur/3)] = tg;

            if(d[i][p+k*(cur/3)] == 2)
               w[i][j] = p+k*(cur/3);
         }
      }

      fr(j,0,cur-1){
         if(d[i][j] == 0)continue ;
         d[i][j] ^= 3*(tag[i][j]^tg);
      }
      fr(j,0,cur-1)a[i][j] = a[i-1][j%(cur/3)]+(cur/3)*d[i][j];
   }

   fr(i,0,cur-1){
      printf("%d ",a[n][i]);
   }
   puts("");
   return 0;
}
/*
2
SRSRRSRRRSRRRR
*/


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

using namespace std;

int main(){
    string S, T, s, t;
    cin >> S;
    T = S;
    reverse(S.begin(), S.end());
    s = S.substr(0, S.length() / 2);
    t = s;
    reverse(t.begin(), t.end());

    puts(S == T and s == t ? "Yes" : "No");
    
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define int            long long
#define ll             long long
#define pb          push_back
#define    endl        '\n'
#define pii         pair<int,int>
#define vi          vector<int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (int)x.size()
#define hell        1000000007
#define rep(i,a,b)    for(int i=a;i<b;i++)
#define dep(i,a,b)    for(int i=a;i>=b;i--)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
using namespace std;

#define N  105

string n;
int k;
int dp[N][5][2];

int rec(int i,int rem,int fl)
{
    if(i==n.size())
        return (rem==0);
    int &res=dp[i][rem][fl];
    if(res!=-1)
        return res;
    res=0;
    res=rec(i+1,rem,(n[i]>'0' or fl));
    if(rem)
    {
        int mx=9;
        if(!fl)
            mx=n[i]-'0';
        int c=rec(i+1,rem-1,1);
        rep(i,1,mx)
        res+=c;
        if(mx!=0)
            res+=rec(i+1,rem-1,fl);
    }
    return res;
}

void solve()
{
    cin>>n>>k;
    memset(dp,-1,sizeof dp);
    int ans=rec(0,k,0);
    cout<<ans;
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int TESTS=1;
//    cin>>TESTS;
    while(TESTS--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
I=input
n=int
for i in range(int(input())):
  I();t=[];x=0
  for i,j in zip(map(n,I().split()[::-1]),I()[::-1]):
    for k in t:i^=k*(i^k<i)
    j=n(j);t.append(i*(j^1));x|=(i>0)&j
  print(x)

Measured memory_bytes: 68620
import java.util.*;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    long mod = (long)1e9+7;
    long cur = 1;
    long[][] dp = new long[s.length()+1][3];
    for(int i=0;i<s.length();++i){
      dp[i+1][0] = dp[i][0];
      dp[i+1][1] = dp[i][1];
      dp[i+1][2] = dp[i][2];
      if(s.charAt(i)=='?'){
        dp[i+1][0]=(3*dp[i][0]+cur)%mod;
        dp[i+1][1]=(3*dp[i][1]%mod+dp[i][0]%mod)%mod;
        dp[i+1][2]=(3*dp[i][2]%mod+dp[i][1]%mod)%mod;
        cur = (cur*3)%mod;
      }else if(s.charAt(i)=='A')dp[i+1][0]=(dp[i][0]+cur)%mod;
      else if(s.charAt(i)=='B')dp[i+1][1]=(dp[i][1]+dp[i][0]%mod)%mod;
      else dp[i+1][2]=(dp[i][2]+dp[i][1]%mod)%mod;
    }
    System.out.println(dp[s.length()][2]);
  }
}

Measured memory_bytes: 30840
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(n); ++i)
#define repr(i, a, b) for (ll i=a; i<(b); ++i)
#define reprev(i, n) for (int i=n-1; i>=0; --i)
#define reprrev(i, a, b) for (int i=b-1; i>=(a); --i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main() {
    cout << fixed << setprecision(10);
    // 2019の約数は 1, 3, 673, 2019
    ll L, R; cin >> L >> R;
    ll syou = L/2019;
    if (L/2019 < R/2019) {
        // LとRの間にmod 2019が0になるものが存在する場合
        cout << 0 << endl;
    } else {
        // mod 2019が0となるものが存在しない場合つまり、1 <= L < R <= 2018の場合
        ll min_mod = 2019;
        repr(i, L, R) {
            repr(j, i+1, R+1) {
                min_mod = min(min_mod, (i*j)%2019);
            }
        }
        cout << min_mod << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin >> N;
    double p[N];
    double dp[N+1][N+1];
    for(int i=0; i<N; i++){
        cin >> p[i];
    }
    for(int i=0; i<=N; i++){
        dp[0][i]=0;
    }
    dp[0][0]=1.0;
    for(int i=1; i<=N; i++){
        for(int j=0; j<=N; j++){
            if(j>i){
                dp[i][j]=0;
            }else{
                dp[i][j] = dp[i-1][j]*(1-p[i-1]) + dp[i-1][j-1]*p[i-1];
            }
        }
    }
    double ans=0;
    for(int i=N/2+1; i<=N; i++){
        ans +=dp[N][i];
    }
    printf("%.10lf",ans);
    return 0;
}

Measured memory_bytes: 70528
#include<bits/stdc++.h>
#define ll long long int
#define vec vector<ll>
#define mat vector<vector<ll>>

using namespace std;

const ll mod=1000000007;
const ll inf=LONG_LONG_MAX;
ll dx4[4]={1,0,-1,0};
ll dy4[4]={0,-1,0,1};
ll dx8[8]={1,0,-1,1,-1,1,0,-1};
ll dy8[8]={1,1,1,0,0,-1,-1,-1};

ll n;
mat G(n);
vec d(n);
ll dfs(ll a){
  if(a!=0 && G[a].size()==1)return 0;
  ll g=0;
  for(ll i=0;i<G[a].size();i++){
    if(d[G[a][i]]<=d[a])continue;
    g^=((dfs(G[a][i]))+1);
  }
  return g;
}

int main(){

  cin >> n;
  G=mat(n);
  for(ll i=0;i<n-1;i++){
    ll a,b;
    cin >> a >> b;
    G[a-1].push_back(b-1);
    G[b-1].push_back(a-1);
  }

  queue<ll> que;
  que.push(0);
  d=vec(n,-1);
  d[0]=0;

  //cout << 5 << endl;

  while(!que.empty()){
    ll v=que.front();
    que.pop();

    for(ll i=0;i<G[v].size();i++){
      if(d[G[v][i]]==-1){
        d[G[v][i]]=d[v]+1;
        que.push(G[v][i]);
      }
    }
  }

  //cout << 5 << endl;/

  //cout << dfs(0) << endl;

  if(dfs(0)==0)cout << "Bob" << endl;
  else cout << "Alice" << endl;


}

Measured memory_bytes: 14028
N, M = [int(a) for a in input().split()]
L = []
R = []

for _ in range(M):
    l, r = [int(a) for a in input().split()]
    L.append(l)
    R.append(r)

mingate = max(L)
maxgate = min(R)
ans = max(maxgate - mingate + 1, 0)
print(ans)

Measured memory_bytes: 16592
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <math.h>

//#define PI 3.141592653589

using namespace std;



int main()
{
	int n;
	long seisuu[3];
	
	cin >> n;
	for (int i=0; i<n; i++) cin >> seisuu[i];
	sort(seisuu, seisuu+n);
	
	for (int i=1; i<=seisuu[0]; i++)
	{
		if (n == 2)
		{
			if (seisuu[0]%i==0 && seisuu[1]%i==0)
			{
				cout << i << endl;
			}
		} else {
			if (seisuu[0]%i==0 && seisuu[1]%i==0 && seisuu[2]%i==0)
			{
				cout << i << endl;
			}
		}
	}
	//for (int i=0; i<n; i++) cout << seisuu[i] << endl;
	
	return 0;
}

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

//C Replacing Integer はもう一回やる

//一番最短の間のみ足さない
int main() {
	int K, N;
	int a[200010] = { 0 };
	
	scanf("%d", &K);//一周
	scanf("%d", &N);//家の数
	

	for (int i = 1; i <= N; i++)
		scanf("%d", &a[i]);

	//最短距離を出す
	int min = K - (a[N] - a[1]);
	for (int i = 1; i <= N; i++) 
		if (a[i] - a[i - 1] > min)
			min = a[i] - a[i - 1];
	
	
	
	cout << K - min;


}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define endl "\n"
#define se second
#define ll long long
#define inf 0x3f3f3f3f
#define fast    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int N = 2e5+10;
const ll mod =   1e9+7;
ll n,k, pre[N],suff[N],arr[N],presum[N];
int main()
{  fast
cin>>n>>k;
for(int i=1;i<=n;i++)
{

cin>>arr[i];
presum[i]=presum[i-1]+arr[i];//cout<<presum[i]<<endl;
}
ll ans=0;
for(int i=1;i<=n;i++)
{
	pre[i]=max(pre[i-1],pre[i-1]+arr[i]);
	suff[n-i+1]=max(suff[n-i+2],suff[n-i+2]+arr[n-i+1]);
}
for(int i=k;i<=n;i++)
{

ans=max(ans,pre[i-k]+suff[i+1]+max(0ll,presum[i]-presum[i-k]));
//cout<<pre[i-k]<<" "<<suff[i+1]<<" "<<presum[i]<<" "<<presum[i-k]<<endl;
}
cout<<ans;
}

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

int main() {
	int i,j;
	bool a[4][13];
	for(i=0;i<4;i++){
		for(j=0;j<13;j++){
			a[i][j]=0;
		}
	}
	char mark;
	int number,n;
	cin >> n;
	for(i=0;i<n;i++){
		cin >> mark >> number;
		number --;
		switch(mark){
		case 'S':
			a[0][number]=1;
			break;
		case 'H':
			a[1][number]=1;
			break;
		case 'C':
			a[2][number]=1;
			break;
		case 'D':
			a[3][number]=1;
			break;
		}
	}
	for(i=0;i<4;i++){
		for(j=0;j<13;j++){
			if (a[i][j] == 0){
				switch(i){
				case 0:
					cout << "S" <<" ";
					break;
				case 1:
					cout << "H" <<" ";
					break;
				case 2:
					cout << "C" <<" ";
					break;
				case 3:
					cout << "D" <<" ";
					break;
				}
				cout << j+1 <<endl;
		    }
		}
	}
	return 0;
}

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

using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)

signed main(){

	lli n;
	cin>>n;
	lli l;
	cin>>l;

	vector<string> s(n);
	REP(i,0,n){
		cin>>s[i];
	}

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

	REP(i,0,n)cout<<s[i];
	cout<<endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);
#define time_taken_start int begtime = clock();
#define time_taken_end int endtime = clock(); \
cerr << "\n\n" << "Time elapsed: " << \
(endtime - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n"; \
return 0;
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define mod 1000000007
#define inf 1000000000000000007
#define eps 0.0000000001
#define pi acosl(-1)
#define pdd pair<ld,ld>
#define pll pair<ll,ll>
#define ff first
#define ss second
#define vpl vector<pll>
#define vll vector<ll>
#define mseti multiset <ll>
#define msetd multiset <ll,greater<ll>>
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound 
#define stp fixed<<setprecision(20)
#define endl '\n'
ll nxt[200009];
ll cnt;
ll e[200009];
ll a[200009];
ll rep;
ll k;
void rec(ll q)
{
	if(e[q]==1)
	{
		rep=q;
		return;
	}
	e[q]=1;
	a[q]=cnt++;
	rec(nxt[q]);
}
void dfs(ll q)
{
	if(k==0)
	{
		cout<<q;
		return;
	}
	k--;
	dfs(nxt[q]);
}
void solve()
{
	ll n;
	cin>>n>>k;
	for(ll i=1;i<=n;i++)
	{
		cin>>nxt[i];
	}
	rec(1);
	for(ll i=0;i<=n;i++)
		e[i]=0;
	if(k<=a[rep])
	{
		dfs(1);
	}
	else
	{
		k-=a[rep];
		k%=(cnt-a[rep]);
		dfs(rep);
	}
}
int main()
{
    FAST
    #ifdef ayk_16
    freopen("input.txt","rt",stdin);
    freopen("output.txt","wt",stdout);
    #endif
    time_taken_start
    ll t=1;
    //cin>>t;
    for(ll i=0;i<t;i++)
    {
        //cout<<"Case #"<<i+1<<": ";
        solve();
    }
    time_taken_end
}

Measured memory_bytes: 8336
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner std = new Scanner(System.in);
		int n = Integer.parseInt(std.next());
		int m = Integer.parseInt(std.next());
		int l = Integer.parseInt(std.next());

		int mat_a[][] = new int[n][m];
		for(int i=0; i<n; i++){
			for (int j=0; j<m; j++){
				mat_a[i][j] = Integer.parseInt(std.next());
			}
		}

		int mat_b[][] = new int[m][l];
		for(int j=0; j<m; j++){
			for (int k=0; k<l; k++){
				mat_b[j][k] = Integer.parseInt(std.next());
			}
		}

//		int mat_c[][] = new int[n][l];
		for(int i=0; i<n; i++){
			String line = "";
			for (int k=0; k<l; k++){
				long sum = 0;
				for(int j=0; j<m; j++){
					sum += mat_a[i][j] * mat_b[j][k];
				}
				if(k!=0){line += " ";}
				line += sum;
			}
			System.out.println(line);
		}
	}
}

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

#場合分けで考える
#b-aが偶数の場合、お互いに移動すればよい
#b-aが奇数の場合、末端に近いほうが端まで移動し、その後いターン消費して、距離をお互いに詰める

if (b-a)%2==0:
    ans = int((b-a)//2)
else:
    #端までの距離が近いほうの移動ステップ
    #端まで移動した際のお互いの距離は変化していない、そこから1ターン消費する
    #距離が偶数になるのでお互いに移動する
    ans = int(min(a-1,n-b)+1+(b-a-1)//2)

print(ans)

Measured memory_bytes: 2940
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    c = (c-(a-b));
    if(c<0){
      c = 0;
    }
    System.out.println(c);
  }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define FastIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
typedef long int li;
typedef long long ll;
typedef long double ld;

int main()
{
    ll r, g, b, k;
    cin >> r >> g >> b >> k;
    // b > g > r
	// 7 2 5
	// 3
    ll s = 0;
    while (g <= r)
	{
        g *= 2;
        s++;
	}
	while (b <= g)
	{
		b *= 2;
		s++;
	}
	if (s <= k)
		cout << "Yes\n";
	else
		cout << "No\n";
}


Measured memory_bytes: 3628
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cfloat>
#include<climits>
#include<cmath>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;

using lint = long long;
using P = pair<int, int>;
using LLP = pair<long long, long long>;

#define REP(i, x, n) for(int i = (x), i##_len = (int)(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = (int)(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = (int)(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = (int)(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = (int)(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())
#define REVERSE(x) reverse((x).begin(), (x).end())
#define TWINS(x) cout << ((x) ? "Yay!" : ":(") << '\n'

constexpr int IINF = (1 << 30) - 1;
constexpr long long LLINF = 1LL << 61;
constexpr double EPS = 1e-10;

constexpr int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
constexpr int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};

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

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

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    rep(i, 3){
        string s;
        cin >> s;
        cout << char(s[0] - ('a' - 'A'));
    }
    cout << endl;

    cout << flush;

    return 0;
}

Measured memory_bytes: 3628
#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#include<algorithm>
#include<cstdlib>

using namespace std;
#define M 1000000007
#define rep2(x,from,to) for(int (x)=(from);x<(to);(x)++)
#define rep(x,to) rep2(x,0,to)
long long  a,b;
long long x;
int main()
{
  cin>>a>>b;
  if(a-b>=2||a-b<=-2)
    {
      cout<<0<<endl;
      return 0;
    }
  if(a>b)
    {
      long long c=a;
      a=b;
      b=c;
    }
  x=1;
  rep(i,a)
    {
      x*=(i+1);
      x%=M;
    }
  rep(i,b)
    {
      x*=(i+1);
      x%=M;
    }
  if(a==b)
    {
      x*=2;
      x%=M;
    }cout<<x<<endl;
  return 0;
}


Measured memory_bytes: 256
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
# from fractions import gcd
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from functools import reduce
from bisect import bisect_left, insort_left
from heapq import heapify, heappush, heappop

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
MAP = lambda: map(int, INPUT().split())
S_MAP = lambda: map(str, INPUT().split())
LIST = lambda: list(map(int, INPUT().split()))
S_LIST = lambda: list(map(str, INPUT().split()))
ZIP = lambda: zip(*(MAP() for _ in range(n)))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def main():
    N = INPUT()
    num = int(N[-1])

    if num == 3:
        print("bon")
    elif num == 0 or num == 1 or num == 6 or num == 8:
        print("pon")
    else:
        print("hon")




if __name__ == '__main__':
    main()


Measured memory_bytes: 10048
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define shosu(n) setprecision(n)
#define INF 1000000000;
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n];
  rep(i, n) cin >> a[i];
  sort(a, a + n);
  cout << a[n - 1] - a[0] << endl;
  return 0;
}


Measured memory_bytes: 256
N = int(input())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
C = [int(x) for x in input().split()]

count = sum(B)
for i in range(N-1):
    if A[i] == A[i+1] - 1:
        count += C[A[i]-1]

print(count)

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

int main(){
  int N;
  cin >> N;
  int count=0;
  vector<long long> A(N);
  for(int i=0;i<N;i++){
    cin >> A.at(i);
    if(A.at(i)%2==1){
      count++;
    }
  }
  if(count%2==0){
    cout << "YES" << endl;
  }
  else{
    cout << "NO" << endl;
  }
}
  
  

Measured memory_bytes: 1024
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		long n=sc.nextLong();
		long k=sc.nextLong();
		long x=k;
		int c=1;
		while(x<=n) {
			x=k*x;
			c++;
		}
		System.out.println(c);

	}

}


Measured memory_bytes: 21332
import sys

def maxHeapify(A, i):
    l = 2 * i + 1
    r = 2 * i + 2

    if l < len(A) and A[l] > A[i]:
        largest = l
    else:
        largest = i

    if r < len(A) and A[r] > A[largest]:
        largest = r

    if largest != i:
        A[i], A[largest] = A[largest], A[i]
        maxHeapify(A, largest)

def buildMaxHeap(A):
    for i in range(len(A) / 2, -1, -1):
        maxHeapify(A, i)

if __name__ == "__main__":
    lines = sys.stdin.readlines()
    A = map(int, lines[1].split())
    buildMaxHeap(A)
    print " " + " ".join(map(str, A))

Measured memory_bytes: 64160
#include<bits/stdc++.h>
#define ull unsigned long long
#define ll long long
#define pb push_back
#define endl '\n'
#define line cout<<"----------------------"<<endl
#define mp make_pair
#define mod 1000000007
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL)
#define filein freopen("input.txt","r",stdin)
#define fileout freopen("output.txt","w",stdout)
using namespace std;
const ll  mx=300009;
struct edge
{
    ll  a,b,c;
};
vector<edge> v;
ll  dp[100009][4];
ll  call(ll  ind, ll  pre)
{
    if(ind==v.size()) return 0;
    ll  &ret=dp[ind][pre];
    if(ret!=-1) return ret;
    ret=0;
    ll  a=0,b=0,c=0;
    auto x=v[ind];
        if(pre==1)
        {
            a=x.b+call(ind+1,2);
            b=x.c+call(ind+1,3);
        }
        else if(pre==2)
        {
            a=x.a+call(ind+1,1);
            b=x.c+call(ind+1,3);
        }
        else if(pre==3)
        {
            a=x.a+call(ind+1,1);
            b=x.b+call(ind+1,2);
        }
        else
        {
            a=x.a+call(ind+1,1);
            b=x.b+call(ind+1,2);
            c=x.c+call(ind+1,3);
        }
    return ret=max(a,max(b,c));
}
int  main()
{
    ll  n ;
    cin>>n;
    for(ll  i=0;i<n;i++)
    {
        ll  a,b,c; cin>>a>>b>>c;
        v.pb({a,b,c});
    }
    memset(dp,-1,sizeof dp);
    cout<<call(0,0)<<endl;



}


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

int main(){
  	//input
  	int N, M;
  	cin >> N >> M;
  	vector<pair<long int, int>> x(N);
  	for(int i=0; i<N; i++){
    	cin >> x[i].first >> x[i].second;
    }
  
  	//compute
  	long int sum = 0l;
  	sort(x.begin(), x.end());
	for(int i=0; i<N; i++){
    	if(M > x[i].second){
        	sum += x[i].second*x[i].first;
          	M -= x[i].second;
        }else if(M <= x[i].second){
        	sum += M*x[i].first;
          	break;
        }
    }
  	cout << sum << endl;
	return 0;
}

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

int main(){
  int64_t A, B, N;
  cin >> A >> B >> N;
  if(N <= B-1){
    cout << A*N/B << endl;
  }else{
    cout << A*(B-1)/B << endl;
  }
  return 0;
}

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

int main() {
    int a[3];
    rep(i, 3) cin >> a[i];
    sort(a, a + 3);
    cout << a[2] * 10 + a[1] + a[0] << endl;
    return 0;
}

Measured memory_bytes: 768
// uno {{{
#include <bits/stdc++.h>
#include <unistd.h>
#define SZ(x) ((int)(x).size())
#define ALL(c) begin(c),end(c)
#define REP(i,n) for ( int i=0; i<(int)(n); i++ )
#define REP1(i,a,b) for ( int i=(int)(a); i<=(int)(b); i++ )
#define FOR(it,c) for ( auto it=(c).begin(); it!=(c).end(); it++ )
#define MP make_pair
#define PB push_back
using namespace std;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef long long LL;

void RI() {}

template<typename... T>
void RI( int& head, T&... tail ) {
    scanf("%d",&head);
    RI(tail...);
}

template<typename T>
void _dump( const char* s, T&& head ) { cerr<<s<<"="<<head<<endl; }

template<typename T, typename... Args>
void _dump( const char* s, T&& head, Args&&... tail ) {
    int c=0;
    while ( *s!=',' || c!=0 ) {
        if ( *s=='(' || *s=='[' || *s=='{' ) c++;
        if ( *s==')' || *s==']' || *s=='}' ) c--;
        cerr<<*s++;
    }
    cerr<<"="<<head<<", ";
    _dump(s+1,tail...);
}

#define dump(...) _dump(#__VA_ARGS__, __VA_ARGS__);

template<typename A, typename B>
ostream& operator <<( ostream &s, const pair<A,B> &p ) { return s<<"("<<p.first<<","<<p.second<<")"; }

template<typename Iter>
ostream& _out( ostream &s, Iter b, Iter e ) {
    s<<"[";
    for ( auto it=b; it!=e; it++ ) s<<(it==b?"":" ")<<*it;
    s<<"]";
    return s;
}

template<typename T>
ostream& operator <<( ostream &s, const vector<T> &c ) { return _out(s,ALL(c)); }
template<typename T>
ostream& operator <<( ostream &s, const set<T> &c ) { return _out(s,ALL(c)); }
template<typename A, typename B>
ostream& operator <<( ostream &s, const map<A,B> &c ) { return _out(s,ALL(c)); }

// }}}

int n;
void input() {
    RI(n);
}

void solve() {
    REP1(i, 0, n/7) {
        int x = n - 7*i;
        if(x % 4 == 0) {
            printf("Yes\n");
            return;
        }
    }
    printf("No\n");
}

int main( int argc, char *argv[] ) {
    input();
    solve();
    return 0;
}


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

template<class T> inline void chmax(T& a, T b) {
  if (a < b) a = b;
}

int main() {
  int N,W;
  cin >> N >> W;
  
  vector<int> weight(N), value(N);
  for (int i; i < N; ++i) cin >> weight[i] >> value[i];
  
  vector<long long> dp(W+1,0);
  for (int i = 0; i < N; ++i) {
    for (int w = W; w >= 0; --w) {
      if (w - weight[i] >= 0) {
        chmax(dp[w], dp[w - weight[i]] + value[i]);
      }
    }
  }
  cout << dp[W] << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, s, n) for (int i = (s); i < (n); ++i)
#define rrep(i, n, g) for (int i = (n)-1; i >= (g); --i)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define len(x) (int)(x).size()
#define dup(x, y) (((x) + (y)-1) / (y))
#define pb push_back
#define Field(T) vector<vector<T>>
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int a, b;
  char c;
  cin >> a >> c >> b;
  if (c == '+')
    cout << a + b << endl;
  else
    cout << a - b << endl;
}

Measured memory_bytes: 3572
//
// Created by myabu on 2020/01/31.
//

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <utility>
#include <math.h>
#include <stack>
#include <queue>
#include <cstdio>
#include <numeric>
#include <iomanip>

using namespace std;


int main(void){
    int N,X;
    cin>>N>>X;

    vector<int> m(N);
    for (int i = 0; i < N; ++i) {
        cin>>m[i];
    }

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

    int ans = 0;
    for(auto i:m){
        X-=i;
        if(X<0){
            cout<<ans<<endl;
            return 0;
        }
        ans++;
    }

    while(1){
        X-=m[0];
        if(X<0){
            cout<<ans<<endl;
            return 0;
        }
        ans++;
    }


    return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<string> S(N);
  for (int i = 0; i < N; ++i) {
    cin >> S[i];
  }

  int ac = 0, wa = 0, tle = 0, re = 0;
  for (int i = 0; i < N; ++i) {
    if (S[i] == "AC") {
      ++ac;
    } else if (S[i] == "WA") {
      ++wa;
    } else if (S[i] == "TLE") {
      ++tle;
    } else {
      ++re;
    }
  }

  cout << "AC x " << ac << endl
       << "WA x " << wa << endl
       << "TLE x " << tle << endl
       << "RE x " << re << endl;
}


Measured memory_bytes: 6404
#include<bits/stdc++.h>
using namespace std;
string s;  int l,r;
bool check(int i,int j)
{ 
    l=i-1 ; r=j-1; 
    while(l<r)
    {if(s[l]!=s[r])
    return false;
     l++;
     r--;
    }return true;
}
void solve()
{  bool x,y,z;
    cin>>s; int n=s.length();
    x=check(1,n);
    y=check(1,(n-1)/2);
    z=check((n+3)/2,n) ;
    if(x&y&z)
    cout<<"Yes";
    else cout<<"No";
}
int main()
{   
   solve();
    return 0;
}


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

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

using namespace std;

int main(){

    int w,h,n;
    int cx,cy,x,y;
    int ans = 0;
    cin >> w >> h >> n;
    cin >> cx >> cy;
    for(int i=0;i<n-1;i++){
	cin >> x >> y;
	if(( cx <= x && cy <= y ) || (cx >= x && cy >= y) ){
	    ans += max(abs(cx-x),abs(cy-y));
	}else{
	    ans += abs(cx-x) + abs(cy-y);
	}
	cx = x;
	cy = y;
    }
    cout << ans  << endl;

    return 0;
}

Measured memory_bytes: 1160
#include <stdio.h>

int main()
{
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    if(a*b*c >= 0 && a*b*c <= 1000000){
        if(a<b && b<c){
            printf("Yes\n");
        }
        else{
            printf("No\n");
        }
    }
    return 0;
}

Measured memory_bytes: 580
#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() {
  vector<vector<int>> card(3,vector<int>(3));
  bool ans = false;
  for(int i = 0;i<3;i++){
    for(int j = 0;j<3;j++){
      cin >> card.at(i).at(j);
    }
  }
  vector<vector<bool>> check(3,vector<bool>(3));
  int N; cin >> N;
  vector<int> B(N);
  rep(i,N){
    cin >> B.at(i);
  }
  for(int k = 0;k<N;k++){
    for(int i = 0;i<3;i++){
      for(int j = 0;j<3;j++){
        if(B.at(k) == card.at(i).at(j)){
          check.at(i).at(j) = true;
        }
      }
    }
  }
  rep(i,3){
    if(check.at(i).at(0) == true && check.at(i).at(2) == true && check.at(i).at(1) == true){
      ans = true;
    }
  }
  rep(i,3){
    if(check.at(0).at(i) == true && check.at(1).at(i) == true && check.at(2).at(i) == true){
      ans = true;
    }
  }
  if(check.at(0).at(0) == true && check.at(1).at(1) == true && check.at(2).at(2) == true){
    ans = true;
  }
  if(check.at(2).at(0) == true && check.at(1).at(1) == true && check.at(0).at(2) == true){
    ans = true;
  }
  if(ans){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}
    

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

const int inf=3010;
double A[inf];
int n;
double dp[inf][inf];

double f(int num, int index){
     if(index==n and num==0) return 1;
     if(index==n) return 0;
     if(num<0) return 0;
    
     
     double&ans=dp[num][index];
     if(ans>=0) return ans;
     
     ans=A[index]*f(num-1, index+1);
     ans+=(1-A[index])*f(num, index+1);
     return ans;
}

int main(){
     memset(dp, -1, sizeof(dp));
     cin>>n;
     for(int i=0;i<n;i++)cin>>A[i];
    
     double ans=0;
     for(int i=n/2+1;i<=n;i++){
          ans+=f(i, 0);
     }
     cout<<fixed<<setprecision(10)<<ans;
}



Measured memory_bytes: 71296
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

int main(void)
{
    int x, y, z, k;

    cin >> x >> y >> z >> k;

    vector<ll> a(x), b(y), c(z), ab, abc;

    for (int i = 0; i < x; i++)
    {
        cin >> a[i];
    }

    for (int i = 0; i < y; i++)
    {
        cin >> b[i];
    }

    for (int i = 0; i < z; i++)
    {
        cin >> c[i];
    }

    for (int i = 0; i < x; i++)
    {
        for (int j = 0; j < y; j++)
        {
            ab.push_back(a[i] + b[j]);
        }
    }

    sort(ab.begin(), ab.end(), greater<ll>());

    for (int i = 0; i < min(k, x * y); i++)
    {
        for (int j = 0; j < z; j++)
        {
            abc.push_back(ab[i] + c[j]);
        }
    }

    sort(abc.begin(), abc.end(), greater<ll>());

    for (int i = 0; i < k; i++)
    {
        cout << abc[i] << endl;
    }
}

Measured memory_bytes: 43368
N=int(input())
A=[list(map(int,input().split())) for i in range(N)]
B=[]
for i in range(N):
  B.append([A[i][0]-A[i][1],A[i][0]+A[i][1]])
C=sorted(B, key=lambda x: x[1])
cnt=0
r=-1*10**9
for i in range(N):
  if r<=C[i][0]:
    cnt+=1
    r=C[i][1]
print(cnt)

Measured memory_bytes: 43560
import java.util.Scanner;

public class Main {
	Scanner sc = new Scanner(System.in);
	public static void main(String[] args){
		new Main();
	}
	public Main(){
		new A().doIt();
	}
	class A{
		void doIt(){
			while(true){
				int n = sc.nextInt();
				if(n == 0)break;
				boolean a[][] = new boolean [n+1][n+1];
				for(int i = 0;i < n;i++){
					int h = sc.nextInt();
					for(int j = 0;j < h;j++){
						int m = sc.nextInt();
						a[i][m] = true;
					}
				}
				int out = sc.nextInt();
				int b[] = new int [out];
				for(int i = 0;i < out;i++){
					b[i] = sc.nextInt();
				}
				int cnt = -1;
				boolean batu = true;
				for(int i = 0;i < n;i++){
					int ans = 0;
					for(int j = 0;j < out;j++){
						if(a[i][b[j]] == true)ans++;
						if(ans == out){
							if(cnt != -1){
								batu = false;
							}
							cnt = i;
						}
					}
				}
				if(!batu)System.out.println("-1");
				else{
					if(cnt != -1)System.out.println(cnt+1);
					else System.out.println("-1");
				}
			}
		}
	}
}

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

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

    int min = 1000000;
    int max = -1000000;
    long sum = 0;
    for (int i = 0; i < n; ++i) {
        int j;
        cin >> j;

        if (j < min) {
            min = j;
        }
        if (max < j) {
            max = j;
        }
        sum += j;
    }
    cout << min << " ";
    cout << max << " ";
    cout << sum << endl;
    return 0;
}

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

int main() {
    int a[3];
    for(int & i : a)
        cin >> i;

    if(a[2] > a[0] and a[2] < a[1])
        cout << "Yes";
    else if(a[2] < a[0] and a[2] > a[1])
        cout << "Yes";
    else
        cout << "No";

}

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

int main() {
	int a[10];
	int n;cin >> n;
	for (int i = 0;i < n;i++) {
		cin >> a[i];
	}
	int max = 0;
	int sum = 0;
	for (int i = 0;i < n;i++) {
		if (max < a[i])max = a[i];
		sum += a[i];
	}
	string ans;
	if (max >= sum - max)ans = "No";
	else ans = "Yes";
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256