akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
template<class S, class T> inline S max_L(S a,T b){
  return a>=b?a:b;
}
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  char f[10];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
int main(){
  int A, B, res;
  rd(A);
  rd(B);
  res =max_L(max_L(A+B, A-B), A*B);
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190820-1

// --- original code ---
// {
//   int A, B, res;
//   rd(A,B);
//   res = max(A+B, A-B, A*B);
//   wt(res);
// }


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

using namespace std;

bool Search(vector<int>& p, int x)
{
    int np = p.size();

    for (int i = 0; i < np; i++)
    {
        if (x == p[i])
        {
            return false;
        }
    }

    return true;
}

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

    vector<int> p(n);
    for (int i = 0; i < n; i++)
        cin >> p[i];


    int j = 1;
  
  if(n==0)
  {
    cout<<x<<endl;
    return 0;
  }
    bool b = Search(p, x);
    if (b)
    {
        cout << x << endl;
        return 0;
    }

    while (true)
    {
        b = Search(p, x - j);
        if (b)
        {
            cout << x - j << endl;
            break;
        }
        b = Search(p, x + j);
        if (b)
        {
            cout << x + j << endl;
            break;
        }
        j++;
    }
}


Measured memory_bytes: 3608
#include <iostream>
#include <algorithm>
#include <cmath>
#define ll long long
#define endl "\n"
#define __ ios::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
using namespace std;

int n;
int t[100001],x[100001],y[100001];

int main(){

	cin >> n;
	for(int i=1; i<=n; i++){
		cin >> t[i] >> x[i] >> y[i];
		int a=t[i]-t[i-1];
		int b = (abs(x[i]-x[i-1])+abs(y[i]-y[i-1]));
		if(a-b>=0 && (a-b)%2==0) continue;
		cout << "No\n";
		return 0;
	}
	cout << "Yes\n";

}

Measured memory_bytes: 1408
S = input()
cnt = 0
pos = 0
pre = ''
while pos < len(S):
  if not pre:
    pre = S[pos]
  elif S[pos] != pre:
    cnt += 1
    pre = S[pos]
  else:
    cnt += 1
    pre = S[pos:pos+2]
    if len(pre) < 2:
      pre = ''
    pos += 1
  pos += 1
cnt += 1 if pre else 0
print(cnt)

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

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int n = scan.nextInt();
		String[] model = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".split("");
		String[] mozi = scan.next().split("");

		for(String s: mozi) {
			for(int i=0;i<model.length;i++) {

				if(s.equals(model[i])) {
					int index = n + i;
					System.out.print(model[index%26]);
				}
			}
		}

		scan.close();

	}

}


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

using namespace std;
using lint = long long;

const lint MOD = 998244353;

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

    vector<lint> d(n);
    for (int i = 0; i < n; i++) {
        cin >> d[i];
    }

    if (d[0] != 0) {
        cout << 0 << endl;
        return 0;
    }

    map<lint, lint> mp;
    for (auto x:d) mp[x]++;

    lint ans = 1;
    for (int i = 1; i < n; i++) {
        ans *= mp[d[i] - 1];
        ans %= MOD;
    }

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


Measured memory_bytes: 7296
#include<bits/stdc++.h>
#define rep(i,f,n) for(ll i=(f); (i) < (n); i++)
#define repe(i,f,n) for(ll i=(f); (i) <= (n); i++)
using namespace std;
using ll = long long;
#define MOD (ll)1000000007
#define PI 3.14159265359
#define debug(x) cout<<#x<<" :: "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n";
#define P pair<int, int>
#define Pl pair<ll, ll>
#define dvec vector<vector<ll>>
//printf("%.10f\n")
//cout << fixed << setprecision(10);
template<class T> inline bool chmax(T& a, T b){if (a < b) { a = b; return true; } return false;}
template<class T> inline bool chmin(T& a, T b){if (a > b) { a = b; return true; } return false;}
ll INF = 1e+18;
int iINF = 1e9;



int main()
{
  int H, W; cin >> H >> W;
  P S; cin >> S.first >> S.second;
  S.first -= 1, S.second -= 1;
  P T; cin >> T.first >> T.second;
  T.first -= 1, T.second -= 1;
  vector<vector<char>> G(H, vector<char>(W));
  rep(i, 0, H) rep(k, 0, W) cin >> G[i][k];

  vector<vector<int>> dist(H, vector<int>(W, -1));
  dist[S.first][S.second] = 0;
  vector<P> direct = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
  queue<P> q;
  queue<P> nxt;
  queue<P> tmp;
  nxt.push(S);

  while(!nxt.empty()){
    q.push(nxt.front());
    nxt.pop();
    while(!q.empty()){
      P node = q.front();
      q.pop();
      int val = dist[node.first][node.second];
      tmp.push(node);
      for(auto add : direct){
        P next = {node.first + add.first, node.second + add.second};
        if(next.first < 0 || H - 1 < next.first|| next.second < 0 || W - 1 < next.second) continue;
        if(G[next.first][next.second] == '#') continue;
        if(val == dist[next.first][next.second]) continue;
        dist[next.first][next.second] = val;
        tmp.push({next.first, next.second});
        q.push({next.first, next.second});
      }
    }
    while(!tmp.empty()){
      P node = tmp.front();
      int val = dist[node.first][node.second];
      tmp.pop();
      rep(i, -2, 3){
        rep(k, -2, 3){
          P next = {node.first + i, node.second + k};
          if(next.first < 0 || H - 1 < next.first|| next.second < 0 || W - 1 < next.second) continue;
          if(G[next.first][next.second] == '#') continue;
          if(dist[next.first][next.second] != -1){
            if(val - 1 == dist[next.first][next.second] || val == dist[next.first][next.second] || val + 1 == dist[next.first][next.second]) continue;
          }
          dist[next.first][next.second] = val + 1;
          nxt.push(next);
        }
      }
    }
  }
  
  cout << dist[T.first][T.second] << endl;
}


