akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
from bisect import *
from collections import *
import fractions
import heapq
from itertools import *
import math
import random
import re
import string
import sys

N = int(input())
As = list(map(int, input().split()))

num = 1
ok = 0
for a in As:
    if a == num:
        num += 1
        ok += 1

if ok == 0:
    print(-1)
else:
    print(N - ok)




Measured memory_bytes: 28924
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

int main(int argc, char* argv[]){
    int n;
    cin >> n;
    if(n % 2 == 0) n /= 2;
    cout << n * 2 << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i=0;i<n;++i)

typedef long long ll;
using namespace std;
int main(){
    cin.tie(0);
   	ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    string s;
    cin >> s;
    vector<int> sum(n,0);
    if(s[0]=='W')sum[0] = 1;
    for(int i=1;i<n;++i){
        sum[i] = sum[i-1];
        if(s[i]=='W'){
            ++sum[i];
        }
    }
    ll ans = n;
    for(int i=0;i<n;++i){
        ll buf = (i==0)? 0 : sum[i-1];
        buf += (n-1-i-(sum[n-1]-sum[i]));
        ans = min(ans, buf);
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 1812
#include<stdio.h>
#include<string.h>

int main()
{
 char w[101];
 char i;
 int r,c=0,j;

 gets(w);


 for(i='a';i<='z';i++)
 {
  c=0;

  for(j=0;w[j]!='\0';j++)
  {
   if(w[j]==i)
   {
    c++;
   }
  }

  if(c>0)
  {
    if(c%2==0)
     r=1;

    if(c%2!=0)
    {
     r=0;
     break;
    }
  }
 }

 if(r==1)
    printf("Yes\n");

 else
  printf("No\n");

 return 0;
}


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

const int N = 200020;

signed main() {
  int n,k;
  cin >> n >> k;

  vector<int> a(n + 1);
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }

  vector<int> visited(N, 0);
  vector<int> path;
  path.push_back(1);

  int pos = 1;
  int cnt = 1;
  int once = 0;
  while(true) {
    visited[pos] = cnt;
    pos = a[pos];

    if(visited[pos] != 0) {
      once = visited[pos] - 1;
      break;
    }

    path.push_back(pos);
    cnt++;
  }

  int loop = path.size() - once;

  int answer = 0;
  if(k <= once) {
    answer = path[k];
  } else {
    k -= once;
    k = k % loop;
    answer = path[k + once];
  }
  cout << answer << endl;
  return 0;

}

Measured memory_bytes: 8484
#include<iostream>
#include<iomanip>
#include<cstdio>

#include<vector>
#include<queue>
#include<set>
#include<map>
#include<string>

#include<algorithm>
#include<cmath>

using namespace std;
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 ll INF = 1e18+1;

ll N, M, L, Q;
//クエリは10^4個

//変形ワーシャルフロイドとか無理?
//dp[i][j] = min(_, dp[i])

//ワーシャルフロイドで、まず全点最短路を張る
//L以内のものを全て1に、その他をINFにする
//もう一回ワーシャルフロイドで

ll G1[300][300];
ll G2[300][300];

int main() {
    cin >> N >> M >> L;
    ll a, b, c;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            G1[i][j] = INF;
            G2[i][j] = INF;
        }
    }
    for (int i = 0; i < M; i++) {
        cin >> a >> b >> c;
        a--; b--;
        G1[a][b] = c;
        G1[b][a] = c;
    }
    cin >> Q;
    vector<int> s(Q), t(Q);
    for (int i = 0; i < Q; i++) {
        cin >> s[i] >> t[i];
        s[i]--; t[i]--;
    }

    
    for (int k = 0; k < N; k++) {
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                if (G1[i][j] > G1[i][k] + G1[k][j]) G1[i][j] = G1[i][k] + G1[k][j];
            }
        }
    }

    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            if (G1[i][j] <= L) G2[i][j] = 1;
        }
    }
    
    
    for (int k = 0; k < N; k++) {
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                if (G2[i][j] > G2[i][k] + G2[k][j]) G2[i][j] = G2[i][k] + G2[k][j];
            }
        }
    }



    for (int i = 0; i < Q; i++) {
        ll num = G2[s[i]][t[i]];
        if (num >= INF) {
            cout << -1 << endl;
        } else {
            cout << num-1 << endl;
        }
    }
}

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

int point[100002];
int times[100002];

