akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define int long long
const int MOD=1e9+7;
 
pair<int,int>p;

bool kaibun(string S){
    if(S.size()==1)return true;
  	for(int i=0;i<=S.size()/2;i++){
        if(S[i]!=S[S.size()-1-i])return false;
    }
    return true;
}

signed main(){
    string S;cin>>S;
    string Z="";
    bool ok=true;
    REP(i,S.size()){
        if(S[i]!='x')Z+=S[i];
    }
    ok=kaibun(Z);
    if(ok){
        int b=0;
        int count=0;
        vector<int>vec(Z.size()+1,0);
        for(int i=0;i<=S.size();i++){
            if(S[i]=='x')b++;
            else{
                vec[count]=b;
                b=0;
                count++;
            }
          	if(i==S.size()&&b!=0){
				vec[count]=b;
            }
        }
        int ans=0;
        for(int i=0;i<(Z.size()+1)/2;i++){
            ans+=abs(vec[i]-vec[Z.size()-i]);
        }
        cout<<ans<<endl;
    }
    else cout<<-1<<endl;
}

Measured memory_bytes: 1408
#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i, n) for(int i=(n); i>=0; --i)
#define FOR(i, n, m) for(int i=(m), i##_len=(n); i<i##_len; ++i)
#define EACH(i, v) for(const auto& i : v)
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class Value>using vec = vector< Value >;
using ll = long long;
using P = pair< long long, long long >;
#define fi first
#define se second
#define el endl
#pragma endregion


void Main();
void solve(long long A, long long B);

int main(){
    std::cin.tie(nullptr);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}

void Main(){
    ll N;
    cin >> N;
    long double cc = N/1.08;
    ll N_n = ceil(cc);
    ll m = N_n*1.08;
    if(m == N){
        cout << N_n << el;
    }else{
        cout << ":(" << el;
    }
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
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 rd(long long &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 N;
int A[200000];
long long K;
int ls[200001];
int nx[200000];
int p[200000];
int res[200000];
int ress;
int main(){
  int i, j, k;
  rd(N);
  rd(K);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=0;Lj4PdHRW<N;Lj4PdHRW++){
      rd(A[Lj4PdHRW]);
    }
  }
  for(i=N-1;i>=0;i--){
    ls[A[i]] = N+i;
  }
  for(i=N-1;i>=0;i--){
    nx[i] = ls[A[i]] + 1;
    while(nx[i] >= N){
      nx[i] -= N;
      p[i]++;
    }
    ls[A[i]] = i;
  }
  i = k = 0;
  for(;;){
    k += p[i];
    i = nx[i];
    if(i==0){
      break;
    }
  }
  K %= k;
  i = 0;
  while(K){
    if(K-p[i] < 0 || (K-p[i] == 0 && nx[i] > 0)){
      res[ress++] = A[i];
      i++;
      if(i==N){
        K--;
        i=0;
      }
      continue;
    }
    K -= p[i];
    i = nx[i];
  }
  {
    int KL2GvlyY;
    if(ress==0){
      putchar_unlocked('\n');
    }
    else{
      for(KL2GvlyY=0;KL2GvlyY<ress-1;KL2GvlyY++){
        wt_L(res[KL2GvlyY]);
        wt_L(' ');
      }
      wt_L(res[KL2GvlyY]);
      wt_L('\n');
    }
  }
  return 0;
}
// cLay varsion 20190721-1

// --- original code ---
// int N, A[2d5];
// ll K;
// 
// int ls[200001];
// int nx[2d5], p[2d5];
// 
// int res[2d5], ress;
// 
// {
//   int i, j, k;
//   rd(N,K,A(N));
// 
//   for(i=N-1;i>=0;i--) ls[A[i]] = N+i;
//   for(i=N-1;i>=0;i--){
//     nx[i] = ls[A[i]] + 1;
//     while(nx[i] >= N) nx[i] -= N, p[i]++;
//     ls[A[i]] = i;
//   }
// 
//   i = k = 0;
//   for(;;){
//     k += p[i];
//     i = nx[i];
//     if(i==0) break;
//   }
// 
//   K %= k;
// 
//   i = 0;
//   while(K){
//     if(K-p[i] < 0 || (K-p[i] == 0 && nx[i] > 0)){
//       res[ress++] = A[i];
//       i++;
//       if(i==N) K--, i=0;
//       continue;
//     }
// 
//     K -= p[i];
//     i = nx[i];
//   }
// 
//   wt(res(ress));
// }


Measured memory_bytes: 5376
import java.util.Arrays;
import java.util.Scanner;

public class Main {

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

		int N = sc.nextInt();
		int X = sc.nextInt();

		int[] unko = new int[N];

		int sum =0;

		for(int i=0;i<N;i++) {
			unko[i] = sc.nextInt();
			sum += unko[i];
		}

		Arrays.sort(unko);

		int result = N;

		int nokori = X - sum;

		result += ( nokori / unko[0]);

		System.out.println(result);
	}

}


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

#define fto(i, a, b) for (int i = a; i <= b; ++i)
#define fdto(i, a, b) for (int i = a; i >= b; --i)
#define ff first
#define ss second
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define ll long long
#define pi = 3.1415926535897
#define oo 1000000007
#define OO 1000000000000000007

using namespace std;

bool cmp (pii a, pii b) {
    return a.ff > b.ff;
}

int n;
int f[100005];
int g[100005];
int a[100005];
vector <pii> even;
vector <pii> odd;

