akhauriyash/Code-Regression huggingface dataset:
// #include <bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;

#define all(x) begin(x), end(x)
#define rep(i,n) for(int i=0; i<n; i++)

int main() {
    ll x, k, d;
    cin >> x >> k >> d;

    ll cnt = abs(x) / d;
    ll ans;

    if (k < cnt) ans = abs(x) - k*d;
    else {
        if ((k-cnt) %2) ans = d - ((abs(x)) %d);
        else ans = abs(x) %d;
    }
    
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3628
import java.util.Scanner;

public class Main {
	Scanner sc = new Scanner(System.in);
	int a;
	int b;
	int[] sa = new int[7];
	int s;

	public void keisan(){
		for(s=0;s<=6;s++){
			a = sc.nextInt();
			b = sc.nextInt();
			sa[s] = a-b;
		}

	}

	public void hyouji(){
		for(s=0;s<=6;s++){
			System.out.println(sa[s]);
		}
	}
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Main go = new Main();
		go.keisan();
		go.hyouji();
	}
}	

Measured memory_bytes: 17312
#include<iostream>
#include<vector>

using namespace std;

int main() {
  int n;
  while(cin>>n && n!=0) {
    vector<vector<int> > manInfo;
    for(int i=0; i<n; i++) {
      int m;
      cin>>m;
      //cout<<m<<"! ";
      vector<int> tmpVec;
      for(int j=0; j<m; j++) {
	int tmp;
	cin>>tmp;
	tmpVec.push_back(--tmp);
	//cout<<tmpVec.size()<<" ";
      }
      //cout<<endl;
      //cout<<"size-"<<tmpVec.size()<<endl;
      manInfo.push_back(tmpVec);
    }

    // print
    /*
    for(int i=0; i<manInfo.size(); i++) {
      for(int j=0; j<manInfo[i].size(); j++) {
	cout<<manInfo[i][j]<<" ";
      }
      cout<<endl;
    }
    */

    int k;
    cin>>k;
    vector<int> outList;
    //cout<<"outlist ";    
    for(int l=0; l<k; l++) {
      int tmp;
      cin>>tmp;
      outList.push_back(--tmp);
    }
    //cout<<endl;
    int ans = -2;
    for(int j=0; j<manInfo.size(); j++) {
      bool outFlag = true;
      for(int k=0; k<outList.size() && outFlag==true; k++) {
	bool flag = true;
	if(manInfo[j].empty()) {
	  outFlag = false;
	}
	for(int l=0; l<manInfo[j].size() && flag==true; l++) {
	  //cout<<outList[k]<<" in "<<manInfo[j][l]<<endl;
	  if(outList[k] == manInfo[j][l]) {
	    //cout<<"out"<<endl;
	    flag = false;
	  }
	  if(l==manInfo[j].size()-1 && flag==true) {
	    outFlag = false;
	    //cout<<j<<"doesn')t have "<<k<<endl;
	  }
	}
      }
      if(outFlag == true) {
	if(ans != -2) {
	  ans = -2;
	  break;
	}
	else {
	  ans = j;
	}
      }
    }
    
    cout<<++ans<<endl;
  }
}

Measured memory_bytes: 1272
// Problem : N - Slimes
// Contest : AtCoder - Educational DP Contest
// URL : https://atcoder.jp/contests/dp/tasks/dp_n
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define int long long
#define db double
#define mod 1000000007
#define pb push_back
#define pp pair<int,int>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repe(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=b;i>=a;i--)
#define maxn 405
#define ss second
#define ff first
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
int inv(int a, int b){
 return 1<a ? b - inv(b%a,a)*b/a : 1;
}
int n;
int dp[maxn][maxn],a[maxn];
void fun(int l,int r)
{
	if(dp[l][r]!=-1)
		return;
	if(l==r)
	{
		dp[l][r]=0;
		return;
	}
	int curr=-1,tmp=0;
	for(int i=l;i<=r;i++)
		tmp+=a[i];
	for(int i=l;i<r;i++)
	{
		int temp=tmp;
		fun(l,i);
		fun(i+1,r);
		temp += dp[l][i];
		temp += dp[i+1][r];
		if(curr == -1)
			curr=temp;
		curr=min(curr,temp);
	}
	dp[l][r]=curr;
}
void solve()
{
	cin >> n;
	memset(dp,-1,sizeof(dp));
	for(int i=0;i<n;i++)
		cin >> a[i];
	fun(0,n-1);
	cout << dp[0][n-1];
}
signed main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
    //cin >> t;
    while(t--)
    solve();
    return 0;
}


Measured memory_bytes: 4888
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 2147483647 / 2;
const long long int llINF = 9223372036854775807 / 2;

using namespace std;
using ll = long long int;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;

typedef pair<ll, ll> pll;
bool paircomp(const pll &a, const pll &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}

#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec)                                                            \
  std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec)                                                            \
  std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define REV(T) greater<T>()
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define VVL(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VVVL(a, b, c, d)                                                       \
  vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))
#define SP(a) setprecision(a)
#define SQRT(a) sqrt((long double)(a))
#define DPOW(a, b) pow((long double)(a), (long double)(b))
#define UNIQUE(vec)                                                            \
  do {                                                                         \
    sort(ALL((vec)));                                                          \
    (vec).erase(std::unique(ALL((vec))), (vec).end());                         \
  } while (0)