int main() {

    int n,r,l;

    cin >> n >> r >> l;

    priority_queue<pair<int,int> > que;//??????,????????????

    que.push(make_pair(0,-1));

    int lasttime = 0;

    for(int i=0;i<r;i++){
        int d,t,x;
        cin >> d >> t >> x;
        pair<int,int> p = que.top();
        while(p.first != point[-p.second] && !que.empty()){
            que.pop();
            p = que.top();
        }

        times[-p.second] += t - lasttime;
        lasttime = t;

        point[d] += x;

        que.push(make_pair(point[d],-d));

    }

    pair<int,int> p = que.top();
    while(p.first != point[-p.second] && !que.empty()){
        que.pop();
        p = que.top();
    }
    times[-p.second] += l - lasttime;

    int ans = -1,anstime = -1;

    for(int i=1;i<=n;i++){
        if(anstime<times[i]){
            ans = i;
            anstime = times[i];
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 11632
// Author: Harshdeep Sharma , IIT  Indore
#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
// #define MOD  998244353
#define ll long long
const double PI = atan(1.0) * 4;
// const ll INF = (int)1e9 ;
const int di[4] = { -1, 0, 1, 0} ;
const int dj[4] = {0, -1, 0, 1} ;
const ll INF = (ll)2e18 + 50;
const int maximum  = numeric_limits<int>::max();
const int minimum  = numeric_limits<int>::min();
// const int N = 1e5 + 5 ;
const ll mod = 1e9 + 7 ;
// const int N = 1e5 + 5 ;

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






int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	// int t ;
	// cin >> t ;
	// while (t--) {
	string s ;
	cin >> s ;
	int ans = 0;
	if (s == "RRS") cout << 2 << "\n";
	else if (s == "RRR") cout << 3 << "\n";
	else if (s == "RSS") cout << 1 << "\n";
	else if (s == "SRS") cout << 1 << "\n";
	else if (s == "SSR") cout  << 1 << "\n";
	else if (s == "SRR") cout  << 2 << "\n";
	else if (s == "RSR") cout << 1 << "\n";
	else cout << 0 << "\n";

	// }





	return 0 ;


}



Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define Maxn 400007
#define modp 1000000007
#define inf 200000000000007LL
using namespace std;
int n,m,s,t;
int cnt=0,last[Maxn],pre[Maxn],other[Maxn],val[Maxn];
int cnt1=0,last1[Maxn],pre1[Maxn],other1[Maxn];
int cnt2=0,last2[Maxn],pre2[Maxn],other2[Maxn];
bool vis[Maxn];
long long f[Maxn],f1[Maxn];
int w[Maxn],w1[Maxn],d[Maxn],d1[Maxn];
int que[Maxn];
priority_queue<pair<long long,int> > pq,pq1;
void insert(int u,int v,int t)
{
	other[++cnt]=v,pre[cnt]=last[u],last[u]=cnt;
	val[cnt]=t;
}
void insert1(int u,int v)
{
	other1[++cnt1]=v,pre1[cnt1]=last1[u],last1[u]=cnt1;
	++d[v];
}
void insert2(int u,int v)
{
	other2[++cnt2]=v,pre2[cnt2]=last2[u],last2[u]=cnt2;
	++d1[v];
}
void tryit1()
{
	memset(vis,false,sizeof(vis));
	for (int i=1;i<=n;i++)
		f[i]=inf;
	f[s]=0;
	pq.push(make_pair(0,s));
	while (!pq.empty())
	{
		int u=pq.top().second;
		pq.pop();
		if (vis[u]) continue;
		vis[u]=true;
		for (int q=last[u];q;q=pre[q])
		{
			int v=other[q];
			if (f[u]+val[q]<f[v])
			{
				f[v]=f[u]+val[q];
				pq.push(make_pair(-f[v],v));
			}
		}
	}
	for (int i=1;i<=n;i++)
	{
		for (int q=last[i];q;q=pre[q])
		{
			int v=other[q];
			if (f[i]==f[v]+val[q]) insert1(v,i);
		}
	}
	w[s]=1;
	int lx=0,rx=0;
	que[++rx]=s;
	while (lx<rx)
	{
		int u=que[++lx];
		for (int q=last1[u];q;q=pre1[q])
		{
			int v=other1[q];
			w[v]=(w[v]+w[u])%modp;
			--d[v];
			if (d[v]==0) que[++rx]=v;
		}
	}
}
void tryit2()
{
	memset(vis,false,sizeof(vis));
	for (int i=1;i<=n;i++)
		f1[i]=inf;
	f1[t]=0;
	pq1.push(make_pair(0,t));
	while (!pq1.empty())
	{
		int u=pq1.top().second;
		pq1.pop();
		if (vis[u]) continue;
		vis[u]=true;
		for (int q=last[u];q;q=pre[q])
		{
			int v=other[q];
			if (f1[u]+val[q]<f1[v])
			{
				f1[v]=f1[u]+val[q];
				pq1.push(make_pair(-f1[v],v));
			}
		}
	}
	for (int i=1;i<=n;i++)
	{
		for (int q=last[i];q;q=pre[q])
		{
			int v=other[q];
			if (f1[i]==f1[v]+val[q]) insert2(v,i);
		}
	}
	w1[t]=1;
	int lx=0,rx=0;
	que[++rx]=t;
	while (lx<rx)
	{
		int u=que[++lx];
		for (int q=last2[u];q;q=pre2[q])
		{
			int v=other2[q];
			w1[v]=(w1[v]+w1[u])%modp;
			--d1[v];
			if (d1[v]==0) que[++rx]=v;
		}
	}
}
int main()
{
	scanf("%d%d",&n,&m);
	scanf("%d%d",&s,&t);
	for (int i=1;i<=m;i++)
	{
		int u,v,t;
		scanf("%d%d%d",&u,&v,&t);
		insert(u,v,t);
		insert(v,u,t);
	}
	tryit1();
	tryit2();
	int ans=(1LL*w[t]*w1[s]%modp)%modp;
	for (int i=1;i<=n;i++)
		if (2LL*f[i]==f[t]&&f[i]==f1[i]) 
		{
			int del=(1LL*w[i]*w1[i])%modp;
			ans=(ans+modp-(1LL*del*del%modp)%modp)%modp;
		}
	for (int i=1;i<=n;i++)
		for (int q=last[i];q;q=pre[q])
		{
			int v=other[q];
			if (2LL*f[i]<f[t]&&2LL*f[v]>f[t]&&f[i]+f1[v]+val[q]==f[t])
			{
				int del=(1LL*w[i]*w1[v])%modp;
				ans=(ans+modp-(1LL*del*del%modp)%modp)%modp;
			}
		}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 31216
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)

ll lcm(ll a, ll b){
  ll tmp, r, x = a * b;
  if(a < b){
    tmp = a;
    a = b;
    b = tmp;
  }
  r = a % b;
  while(r != 0){
    a = b;
    b = r;
    r = a % b;
  }
  return x / b;
}

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

  ll n, m;
  cin >> n >> m;
  string s, t;
  cin >> s >> t;

  ll lc = lcm(n, m);

  if(lc == n * m){
    if(s[0] == t[0]) cout << lc << endl;
    else cout << -1 << endl;
    return 0;
  }

  ll gc = n * m / lc;
  ll rec = 0;
  REP(i, gc){
    if(s[i * (n / gc)] != t[i * (m / gc)]) rec++;
  }
  if(rec) cout << -1 << endl;
  else cout << lc << endl;
}


Measured memory_bytes: 640
// #include {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}

const int N = 1e5 + 10;
int n , m , cnt[N] , sum[N] , odd[N];

int main(){
  scanf("%d%d",&n,&m);
  rep(i,0,n) {
    int x;
    scanf("%d",&x);
    cnt[x]++;
  }
  rep(i,0,m) {
    for(int j=i;j<N;j+=m)
      sum[i]+=cnt[j],odd[i]+=cnt[j]&1;
  }
  int ans=0;
  for(int i=0;i+i<=m;++i) {
    int j=(m-i)%m;
    if(i==j) ans+=sum[i]/2;
    else {
      int a=i,b=j;
      if(sum[a]<sum[b]) swap(a,b);
      ans+=sum[b];
      odd[a]-=sum[b];
      if(odd[a]<0) {
        if(odd[a] & 1)
          odd[a] = 1;
        else
          odd[a] = 0;
      }
      ans+=(sum[a]-sum[b]-odd[a])/2;
    }
  }
  printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long int ll;

int k;
vector<int> dp;
int find(vector<int>& arr, int i) {
	if (i < 0)
		return 1e6;

	if (i == 0)
		return 0;

	if (dp[i] != -1)
		return dp[i];

	int ans = abs(arr[i] - arr[i - 1]) + find(arr, i - 1);
	for (int j = 2; j <= k; j++) {
		if (i - j >= 0)
			ans = min(ans, abs(arr[i] - arr[i - j]) + find(arr, i - j));
	}
	dp[i] = ans;
	return dp[i];
}


int main() {
	int n;
	cin >> n >> k;
	// dp.resize(n, -1);
	vector<int> arr(n);
	for (int i = 0; i < n; i++)
		cin >> arr[i];
	// cout << find(arr, n - 1);
	dp.resize(n, INT_MAX);
	dp[0] = 0;
	for (int i = 0; i < n; i++) {
		for (int j = 1; j <= k; j++) {
			if (i + j < n) {
				dp[i + j] = min(dp[i + j], abs(arr[i] - arr[i + j]) + dp[i]);
			}
		}
	}
	cout << dp[n - 1];
	return 0;
}

Measured memory_bytes: 3988
# coding: UTF-8
n = int(raw_input())
value_list = []
diff_indx1 = 0
diff_indx2 = 0
diff = None
for i in range(n):
    value_list.append(int(raw_input()))
    if i == 1:
        diff = value_list[1] - value_list[0]
        diff_indx1 = 1
    if value_list[i] >= value_list[diff_indx1]:
        diff2 = value_list[i] - value_list[diff_indx2]
        #print("{}:{} - {}:{} = {}@1").format(diff_indx1,value_list[diff_indx1],diff_indx2,value_list[diff_indx2],diff2)
        if diff <= diff2:
            diff = diff2
            diff_indx1 = i
            diff_indx2 = diff_indx2
            #print("{}:{} - {}:{} = {}@2").format(diff_indx1,value_list[diff_indx1],diff_indx2,value_list[diff_indx2],diff)
    if value_list[diff_indx2] > value_list[i]:
        diff_indx2 = i
        diff_indx1 = i
        #print("{}:{}").format(i,value_list[i])
print diff


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

vector<int> parent;
vector<int> depth;
int n;

void init() {
  parent.resize(n);
  depth.resize(n);
  for (int i=0; i<n; i++) {
    parent[i] = i;
    depth[i] = 0;
  }
}
int find(int i) {
  if (parent[i] == i) {
    return i;
  }
  return parent[i] = find(parent[i]);
}
void unite(int i, int j) {
  i = find(i);
  j = find(j);

  if (i == j) {
    return;
  }
  if (depth[i] > depth[j]) {
    parent[j] = i;
  } else {
    parent[i] = j;
    if (depth[i] == depth[j]) {
      ++depth[j];
    }
  }
}

vector<int> graph[200000];
set<int> used;
vector<int> ans;

void dfs(int i, map<int, vector<int> > &m) {
  used.insert(i);
  m[find(i)].push_back(i);

  for (auto to: graph[i]) {
    if (used.find(to) != used.end()) {
      continue;
    }
    dfs(to, m);
  }

}
int main() {
  int k, l;
  cin>>n>>k>>l;
  init();
  for (int i=0; i<k; i++) {
    int p, q;
    cin>>p>>q;
    --p;
    --q;
    unite(p, q);
  }
  for (int i=0; i<l; i++) {
    int r, s;
    cin>>r>>s;
    --r;
    --s;
    graph[r].push_back(s);
    graph[s].push_back(r);
  }
  ans.resize(n);
  for (int i=0; i<n; i++) {
    if (used.find(i) != used.end()) {
      continue;
    }
    map<int, vector<int> > m;
    dfs(i, m);
    for (auto mi: m) {
      int num = mi.second.size();
      for (auto j: mi.second) {
        ans[j] = num;
      }
    }
  }
  cout<<ans[0];
  for (int i=1; i<n; i++) {
    cout<<" "<<ans[i];
  }
  cout<<endl;
}

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

namespace AtCoder_solve
{
    class Program
    {
        public const ulong mod = 1000000007;

        static void Main(string[] args)
        {
            long n = long.Parse(Console.ReadLine());
            var dic = new Dictionary<string, int>();

            for(long i = 0; i < n; i++)
            {
                string vote = Console.ReadLine();
                if (dic.ContainsKey(vote))//すでに投票済みか判定
                {
                    dic[vote]++;//投票済みなら投票数＋１
                }
                else
                {
                    dic.Add(vote, 1);//そうでないなら、辞書に追加
                }

            }

            var max = dic.Select(votes => votes.Value).Max();//最大値取得
            string[] winner = new string[n];//当選者格納用
            long cnt = 0;
            foreach(var votes in dic)
            {
                if (votes.Value == max)//投票数が最も多ければ
                {
                    winner[cnt] = votes.Key;//当選者として格納
                    cnt++;
                }
            }

            Array.Sort(winner, StringComparer.Ordinal);//辞書順ソート{null,null,……,1st,2nd,…}になってる？

            for(long j = cnt; j >0; j--)
            {
                Console.WriteLine(winner[n-j]);
            }


        }
    }
}


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

int main(int argc, char *argv[]) { ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);

  map<string, vector< pair<int, int> > > mp;

  int n;cin>>n;
  for(int i=0;i<n;i++){
    string s;int p;cin>>s>>p;
    mp[s].push_back({p,i+1});
  }
  for(auto &kv : mp) {
    auto vpp = kv.second;
    sort(vpp.rbegin(), vpp.rend());
    for( auto &kv : vpp) {
      cout<<kv.second<<endl;
    }
  }
  
  return 0;
}


Measured memory_bytes: 3596
#include <vector>
#include <iostream>
#include <algorithm>
#include <unordered_map>
using namespace std;
const int mod = 1000000007;
int binpow(int a, int b) {
	int ans = 1;
	while (b > 0) {
		if (b & 1) ans = 1LL * ans * a % mod;
		a = 1LL * a * a % mod;
		b >>= 1;
	}
	return ans;
}
int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	int N;
	cin >> N;
	vector<int> A(N);
	int invsum = 0;
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
		invsum = (invsum + binpow(A[i], mod - 2)) % mod;
	}
	int mx = *max_element(A.begin(), A.end());
	int b = 0;
	while (b * b < mx) ++b;
	vector<bool> prime(b + 1, true);
	prime[0] = false; prime[1] = false;
	for (int i = 2; i <= b; ++i) {
		if (!prime[i]) continue;
		for (int j = i * 2; j <= b; j += i) {
			prime[j] = false;
		}
	}
	vector<int> p;
	for (int i = 2; i <= b; ++i) {
		if (prime[i]) {
			p.push_back(i);
		}
	}
	unordered_map<int, int> d;
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < p.size() && p[j] * p[j] <= A[i]; ++j) {
			if (A[i] % p[j] == 0) {
				int mul = 1;
				while (A[i] % p[j] == 0) {
					A[i] /= p[j];
					mul *= p[j];
				}
				d[p[j]] = max(d[p[j]], mul);
			}
		}
		if (A[i] > 1) {
			d[A[i]] = max(d[A[i]], A[i]);
		}
	}
	int pmul = 1;
	for (pair<int, int> i : d) {
		pmul = 1LL * pmul * i.second % mod;
	}
	int ans = 1LL * invsum * pmul % mod;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 768