int main() {
//    freopen("codef.inp", "r", stdin);
//    freopen("codef.out", "w", stdout);

    scanf("%d", &n);
    fto(i, 1, n) scanf("%d", &a[i]);

    fto(i, 1, n) {
        if (i%2) {
            if (!f[a[i]]) odd.pb(mp(1, a[i]));
            ++f[a[i]];
        }
        else {
            if (!g[a[i]]) even.pb(mp(1, a[i]));
            ++g[a[i]];

        }
    }

    if (odd.size() == 1 && even.size() == 1) {
        if (a[1] == a[2]) printf("%d\n", n/2);
        if (a[1] != a[2]) printf("%d\n", 0);
    }
    else {

        fto(i, 0, (int) odd.size()-1) {
            odd[i].ff = f[odd[i].ss];
        }

        fto(i, 0, (int) even.size()-1) {
            even[i].ff = g[even[i].ss];
        }
        sort(odd.begin(), odd.end(), cmp);
        sort(even.begin(), even.end(), cmp);

        int res;
        if (odd.size() == 1) {
            if (odd[0].ss == even[0].ss) res = n/2-even[1].ff;
            else res = n/2-even[0].ff;
        }

        if (even.size() == 1) {
            if (odd[0].ss == even[0].ss) res = n/2-odd[1].ff;
            else res = n/2-odd[0].ff;
        }

        if (even.size() != 1 && odd.size() != 1) {
            res = n-odd[0].ff-even[0].ff;
            if (odd[0].ss == even[0].ss)
                res = min(n-odd[0].ff-even[1].ff, n-odd[1].ff-even[0].ff);
        }
        printf("%d\n", res);
    }


    return 0;
}



Measured memory_bytes: 2428
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

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

		while (true) {
			final int n = sc.nextInt();

			if(n == 0){
				break;
			}
			
			int[] arr = new int[n];
			long sum = 0;
			for (int i = 0; i < n; i++) {
				arr[i] = sc.nextInt();
				sum += arr[i];
			}

			double sigma = 0;
			for (int i = 0; i < n; i++) {
				sigma += (arr[i] - (sum / (double) (n))) * ((arr[i] - (sum / (double) (n))));
			}
			sigma /= (double) (n);

			System.out.printf("%.7f\n", Math.sqrt(sigma));
		}

	}
}

Measured memory_bytes: 23880
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int n,m;
string s[101];
inline bool cmp(string a,string b){
	return a+b<b+a;
}
int main(void){
	register int i;
	 std::ios::sync_with_stdio(0);
	cin>>n>>m;
	for(i=1;i<=n;++i)
		cin>>s[i];
	sort(s+1,s+n+1);
	for(i=1;i<=n;++i)
		cout<<s[i];
	return 0;
}

Measured memory_bytes: 256
from bisect import bisect
N, *A = map(int, open(0).read().split())

INF = 10 ** 9 + 7
dp = [INF] * (N + 1)
for i in range(N):
    dp[bisect(dp, -A[i])] = -A[i]

print(sum(dp[i] < INF for i in range(N)))

Measured memory_bytes: 71356
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long
#define db double
#define ld long double
#define rep(i,n) for(ll i=0;i<n;i++)
#define rev(i,n) for(ll i=n;i>=0;i--)
#define rep_a(i,a,n) for(ll i=a;i<n;i++)
#define pb push_back
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
#define debug(x) do { std::cerr << #x << ": " << x << std::endl; } while (0);
#define debugg(x,y) do { std::cerr << #x << ": " << x << "  "<< #y << ": " << y << std::endl; } while (0);
#define debugggg(i,j,k,ans) std::cerr << #i << ": " << i << "  "<< #j << ": " << j <<#k << ": " << k <<#ans << ": " << ans << std::endl;
const long long mod = 998244353;
const long long MOD = 1000000007;

typedef vector<ll>              vll;
typedef vector<string>          vstr;
typedef vector<char>            vchar;
typedef vector<pair<ll,ll> >    vpll;
typedef set<ll>                 sll;
typedef set<string>             sstr;
typedef set<pair<ll,ll> >       spll;
typedef map<ll,ll>              mllll;
typedef map<string,ll>          mstrll;
typedef queue<ll>               qll;
ll solve()
{
  ll x;cin>>x;
  ll k;cin>>k;
  ll d;cin>>d;
  ll ans = 0;
  x = abs(x);
  if (x / d < k) {
		ll rest = k - x / d;
		if (rest % 2 == 0) ans = x % d;
		else ans = d - x % d;
	} else {
		ans = x - d * k;
	}
  return ans;
  
}
 
int main()
{
  fast;
	// #ifndef ONLINE_JUDGE
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	// #else
	// #endif
	cout<<solve()<<endl;;
	// #ifndef ONLINE_JUDGE
	// cout<<"\nTime Elapsed: "<<1.0*clock()/ CLOCKS_PER_SEC <<" Sec\n";
	// #endif
	return 0;
}

Measured memory_bytes: 3656
#include<stdio.h>
#include<string.h>
int N,L[11][2],l[11][2],t[11][2],i,j,k,M,m;
int R[4][2]={{1,1},{-1,1},{1,-1},{-1,-1}};

int c(int (*s)[2],int rx,int ry,int d)
{
	int i=0,j=0;
	if(d)
		for(i=0;i<M&&L[i][0]==s[i][0]*rx&&L[i][1]==s[i][1]*ry;i++);
	else
		for(j=0;j<M&&L[j][0]==s[j][1]*rx&&L[j][1]==s[j][0]*ry;j++);
	return i==M||j==M;
}