ll POW(ll n, ll m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = POW(n, m / 2);
    return (tmp * tmp);
  } else {
    return (n * POW(n, m - 1));
  }
}

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll N;
  cin >> N;
  ll ans = 0;
  if (N >= 9)
    ans += 9;
  else if (N >= 1)
    ans += N - 0;

  if (N >= 999)
    ans += (999 - 100) + 1;
  else if (N >= 100)
    ans += N - 100 + 1;

  if (N >= 99999)
    ans += (99999 - 10000) + 1;
  else if (N >= 10000)
    ans += N - 10000 + 1;

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FOR(i,a,b)for(int i=(a),_b=(b);i<=_b;i++)
#define FORN(i,b,a)for(int i=(b);_a=(a);i>=_a;i--)
#define REP(i,n)for(int i=0,_n=n;i<n;i++)
#define ll long long
#define pii pair<int,int>
#define re return
#define vi vector<int>
#define pb push_back
#define si set<int>
#define in insert
#define fl float
#define db double
#define ld long double
#define X first
#define Y second
#define st string
#define ull unsigned long long
#define mod 1000000007
#define INF 1000000007
using namespace std;
inline void read(int &x)
{
	short negative=1;
    x=0;
    char c=getchar();
    while(c<'0' || c>'9')
    {
		if(c=='-')
			negative=-1;
		c=getchar();
	}
    while(c>='0' && c<='9')
        x=(x<<3)+(x<<1)+(c^48),c=getchar();
    x*=negative;
}
int dp[100100];
vector<int>v[100100];
int dfs(int i){
	if(dp[i]!=-1)
	return dp[i];
	REP(j,v[i].size())
		dp[i]=max(dp[i],dfs(v[i][j])+1);
	return dp[i];
}
int main()
{
	int n,m;
	cin>>n>>m;
	REP(i,n)dp[i]=-1; 
	REP(i,m)
	{
		int a,b;
		cin>>a>>b;
		a--;
		b--;
		v[a].pb(b);
	}
	int ans=0;
	REP(i,n)
		ans=max(ans,dfs(i));
	cout<<ans+1<<endl;
	return 0;
}



Measured memory_bytes: 7424
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define repl(i,s,n) for(int i=s; i<=n; ++i)
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define ktya(x) sort(all(x))
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define all(aa) (aa).begin(), (aa).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 1e18
#define INFLL 1000000000000000007LL
#define SIZE 200105
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mind(a,b) (a>b?b:a)
#define maxd(a,b) (a>b?a:b)
#define PI (acos(-1))
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
typedef pair<int,ll> pill; typedef pair<ll,int> plli; 
typedef pair<double, int> pdi;
typedef pair<pair<ll, ll>,int> PP;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
typedef complex<double> P;
typedef pair<pill,int> PA;
//ll MOD;
ll MOD = 1000000007;
//ll MOD=998244353;
typedef ll Weight;
struct Edge {
	int src, dst;
	ll weight;
};

int use[55]={0};
int N;
ll A[55],B[55];
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin>>N;
	bool pos=true;
	rep(i,N)cin>>A[i];
	rep(i,N)cin>>B[i];
	rep(i,N){
		if(A[i] <= 2*B[i] && A[i]!=B[i])pos=false;
	}
	for(int i=50;i>=1;i--){
		// iをつかうか使わないかチェック
		vi checks;
		for(int j=i+1;j<=50;j++){
			if(use[j]==1)checks.pb(j);
		}
		for(int j=1;j<=i-1;j++)checks.pb(j);

		//有向グラフ作成
		int dist[55][55];
		rep(t,55)rep(s,55)dist[s][t]=10000000;
		rep(t,55)dist[t][t]=0;
		rep(k,checks.size()){
			int mo=checks[k];
			for(int pt=mo;pt<=50;pt++){
				dist[pt][pt%mo]=1;
			}
		}
		rep(c,55)rep(a,55)rep(b,55)dist[a][b]=min(dist[a][b],dist[a][c]+dist[c][b]);
		/*if(i<=8){
			cout<<i<<endl;
			//rep(t,checks.size())cout<<checks[t]<<" ";
			//cout<<endl;
			//rep(t,N)cout<<dist[A[t]][B[t]]<<endl;
			rep(a,10){
			rep(b,10){
				ll x=dist[a][b];
				if(x==10000000)x=-1;
				cout<<x<<" ";
			}
			cout<<endl;
			}
		}*/
		bool judge=true;
		rep(j,N){
			if(dist[A[j]][B[j]]==10000000)judge=false;
		}
		if(!judge)use[i]=1;
		
	}
	ll base=1;
	ll ans=0;
	rep(i,55){
		if(use[i]==1)ans+=base;
		base*=2;
	}
	if(!pos)cout<<-1<<endl;
	else{cout<<ans<<endl;}
}

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

#define rep(i, n) for(int i = 0; i < n; i++)

using namespace std;
using ll = long long;
int mod = 1000000007;

int solve(int *A);

int main(void){
    int N; cin >> N;
    int cnt[13] = {};
    int D[N]; rep(i, N) cin >> D[i];
    cnt[0]++;
    rep(i, N) cnt[D[i]]++;
    bool kakutei[13] = {};
    vector<int> futei_num;
    bool ok = true;
    // 1から11が1だと不定
    //不定なものについてbit全探索
    kakutei[0] = true;
    if(cnt[12] >= 1) kakutei[12] = true;
    if(cnt[0] >= 2 || cnt[12] >= 2) ok = false;
    for(int i = 1; i <= 11; i++){
        if(cnt[i] >= 3) ok = false;
        else if(cnt[i] == 2) kakutei[i] = true;
        else if(cnt[i] == 1) futei_num.push_back(i);
    }

    int ans = 0;

    int tm[24] = {0};
    if(ok){
        tm[0] = 1;
        if(kakutei[12]) tm[12] = 1;
        for(int i = 1; i <= 11; i++){
            if(kakutei[i]){
                tm[i] = 1;
                tm[24-i] = 1;
            }
        }
        //bit全探索, 不定な時間について
        int lim = pow(2.0, futei_num.size());
        for(int i = 0; i < lim; i++){
            int val = i;
            vector<int> work;
            for(int j = 0; j < futei_num.size(); j++){
                work.push_back(val % 2);
                val /= 2;
            }
            for(int j = 0; j < futei_num.size(); j++){
                if(work[j] == 1) tm[24 - futei_num[j]] = 1;
                else tm[futei_num[j]] = 1;
            }
            int temp = solve(tm);
            if(temp > ans) ans = temp;
            //後始末
            for(int j = 0; j < futei_num.size(); j++){
                if(work[j] == 1) tm[24 - futei_num[j]] = 0;
                else tm[futei_num[j]] = 0;
            }
        }
        cout << ans << endl;
    }
    else cout << 0 << endl;
    return 0;
}

int solve(int *A){
    int s = 24;
    //0が連続する個数の最小を知りたい
    int row = 0;

    //rep(i, 24) cout << A[i] << " "; cout << endl;

    bool allone = true;
    rep(i, 24) if(A[i] != 1) allone = false;
    if(allone) return 1;

    int i = 0;
    while(A[i] == 1) i++;
    for(; i < 24; i++){
        if(A[i] == 0) row++;
        else{
            if(row < s) s = row;
            while(i < 24 && A[i] == 1) i++;
            row = 1;
        }
    }
    if(row > 0 && row < s) s = row;

    //1の連続も検出したいよねぇ
    if(A[23] == 1) s = 0;
    for(int i = 1; i <= 22; i++) if(A[i] == 1 && A[i-1] == 1) s = 0;
    return s+1;
}

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