a,b,c = map(int,input().split())
if a < b:
    if (a + c) == b:
        print("Yes")
    else:
        print("No")
elif a > b:
    if (b + c) == a:
        print("Yes")
    else:
        print("No")
elif (a + b) == c:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
package main

import (
	"fmt"
)

func main() {
	nums := scanNums(3)
	rest := nums[2] - (nums[0] - nums[1])
	if rest <= 0 {
		rest = 0
	}
	fmt.Println(rest)
}

func scanNums(len int) (nums []int) {
	var num int
	for i := 0; i < len; i++ {
		fmt.Scan(&num)
		nums = append(nums, num)
	}
	return
}

Measured memory_bytes: 512
/**
 * @author torith
 * @date 2018-10-29
 */

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    int N; cin >> N;
    ll sum1 = 0, sum2 = 0;
    ll ans1 = 0, ans2 = 0;
    for (int i = 0; i < N; ++i) {
        ll t; cin >> t;
        if (i == 0) {
            if (t == 0) {
                sum1 = 1; ans1 = 1;
                sum2 = -1; ans2 = 1;
            }else {
                sum1 = t;
                sum2 = t > 0 ? -1 : 1;
                ans2 += abs(t) + 1;
            }
        }
        else {
            if (sum1 < 0 && sum1 + t <= 0){
                ans1 += 1 - sum1 - t;
                sum1 = 1;
            }else if (sum1 > 0 && sum1 + t >= 0){
                ans1 += abs(-1 - sum1 - t);
                sum1 = -1;
            }else{
                sum1 += t;
            }

            if (sum2 < 0 && sum2 + t <= 0){
                ans2 += 1 - sum2 - t;
                sum2 = 1;
            }else if (sum2 > 0 && sum2 + t >= 0){
                ans2 += abs(-1 - sum2 - t);
                sum2 = -1;
            }else{
                sum2 += t;
            }
        }
    }
    cout << min(ans1, ans2) << "\n";

    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MAXN 200005
