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

using namespace std;
using ll  = long long;
using ii  = pair < int , int >;
using i3  = pair < int , ii >;
using vi  = vector < int >;
using vii = vector < ii >;
using vi3 = vector < i3 >;

const int N = 2e5 + 5;
const ll INF = 1e12;
const double eps = 1e-9 , PI = acos(-1);

int n , m;
int a[N];
int ans[N];
vi v;

void solve(){
    scanf("%d" , &n);

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

    for(int i = n ; i >= 1 ; i --){
        int sum = 0;
        for(int j = i ; j <= n ; j += i){
            sum += ans[j];
        }
        if(sum%2 != a[i]){
            bool ok = 0;
            for(int j = i ; j <= n ; j += i){
                if(ans[j] == 0){
                    ans[j] = 1;
                    ok = 1;
                    break;
                }
            }
            if(!ok){
                printf("-1\n");
                return;
            }
        }
    }

    for(int i = 1 ; i <= n ; i ++){
        if(ans[i]){
            v.push_back(i);
        }
    }
    printf("%d\n" , v.size());
    for(int i = 0 ; i < v.size() ; i ++){
        printf("%d%c" , v[i] , i == v.size()-1 ? '\n' : ' ');
    }
}

main(){
    int t = 1;
    //scanf("%d" , &t);

    while( t -- ){
            solve();
    }

    return 0;
}



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

int main(){
  int n;
  cin >> n;
  bool flag = false;
  for(int i = 0; 4*i <= 100; i++){
    if(((n - 4*i)%7 == 0)&& (n - 4*i) >= 0) flag = true;
  }
  string ans = "No";
  if(flag)ans = "Yes";
  cout << ans << endl;

}


Measured memory_bytes: 256
#include <stdio.h>
#include <cstdio>
#include <iostream>
#include <queue>
#include <set>
#include <vector>
#include <cstring>

int main(){
  
  long long int N;
  scanf("%lld", &N);
  
  std::cout << (N*(N-1))/2 << std::endl;
  
  return 0;
}


Measured memory_bytes: 256
/*
    Code written by Talant I.D.
*/
   
#include <bits/stdc++.h>
   
using namespace std;
   
typedef long long ll;
typedef pair <int, int> pii;
typedef tuple <int, int, int> tiii;
   
#define precision(n) fixed << setprecision(n)
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define mp make_pair
#define mt make_tuple
#define mod (int)1e9+7
#define eps (double)1e-9
#define PI 2*acos(-0.0);
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define do_not_disturb ios::sync_with_stdio(0);cin.tie(0);
#define curMod 998244353