int n;

int main(){
    cin >> n;
    if(n < 1200){
        cout << "ABC" << endl;
    }
    else if (n < 2800)
    {
        cout << "ARC" << endl;
    }
    else
    {
        cout << "AGC" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

long long min(long long a,long long b){return a < b ? a : b;}
long long nCr(long long n,long long r)
{
    long long i,ret = 1;
    for (i = 0; i < min(n - r,r); i++)
    {
        ret *= n - i;
        ret /= i + 1;
    }
    return ret;
}

int main()
{
    long long n,p,a[50],i,j,evenodd[2] = {0};

    scanf("%lld %lld",&n,&p);
    for (i = 0; i < n; i++)
    {
        scanf("%lld",&a[i]);
        evenodd[a[i] % 2]++;
    }
    long long c = 1,ans = 0;
    for (i = 0; i < evenodd[0]; i++)
    {
        c *= 2;
    }

    if(p == 1)
    {
        for (i = 1; i <= evenodd[1]; i += 2)
        {
            //if(n - i > evenodd[0])continue;
            //else ans += nCr(evenodd[1],i);
            ans += nCr(evenodd[1],i);
        }
    }
    else
    {
        for (i = 0; i <= evenodd[1]; i += 2)
        {
            ans += nCr(evenodd[1],i);
        }
    }
    
    printf("%lld",ans * c);
}

Measured memory_bytes: 128
from typing import Optional


class Node:
    def __init__(self, arg_parent: Optional["Node"], arg_key: int,
                 arg_left: Optional["Node"], arg_right: Optional["Node"]):
        self.parent = arg_parent
        self.key = arg_key
        self.left = arg_left
        self.right = arg_right


def print_preorder(node: Node) -> None:
    print(f" {node.key}", end="")
    if node.left is not None:
        print_preorder(node.left)
    if node.right is not None:
        print_preorder(node.right)


def print_inorder(node: Node) -> None:
    if node.left is not None:
        print_inorder(node.left)
    print(f" {node.key}", end="")
    if node.right is not None:
        print_inorder(node.right)


def insert(root: Optional[Node], node: Node) -> Node:
    y: Optional[Node] = None
    x = root

    while x is not None:
        y = x
        if node.key < x.key:
            x = x.left
        else:
            x = x.right
    node.parent = y

    if y is None:
        root = node
    elif node.key < y.key:
        y.left = node
    else:
        y.right = node

    assert root is not None
    return root


def find(root: Node, key: int) -> None:
    x: Optional[Node] = root

    while x is not None:
        if key == x.key:
            print("yes")
            return
        elif key < x.key:
            x = x.left
        else:
            x = x.right

    print("no")


if __name__ == "__main__":
    root: Optional[Node] = None
    node_num = int(input())
    for _ in range(node_num):
        command, *value = input().split()
        if "insert" == command:
            root = insert(root, Node(None, int(value[0]), None, None))
        elif "find" == command:
            assert root is not None
            find(root, int(value[0]))
        elif "print" == command:
            assert root is not None
            print_inorder(root)
            print()
            print_preorder(root)
            print()
        else:
            pass



Measured memory_bytes: 86924
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ; //何もしない文
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size()) //unsignedのサイズをint型に変換

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL; 

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const int MAX_N = 1e5+10;
int dp[MAX_N];

//ここから書き始める
int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);	
    int N;
    cin >> N;
    VI h(N);
    REP(i,N)
    {
        cin >> h[i];
    }

    memset(dp, 0, sizeof(dp));

    for(int i=N-1; i>0; i--)
    {
        if(i==N-1)
        {
            dp[i] = dp[i+1]+abs(h[i-1] - h[i]);
        }
        else
        {
            dp[i] = min(dp[i+1]+abs(h[i-1] - h[i]), dp[i+2]+abs(h[i-1] - h[i+1]));
        }
    }

    cout << dp[1] << endl;



}


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

int f(int n){
 if(n % 2 == 0) return n / 2;
  else return 3 * n + 1;
}

int main(void){
  int X, Y;
  cin >> X >> Y;
  cout << X + Y / 2;
  return 0;
}

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

int main()
{
    int N,i,j,k,d;
    int a[6];
    int m[32];
    int M[32];
    for (i=0; i<32; i++)
    {
        m[i]=1000000000;
        M[i]=-1000000000;
    }
    scanf("%d",&N);
    d = 2;
    for (i=0; i<N; i++)
    {
        for (j=0; j<d; j++)
            cin>>a[j];
        for (j=0; j<1<<(d-1); j++)
        {
            int x=a[0];
            for (k=0; k<d-1; k++)
                if (j&(1<<k))
                    x+=a[k+1];
                else
                    x-=a[k+1];
            if (m[j]>x)
                m[j]=x;
            if (M[j]<x)
                M[j]=x;
        }
    }
    int ans=0;
    for (i=0; i<1<<(d-1); i++)
        if (ans<M[i]-m[i])
            ans=M[i]-m[i];
    printf("%d\n",ans);
    return 0;
}

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