typedef long long ll;
const ll mod=1e9+7;
ll fac[MAXN],ifac[MAXN];
ll fastpow(ll a,ll b){
	ll res=1;
	while(b){
		if(b&1)	(res*=a)%=mod;
		(a*=a)%=mod;
		b>>=1;
	}
	return res;
}
ll C(int m,int n){
	return fac[m]*ifac[n]%mod*ifac[m-n]%mod;
}
struct T{
	int x,y;
}a[MAXN];
bool cmp(T a,T b){
	return a.x<b.x||(a.x==b.x&&a.y<b.y);
}
ll ans[MAXN];
int main(){
	fac[0]=ifac[0]=1;
	for(int i=1;i<MAXN;i++)
		fac[i]=fac[i-1]*i%mod,ifac[i]=ifac[i-1]*fastpow(i,mod-2)%mod;
	
	int h,w,n;
	cin>>h>>w>>n;
	for(int i=1;i<=n;i++)
		scanf("%d%d",&a[i].x,&a[i].y);
	sort(a+1,a+n+1,cmp);
	++n;
	a[n].x=h;	a[n].y=w;
	for(int i=1;i<=n;i++)
		ans[i]=C(a[i].x+a[i].y-2,a[i].x-1);
	for(int i=1;i<=n;i++)
		for(int j=i+1;j<=n;j++)
			if(a[i].x<=a[j].x&&a[i].y<=a[j].y){
				ll x=a[j].x-a[i].x+1,y=a[j].y-a[i].y+1;
				ans[j]=(ans[j]-C(x+y-2,x-1)*ans[i]%mod+mod)%mod;
			}
	cout<<ans[n]<<endl;
	return 0;
}

Measured memory_bytes: 4480
w, h, x, y, r = map(int, input().split())

if (x >= -100 and x <= 100) and (y >= -100 and y <= 100):
    if (w > 0 and w <= 100) and (h > 0 and h <= 100) and (r > 0 and r <= 100):
        
        if x > w:
            print("No")
        elif y > h:
            print("No")
        elif x < 0:
            print("No")
        elif y < 0:
            print("No")
        elif (x + r) > w:
            print("No")
        elif (y + r) > h:
            print("No")
        elif x < r:
            print("No")
        elif y < r:
            print("No")
        else:
            print("Yes")

Measured memory_bytes: 7712
#include <iostream>

using namespace std;

int main() {
	
	unsigned long long n;
	unsigned long long a;
	unsigned long long b;
	unsigned long long sum;

	cin >> n >> a >> b;
	unsigned long long set = n / (a + b);
	
	sum = set * a;
	if((n - (a+b)*set) >= a){
	    sum += a;
	}else{
	    sum += (n - (a+b)*set); 
	}

	cout << sum << endl;
}


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

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
typedef long long ll;
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(a >= b){a = b; return true;}return false;}