bool isVowel(char ch){
    ch = tolower(ch);
    return (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u');
}
map <int, int> used;
void f(int n){
    if(!n){
	cout << 1;
	exit(0);
    }
    if(used[n]){
	return ;
    }
    used[n] = 1;
    if(n-100 >= 0)
	f(n-100);
    if(n-101 >= 0)
	f(n-101);
    if(n-102 >= 0)
	f(n-102);
    if(n-103 >= 0)
	f(n-103);
    if(n-104 >= 0)
	f(n-104);
    if(n-105 >= 0)
	f(n-105);
}

int main(){ 
    do_not_disturb
    int n;
    cin >> n;
    f(n);
    cout << 0;
    
    return 0;
} // What is to be written here?


Measured memory_bytes: 384
#include <iostream>
#include <vector>
using namespace std;
int main(void){
    int N;
    cin >> N;
    vector<long long int> A(N+1);
    vector<long long int> B(N);
    for (int i = 0; i < N+1; i++) cin >> A[i];
    for (int i = 0; i < N; i++) cin >> B[i];
    
    long long int ans = 0;
    for (int i = N-1; i >= 0; i--) {
        if (A[i+1] >= B[i]) {
            A[i+1] -= B[i];
            ans += B[i];
            B[i] = 0;
        }
        else {
            ans += A[i+1];
            B[i] -= A[i+1];
            A[i+1] = 0;
            
            if (A[i] >= B[i]) {
                A[i] -= B[i];
                ans += B[i];
                B[i] = 0;
            }
            else {
                ans += A[i];
                B[i] -= A[i];
                A[i] = 0;
            }
        }
    }
    
    cout << ans << endl;
}

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

const int INF = 0x7f7f7f7f;

int n;
int ee,h[200005],nex[200005<<1],to[200005<<1],val[200005<<1];
int dis[100005];

void addedge(int x,int y,int z)
{
	nex[++ee] = h[x];
	to[ee] = y;
	val[ee] = z;
	h[x] = ee;
}

void dijkstra()
{
	priority_queue<pair<int,int>,vector<pair<int,int> >,greater<pair<int,int> > > pq;
	pq.push(make_pair(dis[1]=1,1));
	while(!pq.empty())
	{
		int x=pq.top().second;
		pq.pop();
		for(int i=h[x];i!=-1;i=nex[i])
			if(dis[x]+val[i]<dis[to[i]])
			{
				dis[to[i]] = dis[x]+val[i];
				pq.push(make_pair(dis[to[i]],to[i]));
			}
	}
}

int main()
{
	memset(h,-1,sizeof(h));
	memset(dis,INF,sizeof(dis));
	cin>>n;
	addedge(0,10%n,0);
	for(int i=1;i<n;i++)
	{
		addedge(i,(i+1)%n,1);
		addedge(i,(i*10)%n,0);
	}
	dijkstra();
	cout<<dis[0]<<endl;
	
	return 0;
}

Measured memory_bytes: 5244
#include<cstdio>
#include<cctype>

int main(){
	char ch;
	while(1){
		scanf("%c", &ch);
		if(isalpha(ch)){
			if(islower(ch)) printf("%c", toupper(ch));
			else printf("%c", tolower(ch));
		}else printf("%c", ch);
		
		if(ch == '\n') break;
	}

	return 0;
}

Measured memory_bytes: 944
figures = ["M", "D", "C", "L", "X", "V", "I"]
hoge = {0: 1000, 1: 500, 2: 100, 3: 50, 4: 10, 5: 5, 6: 1}

while True:
    try:
        st = input()
    except:
        break
    idx = figures.index(st[0])
    res = [hoge[idx]]
    pretoken = st[0]
    for i, s in enumerate(st[1:]):
        idx = figures.index(s)
        preidx = figures.index(pretoken)
        if idx < preidx:
            res[i] = -1 * res[i]
        res.append(hoge[idx])
        pretoken = s
    print(sum(res))

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

static const int MAX = 100000+100;

int main(){
    int N;
    cin>>N;
    vector<int> a(N);
    vector<int> b(N);
    vector<int> V(MAX,0);

    for(int i=0; i<N; i++){
        cin>>a[i]>>b[i];
        V[a[i]]++;
        V[b[i]+1]--;
    }

    int ans = 0;
    int sum = 1; //自分を入れる

    for(int i=0; i<MAX; i++){
        sum += V[i];
        if(i > sum) continue;
        ans = i;
    }

    cout<<ans-1<<endl;

    return 0;
}


Measured memory_bytes: 3884
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int prime(ll a){
  if(a==2){return 1;}
  else if(a%2==0 || a==1){return 0;}
  for(ll i=3;i*i<=a;i+=2){
    if(a%i==0){return 0;}
  }
  return 1;
}
int main(){
  ll N,ans=0;
  cin>>N;
  ll n=N,count=0,sqrtN=sqrt(N);
  vector<ll> vec(sqrtN);
  for(ll i=1;i*i<=n;i++){
    count=0;
    while(N%i==0 && N>1 && prime(i)==1){
      N/=i;
      count++;
    }
    if(count>0){
      ll j=1;
        while(count>=j){
          count-=j;
          if(count>=j+1){j++;}
        }
        ans+=j;
    }
    count=0;
    if(n%i==0 && prime(n/i)==1 && N%(n/i)==0){
      while(N%(n/i)==0 && N>1){
        N/=(n/i);
        count++;
      }
      if(count>0){
        ll j=1;
          while(count>=j){
            count-=j;
            if(count>=j+1){j++;}
          }
          ans+=j;
      }
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 11236
//食べる料理の集合Sを決めたとすると、Aiが最大の料理を最後に食べるべき。
//つまり、Aiが小さい順に料理をソートしておけば、添え字が小さい方から食べる問題になる。
//順番が決まったので、あとは「食べる、食べない」の組み合わせを決めるだけになった。
//これは、ナップザック問題の要領でDPできる。
//要約：ソートしてDP
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;

void chmax(int &a, int b) { a = max(a, b); }

int INF = 1e+9;
int n, t;
int a[3000], b[3000];
int dp[3001][3001];

int main() {
	int i, j;
	
	cin >> n >> t;
	
	typedef pair<int, int> P;
	P pa[3000];
	rep(i, n) { cin >> pa[i].first >> pa[i].second; }
	sort(pa, pa + n);
	rep(i, n) { a[i] = pa[i].first; b[i] = pa[i].second; }
	
	rep(i, n + 1) rep(j, t + 1) dp[i][j] = -INF;
	dp[0][0] = 0;
	
	rep(i, n) {
		rep(j, t + 1) {
			if (dp[i][j] == -INF) continue;
			chmax(dp[i + 1][j], dp[i][j]);
			if (j < t) chmax(dp[i + 1][min(t, j + a[i])], dp[i][j] + b[i]);
		}
	}
	
	int ans = -INF;
	rep(j, t + 1) chmax(ans, dp[n][j]);
	cout << ans << endl;
	return 0;
}

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

int main() {
	int n,count=1;
    string hozon;
	
  cin>>n;
  vector<string> s(n);
  for(int i=0;i<n;i++)
  {   cin >> s.at(i);}
  sort(s.begin(),s.end());
  hozon=s.at(0);
	  for(int j=1;j<n;j++)
	  {
        if(hozon!=s.at(j))
        {hozon=s.at(j);
         count++;
        }
	  }
  cout <<count;
}


Measured memory_bytes: 9604
def wczytaj_liste(): 
    wczytana_lista = input()
    lista_znakow = wczytana_lista.split()
    ostateczna_lista = []
    for element in lista_znakow:
        ostateczna_lista.append(int(element))
    return ostateczna_lista 

def ABC():
    N = wczytaj_liste()[0]
    S = input()
    odp = 0 
    for i in range(N-2):
        if S[i] == 'A':
            if S[i+1] == 'B':
                if S[i+2]=='C':
                    odp += 1
    print(odp)
    
ABC()

Measured memory_bytes: 38384
import java.util.Scanner;

class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		String s = sc.next();
		String[] sSplit = s.split("");

		boolean ans = true;
		for(int i=0; i<sSplit.length; i++){
			for(int j=0; j<sSplit.length; j++){
				if(i!=j){
					if(sSplit[i].equals(sSplit[j])){
						ans = false;
						break;
					}
				}
			}
		}

		if(ans){
			System.out.println("yes");
		}else{
			System.out.println("no");
		}

	}

}


Measured memory_bytes: 23764
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#define ll long long
#define gmax(x,y) x=max(x,y)
#define gmin(x,y) x=min(x,y)
#define F first
#define S second
#define P pair
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define V vector
#define RE return
#define ALL(a) a.begin(),a.end()
#define MP make_pair
#define PB emplace_back
#define PF emplace_front
#define FILL(a,b) memset(a,b,sizeof(a))
#define lwb lower_bound
#define upb upper_bound
using namespace std;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n,m;
	cin>>n>>m;
	cout<<n*(n-1)/2+m*(m-1)/2; 
	RE 0;
}




Measured memory_bytes: 256
function main(input){
    let numarray=input.split(' ').map(Number);
    let W,H,x,y,r;
    W=numarray[0];
    H=numarray[1];
    x=numarray[2];
    y=numarray[3];
    r=numarray[4];
    if (x<r || y<r || x+r > W || y+r > H){
        console.log('No');
    } else {
        console.log('Yes');
    }
    
}
main(require("fs").readFileSync("/dev/stdin","utf8"));


Measured memory_bytes: 15112
#include <iostream>
#include <fstream>
#include <set>
#include <vector>
#include <algorithm>
#include <cmath>
#include <chrono>
using namespace std;

int digitsum(int n) {
    int sum = 0;
    while (n > 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}

int main(int argc, const char * argv[]) {
    
    int N;
    cin >> N;
    vector<int64_t> a(3 * N);
    for (int i = 0; i < 3 * N; i++) {
        cin >> a.at(i);
    }
    
    int64_t sum = 0;
    sort(a.begin(), a.end());
    for (int i = 0; i < N; i++) {
        sum += a.at(3 * N - 2 - 2 * i);
    }
    
    cout << sum << endl;
    
    return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep2(i, m, n) for(int i=int(m); i<int(n); i++)
#define rep(i, n) rep2(i, 0, n)
#define ALL(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
const ll INF = ll(1e15)+10;
const ld EPS = 1e-10;
const int MOD = int(1e9)+7;

int main() {
	ll N; cin >> N;
	ll next = 1;
	ll brk = 0;
	rep(i, N) {
		int x;
		cin >> x;
		if (x == next) next++;
		else brk++;
	}
	cout << ((brk == N) ? (-1) : (brk)) << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
typedef long long ll;

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

const long long INF = 1LL << 60;

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

  cout << n/3 << endl;

  return 0;
}


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

typedef unsigned long long ull;

struct P {
  P(ull x) : vol(x) {
  }
  ull vol, cost, fuck;
  bool operator<(const P& p) const {
    if (cost * fuck != p.cost * p.fuck) {
      return cost * fuck < p.cost * p.fuck;
    } else {
      return vol < p.vol;
    }
  }
};

int main() {
  vector<P> x({1, 2, 4, 8});
  x[0].fuck = 8;
  x[1].fuck = 4;
  x[2].fuck = 2;
  x[3].fuck = 1;

  cin >> x[0].cost >> x[1].cost >> x[2].cost >> x[3].cost;
  sort(x.begin(), x.end());

  ull N;
  cin >> N;
  N *= 4;

  ull ans = 0;

  for (int i = 0; i < 4 && N > 0; ++i) {
    // printf("%llu %llu %llu\n", x[i].vol, x[i].cost, N);
    ans += (N / x[i].vol) * x[i].cost;
    N %= x[i].vol;
  }
  printf("%llu\n", ans);
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <vector>
#include <map>
#include <cstring>
#include <cstdio>
#include <cmath>

using namespace std;

void f(const int,const int,int*);

int main()
{
    int N;
    int data[500001];
    cin>>N;
    for(int i=1;i<=N;i++){
        cin>>data[i];
    }
    for(int i=N/2;i>0;i--){
        f(N,i,data);
    }
    for(int i=1;i<=N;i++){
        cout<<" "<<data[i];
    }
    cout<<endl;
}
void f(const int N,const int d,int* data)
{
    int l=d*2;
    int r=d*2+1;
    int largest=d;
    if(l<=N&&data[d]<data[l]){
        largest=l;
    }
    if(r<=N&&data[largest]<data[r]){
        largest=r;
    }
    if(largest!=d){
        swap(data[d],data[largest]);
        f(N,largest,data);
    }
}

Measured memory_bytes: 3112
#include<bits/stdc++.h>
#define MAX 100005
#define f first
#define s second
using namespace std;
typedef pair<pair<int, int>, int> P;

int main(){
  int n, c, ans = 0, re[30], i, j, cnt;
  P p[MAX];
  
  scanf("%d%d", &n, &c);
  for(i = 1; i <= c; i++) re[i] = 0;
  for(i = 0; i < n; i++)
    scanf("%d%d%d", &p[i].f.f, &p[i].f.s, &p[i].s);
  sort(p, p+n);
  
  for(i = 0; i < n; i++){
    cnt = 1;
    re[p[i].s] = p[i].f.s;
    for(j = 1; j <= c; j++)
      if(j != p[i].s && re[j] >= p[i].f.f) cnt++;
    ans = max(ans, cnt);
  }
  printf("%d\n", ans);
}

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

#define debug(x) cout << #x << " = " << x << endl
#define fori(i, ini, lim) for(int i = int(ini); i < int(lim); i++)
#define ford(i, ini, lim) for(int i = int(ini); i >= int(lim); i--)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;

int main() {
    ios_base::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vector<int> d;
    for(int i = 1; i * i <= m; i++) {
        if(m % i == 0) {
            d.push_back(i);
            d.push_back(m / i);
        }
    }
    int ans = 1;
    for(auto &each : d) {
        int _m = m / each;
        if(_m >= n) {
            ans = max(ans, each);
        }
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
            int A = in.nextInt();
            int B = in.nextInt();
            System.out.println(A - 2 * B <= 0 ? 0 : (A - 2 * B));
        }
    }
}


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

int main(){
  while(1){
    string str,str2;
    int N;

    cin>>N;
    if(N==0) break;
    int count=0;
    str2[1]=0;
    for(int i=0;i<N;i++){
      str2[1]=str[1];
      cin>>str;
      if(str[1]==str2[1]) count++;
    }
    cout<<count<<endl;
  }
  return 0;
}

Measured memory_bytes: 1200
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
#define fi first
#define se second
#define sz(x) int(x.size())
using namespace std;
using ll = long long;
using P = pair<int ,int>;
const int INF = 1001001001;
const int MOD = 1000000007;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

#ifdef _DEBUG
#include "debug.h"
#else
#define debug(...)
#define print(...)
#endif

const int dh[] = {-1, 0, 1, 0};
const int dw[] = {0, -1, 0, 1};

int main() {
    cin.tie(0); ios::sync_with_stdio(false);
    int h, w; cin >> h >> w;
    vector<string> mat(h);
    rep(i, h) cin >> mat[i];

    ll ans = 0;
    vector<vector<bool>> seen(h, vector<bool>(w, 0));
    rep(i, h) rep(j, w) {
        if (mat[i][j]=='#') {
            if (seen[i][j]) continue;
            seen[i][j] = 1;
            queue<P> que;
            que.push({i, j});
            ll par = 1ll;
            ll cnt = 0;
            while (!que.empty()) {
                P p = que.front(); que.pop();
                char c = mat[p.fi][p.se];
                rep(i, 4) {
                    int nh = p.fi+dh[i], nw = p.se+dw[i];
                    if (nh<0||nh>h-1||nw<0||nw>w-1) continue;
                    if (seen[nh][nw]!=0) continue;
                    if (mat[nh][nw]==c) continue;
                    seen[nh][nw] = 1;
                    if (mat[nh][nw]=='#') par++;
                    else cnt++;
                    que.push({nh, nw});
                }
            }
            ans += cnt*par;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>  // min, max
#include <fstream>  // ifstream
#include <iomanip>  // setprecision
using namespace std;
typedef long long ll;

int main(void)
{
#ifdef FILE_DEBUG
    ifstream inputFile("data/input.txt");
    cin.rdbuf(inputFile.rdbuf());
#endif
    // これより下にコードを書く

    int N;
    cin >> N;

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

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

    cout << abs(A[0] - A[N-1]) << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define pp pop_back
#define in insert
#define ff first
#define ss second
#define  show for(int j=0;j<v.size();j++) cout<<v[j]<<" ";
#define ld long double
#define e endl
#define bc __builtin_popcount
#define MOD 1000000007
#define MAXN 200005
#define INT_SIZE 32
#define debug cout<<"we are debugging"<<endl;
#define me(x) memset(x,0,sizeof(x))
ll fast_expo(ll x,ll p)
{if(p==0) return 1;
else if(p%2==0){ ll t=fast_expo(x,p/2)%MOD;return (t*t)%MOD;} else return (x*(fast_expo(x,p-1))%MOD)%MOD;}
int main()
{
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
     ll ans=max(a*c,b*d);
          ans=max(d*a,ans);
          ans=max(ans,b*c);
     cout<<ans;
}



Measured memory_bytes: 3620
#include<stdio.h>
    #include<stdlib.h>
    #include<math.h>
    #include<string.h>
    #include <time.h>
    typedef long long ll;
    typedef long double ld;
    #define INF (1LL<<60)
    #define MOD1 1000000007
    /*swap 交換*/
    void swap(ll *a, ll *b){ll c;c=*b;*b=*a;*a=c;}
    /*2つのうち大きい数を返す*/
    ll max2(ll a,ll b){return a>=b?a:b;}
    /*2つのうち小さい数を返す*/
    ll min2(ll a,ll b){return a>=b?b:a;}
    /*絶対値*/
    ll ABS(ll a){return a>=0?a:(-a);}
    typedef struct{
        ll aa;
        ll bb;
    }frequent;
    // 小大
    int compare(const void *a, const void *b){
        return *(ll *)a>*(ll *)b?1:*(ll *)a<*(ll *)b?-1:0;}

    int main(void){
        ll n,a,b,c,d,i;
        scanf("%lld%lld%lld%lld%lld",&n,&a,&b,&c,&d);
        char s[n+5];
        scanf("%s",s);
        // ll r=0;
        if(c<d){
            for(i=a+1;i<c-1;i++){
                if(s[i]=='#'&&s[i-1]=='#'){
                    printf("No\n");
                    return 0;
                }            
            }
            for(i=b+1;i<d-1;i++){
                if(s[i]=='#'&&s[i-1]=='#'){
                    printf("No\n");
                    return 0;
                }            
            }
            printf("Yes\n");
            return 0;
        }
        ll emp=0,ok=0;
        for(i=a;i<c-1;i++){
            if(i!=a){
                if(s[i]=='#'&&s[i-1]=='#'){
                    printf("No\n");
                    return 0;
                }
            }
            if(i>=b-2&&i<=d){
                if(s[i]=='.'){
                    emp++;
                    if(emp>2) ok=1;
                }else{
                    emp=0;
                }
            }
            // printf("%lld ",emp);
        }
        if(ok==1){
            printf("Yes\n");
        }else{
            printf("No\n");
        }
        return 0;
    }


Measured memory_bytes: 384
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Scanner;

/**
 * Created by shoya on 2017/04/12.
 */
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String str1 = sc.next();
        String str2 = sc.next();
        PrintWriter pwout = new PrintWriter(System.out);
        for(Integer i : rabinKarp(str2, str1))
            pwout.println(i);
        pwout.flush();
        return;
    }

    static ArrayList<Integer> rabinKarp(String str1, String str2){
        ArrayList<Integer> list = new ArrayList<>();
        if (str1.length() > str2.length())
            return list;

        final long RADIX = Long.parseUnsignedLong("100000007");
        long t = 1, str1hash = 0, str2hash = 0;
        for (int i = 0; i < str1.length(); i++) {
            t *= RADIX;
            str1hash = str1hash * RADIX + str1.charAt(i);
            str2hash = str2hash * RADIX + str2.charAt(i);
        }
        for (int i = 0; i + str1.length() <= str2.length(); i++) {
            //System.out.println(Long.toUnsignedString(str1hash));
            //System.out.println(Long.toUnsignedString(str2hash));
            //System.out.println();
            if (str1hash == str2hash)
                list.add(i);
            if (i + str1.length() < str2.length()) {
                str2hash = str2hash * RADIX + str2.charAt(i + str1.length()) - str2.charAt(i) * t;
                //System.out.println(Long.toUnsignedString(str2hash));
            }
        }
        return list;
    }
}

Measured memory_bytes: 93072
#include <stdio.h>

int abs(int n)
{
	if (n > 0) return (n);
	
	return (n * -1);
}

int max(int a, int b)
{
	a = abs(a);
	b = abs(b);
	
	if (a > b) return (a);
	
	return (b);
}

int main(void)
{
	int i;
	int n;
	int x[3], y[3];
	int t[2];
	int sum;
	
	scanf("%d %d %d", &t[0], &t[1], &n);
	
	x[0] = y[0] = 1;
	sum = 0;
	scanf("%d %d", &x[0], &y[0]);
	for (i = 0; i < n - 1; i++){
		scanf("%d %d", &x[1], &y[1]);
		
		x[2] = x[1] - x[0];
		y[2] = y[1] - y[0];
		
		if ((x[2] > 0 && y[2] > 0) || x[2] < 0 && y[2] < 0){
			sum += max(x[2], y[2]);
		}
		else {
			sum += abs(x[2]) + abs(y[2]);
		}
		
		x[0] = x[1];
		y[0] = y[1];
	}
	
	printf("%d\n", sum);
	
	return (0);
}

Measured memory_bytes: 596
#include <iostream>
#include <cmath>
#include <climits>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <string>
#include <stack>
#include <algorithm>
#include <map>
#include <numeric>
#include <set>
using namespace std;

#define ll long long
#define ld long double
#define pi 3.14159265359;

// v:vector  type:型  order:greater(大きい順) or less(小さい順)
#define _sort(v,type,order) do { sort(v.begin(),v.end(),order<type>()); } while(0)
// vector 要素の総和算出
// v:vector  default_value:初期値
#define _sum(v,default_value) accumulate(v.begin(),v.end(),default_value )
// vector 最大値( return ite )
#define _max_element(v) max_element(v.begin(),v.end())
// vector 最大値が格納されている要素値
#define _max_element_number(v) distance(v.begin(),max_element(v.begin(),v.end()))
// 特定コンテナの中から特定の値をカウントする
#define _count(v,value) count(v.begin(),v.end(),value)

//set<uint32_t> member;	// 重複するデータを保持する事はできない member.insert(2) member.insert(2) ⇒ member.count(2)は1
//                                                              member.emplace(2)とかも同じ
//multiset<uint32_t> v;	// 重複するデータも保持する事はできる   member.insert(2) member.insert(2) ⇒ member.count(2)は2

// 丸め
#define _round(v) round(v)
// 2乗 / 3乗
#define _square(v) pow(v,2)
#define _cube(v)   pow(v,3)
// 大小判定
#define _max(x,y) max(x,y)
#define _min(x,y) min(x,y)
// string ⇒ int
#define _stringtoi(s) stoi(s)
// double 平方根
#define _sqrt(x) sqrt(x)
// double 引数 x 以上で最小の整数値 ex) 3.30303 ⇒ 4
#define _ceil(x) ceil(x)
// 指定された要素以上の値が現れる最初の位置のイテレータを取得する
#define _lower_bound(v,min) lower_bound(v.begin(), v.end(), min)
// 指定された要素より大きい値が現れる最初の位置のイテレータを取得する
#define _upper_bound(v,min) upper_bound(v.begin(), v.end(), min)

// 順列 n個の数が与えられる
// 0,1,2,...,n-1
// 全ての並べ方を1行ごとに出力する
// ex 0 1 2 / 0 2 1 / 1 0 2 / 1 2 0 / 2 0 1 / 2 1 0
#define _next_permutation(v) do {   \
	for (auto num : v) {            \
		printf("%d ", num);         \
	}                               \
	printf("\n");                   \
} while (next_permutation(v.begin(), v.end()))

// 絶対値
static int32_t _abs(const int32_t x) { return  (x > 0 ? x : -x); }
// 最大公約数
static int gcd(int a, int b)
{
	if (a < b) {
		a ^= b;
		b ^= a;
		a ^= b;
	}
	return b ? gcd(b, a % b) : a;
}
// 最小公倍数
static int lcm(int a, int b) { return a * b / gcd(a, b); }
// 多次元 std::vector 生成
template<class T>
vector<T> make_vec(size_t a) { return vector<T>(a); }
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts) { return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...)); }
// ex) auto dp = make_vec<uint64_t>(SIZE + 1, 2, 2);

// UINT32_MAX
// 4294967295 ≒ 4 * 1e9


/*

*/
// ABC 161 B
// https://atcoder.jp/contests/abc161/tasks/abc161_b
int main()
{
	uint32_t n,m;
	cin >> n >> m;

	vector<uint32_t> v(n);
	for (uint32_t i = 0; i < n; i++) {
		cin >> v[i];
	}
	_sort(v, uint32_t, greater);

	double border = _sum(v, 0) / (double)(4 * m);
	for (uint32_t i = 0; i < m; i++) {
		if ((double)v[i] < border) { 
			printf("No\n");
			return 0;
		}
	}

	printf("Yes\n");
	return 0;
}

Measured memory_bytes: 3608
import java.util.Scanner;

public class Main {
    static public void main(String[] args) {

        int[] H = new int[10000];
        int[] W = new int[10000];
        int a = 0;
        int b = 0;

        Scanner s = new Scanner(System.in);
        for (int i = 0; ; i++) {
            H[i] = s.nextInt();
            W[i] = s.nextInt();
            if ((H[i] == 0) && (W[i] == 0)) {
                break;
            }
        }
        for (int I = 0; H[I] != 0; I++) {
            b = H[I];
            while (b > 0) {
                a = W[I];
                if ((b == H[I]) || (b == 1)) {
                    while (a > 0) {
                        System.out.print('#');
                        a--;
                    }
                } else {
                    a--;
                    System.out.print('#');
                    while(a > 1){
                        System.out.print('.');
                        a--;
                    }
                    System.out.print('#');
                }
                System.out.println("");
                b--;
            }
            System.out.println("");
        }
    }
}



Measured memory_bytes: 38272
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;


public class Main{
	
	static class FastReader 
    { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader() 
        { 
            br = new BufferedReader(new
                     InputStreamReader(System.in)); 
        } 
  
        String next() 
        { 
            while (st == null || !st.hasMoreElements()) 
            { 
                try
                { 
                    st = new StringTokenizer(br.readLine()); 
                } 
                catch (IOException  e) 
                { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
  
        int nextInt() 
        { 
            return Integer.parseInt(next()); 
        } 
  
        long nextLong() 
        { 
            return Long.parseLong(next()); 
        } 
  
        double nextDouble() 
        { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() 
        { 
            String str = ""; 
            try
            { 
                str = br.readLine(); 
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    }
	static int a[];
	static boolean dp[];
	public static void main(String[] args) 
	{
		OutputStream outputStream = System.out;
        FastReader sc = new FastReader();
        PrintWriter out = new PrintWriter(outputStream);
        int n = sc.nextInt();
        int k = sc.nextInt();
        a = new int[n];
        dp = new boolean[k+1];
        Arrays.fill(dp,false);
        
        for(int i = 0; i < n; i++)
        {
        	a[i] = sc.nextInt();
        }
        for(int i = 0; i <= k; i++)
        {
        	for(int j = 0; j < n; j++)
        	{
        		if(i-a[j] >= 0 && dp[i-a[j]] == false && dp[i] == false)
        		{
        			dp[i] = true;
        			break;
        		}
        	}
        }
        out.println(dp[k] == true?"First":"Second");
        out.close();
	}

}


Measured memory_bytes: 23892
splitBy :: Char -> String -> [String]
splitBy _ [] = []
splitBy a x =
  let s = takeWhile (/= a) x
      x'= dropWhile (/= a) x
  in
    if x' == []
    then [s]
    else s:(splitBy a $ drop 1 x')

chk i s r (l:ls) =
  if s + l >= r
  then i
  else chk (i+1) (s+l) r ls

solve i =
  let (v2:v1:l) = reverse i
      s = sum l
      r = s * v1 / (v1+v2)
  in
    chk 1 0 r $ reverse l

main = do
  c <- getContents
  let i = map (map read) $ map (splitBy ',') $ lines c :: [[Float]]
      o = map solve i
  mapM_ print o

Measured memory_bytes: 4252
import java.io.*
import java.util.*

val pw = PrintWriter(System.out)
fun solve(X: Long, A: Long, B: Long){
    val rest = X - A
    println(rest - (rest/B)*B)
    pw.flush()
    return
}


fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }
    class Scanner(stream: InputStream) {
        private val reader = BufferedInputStream(stream).bufferedReader()
        private var st: StringTokenizer? = null
        fun next(): String {
            while (!(st?.hasMoreTokens() ?: false)) st = StringTokenizer(reader.readLine())
            return st!!.nextToken()
        }
    }
    val sc = Scanner(System.`in`)
    val X = sc.next().toLong()
    val A = sc.next().toLong()
    val B = sc.next().toLong()
    solve(X, A, B)
}



Measured memory_bytes: 29596
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array;

void main() {
    readln;
    readln.split.to!(int[]).sort!"a > b"().chunks(2).map!(a => a.length == 2 ? a[0] - a[1] : a[0]).sum().writeln;
}




void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}


Measured memory_bytes: 256
#include <stdio.h>

static const int N = 100;
int c=0;

void BubbleSort(int A[],int n){
  int i,j,temp;
  for(i=0;i<=n-1;i++){
    for(j=n-1;j>=i+1;j--){
      if(A[j]<A[j-1]){
        /*swap*/
	temp=A[j];
	A[j]=A[j-1];
	A[j-1]=temp;
	c++;
      }
    }
  }
}

main(){
  int i,j,n;
  int A[N+1];

  scanf("%d",&n);

  for(i=0;i<n;i++) scanf("%d",&A[i]);

  BubbleSort(A,n);

  for(j=1;j<=n;j++){
    if(j>1) printf(" ");
    printf("%d",A[j-1]);
  }
  printf("\n");
  printf("%d\n",c);
  return 0;
}

Measured memory_bytes: 604
#include <bits/stdc++.h>
using namespace std;
// #define int long long
#define ll long long
#define FOR(i,a,b) for(int i=(a); i<=(b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define loop(k) rep(author_is_masa,k)
#define chmin(a,b) if((a)>(b)) (a)=(b);
#define chmax(a,b) if((a)<(b)) (a)=(b);
#define vi vector<int>
#define pii pair<int,int>
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define pb push_back
#define pf push_front
int gcd(int a,int b){/*a>=0,b>=0,￢(a=b=0)*/
  while(min(a,b)>0){if(a<b)swap(a,b);a%=b;}return max(a,b);
}
int dx[]={1,0,-1,0,1,-1,-1,1};
int dy[]={0,1,0,-1,1,1,-1,-1};
const int MOD = 1e9+7;
const long long INF = 1e18+10;

/*--------------------------------------------------------------------*/

signed main(){
	vi a(3);
	rep(i,3)cin>>a[i];
	sort(all(a));
	if(a[0]+a[1]==a[2]) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}



Measured memory_bytes: 3600
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
 
using namespace std;
 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define C(i) cin>>i
#define C2(i,j) cin>>i>>j
#define C3(i,j,k) cin>>i>>j>>k
#define C4(i,j,k,m) cin>>i>>j>>k>>m
////////////////////////////////////////////////////////////

int main(){
  string s;
  cin >> s;
  int cnt = 1;
  char b = s[0];
  rep(i,1,s.size()){
    if(b == s[i]){
      cnt++;
    }
    else{
      cnt = 1;
    }
    if(cnt >= 3){
      Yes;
      ret 0;
    }

    b = s[i];
  }
  No;
  ret 0;
}

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

int num[1000];
int t;

void push(int x) {
	num[++t] = x;
}

int pop() {
	return num[t--];
}

int main(void) {
	char formula[100];
	int a, b;
	
	t = 0;
	
	while ( scanf("%s", formula) != EOF ) {
		if (formula[0] == '+') {
			a = pop();
			b = pop();
			push( a + b );
		}else if (formula[0] == '-') {
			b = pop();
			a = pop();
			push( a - b );
		}else if (formula[0] == '*') {
			a = pop();
			b = pop();
			push( a * b );
		}else {
			push(atoi(formula));
		}
	}
	
	printf("%d\n", pop());

	return 0;
}

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

int main(){
  int A;
  cin >> A;
  int B;
  cin >> B;
  
  if(A==B){
    cout << 2*A << endl;
  }
  
  else if(A>=B+2){
    cout << 2*A-1 << endl;
  }
  
  else if(B>=A+2){
    cout << 2*B-1 << endl;
  }
  
  else if(A==B+1 || B==A+1){
    cout << A+B << endl;
  }
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
  val sc = if (args.size > 1) java.util.Scanner(java.io.File(args[1])) else java.util.Scanner(System.`in`)
  solve(sc)
}

fun solve(sc: java.util.Scanner) {
  val N = sc.nextInt()
  val K = sc.nextInt()
  println(K * (1..(N-1)).fold(1, { acc, i -> acc * (K-1) }))
}


Measured memory_bytes: 29352
#include<iostream>
#include<string.h>

using namespace std;

int headA = 0;
int headB = 0;
int headC = 0;


int main() {
	char a[110];
	char b[110];
	char c[110];
	char turn;
	char win;

	cin >> a >> b >> c;

	turn = 'a';
	while (turn != '\0') {
		switch (turn) {
		case 'a':
			win = 'A';
			turn = a[headA];
			headA++;
			break;
		case 'b':
			win = 'B';
			turn = b[headB];
			headB++;
			break;
		case 'c':
			win = 'C';
			turn = c[headC];
			headC++;
			break;
		default:
			break;
		}
	}

	cout << win << endl;
}

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

int main() {
 int n,m; cin >> n >> m;
 if(n%2==0 && m%2==0){
   if(n!=m)cout << 0 << endl;
   else{
     ll d=1;
     for(int i=1;i<=n;i++){
       d*=i;
       d%=INF;
     }

     d*=d;d%=INF;d*=2;d%=INF;
     cout << d << endl;
   }
 }

 if(n%2==1 || m%2==1){
   if(abs(n-m)>1)cout << 0 << endl;
   else if(n==m){
     ll d=1;
     for(int i=1;i<=n;i++){
       d*=i;
       d%=INF;
     }
     d*=d;d%=INF;d*=2;d%=INF;
     cout << d << endl;
   }
   else{
     ll d=1;int s=max(n,m);
     for(int i=1;i<=s;i++){
       d*=i;
       d%=INF;
     }
     ll e=1;
     for(int i=1;i<=s-1;i++){
       e*=i;
       e%=INF;
     }
     d*=e;d%=INF;
     cout << d << endl;
   }
 }
}


Measured memory_bytes: 256
/*
 * a.c
 *
 *  Created on: 2017/06/13
 *      Author: AWV060608
 */

#include	<stdio.h>
//#include	<string.h>
//#include	<math.h>

int		main(void)
{
	int		H,W;
	int		i,j;

	while(1)
	{
		scanf("%d",&H);
		scanf("%d",&W);

		if((H==0) && (W==0))
		{
			break;
		}

		for(i=0; i<H; i++)
		{
			for(j=0; j<W; j++)
			{
				printf("#");
			}
			printf("\n");
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 572
def linearSearch(S, N, key):
    i = 0
    S[N] = key
    while S[i] != key:
        i += 1
    if i != N:
        return True
    
N = int(input())
S = list(map(int,input().split()))
q = int(input())
T = list(map(int,input().split()))  

S.append(0)

sum = 0 

for j in range(q):
    if linearSearch(S,N,T[j]) == True:
        sum += 1
    
print(sum)


Measured memory_bytes: 6552
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

//Score    : 各手の得点（連想配列）
var score map[string]int

func main() {
	//入力から N:（勝負数） K:（禁止手） v:（青木君のいるノード） をセット
	N := nextInt()
	K := nextInt()

	// K 回分の手を保存する
	Tk := make([]string, K+1)

	// R:グーの点 S:チョキの点 P:パーの点
	R := nextInt()
	S := nextInt()
	P := nextInt()

	// 得点
	score = make(map[string]int)
	score["r"] = R
	score["s"] = S
	score["p"] = P

	// T:マシンの手
	T := nextString()

	// じゃんけん開始
	// j:0～Kの間で循環し続ける変数⇒Tk[j]：K回前で出した手
	// myscore : 最前手で稼いだ得点
	// winte:勝ち手
	j := 0
	myscore := 0
	winte := ""
	for i := 0; i < N; i++ {
		j %= K
		winte = winTe(T[i : i+1])
		if winte == Tk[j] {
			Tk[j] = alterTe(K, T[i:])
		} else {
			Tk[j] = winte
			myscore += score[winte]
		}
		j++
	}
	fmt.Println(myscore)
}

// 替りの手を返す
// K手先の相手の手（勝ち手以外なら何でもいい）を返す
func alterTe(K int, nokori string) string {
	alterte := ""
	if len(nokori) > K {
		alterte = nokori[K : K+1]
	}
	return alterte
}

// 勝ち手となる手を返す
func winTe(aite string) string {
	winte := ""
	switch aite {
	case "r":
		winte = "p"
	case "s":
		winte = "r"
	case "p":
		winte = "s"
	}

	return winte
}

// 以下、入力用
// 標準入力変数
var stdin = initStdin()

func initStdin() *bufio.Scanner {
	bufsize := 1 * 1024 * 1024 // 1 MB
	var stdin = bufio.NewScanner(os.Stdin)
	stdin.Buffer(make([]byte, bufsize), bufsize)
	stdin.Split(bufio.ScanWords)
	return stdin
}

func nextString() string {
	stdin.Scan()
	return stdin.Text()
}

func nextBytes() []byte {
	stdin.Scan()
	return stdin.Bytes()
}

func nextInt() int {
	i, _ := strconv.Atoi(nextString())
	return i
}

func nextInt64() int64 {
	i, _ := strconv.ParseInt(nextString(), 10, 64)
	return i
}


Measured memory_bytes: 2304
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll long long int
#define ordered_set tree < ll ,  null_type ,  less<ll> ,  rb_tree_tag ,  tree_order_statistics_node_update >
//added two more functions to set
//(1)*(set.find_by_order(k))[kth element in the sorted set] 
//(2)set.order_of_key(k)[count of elements strictly less than k]
typedef vector< int > vi;
typedef vector< ll > lvi;
typedef vector< vi > vvi;
typedef vector< lvi > lvvi;
typedef pair< int,int > ii;
typedef pair< ll,ll > lii;
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(auto i = (c).begin(); i != (c).end(); i++)//remember i is an iterator
#define present(c,x) ((c).find(x) != (c).end())//for sets,maps,multimaps
#define cpresent(c,x) (find(all(c),x) != (c).end())//for vectors
#define tc(t) int (t); cin>>(t);while((t)--)
#define ff first
#define ss second
#define mp make_pair
#define ld long double
#define ull unsigned long long int
#define mod 1000000007
string s;
lvi v;
// lvvi dp;
ll n,y,dp[200000][5];
ll recurs(int idx,int state)
{
	if(idx>=n-1) return 0LL;
	if(dp[idx][state]!=((ll)-1e15)) return dp[idx][state];
	if(s[idx]=='-')
	{
		if(state==0)
		{
			dp[idx][state]=max(recurs(idx+1,state)-v[idx],recurs(idx+1,state+1)-v[idx]);
		}
		if(state==1)
		{

			dp[idx][state]=max(recurs(idx+1,state-1)+v[idx],max(recurs(idx+1,state)+v[idx],recurs(idx+1,state+1)+v[idx]));
		}
		if(state==2)
		{

			dp[idx][state]=max(recurs(idx+1,state)-v[idx],recurs(idx+1,state-1)-v[idx]);
		}
	}
	else
	{
		if(state==0)
		{
			dp[idx][state]=recurs(idx+1,state)+v[idx];
		}
		if(state==1)
		{

			dp[idx][state]=max(recurs(idx+1,state-1)-v[idx],recurs(idx+1,state)-v[idx]);
		}
		if(state==2)
		{
			
			dp[idx][state]=max(recurs(idx+1,state)+v[idx],recurs(idx+1,state-1)+v[idx]);
		}
	}
	// cout<<idx<<" "<<state<<" "<<dp[idx][state]<<endl;
	return dp[idx][state];
}
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);	
	cin>>n>>y;
	// dp.assign(n+2,lvi(4,-1e15));
	for(int i=0;i<(n+2);i++)
	{
		for(int j=0;j<5;j++)
		{
			dp[i][j]=-1e15;
		}
	}
	for(int i=1;i<n;i++)
	{
		char ch;
		cin>>ch;
		ll x;
		cin>>x;
		s.pb(ch);
		v.pb(x);
	}
	ll ans=recurs(0,0)+y;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 10100
n, k, s = map(int, input().split())
a = [0] * n
for i in range(k):
    a[i] = s
if s == 1:
    s = 3
for i in range(k, n):
    a[i] = s - 1
print(a[0], end = "")
for i in a[1:]:
    print("", i, end = "")
print()


Measured memory_bytes: 8968
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int K;
int main(){
	cin>>K;
	if(K==1){
		cout<<1<<'\n';
		cout<<1<<'\n';
		return 0;
	}
	int n=(K+3)/4*2;
	cout<<n<<'\n';
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++){
			int now=(i+j-1)%n+1+(i&1?n:0);
			if(now>K) now-=n;
			cout<<now<<" \n"[j==n];
		}
	return 0;
}


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

int main(){
	ll a,b,c,k;
	cin >> a >> b >> c >> k;
	if (a > k) cout << k << endl;
	else if(a+b>=k) cout << a << endl;
	else cout << 2 * a + b -k << endl;
	return 0;
}


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

def digitSum(X):

    ds = 0
    for x in str(X):
        ds += int(x)
    return ds

ans = N

for i in range(1, N):
    dgtSum = digitSum(i) + digitSum(N - i)
    if ans > dgtSum:
        ans = dgtSum

print(ans)


Measured memory_bytes: 2940
import math
def func1(lst, value):
    return [i+1 for i, x in enumerate(lst) if x == value]
N = int(input())
a = list(map(int,input().split()))

b = [0] * N
# half = math.ceil(N/2)
summ = 0
for i in reversed(range(N)):
# print(i)
    x = N//(i+1)
# print("x",x)
    if x == 1:
        b[i] = a[i]
    else:
        for j in range(x):
            # print(j)
            summ += b[(i+1)*(j+1)-1]
        # summ -= a[i]
        # print("sum=",summ)
        judge=summ%2
        # print("judge",judge)
        if (judge==0 and a[i]==0) or (judge==1 and a[i]==1):
            b[i] = 0
        else:
            b[i] = 1
        summ = 0
        judge = 0
# print(b)
print(sum(b))
if sum(b) != 0:
    ans = func1(b,1)
    # print(ans)
    if len(ans)>1:
        ans = map(str,ans)
        print(" ".join(ans))
    else:
        print(str(ans.pop()))

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

int mp[100010];
bool p[100010];

int main() {
	// your code goes here
	int n, x, y, i, m;
	cin>>n>>m;
	for(i=1; i<=n; ++i)	mp[i]++;
	p[1]=true;
	while(m--) {
		cin>>x>>y;
		if(mp[x]) {
			mp[y]++;
			mp[x]--;
			if(p[x])	p[y]=true;
			if(mp[x]==0)	p[x]=false;
		}
		//cout<<mp[x]<<" "<<mp[y]<<endl;
	}
	int ans=0;
	for(i=1; i<=n; ++i) {
		if(mp[i]>0 && p[i])	ans++;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 768
#include <iostream>
using namespace std;
int main(void){
    
    long int n,a,b,c,d,out;
    
    cin>>n>>a>>b;
    
    d=n%(a+b);
    c=(n-d)/(a+b);
    
    if(d<a){
        out=c*a+d;
    }else{
        out=c*a+a;
    }
    
    cout<<out;
    
}


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

#define all(v) begin(v), end(v)
#define endl   '\n';
#define int    long long
#define pii    pair<int, int>
#define db(x)  cout << #x << " : " << x << '\n';

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

    int n; 
    cin >> n;
    vector<int>  B(n + 1);
    for (int i = 1; i <= n; i++) {
        cin >> B[i];
    }
    int ans = B[1] + B[n-1];
    for (int i = 2; i <= n-1; i++) {
        ans += min(B[i-1], B[i]);
    }
    cout << ans << endl;
}

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

cnt = [0]*N
i = 0
while i < N-1:
    if S[i:i+2] == "AC":
        cnt[i] += 1
        i += 1
    i += 1

AS = [0]*(N+1)
for i in range(1, N+1):
    AS[i] = AS[i-1] + cnt[i-1]

for i in range(Q):
    l, r = map(int, input().split())
    ans = AS[r-1] - AS[l-1]
    print(ans)

Measured memory_bytes: 13816
#include <iostream>
#include <fstream>
#include <typeinfo>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<25;
const double pi=acos(-1);
const double eps=1e-8;
const vi emp;

int a,b;

int main(){
	bool S=0;
	while(1){
		cin>>a>>b;
		if(!a&&!b) break;
		if(S) cout<<endl;
		bool flag=0;
		for(int i=a;i<=b;i++){
			if(i%4==0){
				if(i%100==0){
					if(i%400==0){
						flag=1;
						cout<<i<<endl;
					}
					continue;
				}
				flag=1;
				cout<<i<<endl;
			}
		}
		if(!flag) cout<<"NA"<<endl;
		S=1;
	}
}

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

#ifdef TEST
struct test {
    int ans;
} td[] = {
    {},
};
#endif

void
solver(char *s)
{
    if(s[2] == s[3] && s[4] == s[5])
        printf("Yes\n");
    else {
        printf("No\n");
    }
    return;
}

int
main(int argc, char *argv[])
{
#ifdef TEST
    int tt;
    for(tt = 0; tt < sizeof(td) / sizeof(struct test); tt++) {
        solver();
        printf("%d\n", td[tt].ans);
    }
#endif
    char S[7];
    scanf("%s", S);
    solver(S);
    return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
#define INT long long int
using namespace std;

int n, k, ans = 2020;
vector<int> T[2020];
int main()
{
    cin>>n>>k;
    for(int i = 1, a, b ; i < n ; i++ )
        scanf("%d%d",&a,&b), T[a].push_back(b), T[b].push_back(a);
    if( k%2 == 0 ) for(int i = 1 ; i <= n ; i++ )
    {
        queue<int> Q;
        int chk[2020] = {0}, cnt = 0;
        Q.push(i), chk[i] = 1, cnt++;
        while(!Q.empty())
        {
            int now = Q.front(); Q.pop();
            if( 2*(chk[now] - 1) >= k )
            {
                ans = min(ans, n-cnt);
                break;
            }
            for(int i = 0 ; i < T[now].size() ; i++ )
                if( !chk[T[now][i]] ) Q.push(T[now][i]), chk[T[now][i]] = chk[now]+1, cnt++;
        }
    }
    else
    {
        k--;
        for(int i = 1 ; i <= n ; i++ ) for(int j = 0 ; j < T[i].size() ; j++ )
        {
            queue<int> Q;
            int chk[2020] = {0}, cnt = 0;
            Q.push(i), Q.push(T[i][j]), chk[i] = chk[T[i][j]] = 1, cnt+=2;
            while( !Q.empty() )
            {
                int now = Q.front(); Q.pop();
                if( 2*(chk[now]-1) >= k )
                {
                    ans = min(ans, n-cnt);
                    break;
                }
                for(int i = 0 ; i < T[now].size() ; i++ )
                    if( !chk[T[now][i]] ) Q.push(T[now][i]), chk[T[now][i]] = chk[now]+1, cnt++;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 384