int main()
{
	for(;scanf("%d",&N),N;)
	{
		for(i=0;i<=N;i++)
		{
			if(i==0)
			{
				scanf("%d",&M);
				for(j=0;j<M;j++)
				{
					scanf("%d%d",&L[j][0],&L[j][1]);
					if(j>0)
					{
						L[j][0]-=L[0][0];
						L[j][1]-=L[0][1];
					}
				}
				L[0][0]=L[0][1]=0;
			}
			else
			{
				scanf("%d",&m);
				for(j=0;j<m;j++)
				{
					scanf("%d%d",&l[j][0],&l[j][1]);
					t[m-j-1][0]=l[j][0];
					t[m-j-1][1]=l[j][1];
				}
				for(j=1;j<m;j++)
				{
					l[j][0]-=l[0][0];
					l[j][1]-=l[0][1];
					t[j][0]-=t[0][0];
					t[j][1]-=t[0][1];
				}
				l[0][0]=l[0][1]=t[0][0]=t[0][1]=0;
				if(M==m)
				{
					if(c(l,1,1,1)||c(l,-1,1,0)||c(l,1,-1,0)||c(l,-1,-1,1)||c(t,1,1,1)||c(t,-1,1,0)||c(t,1,-1,0)||c(t,-1,-1,1))
					{
						printf("%d\n",i);
					}
				}
			}
		}
		puts("+++++");
	}
	return 0;
}

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

int main() {
    int sec, h, m, s;
    cin >> sec;
    s = sec % 60;
    m = (sec - s) / 60 % 60;
    h = (sec - s) / 3600;
    cout << h << ":" << m << ":" << s << endl;
    return 0;
}


Measured memory_bytes: 3116
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
#include <numeric>
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define CST(x) cout<<fixed<<setprecision(x)//小数点以下の桁数指定
#define ct(a) cout<<a<<endl
static const double pi = 3.141592653589793;
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1e9+7;
const ll mod=998244353;

vector<ll> k(200005);//kの階乗
vector<ll> f(200005);//kの逆元
// nCk = k[n]*f[n-k]*f[k]

ll mod_pow(ll x, ll n) {
	if (n == 0) return 1;
	ll res = mod_pow(x*x % mod, n / 2);
	if (n & 1) res = res * x % mod;
	return res;
}

void comb_init(void) {
	ll cur = 1;
	k[0] = f[0] = 1;
	FOR(i, 1, 200001) {
		cur = (cur * i) % mod;
		k[i] = cur;
		f[i] = mod_pow(cur, mod - 2);
	}
}

ll combination(ll n, ll s) {
	ll ret = (((k[n] * f[n - s]) % mod) * f[s]) % mod;
	return ret;
}

ll ans;

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

	comb_init();

	ll N, M,K; cin >> N >> M>>K;
	FOR(k, 0, K+1) {
		ans = (ans + ((M * mod_pow(M - 1, N - 1 - k))%mod*combination(N - 1, k))%mod)%mod;
	}
	cout << (ans + mod) % mod << endl;


	return 0;
}

Measured memory_bytes: 5812
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <numeric>
#include <cstdlib>
#include <map>
#include <set>
#include <algorithm>
#include <math.h>
 
using namespace std;

int main() {
    int N;
    string S;
    cin >> N >> S;

    int sum = 0;

    for(int i = 0; i < N-2; i++){
        if(S.substr(i,3) == "ABC"){
            sum++;
        }
    }

    cout << sum << endl;

    return 0;
}

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

using namespace std;

int main()
{
    int n,k=0;
    cin>>n;
    for(int d=1;d<=9;d++)
    {
        for(int i=1;i<=9;i++)
        {
            if(n==d*i)
            {
                k=1;
                cout<<"Yes";
                return 0;
            }
        }
    }
    if(k==0)
        cout<<"No";
    return 0;
}


Measured memory_bytes: 256
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
a = inpl()
d = defaultdict(int)
for i,x in enumerate(a):
    d[i+1-x] += 1
res = 0
for i,x in enumerate(a):
    res += d[i+1+x]
print(res)

Measured memory_bytes: 62624
#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
#include <sstream>

#include <memory>
#include <string>
#include <vector>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <deque>
#include <algorithm>
#include <random>
#include <iomanip>
using namespace std;

int main(int argc, char *argv[]) {
	int n, m;
	string s;
	cin >> n >> m >> s;
	int c = 0;
	for (auto ss : s) {
		if (ss == '1') {
			c++;
			if (c >= m) {
				cout << -1 << endl;
				return 0;
			}
		}
		else {
			c = 0;
		}
	}
	reverse(s.begin(), s.end());
	vector<int> res;
	int index = 0;
	while (index < s.size() - 1) {
		for (int i = index + m; i > index; i--) {
			if (i >= s.size()) continue;
			if (s[i] == '0') {
				
				res.push_back(i - index);
				index = i;
				break;
			}
		}
	}
	reverse(res.begin(), res.end());
	for (auto vv : res)
		cout << vv << " ";
}


Measured memory_bytes: 1144
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define fs first
#define sc second
typedef pair<ll, ll> l_l;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
int n,m;
string b[60],p[60];
bool match(int x,int y){
  rep(i,m){
    rep(j,m){
      if(b[x+i][y+j]!=p[i][j])return false;
    }
  }
  return true;
}
int main(){
  cin>>n>>m;
  rep(i,n)cin>>b[i];
  rep(i,m)cin>>p[i];
  bool f=false;
  for(int i=0;i<=n-m;i++){
    for(int j=0;j<=n-m;j++){
  if(match(i,j))f=true;
    }
  }
  cout<<(f?"Yes":"No")<<endl;
}

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