int main(void){
    ll maxd = 1e18;
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n)cin >> a[i];
    sort(a.begin(), a.end());
    if(a[0] == 0){
        cout << 0 << endl;
        return 0;
    }
    ll sum = 1;
    for(ll i: a){
        if(maxd / i < sum){
            cout << -1 << endl;
            return 0;
        }else{
            sum *= i;
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 4040
import itertools
w, h, n = map(int, input().split())

field = [[0 for x in range(w)] for y in range(h)]

a = [list(map(int, input().split())) for x in range(n)]

def a1(line):
    for l in field:
        for x in range(line[0]):
            l[x] = 1

def a2(line):
    for l in field:
        for x in range(line[0], w):
            l[x] = 1

def a3(line):
    for y in range(line[1]):
        field[h - y - 1] = [1 for x in range(w)]

def a4(line):
    for y in range(line[1], h):
        field[h - y - 1] = [1 for x in range(w)]

for line in a:
    globals()["a" + str(line[2])](line[:2])

print(list(itertools.chain(*field)).count(0))


Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define int long long
using namespace std;

int N, M, V, P;
vector<int> A;

bool C(int X) {
  if (X <= P) {
    return true;
  }
  if (A[X] + M < A[P]) {
    return false;
  }

  int sum = 0;
  sum += M * P;
  sum += M * (N - X);
  for (int i = P; i < X; i++) {
    sum += A[X] + M - A[i];
  }

  if (sum < M * V) {
    return false;
  }

  return true;
}

signed main() {
  cin >> N >> M >> V >> P;
  A.resize(N + 1, 1e10);
  for (int i = 1; i <= N; i++) {
    cin >> A[i];
  }

  sort(A.begin(), A.end(), greater<int>());

  int ok = 1, ng = N + 1;
  while (abs(ok - ng) > 1) {
    int mid = (ok + ng) / 2;
    if (C(mid)) {
      ok = mid;
    } else {
      ng = mid;
    }
  }

  cout << ok << endl;
  return 0;
}

Measured memory_bytes: 1024
#-*-coding:utf-8-*-
 
import sys
 
def main():
    k = int(input())
    sevens=0
    for i in range(1,10**6+1):
        sevens=(sevens*10+7)%k
        if sevens==0:
            print(i)
            exit()
    print(-1)
 
if __name__ == "__main__":
    main()

Measured memory_bytes: 9164
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i ,n) for(int i = 0 ; i < (n) ; i ++ )
#define all(x) (x).begin(),(x).end()
using ll = long long;
using namespace std;

int main() {
  int n;
  cin>>n;
  vector<int> t(n),x(n),y(n);
  rep(i,n){
    cin>>t[i]>>x[i]>>y[i];
  }
  //////入力//ユークリッド距離
  bool ans=true;
  if(t[0]>=abs(x[0])+abs(y[0])&&(t[0])%2==(abs(x[0])+abs(y[0]))%2){
    }
    else{
      ans=false;
      
    }
  rep(i,n-1){
   
   if(t[i+1]-t[i] >= abs(x[i+1]-x[i])+abs(y[i+1]-y[i]) && (t[i+1]-t[i])%2==(abs(x[i+1]-x[i])+abs(y[i+1]-y[i]))%2  ) {
   }
    else{
     ans=false;
     break;
   }
    
    
    
    
  }
  
  
  
  if(ans) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 1408
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#define INF (1e9)
#define N 9
#define M 31
using namespace std;
typedef pair<int,int> P0;
typedef pair<double,P0> P;
void NP(int);
double dijkstra();
int np[N],used[N+1],n,m,p,a,b,ti[N];
double d[M],ans;
vector<P0> edge[M];
 
int main(){
  int x,y,z;
  while(1){
    cin>>n>>m>>p>>a>>b;
    if(!n&&!m&&!p&&!a&&!b) break;
    for(int i=0;i<n;i++) cin>>ti[i];
    a--,b--;
    while(p--){
      cin>>x>>y>>z;
      x--,y--;
      edge[x].push_back(P0(y,z));
      edge[y].push_back(P0(x,z));
    }
    ans=INF;
    NP(0);
    if(ans==INF) cout<<"Impossible"<<endl;
    else cout<<ans<<endl;
    for(int i=0;i<m;i++) edge[i].clear();
  }
  return 0;
}
 
 
void NP(int x){
  if(x==n){
    ans=min(ans,dijkstra());
    return ;
  }
  for(int i=0;i<n;i++){
    if(used[i]) continue;
    used[i]=true;
    np[x]=i;
    NP(x+1);
    used[i]=false;
  }
}


double dijkstra(){
  priority_queue<P,vector<P>,greater<P> > q;
  for(int j=0;j<n;j++)
  for(int i=0;i<m;i++) d[i]=INF;
  q.push(P(0,P0(0,a)));

  while(!q.empty()){
    P t=q.top(); q.pop();
    double dis=t.first;
    int idx=t.second.first,pos=t.second.second;
    if(pos==b)return dis;
    if(d[pos]<dis||idx==n)continue;
    for(int i=0;i<edge[pos].size();i++){
      double ndis=dis+(1.0*edge[pos][i].second/ti[np[idx]]);
      int npos=edge[pos][i].first;
      if(d[npos]>ndis) q.push(P(ndis,P0(idx+1,npos))),d[npos]=ndis;
    }
  }
  return INF;
}

Measured memory_bytes: 1292
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		//????????£???
		Scanner sc = new Scanner(System.in);
		//a??????
		int a = sc.nextInt();
		//b??????
		int b = sc.nextInt();
		
		//?¨???? ??´??°
		int d = a / b;
		//?¨???? ??????
		int r = a % b;
		//???????°???°?????°
		double f = (double) a / (double) b;
		//
		String  f2 = String.format("%.10f", f);
		//???????????¨?????????
		System.out.println(d +" "+ r + " " + f2);
	}
}

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

using namespace std;