int main() {
    int n;cin>>n;
    string s;cin>>s;
    int k=s.size();
    long long ans=0;
    vector<int> r(k+2),g(k+2),b(k+2);
    s='!'+s;
    for(int i=1;i<=k;i++){
        if(s[i]=='R') r[i]++;
        if(s[i]=='G') g[i]++;
        if(s[i]=='B') b[i]++;
    }
    for(int i=k;i>0;i--){
        r[i-1]+=r[i];
        g[i-1]+=g[i];
        b[i-1]+=b[i];
    }
    for(int a=1;a<=k;a++){
        for(int c=a+1;c<=k;c++){
            if(s[a]!=s[c]){
                int o,p,q;o=p=q=1;
                if(s[a]=='R') o=0;
                if(s[a]=='G') p=0;
                if(s[a]=='B') q=0;
                if(s[c]=='R') o=0;
                if(s[c]=='G') p=0;
                if(s[c]=='B') q=0;
                if(o){
                    ans+=r[c];
                    if(c+c-a>k) continue;
                    if(s[c+c-a]=='R'){
                        ans--;
                    }
                }
                else if(p){
                    ans+=g[c];
                    if(c+c-a>k) continue;
                    if(s[c+c-a]=='G'){
                        ans--;
                    }
                }
                else if(q){
                    ans+=b[c];
                    if(c+c-a>k) continue;
                    if(s[c+c-a]=='B'){
                        ans--;
                    }
                }                            
            }
            //cout<<ans<<endl;
        }
    }

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


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

dic = {1:set(), N:set()}

for _ in range(M):
  a,b = map(int, input().split())
  if a == 1:
    dic[1].add(b)
  elif b == N:
    dic[N].add(a)

for i in dic[1]:
  if i in dic[N]:
    print("POSSIBLE")
    exit()
    
print("IMPOSSIBLE")


Measured memory_bytes: 102548
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a[5];
    int ans;
    for(int i=0;i<5;i++) {
        cin>>a[i];
        if(a[i]==0) ans = i+1;
    }
    cout<<ans<<endl;
    return 0;
}

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

int main() {
	priority_queue<int> pq;

	while (1) {
		string com;
		cin >> com;

		if (com[0] == 'i') {
			int key;
			cin >> key;
			pq.push(key);
		}
		else if (com[1] == 'x') {
			cout << pq.top() << endl;
			pq.pop();
		}
		else
			break;
	}

	return 0;
}

Measured memory_bytes: 6860
#include<iostream>
#include<algorithm>
using namespace std;
static const int MAX = 1000;
static const int VMAX = 10000;

int n,A[MAX],s;
int B[MAX],T[VMAX+1];

int solve(){
  int ans = 0;

  bool V[MAX];
  for(int i=0;i<n;i++){
    B[i] = A[i];
    V[i] = false;
  }
  sort(B,B+n);
  for(int i=0;i<n;i++) T[B[i]] = i;

  for(int i=0;i<n;i++){
    if(V[i]) continue;
    int cur = i;
    int S = 0;
    int m = VMAX;
    int an = 0;

    // 1ループを求めるプログラム
    while(1){
      // 辿ったという証拠をのこす
      V[cur] = true;
      // ループの中の端末数を増やす
      an++;
      // 数を保存
      int v = A[cur];
      // ループの中の最小値を保存
      m = min(m,v);
      // ループ全体のコストを記録
      S += v;
      // 並べ変えたときにいるべき場所にいる場所を保存
      cur = T[v];
      // すでにたどった場所なら(ループが完了したなら)while脱出
      if(V[cur]) break;
    }
    ans += min(S+(an-2)*m , m+S+(an+1)*s);
  }
  return ans;
}

int main(){
  cin >> n;
  s = VMAX;
  for(int i=0;i<n;i++){
    cin >> A[i];
    s = min(s,A[i]);
  }

  int ans = solve();
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 3196
#include <bits/stdc++.h>
#define N 3001
using namespace std;
int w,h;
int dx[]={0,1,0,-1};//^>v<
int dy[]={-1,0,1,0};
vector<int> X,Y,d;
map<int,int> x,y;

int compless(vector<int> A,map<int,int> &M){
  sort(A.begin(),A.end());
  int c=0;
  for(int i=0;i<A.size();i++)if(!M.count(A[i]))M[A[i]]=c++;
  return c;
}

int calc(int y,int x,vector<vector<int> >&mp){
  vector<vector<bool> > used(h,vector<bool>(w,0));
  int res=0;
  while(1){
    res++;
    int i=mp[y][x];
    used[y][x]=1;
    while(1){
      y+=dy[i],x+=dx[i];
      if(y<0||x<0||x>=w||y>=h)return res;
      if(mp[y][x]!=-1&&!used[y][x])break;
    }
  }
  assert(0);
}

int main(){
  int n;
  cin>>n;
  X.resize(n),Y.resize(n),d.resize(n);
  for(int i=0;i<n;i++){
    char ch;
    cin>>X[i]>>Y[i]>>ch;
    if(ch=='^')d[i]=0;
    if(ch=='>')d[i]=1;
    if(ch=='v')d[i]=2;
    if(ch=='<')d[i]=3;
  }
  h=compless(Y,y);
  w=compless(X,x);
  vector<vector<int> >mp(h,vector<int>(w,-1));
  for(int i=0;i<X.size();i++)mp[y[Y[i]]][x[X[i]]]=d[i];

  int ans=1;
  for(int i=0;i<n;i++)ans=max(ans,calc(y[Y[i]],x[X[i]],mp));
  cout <<ans<<endl;

  return 0;
}

Measured memory_bytes: 12296
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.Set;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String s = br.readLine();
		int n = Integer.parseInt(s);
		HashSet<Integer> set = new HashSet<Integer>();
		
		for (int i = 0; i < n; i++) {
			s = br.readLine();
			int a = Integer.parseInt(s);
			if(set.contains(a))
				set.remove(a);
			else
				set.add(a);
		}
		//boolean[] nums = new boolean[1000000000];
//		
//		int max = 0;
//		for (int i = 0; i < n; i++) {
//			int number = Integer.parseInt(ss[i]);
//			if(number > max)
//				max = number;
//			if(nums[number])
//				nums[number]=false;
//			else {
//				nums[number] = true;
//			}
//		}
//		int count = 0;
//		for (int i = 0; i <= max; i++) {
//			if(nums[i])
//				count++;
//		}
		System.out.println(set.size());
		

	}

}


Measured memory_bytes: 40152
n, m = gets.split.map(&:to_i)
x = gets.split.map(&:to_i)
y = gets.split.map(&:to_i)

sum_x = 0
n.times do |i|
  sum_x += i * x[i] - (n - 1 - i) * x[i]
end

sum_y = 0
m.times do |i|
  sum_y += i * y[i] - (m - 1 - i) * y[i]
end

puts sum_x * sum_y % (10 ** 9 + 7)

Measured memory_bytes: 15516
n = int(input())
s = list(input())
o_s = list(set(s))
counter = 0
max = 0
for i in range(1,n):
    left = set(s[0:i])
    right = set(s[i:n])
    for j in left:
        if(j in right):
            counter += 1
    if max < counter :
        max = counter
    counter = 0
print(max)


Measured memory_bytes: 3060
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

const double pi = acos(-1);