int main(){
    string str;
    unsigned int N;
    unsigned int num_of_hug = 0;
    cin >> str;
    N = str.size();
    for(unsigned int i=0;i<N/2;i++){
        if(str[i] != str[N-1-i]){
            num_of_hug++;
        }
    }
    
    cout << num_of_hug << endl;
            
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll,lvector,greater<ll>>
#define P pair<ll,ll>
#define ALL(a) (a).begin(),(a).end()
#define rep(i,n) for(ll (i)=0; (i)<(n); ++(i))
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,a,b;cin>>n;
  lvector p(n,0),q(n,0),v(n,0);
  rep(i,n) cin>>p[i];rep(i,n) cin>>q[i];rep(i,n) v[i]=i+1;
  set<lvector> st;
  do {
    st.insert(v);
  }
  while(next_permutation(ALL(v)));
  ll cnt=0;
  for(lvector e:st) {
    if(e==p) a=cnt;
    if(e==q) b=cnt;
    cnt++;
  }
  print(abs(a-b));
  return 0;
}

Measured memory_bytes: 5888
N, K = [int(x) for x in input().split()]
MOD = 10**9 + 7
tmp = N+1
c = N - K + 1
fact = [1] * tmp
for i in range(1, tmp):
    fact[i] = fact[i-1] * i
for i in range(1, K+1):
    print((fact[c]//(fact[c-i]*fact[i])) * (fact[K-1]//(fact[K-i]*fact[i-1])) % MOD)


Measured memory_bytes: 45544
N, K = map(int, input().split())
lis = [[0 for i in range(K)] for j in range(N)]
for i in range(K):
    d = int(input())
    A = list(map(int, input().split()))
    for j in range(d):
        lis[A[j]-1][i] = 1

count = 0
for i in range(N):
    if all([x == 0 for x in lis[i]]) == True:
        count += 1

print(count)


Measured memory_bytes: 9112
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <cstring>
#include <iomanip>
#include <cmath>
#include <tuple>
#include <map>
#include <unordered_map>
using namespace std;
typedef long long ll;

int main(int argc, char *argv[])
{
	int k, n, i, tmp;
	int answer;
	vector<int> a;
	vector<int> diff;
	cin >> k >> n;

	for (i = 0; i < n; i++) {
		cin >> tmp;
		a.push_back(tmp);
	}

	for (i = 0; i < n - 1; i++) 
		diff.push_back(a[i + 1] - a[i]);

	diff.push_back(a[0] + k - a[n - 1]);
	sort(diff.begin(), diff.end());
	answer = 0;
	
	for (i = 0; i < diff.size() - 1; i++) 
		answer += diff[i];
	cout << answer << endl;

	return 0;
}


Measured memory_bytes: 2548
#pragma GCC optimize(2)
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using PII = pair<int, int>;
using PLL = pair<LL, LL>;
const int INF = 1e9;
const int MXN = 0;
const int MXV = 0;
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define FOR(i, L, R) for (int i = L; i != (int)R; ++i)
#define FORD(i, L, R) for (int i = L; i != (int)R; --i)
#define IOS                                                                    \
    cin.tie(nullptr);                                                          \
    cout.tie(nullptr);                                                         \
    ios_base::sync_with_stdio(false);

int main()
{
    IOS;
    int n, m;
    int d[5];
    bool ok = true;
    memset(d, -1, sizeof(d));
    cin >> n >> m;
    FOR(i, 0, m)
    {
        int s, c;
        cin >> s >> c;
        if (d[s] != -1 && d[s] != c)
        {
            ok = false;
            break;
        }
        d[s] = c;
    }
    if (ok == false)
    {
        cout << "-1\n";
    }
    else if (n == 1)
    {
        cout << ((d[1] == -1) ? 0 : d[1]) << '\n';
    }
    else
    {
        if (d[1] == 0)
        {
            cout << -1 << '\n';
        }
        else
        {
            FOR(i, 1, n + 1)
            {
                if (d[i] == -1)
                {
                    cout << (i == 1 ? 1 : 0);
                }
                else
                {
                    cout << d[i];
                }
            }
            cout << '\n';
        }
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int mod=1e9+7;
const int N=4e4+5;

int main(){
ios::sync_with_stdio(0);
int k,a,b;
cin>>k>>a>>b;
if(b/k-a/k>=1||b%k==0||a%k==0)
    cout<<"OK"<<endl;
else
    cout<<"NG"<<endl;

return 0;
}

Measured memory_bytes: 3612
import java.util.*;

/**
 * Grading
 */
public class Main {

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

        out_of_loop: while (true) {
            int a = Integer.parseInt(sc.next());
            int b = Integer.parseInt(sc.next());
            int c = Integer.parseInt(sc.next());

            if (a == -1 && b == -1 && c == -1) {
                break out_of_loop;
            }

            if (a == -1 || b == -1) {
                System.out.println("F");
            } else if (a + b >= 80) {
                System.out.println("A");
            } else if (a + b >= 65) {
                System.out.println("B");
            } else if (a + b >= 50) {
                System.out.println("C");
            } else if (a + b >= 30) {
                if (c >= 50) {
                    System.out.println("C");
                } else {
                    System.out.println("D");
                }
            } else {
                System.out.println("F");
            }
        }
        sc.close();
    }
}


Measured memory_bytes: 26144
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#define int long long
#define mod 1000000007
#define for0(i, n) for(int i = 0; i < (n); i++)
#define for1(i, n) for(int i = 1; i <= (n);i++)
using namespace std;
signed main() {
	string s; cin >> s;
	if (s == "SUN")cout << "7\n";
	else if (s[0] == 'M')cout << "6\n";
	else if (s == "TUE")cout << "5\n";
	else if (s[0] == 'W')cout << "4\n";
	else if (s[1] == 'H')cout << "3\n";
	else if (s[0] == 'F')cout << "2\n";
	else if (s[1] == 'A')cout << "1\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize ("O2")
#pragma GCC optimize ("unroll-loops")
//#pragma GCC optimize("no-stack-protector,fast-math")

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef pair<ll, ll> pll;
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugp(x) cerr<<#x<<"= {"<<(x.first)<<", "<<(x.second)<<"}"<<endl;
#define debug2(x, y) cerr<<"{"<<#x<<", "<<#y<<"} = {"<<(x)<<", "<<(y)<<"}"<<endl;
#define debugv(v) cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;
#define all(x) x.begin(), x.end()
#define pb push_back
#define kill(x) return cout<<x<<'\n', 0;

const ld eps=1e-7;
const int inf=1000000010;
const ll INF=10000000000000010LL;
const int mod = 1000000007;
const int MAXN = 110, LOG=20;

int n, m, k, u, v, x, y, t, a, b, ans;
int A[MAXN];
int cnt[MAXN];

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	cin>>n;
	for (int i=1; i<=n; i++) cin>>A[i];
	sort(A+1, A+n+1);
	if (n==1) kill("Impossible")
	if (n==2){
		if (A[2]==1) kill("Possible")
		kill("Impossible")
	}
	for (int i=1; i<=n; i++) cnt[A[i]]++;
	int d=A[n];
	for (int i=0; i<=d; i++){
		if (!(cnt[max(i, d-i)]--)) kill("Impossible")
	}
	for (int i=1; i<=n; i++) if (cnt[i]){
		if (i<((d+1)/2+1) || d<i) kill("Impossible")
	}
	kill("Possible")
	
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
 
const ll MOD=1e9+7;
const ll INF=1e18;
 
int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};

int dp1[310][310];
int dp2[310];

int main(){
    int n,w[310];

    while(true){
        cin >> n;
        if(n == 0)break;
        for(int i = 0;i < 305;i++){ //初期化
            dp2[i] = 0;
            for(int j = 0;j < 305;j++){
                dp1[i][j] = 0;
            }
        }
        for(int i = 0;i < n;i++)cin >> w[i];
        for(int len = 1;len < n;len+=2){
            for(int i = 0;i+len < n;i++){
                int j = i + len;
                if(abs(w[i]-w[j]) <= 1 && (len == 1 || dp1[i+1][j-1] != 0)){
                    dp1[i][j] = dp1[i+1][j-1] + 2;
                }else{
                    for(int k = 1;i+k < j-1;k++){
                        if(dp1[i][i+k] != 0 && dp1[i+k+1][j] != 0){
                            dp1[i][j] = len+1;
                        }
                    }
                }
            }
        }
        for(int i = 1;i < n;i++){
            dp2[i] = dp1[0][i];
            for(int j = 0;j < i;j++){
                dp2[i] = max(dp2[i],dp2[j]+dp1[j+1][i]);
            }
        }
        cout << dp2[n-1] << endl;
    }
}


Measured memory_bytes: 3436
//
#include <vector>
#include <set>
#include <array>
#include <iostream>
#include <algorithm>
#include <numeric>
#include <bitset>
#include <cstdio>
#include <cstdint>
#include <cmath>
//
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);++i)
inline void yes(bool cond) { cond ? puts("Yes") : puts("No"); }
template<typename Type> inline void chmin(Type& a, Type b) { if (a > b) a = b; }
template<typename Type> inline void chmax(Type& a, Type b) { if (a < b) a = b; }
template<typename Type> inline void sort(Type& arr) { std::sort(arr.begin(), arr.end()); }
template<typename Type> inline Type nth(vector<Type>& arr, size_t pos) { std::nth_element(arr.begin(), arr.begin() + pos, arr.end()); return arr[pos]; }
constexpr ll BIGP = 1000000007L;
constexpr ll INF_I = std::numeric_limits<ll>::max();
constexpr ld INF_F = std::numeric_limits<float>::infinity();
constexpr ld PI = 3.14159265358979323846L;
//
int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    string S, T, U;
    ll A, B;
    cin >> S >> T;
    cin >> A >> B;
    cin >> U;
    //
    if (S == U) --A;
    if (T == U) --B;
    cout << A << " "<<B;

    return 0;
}

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