typedef long long int ll;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
#define sz(a) (ll)(a.size())
#define endl "\n"

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    
    ll N, M, X, Y;
    cin >> N >> M >> X >> Y;

    ll m1 = X;
    ll m3 = X;
    for(ll i=0; i<N; i++)
    {
        ll x;
        cin >> x;

        m1 = max(m1, x);
        m3 = min(m3, x);
    }

    ll m2 = Y;
    ll m4 = Y;
    for(ll i=0; i<M; i++)
    {
        ll x;
        cin >> x;

        m2 = max(m2, x);
        m4 = min(m4, x);
    }

    if(m1<m4)
    {
        cout << "No War" << endl;
    }

    else
    {
        cout << "War" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
/*
AizuOnline A1002
Title Extraordinary Grid I
*/
#include <stdio.h>
// Select Below
//#include <stdlib.h>
//#include <string.h>
//#include <float.h>
//#include <math.h>
//#include <limits.h>
#define min(x,y) (((x)<(y))?(x):(y))
#define max(x,y) (((x)>(y))?(x):(y))
//Global data section
int T;
int N;
char book[40001];
//
int count_cost()
{
  int jou,ge,h1,h2,i,ret,jlast,glast,jfirst,gfirst;
  
  jou=ge=0;

  if(book[0]=='Y')
    jou++;
  for(i=0;i<N-1;i++)
    if(book[2*i+1]=='Y'||book[2*i+2]=='Y')
      {
	jou++;
      }
  
  if(book[2*N-1]=='Y')
      {
	jou++;
      }
  
  //-----*--------
  if(book[2*N]=='Y')
    ge++;
  for(i=0;i<N-1;i++)
    if(book[2*N+2*i+1]=='Y'||book[2*N+2*i+2]=='Y')
      {
	ge++;

      }
  if(book[4*N-1]=='Y')
      {
	ge++;
      }
  //--*--
  jlast=0;glast=0;
  for(i=2*N-1;i>=0;i--)
    if(book[i]=='Y')
      { 
	jlast=i;
	break;
      }
  for(i=2*N-1;i>=0;i--)
    if(book[2*N+i]=='Y')
      {
	glast=i;
	break;
      }  
//--*--
  jfirst=2*N;gfirst=2*N;
  for(i=0;i<2*N;i++)
    if(book[i]=='Y')
      { 
	jfirst=i;
	break;
      }
  for(i=0;i<2*N;i++)
    if(book[2*N+i]=='Y')
      {
	gfirst=i;
	break;
      }

  ret=N+jou+ge+(((jou==0)&&ge)?2:0)+((jou&&ge&&(glast>jlast))?1:0);
  ret+=((jou&&ge&&(gfirst<jfirst))?1:0);
  //printf("%d %d %d %d %d %d :%d\n",jou,ge,jlast,glast,jfirst,gfirst,ret);
  return(ret);
}

main()
{
  int i;
  int cost;

  scanf("%d",&T);
  for(i=0;i<T;i++)
    {
      scanf("%d",&N);
      scanf("%s",book); 
      printf("%d\n",count_cost());
    }
return(0);
}

Measured memory_bytes: 1064
#include <bits/stdc++.h>
#define repp(i,l,r)for(long long i=(l);i<(r);i++)
#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define per(i,n) for (long long i = (n); i >= 0; --i)
const int INF = 2147483647;//int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//ミョ(-ω- ?)
int main() {
    ll n;
    cin >> n;
    vector<ll> a(n,0);
    rep(i,n)cin >> a[i];
    sort(a.rbegin(),a.rend());
    ll res = 0;
    rep(i,n-1){res += a[(i+1)/2];}
    cout << res << endl;
    return 0;
}


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

int main() {
  int n,a,b;
  cin>>n;
  a=n/100;
  b=n%100;
  if(a==0||a>12){
    if(b==0||b>12)
      cout<<"NA"<<endl;
    else 
      cout<<"YYMM"<<endl;
  }
  else{
    if(b==0||b>12)
      cout<<"MMYY"<<endl;
    else
      cout<<"AMBIGUOUS"<<endl;
  }
  
  
  
                           
}

Measured memory_bytes: 256
import java.util.LinkedHashSet;
import java.util.Scanner;
import java.util.Set;

public class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		Set<String> set = new LinkedHashSet<String>();
		String[] W = new String[N];
		for(int i = 0; i < N; i++) {
			String t = scan.next();
			set.add(t);
			W[i] = t;
		}
		scan.close();
		if(N != set.size()) {
			System.out.println("No");
			System.exit(0);
		}
		char c = W[0].charAt(W[0].length() - 1);
		for(int i = 1; i < N; i++) {
			if(c != W[i].charAt(0)) {
				System.out.println("No");
				System.exit(0);
			}
			c = W[i].charAt(W[i].length() - 1);
		}
		System.out.println("Yes");
	}
}

Measured memory_bytes: 23892
#include <bits/stdc++.h>
#define rep(i,n) for(long long i = 0; i < (long long)(n); ++i)

using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int> a(n + 1);
	rep(i, n - 1) {
		int x;
		cin >> x;
		a[x]++;
	}
	rep(i, n) cout << a[i + 1] << endl;
	return 0;
}


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

int main() {
    vector<char> S(3);
    cin >> S.at(0) >> S.at(1) >> S.at(2);
    if(S.at(0) == S.at(1) && S.at(0) == S.at(2)){
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }

    return 0;
}


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

int main(){
    string s,t;
    cin >> s >> t;
    sort(s.begin(),s.end());
    sort(t.begin(),t.end(),greater<>());
    if(s<t)cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef pair<int, int> Pii;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
typedef vector<vector<int>> Graph;
const int inf = 1e9;
const int mod = 1e9 + 7;

int n, d;
VV c;
V sm;

bool update() {
    // int M, m;
    // M = *max_element(all(sm));
    // m = *min_element(all(sm));

    V cand = sm;
    sort(all(cand));
    reverse(all(cand));
    rep(i, n) {
        // if (!c[i].empty() && M - min(m, sm[i] - c[i].back()) <= d) {
        //     sm[i] -= c[i].back();
        //     c[i].pop_back();
        //     return true;
        // }
        if (!c[i].empty()) {
            int M, m;
            M = (sm[i] == cand[0] ? cand[1] : cand[0]);
            m = min(cand.back(), sm[i] - c[i].back());
            if (M - m <= d) {
                sm[i] -= c[i].back();
                c[i].pop_back();
                return true;
            }
        }
    }
    return false;
}

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

    while (cin >> n >> d, n) {
        c.clear();
        c.resize(n);
        rep(i, n) {
            int m;
            cin >> m;
            rep(j, m) {
                int x;
                cin >> x;
                c[i].emplace_back(x);
            }
        }
        sm.clear();
        sm.resize(n);
        rep(i, n) {
            sm[i] = accumulate(all(c[i]), 0);
        }

        while (update()) {
            // rep(i, n) {
            //     cout << i << ", " << sm[i] << " :";
            //     for (auto x : c[i]) cout << " " << x;
            //     cout << endl;
            // }
            // cout << endl;

        }

        cout << (*max_element(all(sm)) <= 0 ? "Yes" : "No") << endl;
    }
}

Measured memory_bytes: 3188
import sys
n = int(input())
h = list(map(int,input().split()))
result = []
c = 0
if n == 1:
    print(0)
    sys.exit()
for i in range(n-1):
    if h[i] >= h[i+1]:
        c += 1
    else:
        result.append(c)
        c = 0
    if i == n-2:
        result.append(c)

print(max(result))