int main()
{
    double a, b, x;
    cin >> a >> b >> x;
    x = x * 1.0 / a;
    if(b * a / 2 > x){
        cout << fixed << setprecision(15) << 90 - atan(x * 2 / (b * b)) / pi * 180.0;
    }
    else{
        cout << fixed << setprecision(15) << atan((a * b * 2 - x * 2) / (a * a)) / pi * 180.0;
    }
}

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

using namespace std;

long long y[100010];
long long res_y[100010];
#include <vector>
#include <array>
#include <cmath>
#include <cassert>


constexpr unsigned int log_2(unsigned long long n)
{
    return n > 1 ? log_2((n+1)/2) +1 : 0;
}


template<const unsigned long long Limit> class Permutation {

public:
    Permutation(const std::vector<int> &p){
        for(int i = 0 ; i < p.size() ; i++){
            assert(0 <= p[i] && p[i] < p.size());
        }
        p_doubling[0] = p;
        for(int i = 1 ; i < p_doubling.size() ; i++){
            p_doubling[i] = apply_inner(p_doubling[i-1], p_doubling[i-1]);
        }
    }

    int get_pos_after_K(unsigned long long K, int idx){
        assert(K <= Limit);
        for(int i = 0 ; i < p_doubling.size() && (K >> i) > 0 ; i++){
            if( K >> i & 1 ){
                idx = p_doubling[i][idx];
            }
        }
        return idx;
    }

private:
    // p[i] := move the element at positon i to position p[i]
    // i := 0-origin

    std::array< std::vector<int>, log_2(Limit)+1> p_doubling;

    std::vector<int> apply_inner(const std::vector<int> &arr, const std::vector<int> &p){
        assert(arr.size() == p.size());
        std::vector<int> res(arr.size());
        for(int i = 0 ; i < arr.size() ; i++){
            res[i] = arr[p[i]];
        }
        return res;
    }

};




void solve(long long N, vector<long long> x, long long M, long long K, vector<long long> a) {
    for (int i = 0; i < M; i++) a[i]--;
    vector<int> p(N - 1);
    for (int i = 0; i < N - 1; i++) p[i] = i;

    vector<int> q = p;

    for (int i = 0; i < M; i++) {
        swap(p[a[i]], p[a[i] - 1]);
    }
    Permutation<1000000000000000000ull> perm(p);

    for (int i = 0; i < N - 1; i++) y[i] = x[i + 1] - x[i];
    for (int i = 0; i < N - 1; i++) {
        res_y[i] = y[perm.get_pos_after_K(K, i)];
    }

    long long ans = x[0];
    for (int i = 0; i < N - 1; i++) {
        cout << ans << endl;
        ans += res_y[i];
    }
    cout << ans << endl;


}

int main() {
    long long N;
    scanf("%lld", &N);
    vector<long long> x(N);
    for (int i = 0; i < N; i++) {
        scanf("%lld", &x[i]);
    }
    long long M;
    scanf("%lld", &M);
    long long K;
    scanf("%lld", &K);
    vector<long long> a(M);
    for (int i = 0; i < M; i++) {
        scanf("%lld", &a[i]);
    }
    solve(N, x, M, K, a);
    return 0;
}