Measured memory_bytes: 8568
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        int c = Integer.parseInt(sc.next());
        sc.close();

        // 主処理
        int ab = a + b;
        int ac = a + c;
        int bc = b + c;
        int result = Math.min(Math.min(ab, ac), bc);

        // 出力
        System.out.println(result);
    }
}


Measured memory_bytes: 23764
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<stack>
#include<vector>
using namespace std;
typedef long long ll;

const int A = 1e3 + 10;
int C[A],S[A],F[A];

int main(){
    int n;
    scanf("%d",&n);

    for(int i=1 ;i<n ;i++) scanf("%d%d%d",&C[i],&S[i],&F[i]);
    for(int i=1 ;i<n ;i++){
        int now = 0;
        for(int j=i ;j<n ;j++){
            if(now < S[j]) now = S[j];
            else{
                int num = (now-S[j])/F[j];
                if((now-S[j]) % F[j]) num++;
                now = S[j] + num*F[j];
            }
            now += C[j];
        }
        printf("%d\n",now);
    }
    puts("0");
    return 0;
}


Measured memory_bytes: 128
#include "bits/stdc++.h"

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
constexpr double EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max()/2;
constexpr int MOD = 1e9+7;

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

    char x,y;cin>>x>>y;
    if(x<y) cout<<"<"<<endl;
    else if(x==y) cout<<"="<<endl;
    else cout<<">"<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<deque>
using namespace std;
typedef long long ll;
ll pl[303030], tm[303030];
int main()
{
	int num, len;
	scanf("%d%d", &num, &len);
	for (int i = 0; i < num; i++)scanf("%lld", &pl[i]);
	ll ad = 0;
	vector<ll>v1, v2;
	deque<ll>deq;
	ll maxi = 0, v3 = -1;
	for (int i = 0; i < num; i++)
	{
		ll z;
		scanf("%lld", &z);
		ad += (z - 1) / (len * 2);
		z = (z - 1) % (len * 2) + 1;
		bool f1 = (z <= (len - pl[i]) * 2), f2 = (z <= pl[i] * 2);
		if (f1&&f2)deq.push_back(pl[i]);
		if (f1&&!f2)v1.push_back(pl[i]);
		if (!f1&&f2)v2.push_back(pl[i]);
		if (!f1&&!f2)v3 = pl[i], ad++;
		if (f1 || f2)maxi = pl[i];
	}
	if (!v2.empty())
	{
		ll ans = v1.size() + v2.size() + 1;
		for (int i = 0; i < v1.size(); i++)if (!deq.empty() && deq[0] < v1[i])deq.pop_front();
		v2.push_back(v2[v2.size() - 1]);
		for (int i = v2.size() - 1; i >= 0; i--)
		{
			if (!deq.empty() && v2[i] < deq[deq.size() - 1])deq.pop_back();
			else maxi = len;
		}
		ans += (deq.size() + 1) / 2;
		if (deq.size() % 2 == 1)maxi = len;
		if (maxi < v3)ans++;
		printf("%lld\n", (ad + ans)*len * 2);
	}
	else
	{
		if (!v1.empty())
		{
			for (int i = 0; i < v1.size(); i++)
			{
				if (deq.empty() && v3 < maxi)
				{
					printf("%lld\n", (ad + v1.size())*len * 2);
					return 0;
				}
				if (!deq.empty() && deq[0] < v1[i])deq.pop_front();
			}
			ll ans = v1.size() + 1;
			ans += deq.size() / 2;
			if (deq.size() % 2 == 0)maxi = len;
			if (maxi < v3)ans++;
			printf("%lld\n", (ad + ans)*len * 2);			
		}
		else
		{
			ll ans = 1;
			ans += deq.size() / 2;
			if (deq.size() % 2 == 0)maxi = len;
			if (maxi < v3)ans++;
			printf("%lld\n", (ad + ans)*len * 2);
		}
	}
}

Measured memory_bytes: 8560
n, k = map(int, input().split())
a = [int(i) for i in input().split()]


lst = []
visit_now = 1
visit_list = [-1] * (n + 1)
cnt = 0

while visit_list[visit_now - 1] == -1:
    visit_list[visit_now - 1] = cnt
    lst.append(visit_now)
    visit_now = a[visit_now - 1]
    cnt += 1

start = visit_list[visit_now - 1]
loop_num = cnt - start

if k <= start:
    ans = lst[k]
else:
    k -= start
    k %= loop_num
    ans = lst[start + k]

print(ans)

Measured memory_bytes: 32276
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<queue>
using namespace std;
void read(int &x){
    char ch;bool ok;
    for(ok=0,ch=getchar();!isdigit(ch);ch=getchar())if(ch=='-')ok=1;
    for(x=0;isdigit(ch);x=x*10+ch-'0',ch=getchar());if(ok)x=-x;
}
#define rg register
const int maxn=1e5+10;
int x,y,z,n;long long ans,sum[maxn],num;
struct oo{int x,y;}a[maxn];
bool cmp(oo a,oo b){return a.x-a.y<b.x-b.y;}
priority_queue<int,vector<int>,greater<int> >q;
int main(){
	read(x),read(y),read(z),n=x+y+z;
	for(rg int i=1,u,v,w;i<=n;i++){
		read(u),read(v),read(w);
		num+=u,v-=u,w-=u;
		a[i].x=v,a[i].y=w;
	}
	sort(a+1,a+n+1,cmp);long long now=0;
	for(rg int i=1;i<=z;i++)now+=a[i].y,q.push(a[i].y);
	for(rg int i=z+1;i<=n;i++){
		sum[i-1]=now,q.push(a[i].y);
		now+=a[i].y,now-=q.top();q.pop();
	}
	sum[n]=now;
    while(!q.empty())q.pop();now=0;
	for(rg int i=n;i>=n-y+1;i--)now+=a[i].x,q.push(a[i].x);
	for(rg int i=n-y;i>=z;i--){
	    ans=max(ans,now+sum[i]+num),q.push(a[i].x);
		now+=a[i].x,now-=q.top();q.pop();
	}
    printf("%lld\n",ans);
}


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