Measured memory_bytes: 15020
use std::cmp::min;
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
    s: chars
    }
    let n = s.len();
    let s1 = (0..n).map(|x| if x % 2 == 0 {'1'} else {'0'}).collect::<Vec<_>>();
    let s2 = (0..n).map(|x| if x % 2 == 0 {'0'} else {'1'}).collect::<Vec<_>>();
    let (mut c1, mut c2) = (0, 0);
    for i in 0..n {
        if s1[i] != s[i] {c1 += 1}
        if s2[i] != s[i] {c2 += 1}
    }
    let ans = min(c1, c2);
    println!("{}", ans);
}


Measured memory_bytes: 4352
//It doesn't matter how slow you go, Unless you don't stop.
#include<iostream>
#include<algorithm>
#include<bitset>
 
#include<cmath>
#include<cstring>
#include<climits>
 
#include<deque>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
 
#include<fstream>
#include<chrono>
using namespace std;
 
typedef long long LL;
typedef pair<LL,LL> p64;
typedef vector<LL> v64;
typedef map<LL,LL> mp64;
 
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define rep(i,s,e) for(long long i=s;i<=e;i++)
#define brep(i,s,e) for(long long i=s;i>=e;i--)
#define all(x) x.begin(),x.end()
#define mem(x,y) memset(x,y,sizeof(x))
#define DANGER std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
const int MOD = 1e9+7;
void solve()
{
     int n,m;cin>>n>>m;
     char a[n][m];
     for(int i=0;i<n;i++)
     {
         for(int j=0;j<m;j++)
         {
             cin>>a[i][j];
         }
     }
     int dp[n][m];
     //basecase
     bool flag = true;
     for(int i=0;i<n;i++)
     {
         //cout<<i<<endl;
         if(a[i][0]=='#')
         {
             //cout<<"ran";
             dp[i][0] = 0;
             flag = false;
         }
         else
         {
             if(flag==true)
             {
                 dp[i][0] = 1;
             }
             else
             {
                 dp[i][0] = 0;
             }
         }
     }
     flag = true;
     for(int i=0;i<m;i++)
     {
         //cout<<i<<endl;
         if(a[0][i]=='#')
         {
             //cout<<"ran";
             dp[0][i] = 0;
             flag = false;
         }
         else
         {
             if(flag==true)
             {
                 dp[0][i] = 1;
             }
             else
             {
                 dp[0][i] = 0;
             }
         }
     }
     //solving
     for(int i=1;i<n;i++)
     {
         for(int j=1;j<m;j++)
         {
             if(a[i][j]=='#')
             {
                 dp[i][j] = 0;
             }
             else
             {
                 dp[i][j] = ((dp[i-1][j])%MOD + (dp[i][j-1])%MOD)%MOD;
                 dp[i][j] %= MOD;
             }
             
         }
     }
    cout<<dp[n-1][m-1]<<endl;

}
 
int main()
{
    DANGER;
    ofstream out("output.txt");
 
    auto start = chrono::high_resolution_clock::now();
    
    LL t = 1;
    // cin>>t;
    rep(test,1,t)
    {
        solve();
    }
    
    auto stop = chrono::high_resolution_clock::now();
    // auto duration = chrono::duration_cast<chrono::milliseconds>(stop - start); 
    // cout << "Time taken by function: " << duration.count() << " milliseconds" << endl;
}

Measured memory_bytes: 5120
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars};
#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
	input! {
		n: usize,
		txy: [(isize, isize, isize); n],
	}

	let mut prev = (0isize, 0isize, 0isize);
	for i in 0..n {
		let dt = txy[i].0 - prev.0;
		let dx = (txy[i].1 - prev.1).abs();
		let dy = (txy[i].2 - prev.2).abs();

		if dt < dx+dy {
			println!("No");
			return;
		}
		if (dt - (dx+dy)) % 2 == 1 {
			println!("No");
			return;
		}
		prev = txy[i];
	}
	println!("Yes");
}



Measured memory_bytes: 5588
class Strider
  def solve(x)
    i = 1
    while true
      if 360 * i % x == 0
        return 360 * i / x
      else
        i += 1
      end
    end
  end
  
  def run
    x = gets.chomp.to_i
    puts solve(x)
  end
end

if $0 == __FILE__
  Strider.new.run
end


Measured memory_bytes: 14396
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
int a,saikou,saitei;


 for(a=0;a<=6;a++){
	 saikou =sc.nextInt();
	 saitei=sc.nextInt();

System.out.println(saikou-saitei);
	
 }
	
		
	}

}

Measured memory_bytes: 17312
n=int(input())
s=[]
f_l_checker=True
s.append(input())
for i in range(1,n):
    s.append(input())
    if f_l_checker:
        if s[i][0]==s[i-1][-1]:
            for j in range(i):
                if s[j]==s[i]:
                    f_l_checker=False
        else:
            f_l_checker=False
if f_l_checker:
    print("Yes")
else :
    print("No")


Measured memory_bytes: 3060
import java.util.*;
public class Main {
	Scanner sc;
	int w;
	int h;
	int[][] map;
	P s;
	int count;
	boolean[][] visited;
	void run() {
		sc = new Scanner(System.in);
		while (true) {
			count =0;
			w = sc.nextInt();
			h = sc.nextInt();
			if(w==0 && h ==0) break;
			visited = new boolean[h+2][w+2];
			map = new int[h+2][w+2];
			for (int i=1;i<h+1;i++) {
				String str = sc.next();
				for (int j=1;j<w+1;j++) {
					visited[i][j] = false;
					if (str.charAt(j-1)=='.') visited[i][j] = true;
					else if(str.charAt(j-1)=='#') visited[i][j] = false;
					else if(str.charAt(j-1) == '@'){
						visited[i][j] = true;
						s = new P(j,i);
					}
					
					
				}
			}
			count = 0;
			solve(s);
			System.out.println(count);
			
		}
	}
	int dx[] = {-1,0,1,0};
	int dy[] = {0,-1,0,1};
	void solve(P p) {
		count++;
		visited[p.y][p.x] = false;
		for (int i=0;i<4;i++) 
			if (visited[p.y+dy[i]][p.x+dx[i]]) solve(new P(p.x+dx[i],p.y+dy[i])); 
	}
		
	
	
	class P {
		int x;
		int y;
		P(int x,int y) {
			this.x = x;
			this.y = y;
		}
	}
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 12000
S = input()

if S == 'SUN':
    print(7)
elif S == 'MON':
    print(6)
elif S == 'TUE':
    print(5)
elif S == 'WED':
    print(4)
elif S == 'THU':
    print(3)
elif S == 'FRI':
    print(2)
elif S == 'SAT':
    print(1)

Measured memory_bytes: 9048
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, j, n) for (ll i = j; i < n; i++)
#define all(x) (x).begin(),(x).end()
#define INF (1000000000000)
#define MOD (1000000007)
#define MAX (500000)
#define pii pair<int, int>