Measured memory_bytes: 30592
#include<bits/stdc++.h>
using namespace std;
int main(){
	string a,b;
	cin>>a>>b;
	int ans=b.size();
	for(int i=0;i<=a.size()-b.size();i++){
		int diff=0;
		for(int j=0;j<b.size();j++){
			if(b[j]!=a[i+j]){
				diff++;
			}
		}
		ans=min(ans,diff);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 3576
import java.util.Scanner;
import java.math.BigInteger;
import java.util.Arrays;


public class Main {
	
	
	 static int ret=10;

	 public static void main(String[] args) {
	        
         Scanner scan = new Scanner(System.in);
         int  a,b,c,i,n,f=0;
         String s,s1;
         n=scan.nextInt();
         if(n==1)
               System.out.println("0");
         else
             System.out.println("1");
	 }
	
}
	


Measured memory_bytes: 35680
#E
import bisect

s = input()
t = input()
lens = len(s)

s_n = {}
for i in range(len(s)):
    if s[i] in s_n:
        s_n[s[i]].append(i+1)
    else:
        s_n[s[i]] = [i+1]
        
#print(s_n)

d1=0
d2=0
for i in t:
    if not(i in s_n):
        print(-1)
        break
    else:
        if d1 >= s_n[i][-1]:
            d1 = s_n[i][0]
            d2 += lens
        else:
            index = bisect.bisect(s_n[i],d1)
            d1 = s_n[i][index]
else:
    print(d1+d2)



Measured memory_bytes: 46320
#include <bits/stdc++.h>
#define rep(i,N) for(int i=0;i<N;i++)
#define rep2(i,N) for(int i=1;i<=N;i++)
using namespace std;
long long  INF=1000000000000000000;
long long mod=1000000007;


int a[85][85];
int b[85][85];
int d[85][85];




int main(){

int h,w;
cin>>h>>w;

rep2(i,h)rep2(k,w)cin>>a[i][k];

rep2(i,h)rep2(k,w)cin>>b[i][k];

rep2(i,h)rep2(k,w)d[i][k]=abs(a[i][k]-b[i][k]);

long long size=2*80*160+1;

bool d_sum[85][85][size];

d_sum[1][1][d[1][1]]=true;

rep2(i,h){
    rep2(k,w){
        for(int p=0;p<size;p++){
            if(d_sum[i-1][k][p]){
                d_sum[i][k][p+d[i][k]]=true;
                d_sum[i][k][abs(p-d[i][k])]=true;
            }
            if(d_sum[i][k-1][p]){
                d_sum[i][k][p+d[i][k]]=true;
                d_sum[i][k][abs(p-d[i][k])]=true;
            }
        }
    }
}

for(int p=0;p<size;p++){
    if(d_sum[h][w][p]){
        cout<<p<<endl;
        break;
    }
}


return 0;
}
/*
2 2
1 2
3 4
3 4
2 1

0

2 3
1 10 80
80 10 1
1 2 3
4 5 6

2
*/


Measured memory_bytes: 170880
#include <bits/stdc++.h>
using namespace std;
#define ft first
#define sd second
using ll = long long;
const int INF = 1e9+7;
const int EPS = -1e6;
const int maxn = 100000+5;
inline void fastio() {ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);}

char s[maxn];

int main(){
    //freopen("input.txt", "r", stdin);
    fastio();

    scanf("%s", s);
    int len = strlen(s);

    int ans1 = 0;
        for(int i = 0; i < len; ++i){
            if(!(i&1) && s[i] != '0')
                ans1++;
            if(i&1 && s[i] != '1')
                ans1++;
        }

    int ans2 = 0;
        for(int i = 0; i < len; ++i){
            if(!(i&1) && s[i] != '1')
                ans2++;
            if(i&1 && s[i] != '0')
                ans2++;
        }

    printf("%d\n", min(ans1, ans2));

    return 0;
}



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

ll sum(ll n){
  return n*(n+1)/2;
}
int main()
{
  ll N; cin >> N;
  ll ans = sum(N)-sum(N/3)*3-sum(N/5)*5+sum(N/15)*15;
  cout << ans << endl;
}


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

int main() {
  int i, j;

  char temp[110];
  int h, w;
  int num[27];
  for (i = 0; i < 27; i++) {
    num[i] = 0;
  }

  scanf("%d %d ", &h, &w);

  for (i = 0; i < h; i++) {
    scanf("%[^\n]%*c", temp);
    j = 0;
    while (temp[j] != '\0') {
      num[temp[j]-'a']++;
      j++;
    }
  }

  int flag = 0;
  if (h % 2 == 0 && w % 2 == 0) {
    //printf("ee\n");
    for (i = 0; i < 27; i++) {
      if (num[i] % 4 != 0) {
        flag = 1;
        break;
      }
    }
  }
  else if(h%2 == 1 && w%2 == 1) {
    //printf("oo\n");
    int odd = 0;
    int even = 0;
    int four = 0;
    int oddnum = 0;
    int max = (w - 1) / 2 + (h - 1) / 2;
    for (i = 0; i < 27; i++) {
      if(num[i] % 4 == 0) {
        four++;
      }
      else if(num[i] % 2 == 0){
        even++;
      }
      else{
        odd++;
        oddnum = num[i];
      }
    }

    //printf("%d %d %d %d %d", odd, even, four, oddnum, max);

    if(odd != 1) {
      flag = 1;
    }
    else {
      if((oddnum-1)%4 != 0){
        even++;
      }
      if(even > max) {
        flag = 1;
      }
    }
  }
  else if(h%2 == 1){
    ///printf("oe\n");
    int odd = 0;
    int even = 0;
    int four = 0;
    int oddnum = 0;
    int max = w / 2;
    for (i = 0; i < 27; i++) {
      if(num[i] % 4 == 0) {
        four++;
      }
      else if(num[i] % 2 == 0){
        even++;
      }
      else{
        odd++;
        oddnum = num[i];
      }
    }

    //printf("%d %d %d %d %d", odd, even, four, oddnum, max);


    if(odd != 0) {
      flag = 1;
    }
    else {
      if(even > max) {
        flag = 1;
      }
    }
  }
  else {
    //printf("eo");
    int odd = 0;
    int even = 0;
    int four = 0;
    int oddnum = 0;
    int max = h / 2;
    for (i = 0; i < 27; i++) {
      if(num[i] % 4 == 0) {
        four++;
      }
      else if(num[i] % 2 == 0){
        even++;
      }
      else{
        odd++;
        oddnum = num[i];
      }
    }

    //printf("%d %d %d %d %d", odd, even, four, oddnum, max);


    if(odd != 0) {
      flag = 1;
    }
    else {
      if(even > max) {
        flag = 1;
      }
    }
  }



  if(flag == 1) {
    printf("No");
  }
  else {
    printf("Yes");
  }

  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define ll long long 
#define ld long double
#define pb push_back
#define vl vector
#define ff first
#define ss second
using namespace std;
int main()
{
    ll a,b,i,j,n,t;
    cin>>n;
    n--;
    a=n*(n+1);
    a/=2;
    cout<<a;
}

Measured memory_bytes: 3592
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Main main = new Main();
		main.run();
	}

	void run() {
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
	    int[] A = new int[N];
	    long ans = 1;
	    int count = 0;
	    for (int i = 0; i < N; i++){
	      A[i] = sc.nextInt();
	    }
	    Arrays.sort(A);
	    for (int i = N - 1; i > 0; i--){
	      if (A[i] == A[i - 1]){
	        ans *= A[i];
	        i--;
	        count++;
	      }
	      if (count >= 2){
	      System.out.println(ans);
	      return;
	      }
	    }
	    System.out.println(0);

	}

	//以下テンプレート

	public static int[] extgcd(int a, int b) {

		int x0 = 1;
		int x1 = 0;

		int y0 = 0;
		int y1 = 1;

		while (b != 0) {
			int q = a / b;
			int r = a % b;

			int x2 = x0 - q * x1;
			int y2 = y0 - q * y1;

			a = b;
			b = r;

			x0 = x1;
			x1 = x2;

			y0 = y1;
			y1 = y2;
		}

		return new int[] { a, x0, y0 };

	}

	static int gcd(int a, int b) {

		if (b == 0)
			return a;

		if (a < b) {
			int t = a;
			a = b;
			b = t;
		}

		return gcd(b, a % b);

	}

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

	static void swap(int[] a) {
		int t;

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

		return;
	}

	static <T> void output(List<T> list) {

		for (int i = 0; i < list.size(); i++) {
			System.out.print(list.get(i));

			if (i != list.size() - 1) {
				System.out.print(" ");
			} else {
				nl();
			}
		}

	}

	static void output(String[][] str) {

		for (int i = 0; i < str.length; i++) {
			for (int j = 0; j < str[i].length; j++) {
				print(str[i][j]);
			}

			nl();
		}

	}

	static void output(boolean flg, String Yes, String No) {

		if (flg) {
			pln(Yes);
		} else {
			pln(No);
		}

	}

	static void output(String[][] str, int digit) {

		String dig = "%" + String.valueOf(digit) + "s";

		for (int i = 0; i < str.length; i++) {
			for (int j = 0; j < str[i].length; j++) {
				System.out.printf(dig, str[i][j]);
			}
			nl();
		}

	}

	static void pln(String str) {
		System.out.println(str);
	}

	static void pln(int x) {
		System.out.println(x);
	}

	static void print(String str) {
		System.out.print(str);
	}

	static void print(int x) {
		System.out.print(x);
	}

	static void print(String str, int times) {
		for (int i = 0; i < times; i++) {
			print(str);
		}
	}

	static void print(int x, int times) {
		for (int i = 0; i < times; i++) {
			print(x);
		}
	}

	static void nl() {
		System.out.println();
	}

}