int main(){

 int a,b,c,d,e,f,g;
 cin>>a>>b>>c>>d>>e;

 if(b%d==0)
  f = b/d;
 else
  f = b/d+1;
 
 if(c%e==0)
  g = c/e;
 else
  g = c/e+1;
 
 if(f>=g)
  cout<<a-f<<'\n';
 else
  cout<<a-g<<'\n';

return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#include <string>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <map>
#include <bitset>
#include <cmath>
#include <set>
#include <utility>

#define INF 1000000000000
#define MOD 1000000007 //10^9+7:合同式の法

using namespace std;
typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)


int main(){
    int N,T,min=10000;
    cin >> N >> T;
    vector<int>c(N),t(N);
    bool fla = false;

    for(ll i = 0;i < N;i++){
        cin >> c.at(i) >> t.at(i);
    }

    for(ll i = 0;i < N;i++){
        if(t.at(i) <= T){
            if(min > c.at(i))
                min = c.at(i);
            fla = true;
        }
    }

    if(fla)
        cout << min << endl;
    else
        cout <<"TLE"<< endl;

}

Measured memory_bytes: 3540
#include <iostream>
#include <algorithm>
using namespace std;
using ll = long long;
 
int main() {
    ll X, K, D;
    cin >> X >> K >> D;
    X = abs(X);
 
    ll straight = min(K, X / D);
    K -= straight;
    X -= straight * D;
 
    if (K % 2 == 0) {
        cout << X << endl;
    } else {
        cout << D - X << endl;
    }
 
    return 0;
}