/////////////////////////////////////////////////////////

class XY{
public:
  ll x, y;
  XY() {x = y = 0;}
  XY(ll u, ll v) {x = u; y = v;}
};

class e{
public:
  ll a, b;
  e() {a = b = -1;}
  e(ll u, ll v) {a = u; b = v;}
};

template<typename T1, typename T2>
void chmin(T1 &a, T2 b) {if(a > b) a = b;}
template<typename T1, typename T2>
void chmax(T1 &a, T2 b) {if(a < b) a = b;}

template<typename T1, typename T2>
ll mypow(T1 a, T2 n){
  if(n == 0) return 1;
  if(n == 1) return a;
  if(n % 2) return a * mypow(a, n - 1);
  ll tmp = mypow(a, n / 2);
  return tmp * tmp;
}

template<typename T>
int BS(vector<T> &V, int left, int right, T key){
  int mid = (left + right) / 2;
  if(V[mid] <= key) left = mid;
  else right = mid;
  if(right - mid == 1) return left;
  else return BS(V, left, right, key);
}

ll comb(ll n, ll r){
	ll res = 1;
  rep(i, 0, r){
    res *= n - i;
    res /= i + 1;
  }
  return res;
}

template<typename T>
T euclid(T a, T b){
  if(b == 0) return a;
  else return euclid(b, a % b);
}

vector<ll> fact(MAX, 0), fact_inv(MAX, 0);

ll pow_mod(ll a, ll b){
	ll res = 1;
	while(b > 0){
		if(b & 1) res = res * a % MOD;
		a = a * a % MOD;
		b >>= 1;
	}
	return res;
}

void prepare_comb_mod(ll n){
	fact[0] = 1LL;
	for(ll i = 0; i < n; i++) fact[i+1] = fact[i] * (i + 1) % MOD;
	fact_inv[n] = pow_mod(fact[n], MOD - 2);
	for(ll i = n - 1; i >= 0; i--) fact_inv[i] = fact_inv[i + 1] * (i + 1) % MOD;
}

ll comb_mod(ll n, ll r){
	return (fact[n] * fact_inv[r]) % MOD * fact_inv[n - r] % MOD;
}

/////////////////////////////////////////////////////////

void DFS(int p, int cur, vector<vector<pair<int, ll>>> &V, vector<ll> &D, ll sum){
  D[cur] = sum;
  rep(i, 0, V[cur].size()){
    if(V[cur][i].first == p) continue;
    DFS(cur, V[cur][i].first, V, D, sum + V[cur][i].second);
  }
}

void Main() {
  int N; cin >> N;
  vector<int> A(N);
  rep(i, 0, N) cin >> A[i];
  sort(all(A));
  bool end = false;
  int l, m, r;
  l = 0; m = 0; r = N - 1;
  int res = N;
  while(true){
    while(true){
      if(A[l] == A[l + 1]){
        m = l + 1;
        break;
      }
      l++;
      if(l == N - 1){
        end = true;
        break;
      }
    }
    if(end) break;
    while(true){
      if(A[r - 1] == A[r]){
        break;
      }
      r--;
      if(r == l){
        end = true;
        break;
      }
    }
    if(end) break;
    res -= 2;
    if(m == r){
      break;
    }
    l++;
    r--;
    if(r <= l){
      break;
    }
  }
  cout << res << endl;
}

/////////////////////////////////////////////////////////

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

  Main();
}


Measured memory_bytes: 8448
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        List<Long> list = new ArrayList<>();
        for(long i=0; i<n; i++) {
            list.add(sc.nextLong());
        }
        if(n <= k) {
            System.out.println(0);
            return;
        }
        Collections.sort(list);
        long total = 0;
        for(int i = n; i >= 0; i--, k--) {
            if(k >= 0) continue;
            total += list.get(i);
        }
        System.out.println(total);
    }
}

Measured memory_bytes: 66376
#include <bits/stdc++.h>
using namespace std;
string s;
int a,b,c;
int main()
{
    cin>>s;
    for (int i=0;i<s.size();i++)
    {
        if (s[i]=='a')
            a++;
        else if (s[i]=='b')
            b++;
        else if (s[i]=='c')
            c++;
    }
    if (a==b&&b==c)
        cout<<"Yes";
    else
        cout<<"No";
    return 0;
}


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

#define FOR(i, a, b) for (int i = (a); i < static_cast<int>(b); i++)
#define FORR(i, a, b) for (int i = (a); i >= static_cast<int>(b); i--)
#define rep(i, n) FOR (i, 0, n)
#define repall(i, arr) for (auto& i : (arr))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define dump(x) cerr << #x << " = " << (x) << '\n'
template <typename T>
void print(const vector<vector<T>> matrix);
template <typename T>
void print(const vector<T> vec);
template <typename Arg>
void print(const Arg arg);
template <typename Head, typename... Args>
void print(const Head head, const Args... args);
template <typename T>
using pq = priority_queue<T>;
template <typename T>
using pqr = priority_queue<T, vector<T>, greater<T>>;
const int INF = INT_MAX / 2;
using ll = long long;

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

    while (true) {
        int a = n / 100;
        int b = n / 10 - a * 10;
        int c = n % 10;
        if (a == b and b == c) {
            print(n);
            break;
        }
        n++;
    }

    return 0;
}

//---------------------------------------------
template <typename T>
void print(const vector<vector<T>> matrix) {
    repall (vec, matrix)
        print(vec);
}
template <typename T>
void print(const vector<T> vec) {
    unsigned int len = vec.size();
    rep (i, len - 1)
        cout << vec[i] << ' ';
    cout << vec[len - 1] << '\n';
}
template <typename Arg>
void print(const Arg arg) {
    cout << arg << '\n';
}
template <typename Head, typename... Args>
void print(const Head head, const Args... args) {
    cout << head << " ";
    print(args...);
}


Measured memory_bytes: 384
n,m,x,y = map(int,input().split())
X = list(map(int,input().split()))
Y = list(map(int,input().split()))
X = sorted(X)
Y = sorted(Y)
for i in range(x+1,y+1):
    if X[-1]<i and Y[0]>=i:
        print('No War')
        exit()
print('War')


Measured memory_bytes: 3060