Measured memory_bytes: 50840
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
ll ar1[5000000];
int main()
{
    ll test,j,n,s=0;
    cin>>n;
    int i;
    for(i=0; i<n; i++)
    {
        cin>>ar1[i];
        s+=ar1[i];
    }
    j=s/n;
    ll ans=0;
    ll m=s%n;
    if(m>n/2)j++;
    for(i=0; i<n; i++)
    {
        ans+=(abs(j-ar1[i]))*(abs(j-ar1[i]));
    }
    cout<<ceil(ans)<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int h,w;
    cin>>h>>w;
    vector<string> grid(h);
    for(int i=0;i<h;i++)
    {
        cin>>grid[i];
    }
    long dp[h][w];
    bool yes=true;
    for(int i=1;i<w;i++)
    {
        if(grid[0][i]=='#') yes=false;
        if(yes) dp[0][i]=1;
        else dp[0][i]=0;
    }
    yes=true;
    for(int i=1;i<h;i++)
    {
        if(grid[i][0]=='#') yes=false;
        if(yes) dp[i][0]=1;
        else dp[i][0]=0;
    }
    long mod=1000000007;
    for(int i=1;i<h;i++)
    {
        for(int j=1;j<w;j++)
        {
            if(grid[i][j]=='#') dp[i][j]=0;
            else dp[i][j]=(dp[i-1][j]+dp[i][j-1])%mod;
        }
    }
    cout<<dp[h-1][w-1]<<endl;
}

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

ab = [list(map(int,input().split())) for _ in range(N)]
AB = sorted(ab, key=lambda x: x[1])

time = 0

for i in range(N):
  time += AB[i][0]
  if time > AB[i][1]:
    print("No")
    exit()
print("Yes")


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

string s, t;
vector<int> pos[26];

int main() {
  ios::sync_with_stdio(false);
  cin >> s >> t;
  for(int i = 0; i < s.size(); i++)
    pos[s[i]-'a'].push_back(i);
  long long ans = 0, cur = 0;
  for(int i = 0; i < t.size(); i++) {
    auto& v = pos[t[i]-'a'];
    auto it = lower_bound(v.begin(), v.end(), cur);
    if (it != v.end()) {
      cur = *it+1;
      continue;
    }
    ans += s.size();
    cur = 0;
    it = lower_bound(v.begin(), v.end(), cur);
    if (it != v.end())
      cur = *it+1;
    else {
      cout << -1;
      return 0;
    }
  }
  cout << ans + cur;
}


Measured memory_bytes: 1228
import java.io.PrintWriter

val pw = PrintWriter(System.out)

fun main(args : Array<String>) {
    func()
    pw.flush()
}

fun func() {
    val s = next()
    println(s.replace("2017", "2018"))
}

fun next() = readLine()!!

fun println(value : Any) {
    pw.println(value)
}

Measured memory_bytes: 37820
class Main{
    public static void main(String[] args){
        int times = new java.util.Scanner(System.in).nextInt();

        int h = times / 3600;
        int m = (times % 3600) / 60;
        int s = (times % 3600) % 60;

        System.out.println(h + ":" + m + ":" + s);
    }
}


Measured memory_bytes: 26112
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	int m;
	cin>>m;
	int A[m];
	int ans=0;
	for(int i=0;i<m;i++){
		cin>>A[i];
		ans+=A[i];
	}
	if(n>=ans)
	cout<<n-ans<<endl;
	else
	cout<<-1<<endl;
	
  return 0;
}

Measured memory_bytes: 3648
import sys
N = input()
a, b, c, d = int(N[0]),int(N[1]), int(N[2]), int(N[3])
n = a + b + c + d
if n == 7:
    print("{}+{}+{}+{}=7".format(a, b, c, d))
    sys.exit()
n = a - b + c + d
if n == 7:
    print("{}-{}+{}+{}=7".format(a, b, c, d))
    sys.exit()
n = a + b - c + d
if n == 7:
    print("{}+{}-{}+{}=7".format(a, b, c, d))
    sys.exit()
n = a + b - c + d
if n == 7:
    print("{}+{}-{}+{}=7".format(a, b, c, d))
    sys.exit()
n = a + b + c - d
if n == 7:
    print("{}+{}+{}-{}=7".format(a, b, c, d))
    sys.exit()
n = a - b - c + d
if n == 7:
    print("{}-{}-{}+{}=7".format(a, b, c, d))
    sys.exit()
n = a + b - c - d
if n == 7:
    print("{}+{}-{}-{}=7".format(a, b, c, d))
    sys.exit()
n = a - b + c - d
if n == 7:
    print("{}-{}+{}-{}=7".format(a, b, c, d))
    sys.exit()
n = a - b - c - d
if n == 7:
    print("{}-{}-{}-{}=7".format(a, b, c, d))
    sys.exit()

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
using namespace std;
static const int MAX = 200000;
int main(){
    int R[MAX], n;
    cin >> n;
    for(int i=0; i<n; i++){
        cin >> R[i];
    }
    int maxValue = -2000000000;
    int minValue = R[0];
    for(int j=1; j<n; j++){
        maxValue = max(maxValue, R[j]-minValue);
        minValue = min(minValue, R[j]);
    }
    cout << maxValue << endl;
    return 0;
}

Measured memory_bytes: 3864
import sys
readline = sys.stdin.readline

N = int(readline())
D = list(map(int,readline().split()))

counts = [0] * (max(D) + 1)

from collections import Counter
counter = Counter(D)

for k,v in counter.items():
  counts[k] = v

if D[0] != 0 or counts[0] != 1:
  print(0)
  exit(0)
  
ans = 1
DIV = 998244353
for i in range(1, len(counts)):
  ans *= pow(counts[i - 1],counts[i],DIV)
  ans %= DIV

print(ans)

Measured memory_bytes: 20512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF (1LL<<50)
#define MOD 1000000007