int main()
{
  int input_n;
  char input_c[100];
  char ch;
  int counter_i, counter_j;

  for( ; ; )
  {
    int hyou_counter[26] = {0};
    int winner = 0;

    for(counter_i = 0 ; counter_i <= 25 ; counter_i++)
      hyou_counter[counter_i] = 0;

    scanf("%d", &input_n);
    if(input_n == 0)
      break;

    for(counter_i = 0 ; counter_i < input_n ; counter_i++)
    {
      scanf("%c", &ch);
      scanf("%c", &input_c[counter_i]);
    }

    for(counter_i = 0 ; counter_i < input_n ; counter_i++)
    {
      int hyou_nokori = input_n - counter_i - 1;
      int max_hyou = 0, second_max_hyou = 0, max_index = 0;

      hyou_counter[input_c[counter_i] - 'A'] += 1;

      for(counter_j = 0 ; counter_j <= 25 ; counter_j++)
      {
        if(hyou_counter[counter_j] >= max_hyou)
        {
          second_max_hyou = max_hyou;
          max_hyou = hyou_counter[counter_j];
          max_index = counter_j;
        }
        else if(hyou_counter[counter_j] >= second_max_hyou)
        {
          second_max_hyou = hyou_counter[counter_j];
        }
      }

      if(max_hyou > second_max_hyou + hyou_nokori)
      {
        printf("%c %d\n", 'A' + max_index, counter_i + 1);
        winner = 1;
        break;
      }
    }

    if(!winner)
    {
      printf("TIE\n");
    }
  }
  return 0;
}



Measured memory_bytes: 2104
#include <iostream>

using namespace std;

const int Z = 1e9+7;

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

    int n, k;
    cin >> n >> k;

    int inv[n+1], fac[n+1], ifac[n+1];
    for (int i = 0; i <= n; i++) {
        inv[i] = i <= 1 ? i : 1ll * (Z - Z / i) * inv[Z%i] % Z;
        fac[i] = i == 0 ? 1 : 1ll * fac[i-1] * i % Z;
        ifac[i] = i == 0 ? 1 : 1ll * ifac[i-1] * inv[i] % Z;
    }

    int ans = 0;
    for (int i = 0; i <= min(n - 1, k); i++) {
        ans = (ans + 1ll * fac[n] * ifac[i] % Z * ifac[n-i] % Z * fac[n-1] % Z * ifac[i] % Z * ifac[n-1-i]) % Z;
    }

    cout << ans << endl;

    return 0;
}


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

int main() {
  int N,K;
  cin >> N >> K;
  
  int intX = 1;

  for(int i = 0; i < N; i++){
    if(intX < K){
      intX = intX * 2;
    }
    else{
      intX = intX + K;
    }
  }    
    
  cout << intX << endl;
}


Measured memory_bytes: 3556
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstdlib>
#include <cmath>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl

using namespace std;

typedef long long int lli;

bool check(vector<int> &v) {
    REP (i, 1, v.size()) {
        if (v[i - 1] > v[i]) return false;
    }
    return true;
}