Measured memory_bytes: 3568
#include <bits/stdc++.h>
using namespace std;
#define forn(i, n) for(int i = 0; i < int(n); i++)
#define fore(i, l, r) for(int i = int(l); i < int(r); i++)
#define pb push_back
#define all(x) x.begin(), x.end()
#define sz(a) int((a).size())
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> pii;
const int mod = 1e9 + 7;
template<class T, class U> inline void add_self(T &a, U b){a += b;if (a >= mod) a -= mod;if (a < 0) a += mod;}
template<class T, class U> inline void min_self(T &x, U y) { if (y < x) x = y; }
template<class T, class U> inline void max_self(T &x, U y) { if (y > x) x = y; }

#define _deb(x) cout<<x;
void _print() {cerr << "]\n";} template <typename T, typename... V>void _print(T t, V... v) {_deb(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
template <class T, class U> void print_m(const map<T,U> &m, int w=3){if(m.empty()){cout<<"Empty"<<endl; return;}for(auto x: m)cout<<"("<<x.first<<": "<<x.second<<"),"<<endl;cout<<endl;}
template<class T, class U>void debp(const pair<T, U> &pr, bool end_line=1){cout<<"{"<<pr.first<<" "<<pr.second<<"}"; cout<<(end_line ? "\n" : ", ");}
template <class T> void print_vp(const T &vp, int sep_line=0){if(vp.empty()){cout<<"Empty"<<endl; return;}if(!sep_line) cout<<"{ ";for(auto x: vp) debp(x,sep_line);if(!sep_line) cout<<"}\n";cout<<endl;}
template <typename T>void print(const T &v, bool show_index = false){int w = 2;if(show_index){for(int i=0; i<sz(v); i++)cout<<setw(w)<<i<<" ";cout<<endl;}for(auto &el: v) cout<<setw(w)<<el<<" ";cout<<endl;}
template <typename T>void print_vv(const T &vv){if(sz(vv)==0) {cout<<"Empty"<<endl; return;} int w = 3;cout<<setw(w)<<" ";for(int j=0; j<sz(*vv.begin()); j++)cout<<setw(w)<<j<<" ";cout<<endl;int i = 0;for(auto &v: vv){cout<<i++<<" {";for(auto &el: v) cout<<setw(w)<<el<<" ";cout<<"},\n";}cout<<endl;}

int main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    string s;
    while(cin>>s){
        ll sum = 0;
        for(auto x: s){
            sum+=(x-'0');
        }
        sum%=9;
        cout<<(sum==0 ? "Yes\n" : "No\n");
    }
    return 0;
}

Measured memory_bytes: 3732
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aajisaka
 */

#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
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; }

using ll = long long;
using P = pair<ll, ll>;

constexpr double PI = 3.14159265358979323846;
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());

class FStrangeNim {
public:
    void solve(istream& cin, ostream& cout) {
      SPEED;
      int n; cin >> n;
      unsigned int ans = 0;
      rep(i, n) {
        unsigned int a, k; cin >> a >> k;
        while(a%k != 0) {
          unsigned int r = (a/k)+1;
          unsigned int p = 1;
          if (a%k > r) {
            p = (a%k)/r;
          }
          a -= p*r;
        }
        ans ^= (a/k);
      }

      if (ans==0) {
        cout << "Aoki" << endl;
      } else {
        cout << "Takahashi" << endl;
      }
    }
};