int main(){
    int N,M;
    cin >> N >> M;
    vector<string> A(N);
    vector<string> B(M);
    rep(i,N){
        cin >> A[i];
    }
    rep(i,M){
        cin >> B[i];
    }

    for(int i=0;i<=N-M;i++){
        for(int j=0;j<=N-M;j++){
            string Asub = A[i].substr(j,M);
            bool flg = true;
            if(Asub==B[0]){
                for(int k=1;k<M;k++){
                    if(A[i+k].substr(j,M)==B[k]){
                        continue;
                    }else{
                        flg = false;
                        break;
                    }
                }
                if(flg){
                    cout << "Yes" << endl;
                    return 0;
                }
            }
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long
using namespace std;
ll dp[100010][3], v[100010][3], n;
ll f(int pos, int stts, int cnt){
    if(n == pos) return 0;
    ll &ans = dp[pos][stts];
    if(ans != -1) return ans;
    ans = -2e9;
    if(stts == 0){
        if(cnt < 2)
            ans = max(ans, f(pos + 1, 0, 2));
        ans = max(ans, f(pos + 1, 1, 1) + v[pos][stts]);
        ans = max(ans, f(pos + 1, 2, 1) + v[pos][stts]);
    }else if(stts == 1){
        if(cnt < 2)
            ans = max(ans, f(pos + 1, 1, 2));
        ans = max(ans, f(pos + 1, 0, 1) + v[pos][stts]);
        ans = max(ans, f(pos + 1, 2, 1) + v[pos][stts]);
    }else{
        if(cnt < 2)
            ans = max(ans, f(pos + 1, 2, 2));
        ans = max(ans, f(pos + 1, 1, 1) + v[pos][stts]);
        ans = max(ans, f(pos + 1, 0, 1) + v[pos][stts]);
    }
    return ans;
}
int main(){
    fast;
    memset(dp, -1, sizeof dp);
    cin >> n;
    for(int i = 0; i < n; i++)
        cin >> v[i][0] >> v[i][1] >> v[i][2];
    cout << max(f(0, 0, 1), max(f(0, 1, 1), f(0, 2, 1))) << "\n";
	return 0;
}


Measured memory_bytes: 14552
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
        char[] c = str.toCharArray();
        int n = c.length;
        int nown = n / 2;
        while (true) {
            boolean ok = true;
            for (int i = 0; i < nown; i++) {
                if (c[i] != c[i+nown]) {
                    ok = false;
                    break;
                }
            }
            
            if (ok) {
                if (nown*2 == n) {
                    nown -= 1;
                    continue;
                }
                System.out.println(nown*2);
                return;
            } else {
                nown -= 1;
            }
        }
    }
}

Measured memory_bytes: 21844
{
  const run = (input: string) => {
    let split = input.trim().split("\n")
    const [n, k] = split[0].split(" ").map(v => parseInt(v))
    const fruits = split[1].split(" ").map(v => parseInt(v))
    fruits.sort((a:number, b:number) => a - b)

    let result = 0
    for (let i = 0; i < k; i++) {
      result += fruits[i]
    }

    return result
  }

  const Main = (input: string) => {
    console.log(run(input))
  };

  Main(require("fs").readFileSync("/dev/stdin", "utf8"));
}


Measured memory_bytes: 29632
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();

int main() {
    int k,a,b;
    cin >> k>>a>>b;
    int ks = k;
    string ans = "NG";
    while(ks<=b){
        if(ks>=a) ans="OK";
        ks +=k;
    }
    cout << ans << endl;
    return 0;
}

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

#define rep(i, n) for(int i = 0; i < n; ++i)
#define rep2(i, a, b) for(int i = a; i <= b; ++i)
#define ll long long
#define eb emplace_back
#define all(c) (c).begin(), (c).end()
#define vi vector<int>
#define N 110
#define MOD 998244353 //1000000007
#define pll pair<ll,ll>


int main() {
	char a[N][N];
	bool b[N][N];
	vi ss;
	rep(i, N) {
		rep(j, N) {
			a[i][j] = 0;
		}
	}
	int n, m, c, ans;
	cin >> n >> m;
	rep(i, n)cin >> a[i];
	mcf_graph<int, int> g(2 * n*m + 2);
	rep(i, n*m)g.add_edge(n*m + i, 2 * n*m + 1, 1, 0);
	c = 0;
	rep(i, n) {
		rep(j, m) {
			if (a[i][j] == 'o') {
				g.add_edge(2 * n*m, i*m + j, 1, 0);
				c++;
				rep(ii, n) {
					rep(jj, m)b[ii][jj] = false;
				}
				b[i][j] = true;
				rep(ii, n) {
					rep(jj, m) {
						if (a[ii][jj] != '#') {
							if (ii > 0) {
								if (b[ii - 1][jj]) {
									b[ii][jj] = true;
								}
							}
							if (jj > 0) {
								if (b[ii][jj - 1] && (!b[ii][jj])) {
									b[ii][jj] = true;
								}
							}
						}
						if(b[ii][jj])g.add_edge(i*m + j, n*m + (ii*m) + jj, 1, 100 + i + j - ii - jj);
					}
				}
			}
		}
	}
	ans = (g.flow(2 * n*m, 2 * n*m + 1)).second;
	ans = 100 * c - ans;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 7196
#include <iostream>
#include <cstdio>
#include <map>
using namespace std;

int main(){
    long long  N;
    long long K;
    cin >> N >> K;
    map<long long , long long> mp;
    long long  a,b;
    for(int i=0; i<N;i++){
        //cin >> a >> b;
        scanf("%lld %lld", &a, &b);
        if(mp.find(a) == mp.end()){
            mp[a] = b;
        }else{
            mp[a] += b;
        }
    }                                                                                                                                                                                                       

    long long sum = 0;
    for(auto itr = mp.begin(); itr != mp.end(); itr++){
        sum += itr->second;
        if(sum >= K){ 
            cout << itr->first << endl;
            return 0;
        }   
    }   
    return 0;
}

Measured memory_bytes: 4224
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

fn main() {
    let n = read::<usize>();
    let ps = read_vec::<u32>();

    let mut count = 0;
    for i in 0..n-2 {
        let mut sl = ps[i..i+3].iter().map(|j| *j).collect::<Vec<u32>>();
        sl.sort();
        if sl[1] == ps[i+1] {
            count += 1;
        }
    }
    println!("{}", count);
}


Measured memory_bytes: 4476