int main() {
    int N;
    cin >> N;
    vector<int> a(N);
    REP (i, 0, N) cin >> a[i];
    int ind = 0;
    REP (i, 1, N) {
        if (abs(a[ind]) < abs(a[i])) {
            ind = i;
        }
    }
    if (a[ind] < 0) {
        cout << 2 * (N - 1) << endl;
        REP (i, 0, N) {
            if (i != ind) {
                a[i] += a[ind];
                cout << ind + 1 << ' ' << i + 1 << endl;
            }
        }
        for (int i = N - 1; i > 0; i--) {
            a[i - 1] += a[i];
            cout << i + 1 << ' ' << i - 1 + 1 << endl;
        }
    } else if (a[ind] > 0) {
        cout << 2 * (N - 1) << endl;
        REP (i, 0, N) {
            if (i != ind) {
                a[i] += a[ind];
                cout << ind + 1 << ' ' << i + 1 << endl;
            }
        }
        REP (i, 1, N) {
            a[i] += a[i - 1];
            cout << i - 1 + 1 << ' ' << i + 1 << endl;
        }
    } else {
        cout << 0 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
using System;
namespace A
{
  class A
  {
    static void Main()
    {
      string day = Console.ReadLine();
      switch (day){
        case "SUN":
          Console.WriteLine("7");
          break;
        case "MON":
          Console.WriteLine("6");
          break;
        case "TUE":
          Console.WriteLine("5");
          break;
        case "WED":
          Console.WriteLine("4");
          break;
        case "THU":
          Console.WriteLine("3");
          break;
        case "FRI":
          Console.WriteLine("2");
          break;
        case "SAT":
          Console.WriteLine("1");
          break;
        default:
          Console.WriteLine("0");
          break;
      }
    }
  }
}

Measured memory_bytes: 13152
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<algorithm>
#include<vector>
#include<queue>
#define ll long long
ll read()
{
	ll tmp=0;char c=getchar(),f=1;
	while(c<'0'||'9'<c){if(c=='-')f=-1;c=getchar();}
	while('0'<=c&&c<='9'){tmp=tmp*10+c-48;c=getchar();}
	return tmp*f;
}
using namespace std;
ll a,b,c,d,e,f;
int canw[110],cans[3010];
int main()
{
	int i,j;
	a=read(); b=read(); c=read(); d=read(); e=read(); f=read();
	canw[0]=1;
	for(i=1;i*100<=f;i++){
		canw[i]=0;
		if(i>=a)canw[i]=canw[i]|canw[i-a];
		if(i>=b)canw[i]=canw[i]|canw[i-b];
	}
	cans[0]=1;
	for(i=1;i<=f;i++){
		cans[i]=0;
		if(i>=c)cans[i]=cans[i]|cans[i-c];
		if(i>=d)cans[i]=cans[i]|cans[i-d];
	}
	ll ans=0,tot=a*100;
	for(i=1;100*i<=f;i++)
		for(j=0;(j<=i*e)&&(100*i+j<=f);j++)
			if(canw[i]&&cans[j]&&1.0*j/(100*i+j)>1.0*ans/tot)ans=j,tot=100*i+j;
	printf("%lld %lld\n",tot,ans);
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(void){
    int h,w ;
    scanf ("%d%d",&h,&w) ;
    for (int i=0; i<h; i++){
        char c[w] ;
        scanf("%s",c) ;
        printf ("%s\n%s\n",c,c) ;
    }
    return 0 ;
}

Measured memory_bytes: 128
k = int(input())
cnt_odd = 0
cnt_even = 0
if k&1:
    while k >= 1:
        cnt_odd += 1
        k -= 2
    cnt_even = cnt_odd - 1
else:
    while k > 0:
        cnt_even += 1
        k -= 2
    cnt_odd = cnt_even

print(cnt_even * cnt_odd)

Measured memory_bytes: 38256
N=int(input())
S=input()
# upper-case A-Z
alp=[chr(i) for i in range(65,65+26)]
nS=[]
for i in range(len(S)):
  l=alp.index(S[i])
  nl=(l+N)%26
  nS.append(alp[nl])
print("".join(nS))

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
typedef long long ll;
ll MOD = 1e9+7;

using namespace std;

int main()
{
	int h,w;
	string s[50];
	int cnt=0;
	
	cin>>h>>w;
	for(int i=0;i<h;i++)
	{
		cin>>s[i];
	}
	for(int i=0;i<h;i++)
	{
		for(int j=0;j<w;j++)
		{
			if(s[i][j]=='#')
			{
				continue;
			}
			cnt=0;
			//左上
			if(i>0&&j>0&&s[i-1][j-1]=='#')
				cnt++;
			//上
			if(i>0 && s[i-1][j]=='#')
				cnt++;
			//右上
			if(i>0&&j<w-1&&s[i-1][j+1]=='#')
				cnt++;
			//左
			if(j>0&&s[i][j-1]=='#')
				cnt++;
			//右
			if(j<w-1&&s[i][j+1]=='#')
				cnt++;
			//左下
			if(i<h-1&&j>0&&s[i+1][j-1]=='#')
				cnt++;
			//下
			if(i<h-1&&s[i+1][j]=='#')
				cnt++;
			//右下
			if(i<h-1&&j<w-1&&s[i+1][j+1]=='#')
				cnt++;
			
			s[i][j]=(char)('0'+cnt);
		}
	}
	for(int i=0;i<h;i++)
		cout<<s[i]<<endl;
	return 0;
}

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

int main() {
  int n; cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  sort(all(a));

  LL ans = 0;
  for (int i = n - 1; i >= 0; i --) {
    for (int j = i - 1; j >= 0; j --) {
      int x = lower_bound(a.begin(), a.end(), a[i] + a[j]) - a.begin();
      ans += x - i - 1;
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr
n = int(input())
fact = factorization(n)

cnt = 0
for f in fact:
    fact_num = f[-1] # 何乗か
    tmp = 1  # 1ずつ増やす。
    while True:
        fact_num -= tmp
        #print("fact_num:%d, tmp:%d" % (fact_num,tmp))
        if fact_num >= 0:
            cnt += 1
        else:
            break
        tmp += 1

if n == 1:
    print(0)
else:
    print (cnt)

Measured memory_bytes: 63368
//Nim

#define _CRT_SECURE_NO_WARNINGS
#include<cstdio>
#include<cstring>
#define clr(a,v) memset((a),(v),sizeof(a))
const int MAX_N = 10, MAX_S = 1 << 13;

int n, S, M[2 * MAX_N];
int dp[2 * MAX_N][MAX_S + 1];

bool rec(int i, int j){
	if (j <= 1)return false;
	int &ret = dp[i][j];
	if (ret != -1)return ret;
	for (int k = 1; k <= M[i]; ++k){
		if (j - k >= 1){
			if (!rec((i + 1) % (n << 1), j - k))return ret = true;
		}
	}
	return ret = false;
}

int main(){
	while (scanf("%d", &n), n){
		scanf("%d", &S);
		for (int i = 0; i < (n << 1); ++i){
			scanf("%d", M + i);
		}
		clr(dp, -1);
		printf("%d\n", rec(0, S));

	}
	return 0;
}

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

int main(){
    string s;
    
    char ch;
    int sum;
    getline(cin,s);
    while(s != "0"){
        sum =0;
        for(int i=0; i<s.size(); i++){
            ch = s.at(i);
            sum += ch-'0';
        }
        cout << sum << endl;
        getline(cin,s);
    }
    return 0;
}


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

#define int long long
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

const int inf = 1LL<<60;
const int mod = 1e9 + 7;
const double eps = 1e-9;

/*{
  }*/

int mypow(int a, int b)
{
  if(b == 0) return 1; 
  return mypow(a*a%mod, b/2)*(b%2?a:1)%mod;
}

signed main()
{
  vi f(100010), s(100010);
  f[0] = 1;
  repi(i, 1, 100010) f[i] = f[i-1]*i%mod;
  repi(i, 1, 100010) s[i] = (s[i-1]+mypow(i, mod-2))%mod;

  int n;
  cin >> n;

  vi a(n);
  int res = 0;
  rep(i, n){
    cin >> a[i];
    res += (s[i+1]+s[n-i]-1)*a[i]%mod;
    res %= mod;
  }

  res *= f[n];
  res %= mod;

  cout << res << endl;

  return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <map>
#include <unordered_map>
#include <chrono>
#include <numeric>
using namespace std;
using ll = long long;
const long long INF = (long long)1e18+1;
#define DIV 1000000007
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
#ifdef TEST
    chrono::system_clock::time_point start, end;
    start = chrono::system_clock::now();
#endif
    long idx=0;
    string S;
    cin >> S;
    if(S == "Sunny") cout << "Cloudy" << endl;
    else if (S == "Cloudy") cout << "Rainy" << endl;
    else cout << "Sunny" << endl;
#ifdef TEST
    end = chrono::system_clock::now();
    cerr << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0) << "[ms]" << endl;
#endif
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#define debug(x) cerr << #x << ':' << x << endl
#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()
using namespace std;
typedef long long ll;

int main(){
    int n, m;
    cin >> n >> m;
    vector<int> X(m, 0);
    REP(i,m) cin >> X[i];
    sort(X.begin(), X.end());

// 0 1  2  3  4 m
// 1 2 10 12 14
//  1 8  2  2
    vector<int> dist(m-1,0);
    REP(i,m-1) dist[i]=X[i+1]-X[i];
    sort(ALL(dist));
    int ans = 0;
    for(int i=0; i<m-1-(n-1); i++)
        ans+=dist[i];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <cassert>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;

const long long MOD = 1000000007;
const long long INF = 1LL << 60;
const int INT_INF = 1000000000;

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

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll A, B, C, K;
  cin >> A >> B >> C >> K;
  ll ans = min(A, K) - (max(0LL, K - (A + B)));
  cout << ans << endl;
  return 0;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, s, e) for (int i = (int)(s); i < (int)(e); i++)
#define _rep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define _REP(i, e, s) for (int i = (int)(e - 1); i >= (int)(s); i--)

#define yes cout << "yes" << endl;
#define Yes cout << "Yes" << endl;
#define YES cout << "YES" << endl;

#define no cout << "no" << endl;
#define No cout << "No" << endl;
#define NO cout << "NO" << endl;

#define AC cout << "AC" << endl;
#define WA cout << "WA" << endl;

#define out(s) cout << s << endl;

#define ll long long
#define ull unsigned long long

const unsigned int BIT_FLAG_0 = (1 << 0);  // 0000 0000 0000 0001
const unsigned int BIT_FLAG_1 = (1 << 1);  // 0000 0000 0000 0010
const unsigned int BIT_FLAG_2 = (1 << 2);  // 0000 0000 0000 0100
const unsigned int BIT_FLAG_3 = (1 << 3);  // 0000 0000 0000 1000
const unsigned int BIT_FLAG_4 = (1 << 4);  // 0000 0000 0001 0000
const unsigned int BIT_FLAG_5 = (1 << 5);  // 0000 0000 0010 0000
const unsigned int BIT_FLAG_6 = (1 << 6);  // 0000 0000 0100 0000
const unsigned int BIT_FLAG_7 = (1 << 7);  // 0000 0000 1000 0000

const double PI = 3.14159265358979323846;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

unsigned GetDigit(ull num) {
    return log10(num);
}

void nextPernutationPrint(const vector<int>& v) {
    for_each(v.begin(), v.end(), [](int x) { cout << x << " "; });
    cout << endl;
}

int main() {
    int N = 3, ans;
    string A, S = "";
    cin >> A;

    for (int bit = 0; bit < (1 << N); bit++) {
        S = A[0];
        ans = A[0] - '0';
        for (int i = 0; i < N; i++) {
            if (!(bit & (1 << i))) {
                S += '+';
                S += A[i + 1];
                ans += A[i + 1] - '0';
            } else {
                S += '-';
                S += A[i + 1];
                ans -= A[i + 1] - '0';
            }
        }

        if (ans == 7) {
            cout << S << "=7" << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 3672
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;

int main(){
	int a,b,c,d;
	cin >>a>>b>>c>>d;
	set<int> t;
	t.insert(a);
	t.insert(b);
	t.insert(c);
	t.insert(d);
	if (t.count(1)&&t.count(9)&&t.count(7)&&t.count(4))
		cout <<"YES"<<endl;
	else
		cout<< "NO"<<endl;

}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <functional>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <limits>

using namespace std;

#define ll long long

#define in(x) cin >> x
#define out(x) cout << x << endl

#define PI acos(-1)
#define pp push_back

#define Yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define No cout << "No" << endl
#define NO cout << "NO" << endl

#define vec2(type) vector<vector<type>>
#define vec3(type) vector<vector<vector<type>>>

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

template<typename T> void input(T *data, int n){
	For(i, n){
		cin >> data[i];
	}
}

template<typename T> void input(vector<T> &vec, int n){
	T temp;
	For(i, n){
		cin >> temp;
		vec.push_back(temp);
	}
}

template<typename T> void sort(vector<T> &ary){
	sort(ary.begin(), ary.end());
}

template<typename T> void rsort(vector<T> &ary){
	sort(ary.rbegin(), ary.rend());
}

void rstring(string &str){
	string temp = str;

	For(i, (int)str.size()){
		str[i] = temp[(str.size() - 1) - i];
	}
}

struct Vec{
	int x, y;
	Vec():
	x(0), y(0){}
	Vec(int _x, int _y):
	x(_x), y(_y){}
};

template<typename T> void print(T *x, int n){
	For(i, n){
		cout << x[i] << " ";
	}
	cout << endl;
}

template<typename T> void print(vector<T> &x){
	For(i, (int)x.size()){
		cout << x[i] << " ";
	}
	cout << endl;
}

int gcd(int n, int m){
	if(n % m == 0){
		return m;
	}
	else{
		return gcd(m, n % m);
	}
}

unsigned ll func(unsigned ll n, unsigned ll i){

	n++;
	if(n >> i == 0){
		return 0;
	}
	unsigned ll num_one = (n / (2 << i)) * (1 << i);

	if((n % (2 << i)) != 0 && (n % (2 << i)) - (1 << i) > 0){
		num_one += (n % (2 << i)) - (1 << i);
	}

	return num_one;

}

int main(){

	int n ,k;
	cin >> n >> k;	

	out(n - k + 1);

	return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fastIO ios::sync_with_stdio(0), cin.tie(0)
#define endl '\n'
#define ft first
#define sd second
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<char,char> pcc;
typedef pair<long long,int> pll;

int main(){
    #ifndef LOCAL
        fastIO;
    #endif
    int n,mod;
  	cin >> n;
  	mod=n%10;
  	if(mod==3) cout << "bon" << endl;
  	else if(mod==0 || mod==1 || mod==6 || mod==8) cout << "pon" << endl;
  	else cout << "hon" << endl;
    return 0;
}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

#define rep(i, n) for (int i = 0; i < n; ++i)
#pragma region Debug
template <typename T>
void view(const std::vector<T> &v)
{
    for (const auto &e : v)
    {
        std::cout << e << " ";
    }
    std::cout << std::endl;
}
template <typename T>
void view(const std::vector<std::vector<T>> &vv)
{
    for (const auto &v : vv)
    {
        view(v);
    }
}
#pragma endregion

vector<ll> c;
vector<vector<int>> t;
vector<int> a;
vector<int> d;

void dfs(int v, int x, int dp, int p = -1)
{
    if (d[v] > 0 && d[v] < dp)
    {
        return;
    }
    d[v] = dp;
    x += a[v];
    c[v] += x;
    for (auto nv : t[v])
    {
        if (nv == p)
        {
            continue;
        }
        dfs(nv, x, dp + 1, v);
    }
}

int main()
{
    int n, q;
    cin >> n >> q;
    t = vector<vector<int>>(n, vector<int>());
    c = vector<ll>(n, 0);
    d = vector<int>(n);

    rep(i, n - 1)
    {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        t[a].emplace_back(b);
        t[b].emplace_back(a);
    }

    a = vector<int>(n, 0);
    rep(j, q)
    {
        int p, x;
        cin >> p >> x;
        p--;
        a[p] += x;
    }

    dfs(0, 0, 1);

    view(c);

    return 0;
}

Measured memory_bytes: 28928
package main

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

var (
	readString func() string
	readBytes  func() []byte
	stdout     *bufio.Writer
)

func init() {
	readString, readBytes = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		return []byte(f1())
	}
	return f1, f2
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

func eprintf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(os.Stderr, f, args...)
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func min64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func max64(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func abs64(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

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

func gcd64(a, b int64) int64 {
	if b == 0 {
		return a
	}
	return gcd64(b, a%b)
}

// readString() string
// readInt() int
// readInt64() int64
// readFloat64() float64

// -----------------------------------------------------------------------------

func main() {
	defer stdout.Flush()
	S := readBytes()
	p := byte('_')
	for _, b := range S {
		if p == b {
			println("Bad")
			return
		}
		p = b
	}
	println("Good")
}

// -----------------------------------------------------------------------------


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI (3.1415926535897932384)

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}

template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>void tf(bool b,S t,T f){if(b)puta(t);else puta(f);}
void YN(bool b){tf(b,"YES","NO");}
void Yn(bool b){tf(b,"Yes","No");}
void yn(bool b){tf(b,"yes","no");}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1;for(auto s:t){os<<(a?"":" ")<<s;a=0;}return os;}
template<class S>auto&operator>>(istream&is,vector<S>&t){for(S&a:t)cin>>a;return is;}

/*他のライブラリを入れる場所*/


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n;
	cin>>n;
	vl a(n);
	cin>>a;
	sort(rall(a));
	vector<pll> ap;
	range(i,1,n-1){
		if(a[i]>=0){
			ap.emplace_back(a.back(),a[i]);
			a.back()-=a[i];
		}else{
			ap.emplace_back(a.front(),a[i]);
			a.front()-=a[i];
		}
	}
	ap.emplace_back(a.front(),a.back());
	a.front()-=a.back();
	puta(a.front());
	for(auto&p:ap)puta(p.fs,p.sc);
	return 0;
}

Measured memory_bytes: 4336
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long int lli;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    lli n;
    cin>>n;
    cout<<(1000 - (n%1000))%1000;
    return 0;
}

Measured memory_bytes: 3644
#include <iostream>

using namespace std;

int main() {
    int i, j, k, n, m, l;
    int a[100][100] = {};
    int b[100][100] = {};
    long long c[100][100] = {};

    cin >> n >> m >> l;

    for (i = 0; i < n; i++) {
        for (j = 0; j < m; j++) {
            cin >> a[i][j];
        }
    }

    for (i = 0; i < m; i++) {
        for (j = 0; j < l; j++) {
            cin >> b[i][j];
        }
    }

    for (i = 0; i < n; i++) {
        for (j = 0; j < l; j++) {
            for (k = 0; k < m; k++) {
                c[i][j] += a[i][k] * b[k][j];
            }
            cout << c[i][j];
            if (j != l - 1) cout << " ";
        }
        cout << endl;
    }


    return 0;
}


Measured memory_bytes: 3260
#include <iostream>
#include <math.h>
#define ll long long int
using namespace std;

int main(){
    int N;
    cin >> N;
    int a[110];
    int min=100;
    int max=-100;
    for(int i=0;i<N;++i){
        cin >> a[i];
        if(a[i] > max) max = a[i];
        if(a[i] < min) min = a[i];
    }

    ll ans=__LONG_LONG_MAX__;
    for(int j=min; j<= max; j++){
        ll cost = 0;
        for(int i=0; i<N; i++){
            cost += pow(j-a[i],2);
        }
        if(ans >= cost){
            ans = cost;
        }
    }
    cout << ans <<endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <string>
#include <cstdio>
#include <cmath>
#include <sstream>
#include <algorithm>

using namespace std;

int main() {
	int N, P;
	cin >> N >> P;
	int n2 = 0;

	for (int i = 0; i < N; i++) {
		int t;
		cin >> t;
		if (t % 2 == 0) n2++;
	}
	long long int p2 = pow(2,N);
	if (n2 == N) {
		if (P == 0) {
			cout << p2 << endl;
		}
		else {
			cout << 0 << endl;
		}
	}
	else {
		cout << p2 / 2 << endl;
	}


}


Measured memory_bytes: 256
#include <cmath>

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

using ll = long long;
using ld = long double;
using vi = vector<int>;

int a;
int b;
int c;

void input() {
  cin >> a >> b >> c;
}

void solve() {
  swap(a, b);
  swap(a, c);

  cout << a << ' ' << b << ' ' << c << '\n';
}

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

  cout.precision(16);
  cout << fixed;

  int _times = 1;

#ifdef _DEBUG
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);

  _times = 3;
#endif

  // cin >> _times;

  while (_times--) {
    input();
    solve();
  }
}


Measured memory_bytes: 3560
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<cstdio>
#include<queue>
using namespace std;
typedef pair<int,int> ii;
typedef long long ll;
const int INF=1e9;

ll gcd(ll x,ll y){
    if(y==0) return 0;
    return gcd(y,x%y);
}

int main(){
    int x,y;cin>>x>>y;
    int ans=0;
    if(x>=0){
        if(y>=x) ans=y-x;
        else if(0<y&&y<x) ans=1+(x-y)+1;
        else if(-x<y&&y<=0) ans=1+x+y;
        else ans=-y-x+1;
    }else{
        if(y<=x) ans=1+(x-y)+1;
        else if(x<y&&y<=0) ans=y-x;
        else if(0<y&&y<=-x) ans=(-y-x)+1;
        else ans=1+y+x;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long lef=2,rig=2;
int n,ans[100010];
int main()
{
	cin>>n;
	for(int i=1; i<=n; i++)
	{
		cin>>ans[i];
	}
	for(int i=n; i>=1; i--)
	{
		lef=((lef-1)/ans[i]+1)*ans[i];
		rig=rig/ans[i]*ans[i]+ans[i]-1;
	}
	if(lef>rig)cout<<-1;
	else cout<<lef<<" "<<rig;
	return 0;
}

Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;
#define ll long long
vector<int>dp(100001);
int n ,m,x,y;
int vis[100001]={0};
vector<int>g[100001];
void solve(int vertex)
{
    vis[vertex]=1;
    dp[vertex]=0;
    for(int child:g[vertex])
    {
        if(!vis[child])
        {
            solve(child);
        }
       dp[vertex]=max(dp[vertex],1+dp[child]);
    }

}
int main()
{
    cin>>n>>m;
    for(ll i=0;i<m;i++)
    {
        cin>>x>>y;
        g[x].push_back(y);
    }
    for(ll i=1;i<=n;i++)
    {
        if(!vis[i])
        {
          solve(i);
        }
    }
    int ans=0;
   for(int i=1;i<=n;i++)
   {
       ans=max(ans,dp[i]);
   }
   cout<<ans;
}


Measured memory_bytes: 12232
#include <iostream>
#include <iomanip>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define sz(c) ((int)(c).size())

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
//typedef pair<int, int> P;
//typedef pair<int, pair<int, int> > PP;
//const int MAX=;
int main(){
	int N;
	cin>>N;
	int ct[100];
  	rep(i,100)ct[i]=0;
	rep(_,N){
		int a;
		cin>>a;
		ct[a]++;
	}
	int l=1,r=99;
	while(true){
		if(ct[l]>0)break;
		l++;
	}
	while(true){
		if(ct[r]>0)break;
		r--;
	}
	
  	bool ans=true;
	if(r==2*l){
      	if(ct[l]!=1)ans=false;
		for(int i=l+1; i<=r; i++)if(ct[i]<2)ans=false;
	}
	else if(r==2*l-1){
		if(ct[l]!=2)ans=false;
		for(int i=l+1; i<=r; i++)if(ct[i]<2)ans=false;
	}
	else ans=false;
  
	if(ans)cout<<"Possible";
	else cout<<"Impossible";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD=1e9+7;

int main() {
  int n;
  cin>>n;
  set<int> A;
  rep(i,n){
    int a;
    cin>>a;
    if(A.count(a)!=0) A.erase(a);
    else A.insert(a);
  }
  
  cout<<A.size()<<endl;
}

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

c_list = [s for s in input()]
back = N - 1


def check(forward):
    global back
    for i in range(back, -1, -1):
        if i < forward:
            return -1
        if c_list[i] == "R":
            back = i - 1
            return i
    return -1


count = 0
for i, c in enumerate(c_list):
    if c_list[i] == "W":
        temp = check(i + 1)
        if temp != -1:
            c_list[i] = "R"
            c_list[temp] = "W"
            count += 1
        else:
            break
print(count)

Measured memory_bytes: 87284
#include<stdio.h>

int main(void) {
	int r, c,i,j,sum,total=0;
	int element[101][101];

	scanf("%d %d", &r, &c);

	
	for (i = 1; i <= r; i++) {
		for (j = 1; j <= c; j++) {
			scanf("%d",&element[i][j]);
		}
	}

	for (i = 1; i <= r; i++) {
		sum = 0;
		for (j = 1; j <= c; j++)sum += element[i][j];
		element[i][0] = sum;
		total += sum;
	}

	for (j = 1; j <= c; j++) {
			sum = 0;
		for (i = 1; i <= r; i++) sum += element[i][j];
		element[0][j] = sum;
	}
	
	for (i = 1; i <= r ; i++) {
		for (j = 1; j <= c; j++) {
			printf("%d ", element[i][j]);	
		}
		printf("%d\n", element[i][0]);
	}

	for (j = 1; j <= c; j++) {
		printf("%d ", element[0][j]);
	}
	printf("%d\n", total);

	return 0;
}


Measured memory_bytes: 2708
#include<cstdio>
#include<cstdlib>
#include<string>
#include<iostream>
using namespace std;

struct Node{
  int key;
  Node *right,*left,*parent;
};

Node *root,*NIL;

Node *find(Node *u,int k){
  while(u!=NIL && k!= u->key){
    if(k < u->key)u=u->left;
    else u=u->right;
  }
  return u;
}

void insert(int k){
  Node *y=NIL;
  Node *x=root;
  Node *z;
  
  z=(Node *)malloc(sizeof(Node));
  z->key=k;
  z->left=NIL;
  z->right=NIL;
  
  while(x!=NIL){
    y=x;
    if(z->key <x->key){
      x=x->left;
    }else{
      x=x->right;
    }
  }
  z->parent=y;
  if(y==NIL){
    root=z;
  }else{
    if(z->key<y->key){
      y->left=z;
    }else{
      y->right=z;
    }
  }
}

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

int main(){
  int n,i,x;
  string com;
  
  scanf("%d",&n);
  
  for(i=0;i<n;i++){
    cin >> com;
    if(com[0]=='f'){
      scanf("%d",&x);
      Node*t=find(root,x);
      if(t!=NIL)printf("yes\n");
      else printf("no\n");
    }else if(com=="insert"){
      scanf("%d",&x);
      insert(x);
    }else if(com=="print"){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }
  return 0;
}



Measured memory_bytes: 22020
fun main(args: Array<String>?): Unit {
    val mod = 1000000007L
    val (n, m) = readLine()!!.trim().split(' ').map(String::toInt)
    val stripes = readLine()!!.trim().split(' ').map(String::toLong).toLongArray()
    val borders = readLine()!!.trim().split(' ').map(String::toLong).toLongArray()
    var xSum = 0L
    for (i in stripes.indices.drop(1)) {
        xSum += stripes[i] * i % mod - stripes[i - 1]
        stripes[i] += stripes[i - 1] % mod
        xSum %= mod
    }
    var ySum = 0L
    for (i in borders.indices.drop(1)) {
        ySum += borders[i] * i % mod - borders[i - 1]
        borders[i] += borders[i - 1] % mod
        ySum %= mod
    }
    println((xSum * ySum % mod + mod) % mod)
}


Measured memory_bytes: 84628
package main

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

var bufin *bufio.Reader
var bufout *bufio.Writer

func main() {
	bufin = bufio.NewReader(os.Stdin)
	bufout = bufio.NewWriter(os.Stdout)
	defer bufout.Flush()
	var N int
	var T int64
	fmt.Fscanf(bufin, "%d %d\n", &N, &T)
	if N == 1 {
		fmt.Fprintf(bufout, "%d\n", 0)
		return
	}
	var nums = make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Fscanf(bufin, "%d\n", &nums[i])
	}
	var maxv = make([]int, N)
	var maxi = make([]int, N)
	maxv[N-1] = 0
	maxi[N-1] = -1
	for i := N - 2; i >= 0; i-- {
		if nums[i+1] > maxv[i+1] {
			maxv[i] = nums[i+1]
			maxi[i] = i + 1
		} else {
			maxv[i] = maxv[i+1]
			maxi[i] = maxi[i+1]
		}
	}
	var memo = make(map[int64][]int)
	var maxQ int64 = 0
	for i := N - 2; i >= 0; i-- {
		memo[T*int64(maxv[i]-nums[i])] = append(memo[T*int64(maxv[i]-nums[i])], maxi[i])
		if maxQ < T*int64(maxv[i]-nums[i]) {
			maxQ = T * int64(maxv[i]-nums[i])
		}
	}

	fmt.Fprintf(bufout, "%d\n", len(memo[maxQ]))
}


Measured memory_bytes: 14464
import java.util.*;
import java.io.*;

public class Main{
	public static void main(String args[]) throws IOException{
		BufferedReader br = new BufferedReader(
				new InputStreamReader(System.in));
		int N = Integer.parseInt(br.readLine());
		int result = 0;
		ArrayList<Integer> data = new ArrayList<>();
		String str = br.readLine();
		String L[] = str.split(" ",0);
		for(int i = 0; i < 2*N; i++){
			data.add(Integer.parseInt(L[i]));
		}
		Collections.sort(data);
		for(int i = 0; i < 2*N; i= i+2){
			result += data.get(i);
		}
		System.out.println(result);
	
	}
}

Measured memory_bytes: 8020
#include <stdio.h>
#include <stdlib.h>
 
#include <iostream>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <stdint.h>
#include <string.h>
 
//#define _USE_MATH_DEFINES
//#include <math.h>
 
#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <deque>
#include <string>
 
#include <algorithm>
#include <functional>
#include <bitset>
#include <functional>
#include <chrono>
#include <random>
#define sqr(x) (x) * (x)
 
typedef unsigned int u32;
typedef int i32;
typedef unsigned long long int u64;
typedef long long int i64;
typedef uint16_t u16;
typedef int16_t i16;
typedef uint8_t u8;
typedef int8_t i8;
 
using namespace std;
using namespace std::chrono;
 
//const i64 mod = 1000000007ll;
const i64 smod = 998244353ll;
const i64 inf = 10000000000000007ll;
 
const double eps = 1e-8;
 
const i64 MAXN = 1'000'000 + 6;
 
i64 n;
 
int main(int argc, char* argv[]) {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.precision(15); cout.setf(ios::fixed);
 
    cin >> n;
    while (n) {
        if (n % 10 == 7) {
            cout << "Yes" << endl;
            return 0;
        }
        n /= 10;
    }
    cout << "No" << endl;
 
    return 0;
}

Measured memory_bytes: 3132