signed main() {
  FStrangeNim solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#define max(a, b)	(((a) > (b)) ? (a) : (b))		/* ２個の値の最大値 */
#define min(a, b)	(((a) < (b)) ? (a) : (b))		/* ２個の値の最小値 */
#define ENTER		printf("\n")					/* 改行プリント */
int DBG = 1;										/* デバッグプリント 提出時は0 */
/* main *************************************************************/
int main()
{
	int		a,b,c,i,j,k,n,m,x,y;
	char	str[256];
	double  ans;
	
	scanf("%d %d", &a , &b);
 
	if ( (a >= 1) && (a <=9) && (b >= 1) && (b <=9) ) {
		printf("%d\n",a*b);
	} else {
		printf("-1\n");
	}
 
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#define ALL(a)  (a).begin(),(a).end()
using namespace std;
int main(){
    int n, l;
    cin >> n >> l;

    vector<string> s(n);
    for(int i = 0; i < n; ++i){
        cin >> s[i];
    }
    
    sort(ALL(s));
    for(int i = 0; i < n; ++i){
        cout << s[i];
    }
    cout << endl;    
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <map>
#include <cmath>
#include <cstring>

#define fi first
#define se second
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for (int i = 1; i < (n); ++i)
#define drep(i,n) for (int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define all(x) (x).begin(), (x).end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define pb push_back
#define sz(x) (int)(x).size()
#define PQ(T) priority_queue<T, v(T), greater<T> >

using namespace std;
typedef long long ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;

const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;

const int mod = 1000000007;
vector<int> c;
vector<vector<P> > t;
void dfs(int v) {
    if (c[v] == 1) return;
    c[v] = 1;

    rep(i,t[v].size()) {
        int x = t[v][i].fi;
        int y = t[v][i].se;
        if (y == 1) dfs(x);
    }
    return;
}

int main() {
    int n;
    cin >> n;
    t.resize(n);
    c.resize(n);
    rep(i,n) {
        int a; 
        cin >> a;
        rep(j,a) {
            int x, y;
            cin >> x >> y;
            --x;
            t[i].pb(P(x,y));
        }
    }
    int ans = 0;
    int cnt;
    for (int bit = 0; bit < (1 << n); ++bit) {
        bool ok = true;
        rep(i,n) c[i] = -1;
        cnt = 0;
        for (int i = 0; i < n; ++i) {
            if (bit & (1<<i)) {
                dfs(i);
            }
        }
        for (int i = 0; i < n; ++i) {
            if (bit & (1<<i) || c[i] == 1) {
                ++cnt;
                rep(j, t[i].size()) {
                    int xi = t[i][j].fi;
                    int yi = t[i][j].se;
                    if (c[xi] == -1) c[xi] = yi;
                    else {
                        if (c[xi] != yi) {
                            ok = false;
                            //cout << "bit: " << bit << " xi: " << xi << " cx: " << c[xi] << " y: " << yi << endl;
                        }
                    }
                }
            }
        }
        if (ok) ans = max(ans,cnt);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<set>
#include<algorithm>

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

vector<string> split(const string &s, char delim) {
    vector<string> elems;
    string item;
    for (char ch: s) {
        if (ch == delim) {
            if (!item.empty())
                elems.push_back(item);
            item.clear();
        }
        else {
            item += ch;
        }
    }
    if (!item.empty())
        elems.push_back(item);
    return elems;
}

int main(void) {
    Int N,K;
    vector<Int> h;
    Int diff;

    cin>>N>>K;

    for(int i = 0;i < N;i++) {
        Int temp;
        cin>>temp;
        h.push_back(temp);
    }

    sort(h.begin(),h.end(),greater<Int>());
    int head = 0;
    int tail = K-1;
    diff = h[head]-h[tail];
    for(int i = 1;i < N-K+1;i++) {
        head++;
        tail++;
        diff = min(diff,h[head]-h[tail]);
    }

    cout<<diff<<endl;

    return 0;
}



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

int main(){
    int n; cin >> n;
    vector<int> lis(n, 0);
    for(int i = 0; i < n; i++){
        cin >> lis[i];
    }
    ll ans = 10000000;
    for(int i = 0; i <= 100; i++){
        ll mid = 0;
        for(int l = 0; l < n; l++){
            mid += (lis[l] - i) * (lis[l] - i);
        }
        ans = min(mid, ans);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main (){
	int a,b,gou,p,i;
		gou=0;
		while(cin>>a>>b){
		gou=a+b;
		for(int j=0;j<7;j++){
			if(gou>0){
				p++;
			}
			else if(gou<=0){
				break;
			}
			gou=gou/10;
		}
		cout<<p<<endl;
		p=0;
		}
	return 0;
}


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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;
struct Edge{
  int to, cost;

  Edge(int t, int c = 0): to(t), cost(c)
  {}
  bool operator>(const Edge& rhs) const{
	return cost > rhs.cost;
  }
  bool operator<(const Edge& rhs) const{
	return cost < rhs.cost;
  }

};
using Graph =  vector< vector<Edge> >;

void add_edge(Graph& graph, int u, int v, int cost = 0){
  graph[u].push_back(Edge(v,cost));
  graph[v].push_back(Edge(u,cost));
}

/**
 * lowlink????¨????????????¢??????????????????
 * ??????v?????¢?????? <=> v??¨??????????????????????????¨???????????£????????????
 *   pre-condition:
 *   num == 0
 *   p = -1
 *   ord.size == low.size == V
 *   ord[u] < 0 for all u
 * O(V + E)
 * ??????v?????¢?????? iff
 *    v is root => dfs tree????????????????????°???2??\???
 *    o.w. => ??????v??????c????????¨??????ord[v] <= low[c]
 * ?????????ord[u]???dfs???pre-order
 * low[u]??????????????????1???????????£?????°?????????????????????ord???????°????
 */
void lowlink_art(int u, int p, int& num, const Graph& G, VI& ord, VI& low, VI& art){
  int chd = 0, chd_mx = -1;
  ord[u] = low[u] = num++;
  
  for(auto& e: G[u]){
	int to = e.to;
	if(to == p) continue;
	if(ord[to] < 0){
	  ++chd;
	  lowlink_art(to, u, num, G, ord, low, art);
	  low[u] = min(low[u], low[to]);
	  if(chd_mx < low[to])
		chd_mx = low[to];
	}
	else{
	  low[u] = min(low[u], ord[to]);
	}
  }

  if(p == -1){ // case u is root
	if(chd >= 2)
	  art.push_back(u);
  }
  else{
	if(ord[u] <= chd_mx)
	  art.push_back(u);
  }
}

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

  int V, E;
  cin >> V >> E;
  Graph G(V);
  REP(i,E){
	int u, v;
	cin >> u >> v;
	add_edge(G, u, v);
  }

  int num = 0;
  VI ord(V, -1);
  VI low(V, -1);
  VI art;
  lowlink_art(0, -1, num, G, ord, low, art);
  SORT(art);
  for(int v: art) cout << v << endl;

  return 0;
}

Measured memory_bytes: 5360
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) int((x).size())
#define OUT(x) cout << (x) << endl
typedef long long ll;
typedef vector<int> V;
typedef vector<vector<int>> VV;
typedef pair<int, int> P;
typedef map<string, int> M;
typedef unordered_map<int, int> HM;
typedef set<int> S;
typedef multiset<int> MS;
typedef queue<int> Q;

int main(){
    int n,l; cin>>n>>l;
    V dic(n);
    for(int i=0; i<n; i++){
        dic[i] = l+i;
    }
    int m = 1000;
    for(int i : dic){
        if(abs(m) > abs(i))
            m = i;
    }
    int ans = 0;
    for(int i=0; i<n; i++){
        if(dic[i] == m) continue;
        ans += dic[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
def main():
    s = input()
    n = int(input())

    for i in range(n):
        cmds = input().split(' ')

        if 'reverse' == cmds[0]:
            a = int(cmds[1])
            b = int(cmds[2])+1

            s = s[:a]+''.join(reversed(s[a:b]))+s[b:]

        if 'replace' == cmds[0]:
            a = int(cmds[1])
            b = int(cmds[2])+1
            res = cmds[3]

            s = s[:a]+res+s[b:]

        if 'print' == cmds[0]:
            a = int(cmds[1])
            b = int(cmds[2])+1

            print(s[a:b])

if __name__ == '__main__': main()

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

int main(){
  ll K;cin>>K;
  if(K%2==0) cout<<-1<<endl;
  else{
    ll now=0;
    for(ll i=1;i<=1e7;++i){
      now = (now*10+7)%K;
      if(now==0){cout<<i<<endl;return 0;}
    }
    cout<<-1<<endl;
    }
  }

Measured memory_bytes: 3628
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        int n = sc.NextInt();
        long[] a = sc.LongArray();

        long answer1 = 0;
        {
            long sum = 0;
            bool plus = true;
            for (int i = 0; i < n; i++)
            {
                sum += a[i];
                if (plus)
                {
                    if (sum <= 0)
                    {
                        answer1 += (1 - sum);
                        sum = 1;
                    }
                }
                else
                {
                    if (sum >= 0)
                    {
                        answer1 += (sum - (-1));
                        sum = -1;
                    }
                }
                plus = !plus;
            }
        }

        long answer2 = 0;
        {
            long sum = 0;
            bool plus = false;
            for (int i = 0; i < n; i++)
            {
                sum += a[i];
                if (plus)
                {
                    if (sum <= 0)
                    {
                        answer2 += (1 - sum);
                        sum = 1;
                    }
                }
                else
                {
                    if (sum >= 0)
                    {
                        answer2 += (sum - (-1));
                        sum = -1;
                    }
                }
                plus = !plus;
            }
        }

        long answer = Math.Min(answer1, answer2);

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

Measured memory_bytes: 27228
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+10;
ll a[maxn],n,m,v,p;
int l,r,mid;
bool check(int x){
    ll t=v-(p-1)-1-(x-1);
    ll sum=0;
    for (int i=x+1;i<=n-(p-1);i++) {
        if (a[x]+m<a[i]) return 0;
        sum+=a[x]+m-a[i];
    }
    return sum>=t*m;
}
int main(){
    cin >> n >> m >> v >> p;
    for (int i=1;i<=n;i++) cin >> a[i];
    sort(a+1,a+n+1);
    l=0; r=n;
    while (r-l>1){
        mid=(l+r)>>1;
        if (check(mid)) r=mid; else l=mid;
    }
    cout << n-l << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define maxn 309
using namespace std;
long long n,a;
long long solve(long long n,int t){
    long long val=1;
    while(1){
        long long cur=1;
        for(int i=0;i<t;i++)
            cur*=val;
        if(cur>n)
            break;
        val++;
    }
    val--;
    long long cur=1;
    for(int i=0;i<t;i++)
        cur*=val;
    if(cur==n){
        return t*val;
    }
    else{
        long long ans=1e18;
        for(int i=0;i<=t-1;i++){
            long long cur=0,pro=1;
            for(int j=1;j<=i;j++){
                cur+=val;
                pro*=val;
            }
            for(int j=1;j<=t-1-i;j++){
                cur+=val+1;
                pro*=val+1;
            }
            cur+=(n+pro-1)/pro;
            ans=min(ans,cur);
        }
        return ans;
    }
}
int main(){
    cin>>n>>a;
    long long ans=n;
    for(int i=1;i<=59;i++){
        ans=min(ans,i*a+solve(n,i+1));
    }
    cout<<ans<<endl;
    //system("pause");
    return 0;
}

Measured memory_bytes: 384
import collections
import heapq


class Dijkstra():
    def __init__(self):
        self.e = collections.defaultdict(list)

    def add(self, u, v, d):
        self.e[u].append([v, d])
        self.e[v].append([u, d])

    def delete(self, u, v):
        self.e[u] = [_ for _ in self.e[u] if _[0] != v]
        self.e[v] = [_ for _ in self.e[v] if _[0] != u]

    def search(self, s):
        """
        :param s: 始点
        :return: 始点から各点までの最短経路
        """
        d = collections.defaultdict(lambda: float('inf'))
        d[s] = 0
        q = []
        heapq.heappush(q, (0, s))
        v = collections.defaultdict(bool)
        while len(q):
            k, u = heapq.heappop(q)
            if v[u]:
                continue
            for uv, ud in self.e[u]:
                if v[uv]:
                    continue
                vd = k + ud
                if d[uv] > vd:
                    d[uv] = vd
                    heapq.heappush(q, (vd, uv))

        return d


N, M, S, T = map(int, input().split())
UVAB = [list(map(int, input().split())) for i in range(M)]
graph1 = Dijkstra()
graph2 = Dijkstra()

for u, v, a, b in UVAB:
    graph1.add(u, v, a)
    graph2.add(u, v, b)

result_a = graph1.search(S)
result_b = graph2.search(T)
ans_list = [float('inf')]
for i in range(N, 0, -1):
    cur = result_a[i] + result_b[i]
    if cur > ans_list[-1]:
        cur = ans_list[-1]
    ans_list.append(cur)

for i in range(len(ans_list[1:])):
    print(10**15-ans_list[-(i+1)])


Measured memory_bytes: 170748
#include <stdio.h>
int main(){
  int H,W,a,b,c,d,e,n,m;
  for(;;){ 
    scanf("%d%d",&H,&W);
    if(H==0&&W==0) break;
 
    for (a =0 ; a < H; a++ ){
      for (b =0 ; b < W; b++ ){
	if(0==a%2&&b%2==0||a%2!=0&&b%2!=0) {
	  printf("#");
	} else{
	  printf(".");
	}
      }
      printf("\n");
    }

    printf("\n");
 
  }

  return 0;
}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}

int main2() {
  int a = nextInt(), b = nextInt();
  cout << (a - (a > b)) << endl;
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}


Measured memory_bytes: 256