akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <cstring>
using namespace std;

int N;
int c[555], s[555], f[555];
int ans[555];

void solve() {
    cin>>N;
    for(int i = 1;i <= N - 1;i++) {
        scanf("%d %d %d", &c[i], &s[i], &f[i]);
    }
    memset(ans, 0, sizeof(ans));
    for(int i = 1;i <= N;i++) {
        for(int j = i;j < N;j++) {
            if(ans[i] <= s[j]) ans[i] = s[j] + c[j];
            else {
                int temp;
                if((ans[i] - s[j]) % f[j] == 0) temp = f[j];
                else temp =(ans[i] - s[j]) % f[j];
                ans[i] += f[j] - temp + c[j];
            }
        }
    }
    for(int i = 1;i <= N;i++) printf("%d\n", ans[i]);
}

int main() {
    solve();
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <ctype.h>
#include <functional>
#include <iostream>
#include <cassert>
#include <cfloat>
#include <climits>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
int main() {
	string S;
	cin >> S;
	int res=0;
	for(int i=1;i<S.size();i++){
		if(S[i]!=S[i-1]){
			res++;
		}
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 512
def main():
    IN = [int(_) for _ in input().split()]
    N = IN[0]
    M = IN[1]

    if N == 1 and M != 1:
        print(M-2)
    elif M == 1 and N != 1:
        print(N-2)
    elif N == 1 and M == 1:
        print(1)
    else:
        print((N-2)*(M-2))

if __name__ == "__main__":
    main()

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
#include <numeric>
#include <iomanip>
#include <cmath>
#include <cstring>
using namespace std;
int grid[50][50];
bool used[50][50];
int move_h[8] = {-1, 1, 0, 0, -1, 1, -1, 1};
int move_w[8] = {0, 0, -1, 1, 1, -1, -1, 1};

void dfs(int cur_h, int cur_w, int h, int w){
  used[cur_h][cur_w] = true;
  for(int i = 0; i < 8; i++){
    int next_h = cur_h + move_h[i];
    int next_w = cur_w + move_w[i];

    if(0 <= next_h && next_h < h && 0 <= next_w && next_w < w 
        && !used[next_h][next_w] && grid[next_h][next_w] == 1){
      dfs(next_h, next_w, h, w);
    }
  }
}
int main(){
  while(true){
    int w;
    int h;
    cin >> w >> h;
    if(w == 0 && h == 0){
      break;
    }
    for(int i = 0; i < h; i++){
      for(int j = 0; j < w; j++){
        cin >> grid[i][j];
        used[i][j] = false;
      }
    }

    int ans = 0;
    for(int i = 0; i < h; i++){
      for(int j = 0; j < w; j++){
        if(!used[i][j] && grid[i][j] == 1){
          ans ++;
          dfs(i, j, h, w);
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}


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

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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> tiii;

const int INF=1<<30;
const ll LINF = 1e18+5;

int x[15][15];
int y[15][15];

int main() {
    int N;
    int A[15] = {};
    cin >> N;
    rep(i, N) {
        cin >> A[i];
        rep(j, A[i]) {
            cin >> x[i][j] >> y[i][j];
            x[i][j]--;
        }
    }
    int isHonest[15] = {};
    int ans = 0;
    for(int i = (int)pow(2,N)-1; i>=0; i--) {
        int count = 0;
        rep(j, N) {
            isHonest[j] = i>>j & 1;
            if(isHonest[j]) count++;
        }
        if (count < ans) continue;
        bool dameflag = false;
        rep(j, N) {
            if (!isHonest[j]) continue;
            rep(k, A[j]) {
                if (isHonest[x[j][k]] != y[j][k]) {
                    dameflag = true;
                    break;
                }
            }
            if (dameflag) break;
        }
        if (!dameflag) ans = count;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG//実行時、何も出なかったらこれを使う
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<numeric>
#include<climits>
#include<limits>//
#include <stdio.h>//
#include<cmath>
#include<iomanip>

using namespace std;

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

typedef long long ll;

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

int dy[] = {1,0,-1,0}; //次に行くところ
int dx[] = {0,1,0,-1}; //s上に同じ

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n,cnt = 0;
  cin >> n;
  vector<int> l(n);

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

  sort(l.begin(),l.end());
  
  for (int i = 0; i < n; i++){
    for (int j = i+1; j < n; j++){
      for (int k = j+1; k < n; k++){
        if (l[k] < l[i]+l[j] && i != j && k != j && k != i && l[i] != l[k] && l[j] != l[k] && l[j] != l[i]){
          cnt++;
        }
      }
    }
  }
  
  cout << cnt << '\n';

  return 0;
}

Measured memory_bytes: 3596
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

inline char get(void) {
	static char buf[100000], *S = buf, *T = buf;
	if (S == T) {
		T = (S = buf) + fread(buf, 1, 100000, stdin);
		if (S == T) return EOF;
	}
	return *S++;
}
inline void read(int &x) {
	static char c; x = 0; int sgn = 0;
	for (c = get(); c < '0' || c > '9'; c = get()) if (c == '-') sgn = 1;
	for (; c >= '0' && c <= '9'; c = get()) x = x * 10 + c - '0';
	if (sgn) x = -x;
}
inline int read(char *s) {
	static char c; int len = 0;
	for (c = get(); c < 'a' || c > 'z'; c = get());
	for (; c >= 'a' && c <= 'z'; c = get()) s[len++] = c;
	s[len] = 0; return len;
}

int k, n, x, y, ans;
int a[10101];

int main(void) {
	read(k); read(n);
	for (int i = 1; i <= n; i++) read(a[i]);
	x = *max_element(a + 1, a + n + 1);
	y = k - x;
	if (x <= y + 1) ans = 0;
	else ans = x - y - 1;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
	int n;
	cin>>n;
	int ans=0;
	for(int i=1;i<=n;i*=100) {
		int mx=i*10-1;
		mx=min(mx, n);
		ans+=mx-i+1;
	}
	cout<<ans<<"\n";
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <numeric>

using namespace std;

/*-----------------------------------------------------------------------------
　定義
 -------------------------------------------------------------------------------*/
#define ALL(x)					(x).begin(),(x).end()
#define REP(i, n)				for (int (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n)			for (int (i) = m ; (i) < (ll)(n) ; ++(i))
#define INF						(int)2e9
#define MOD						(1000 * 1000 * 1000 + 7)
#define Ceil(x, n)				(((((x))+((n)-1))/n))		/* Nの倍数に切り上げ割り算 */
#define CeilN(x, n)				(((((x))+((n)-1))/n)*n)		/* Nの倍数に切り上げ */
#define FloorN(x, n)			((x)-(x)%(n))				/* Nの倍数に切り下げ */
#define IsOdd(x)				(((x)&0x01UL) == 0x01UL)			
#define IsEven(x)				(!IsOdd((x)))						
#define M_PI					3.14159265358979323846
typedef long long				ll;
typedef pair<ll, ll>			P;

/*-----------------------------------------------------------------------------
　処理
 -------------------------------------------------------------------------------*/
/* 素数判定 */
bool isPrime(ll p) 
{
	for (ll i = 2; i <= sqrt(p); i++) if (p % i == 0) return false;
	return p > 1;
}

int main()
{
	int Q;
	cin >> Q;
	vector<int> l(Q), r(Q);
	REP(i, Q) cin >> l[i] >> r[i];

	vector<int> abIsPrime(100000, false);
	vector<int> ruiseki(100001, 0);
	abIsPrime[2] = true;
	REPN(i, 2, 100000) {
		ruiseki[i + 1] = ruiseki[i];
		if (IsOdd(i)) {
			abIsPrime[i] = isPrime(i);
			if (abIsPrime[i]) {
				if (abIsPrime[(i + 1) / 2]) {
					ruiseki[i + 1]++;
				}
			}
		}
	}

	REP(i, Q) {
		int ans = ruiseki[r[i] + 1] - ruiseki[l[i]];
	 	cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 2176
#include <cstdint>
#include <iostream>

using namespace std;

static uint32_t num4;
static uint32_t even;
static uint32_t odd;

int32_t main()
{
  uint64_t N;
  cin >> N;

  for (uint64_t i = 0; i < N; i++) {
    uint64_t num;
    cin >> num;
    if ((num % 4) == 0) {
      num4++;
    } else if ((num % 2) == 0) {
      even++;
    } else {
      odd++;
    }
  }

  bool res = false;
  if ((num4 + 1) == odd) {
    if (even == 0) res = true;
  } else if (num4 >= odd) {
    res = true;
  }

  if (res) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include<cstring>
#include<map>
#include<set>
#include<cstdlib>
#include<bitset> 
using namespace std;
typedef long long ll;
ll a[200005];
ll n,k;
ll b[200005]={0};
ll c[200005]={0};
int main(void)
{
	scanf("%lld%lld",&n,&k);
	for(ll i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
	}
	for(ll i=0;i<=n;i++) c[i]=-1;
	ll last=1;
	ll num=0;
	for(ll i=1;i<=n;i++)
	{
		b[i]=a[last];
		last=a[last];
		if(c[last]!=-1)
		{
			num=i;
			break;
		}
		c[last]=i;	
	}
//	printf("%lld\n",num-c[last]);
//	for(ll i=1;i<=num;i++)
//	{
//		printf("%lld ",b[i]);
//	}
	if(k<=num) printf("%lld",b[k]);
	else
	{
		ll round=num-c[last];
		k-=c[last];
		k%=round;
		printf("%lld",b[k+c[last]]);
	}
}

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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz size()
#define pb(x) push_back(x) 
#define bg begin()
#define ed end()
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define mp(x,y) make_pair(x,y)
const ll MOD=1000000007;
vector<ll> enum_div(ll n)//nの約数を列挙
{
	vector<ll> ret;
	for(ll i=1 ; i*i<=n ; ++i)
	{
		if(n%i == 0)
		{
			ret.push_back(i);
			if(i!=1 && i*i!=n)
			{
				ret.push_back(n/i);
			}
		}
	}
	return ret;
}

int main()
{
	ll N,K; cin>>N>>K;
	ll sum=0;
	vector<ll> A(N);
	rep(i,N){
		cin>>A[i];
		sum+=A[i];
	}
	vector<ll> r = enum_div(sum);
	
	r.pb(sum);
	sort(r.bg,r.ed,greater<ll>());
	rep(i,r.sz){
		vector<ll> B;
		ll Bsum=0;
		rep(j,N){
			B.pb(A[j]%r[i]);
			Bsum+=B[j];
		}
		sort(B.bg,B.ed,greater<ll>());
		ll tmpsum=0;
		rep(k,Bsum/r[i]) tmpsum+=(r[i]-B[k]);
		if(tmpsum<=K){
			cout<<r[i];
			return 0;
		}
	}
	return 0; 
}

Measured memory_bytes: 256
def main():

    N = int(input())
    food1, food2 = [], []
    for i in range(N):
        a, b = map(int, input().split())
        food1.append([a+b, a, b, i])
        food2.append([-a-b, a, b, i])
    food1.sort()
    food2.sort(reverse = True)
    used = set()
    ans = 0
    while food1 or food2:
        while food1 and food1[-1][3] in used:
            food1.pop()
        if food1:
            _, a, _, i = food1.pop()
            used.add(i)
            ans += a
        while food2 and food2[-1][3] in used:
            food2.pop()
        if food2:
            _, _, b, i = food2.pop()
            used.add(i)
            ans -= b
    return ans


if __name__ == '__main__':
    print(main())

Measured memory_bytes: 86360
#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
vector<int> a[110], b[111];
ll mem[1<<20][100];
int mp[55][55], mskk[55];
vector<int> v;
void dfs(int x, int par){
    v.push_back(x);
    for(int i=0; i<a[x].size(); ++i){
        if(a[x][i]==par)
            continue;
        dfs(a[x][i], x);
    }
}
void dfs2(int x, int par){
    v.push_back(x);
    for(int i=0; i<a[x].size(); ++i){
        if(a[x][i]==par)
            continue;
        dfs2(a[x][i], x);
        v.push_back(x);
    }
}
int m;
int pos[55];
ll dp(int x, int msk){
    if(x+1==v.size()){
        return msk==(1<<m)-1;
    }
    if(mem[msk][x]!=-1){
        return mem[msk][x];
    }
    ll res=0;
    res=dp(x+1, msk);
    if(mp[v[x]][v[x+1]]!=-1 && x<pos[v[x+1]])
        res+=dp(x+1, msk|mskk[mp[v[x]][v[x+1]]]);
    mem[msk][x]=res;
    return res;
}
int x[55], y[55], l[55][55];
int main(){
    int n;
    while(cin>>n){
        ll ans=0;
        memset(mp, -1, sizeof mp);
        for(int i=0; i<n-1; ++i){
            scanf("%d%d",&x[i],&y[i]);
            a[x[i]].push_back(y[i]);
            a[y[i]].push_back(x[i]);
            mp[x[i]][y[i]]=mp[y[i]][x[i]]=i;
        }
        int q1[22], q2[22];
        cin>>m;
        memset(l, -1, sizeof l);
        for(int i=0; i<m; ++i){
            scanf("%d%d",q1+i, q2+i);
            l[q1[i]][q2[i]]=l[q2[i]][q1[i]]=i;
        }
        vector<int>v1, v2;
        for(int i=0; i<n-1; ++i){
            int x1=x[i], x2=y[i];
            dfs(x1, x2);
            v1=v;v.clear();
            dfs(x2, x1);
            v2=v;v.clear();
            for(int j=0; j<v1.size(); ++j){
                for(int k=0; k<v2.size(); ++k){
                    if(l[v1[j]][v2[k]]>-1){
                        mskk[i]|=(1<<l[v1[j]][v2[k]]);
                    }
                }
            }
        }
        memset(mem, -1, sizeof mem);
        dfs2(1,-1);
        for(int i=(int)(v.size())-1; i>=0; --i){
            pos[v[i]]=i;
        }
        assert(v.size()<110);
        ans=dp(0, 0);
        cout<<ans<<endl;
    }
  return 0;
}




Measured memory_bytes: 819456
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int count=1;
		while(true){
			int x=sc.nextInt();
			if(x==0){
				break;
			}
			System.out.println("Case "+count+": "+x);
			count++;
		}
	}

}



Measured memory_bytes: 41600
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cstring>
#include <cmath>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
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; }

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int m, k;
  cin >> m >> k;
  int lim = 1<<m;
  if (k >= lim || m == 1 && k != 0) {
    cout << -1 << endl;
    return 0;
  }
  if (m == 1) {
    cout << "0 0 1 1" << endl;
    return 0;
  }
  vector<int> ans;
  rep(i, k)
    ans.push_back(i);
  ans.push_back(k);
  for (int i = k-1; i>=0; i--)
    ans.push_back(i);
  for (int i = k+1; i<lim; i++)
    ans.push_back(i);
  ans.push_back(k);
  for (int i = lim-1; i>k; i--)
    ans.push_back(i);
  rep(i, ans.size())
    cout << ans[i] << (i+1<ans.size()?' ':'\n');
  return 0;
}

Measured memory_bytes: 2932
H,W = (int(x) for x in input().split())
a=[input() for i in range(H)]
for i in range(W+1):
    print('#',end='')
print('#')
for i in a:
    print('#',end='')
    print(i,end='')
    print('#')
for i in range(W+1):
    print('#',end='')
print('#')

Measured memory_bytes: 3064
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int main(void){
	int t[2],i;
	ll a[2],b[2],d=0ll,p,q,ans;
	cin >> t[0] >> t[1];
	cin >> a[0] >> a[1];
	cin >> b[0] >> b[1];
	for(i=0; i<2; ++i){
		d += (a[i]-b[i])*t[i];
	}
	if(d<0ll){
		for(i=0; i<2; ++i){
			swap(a[i],b[i]);
		}
	}
	p = (a[0]-b[0])*t[0];
	q = p + (a[1]-b[1])*t[1];
	if(!q){
		cout << "infinity" << endl;
	}else if(p>0){
		cout << 0 << endl;
	}else{
		ans = (q-p)/q;
		ans *= 2;
		if((q-p)%q){
			--ans;
		}else{
			ans -= 2;
		}
		cout << ans << endl;
 	}
	return 0;
}


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

int main(){
    int n;
    int a[100000] = {};

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

    sort(a,a+n);

    int ans = 0, cou = 1;
    int ch = a[0];
    for(int i = 1; i < n; i++){
        if(a[i] == ch){
            cou++;
        }
        else{
            if(ch > cou){
                ans += cou;
            }
            else{
                ans += cou - ch;
            }
            ch = a[i];
            cou = 1;
        }
    }
    if(ch > cou){
        ans += cou;
    }
    else{
        ans += cou - ch;
    }

    cout << ans << endl;
}

Measured memory_bytes: 768
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <bitset>

using namespace std;

using ll = long long;

#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--)

#define input(...) __VA_ARGS__; in(__VA_ARGS__)

template<class T>
void print(vector<T> a) {
  cout << "[ ";
  REP(i, a.size()) cout << a[i] << " ";
  cout << "]" << endl;
}

void print() {
  std::cout << std::endl;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  std::cout << head << " ";
  print(std::forward<Tail>(tail)...);
}

void in() { }

template <class Head, class... Tail>
void in(Head&& head, Tail&&... tail) {
  cin >> head;
  in(std::forward<Tail>(tail)...);
}

bool within_area(int x, int y) {
  return 0 <= x && x < 8 && 0 <= y && y < 8;
}

vector<pair<ll, ll>> positions(int x, int y) {
  vector<pair<ll, ll>> p;
  REPD(i, 8) {
    if (i == 0) {
      p.push_back({x, y});
      continue;
    }
    if (within_area(x - i, y - i)) p.push_back({x - i, y - i});
    if (within_area(x + i, y + i)) p.push_back({x + i, y + i});
    if (within_area(x - i, y + i)) p.push_back({x - i, y + i});
    if (within_area(x + i, y - i)) p.push_back({x + i, y - i});
  }
  return p;
}

bool check(vector<vector<bool>> &board, int i, int j) {
  if (board[i][j]) return false;
  for (auto position: positions(i, j)) {
    board[position.first][position.second] = true;
  }
  return true;
}

int main() {
  vector<bitset<8>> grid(8, 0);
  vector<int> index(8);
  REP(i, 8) {
    grid[i][i] = 1;
    index[i] = i;
  }
  vector<int> x(index);

  int input(k);
  vector<vector<bool>> default_board(8, vector<bool>(8));
  REP(i, k) {
    int input(a, b);
    default_board[a][b] = true;
  }
  
  do {
    vector<vector<bool>> board(8, vector<bool>(8));

    bool ans = true;
    int cnt = 0;
    REP(i, 8) {
      ans &= check(board, i, x[index[i]]);
      if (default_board[i][x[index[i]]]) {
        cnt++;
      }
    }
    if (ans) {
      if (cnt != k) continue;
      REP(i, 8) {
        REP(j, 8) {
          if (j == x[index[i]]) cout << "Q";
          else cout << ".";
        }
        cout << endl;
      }
      break;
    }
  } while (next_permutation(index.begin(), index.end()));
}



Measured memory_bytes: 3104
#!/usr/bin/env python

x,y=list( int(i) for i in input().split() )

g1=[1,3,5,7,8,10,12]
g2=[4,6,9,11]

def getGroup(num):
    if(num==2):
        return 3;
    for i in g2:
        if(i==num):
            return 2;
    return 1;

if(getGroup(x)==getGroup(y)):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main () {
  string S;
  cin >> S;
  int counta = 0, countc = 0, count = 0;
  for (int i = 0; i < S.size(); i++) {
    if((S.at(i) - 'A') == 'A' - 'A' && i == 0) counta++;
    if((S.at(i) - 'A') == 'C' - 'A' && (i > 1 && i < S.size() - 1)) countc++;
    if((S.at(i) - 'A') < ('A' - 'A') || (S.at(i) - 'A') > ('Z' - 'A')) count++;
  }
  if((count == S.size() - 2) && counta == 1 && countc == 1) cout << "AC" << endl;
  else cout << "WA" << endl;
  return 0;
}


Measured memory_bytes: 256
import java.io.IOException;
import java.util.Arrays;
import java.util.Scanner;

class Main {
    public static void main (String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Node[] nodes = new Node[n];
        boolean[] isRoot = new boolean[n];
        Arrays.fill(isRoot, true);
        for (int i = 0; i < n; i++) {
            int id = sc.nextInt();
            int k = sc.nextInt();
            int[] children = new int[k];
            for (int j = 0; j < k; j++) {
                children[j] = sc.nextInt();
                isRoot[children[j]] = false;
            }
            nodes[id] = new Node(children);
        }

        for (int i = 0; i < n; i++) {
            if (isRoot[i]) {
                solve(nodes, -1, i, 0);
                break;
            }
        }

        StringBuilder sb = new StringBuilder("");
        for (int i = 0; i < n; i++) {
            sb.append("node ").append(i).append(": parent = ").append(nodes[i].parent).append(", depth = ").append(nodes[i].depth).append(", ");

            if (nodes[i].parent == -1) sb.append("root");
            else if (nodes[i].children.length == 0) sb.append("leaf");
            else sb.append("internal node");

            sb.append(", [");
            for (int j = 0; j < nodes[i].children.length; j++) {
                sb.append(nodes[i].children[j]);
                if (j != nodes[i].children.length - 1) sb.append(", ");
            }
            sb.append("]\n");
        }
        System.out.print(sb);
    }

    public static void solve(Node[] nodes, int parent, int id, int depth) {
        nodes[id].parent = parent;
        nodes[id].depth = depth;

        for (int i = 0; i < nodes[id].children.length; i++) {
            solve(nodes, id, nodes[id].children[i], depth + 1);
        }
    }
}

class Node {
    public int parent;
    public int depth;
    public int[] children;
    public Node(int[] children) {
        this.children = children;
    }
}

Measured memory_bytes: 111348
from collections import deque
from collections import Counter
from itertools import product, permutations,combinations
from operator import itemgetter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right, bisect
#pypyではscipy, numpyは使えない
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, minimum_spanning_tree
#from scipy.sparse import csr_matrix, coo_matrix, lil_matrix
#import numpy as np
from fractions import gcd
from math import ceil,floor, sqrt, cos, sin, pi, factorial
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7

def main():
  n, m = map(int, readline().split())
  sw = [[] for _ in range(m)]
  for i in range(m):
    sw[i] = list(map(int, readline().split()[1:]))
  p = [int(x) for x in input().split()] # 不要
  answer = 0
  
  for jotai in product([0,1], repeat=n):
    bl = True
    for i in range(m):
      s = sum([jotai[s-1] for s in sw[i]])
      if (s-p[i])%2 != 0:
        bl = False
        break
    if bl:
      answer += 1
  print(answer)
  
  
  
if __name__ == '__main__':
  main()

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

int main(){
    int N;
    cin >> N;
    set<vector<int>> st;
    for(int i=0;i<N;i++){
        int a,b,c;
        cin >> a >> b >> c;
        vector<int> p = {a,b,c};
        sort(p.begin(), p.end());
        st.insert(p);
    }

    cout << N - st.size() << endl;
}


Measured memory_bytes: 3236
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM

newUF n = VUM.replicate n (-1 :: Int)

root uf x = do
    p <- VUM.read uf x
    if p < 0
        then return x
        else do
            r <- root uf p
            VUM.write uf x r
            return r

same uf x y = liftM2 (==) (root uf x) (root uf y)

unite uf x y = do
    px <- root uf x
    py <- root uf y
    when (px /= py) $ do
        sx <- VUM.read uf px
        sy <- VUM.read uf py
        let (par, chld) = if sx < sy then (px, py)　else (py, px)
        VUM.write uf chld par
        VUM.write uf par (sx + sy) 

size uf x = do
    px <- root uf x
    s <- VUM.read uf px
    return $ abs s

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    [n,m,k] <- getIntList
    ab <- replicateM m $ do
        [a,b] <- getIntList
        return (a-1,b-1)
    cd <- replicateM k $ do
        [c,d] <- getIntList
        return (c-1,d-1)
    let friends = VU.create $ do
            count <- VUM.replicate n (-1 :: Int)
            uf <- newUF n
            forM_ ab $ \(a,b) -> do
                unite uf a b
                VUM.modify count pred a
                VUM.modify count pred b
            forM_ [0..n-1] $ \i -> do
                s <- size uf i
                VUM.modify count (+ s) i
            forM_ cd $ \(c,d) -> do
                b <- same uf c d
                when b $ do
                    VUM.modify count pred c
                    VUM.modify count pred d
            return count
    putStrLn . unwords . map show $ VU.toList friends

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

namespace AtCoder
{
	public class Program
	{
		// ABC132-C
		static void Main(string[] args)
		{
			string n = Console.ReadLine();
			string str = Console.ReadLine();

			int[] vs = str.Split().Select(p => int.Parse(p)).OrderBy(p => p).ToArray();

			int abc = vs[vs.Length / 2 - 1], arc = vs[vs.Length / 2];

			Console.WriteLine(arc - abc);
		}
	}
}


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

/*bool subseq(string s,string t){
    ll y=0;
    for(ll i=0;y<s.size()&& i<t.size();i++){
        if(s[y]==t[i]){
            y++;
        }
    }
        if(y==s.size())
            return true;
        else  return false;
}*/
/*ll x=1000000001;
vector<bool>p(x,false);
void prime(){
    p[2]=true;
    for(ll i=3;i<x;i=i+2)
        p[i]=true;
    for(ll i=0;i<x;i=i+2){
        if(p[i]){
            for(ll j=i*i;j<x;j=j+i)
                p[j]=false;
        }
    }
}*/
/*vector<ll> divisor(ll n){
    vector<ll> d;
    for(ll i=1;i<=sqrt(n);i++){
        if(n%i==0){
        d.push_back(i);
        d.push_back(n/i);
        }
    }
    sort(d.begin(),d.end(),greater<ll>());
    return d;
}*/
/*bool bs(ll n,string s){
    ll a[4]={0};
    for(ll i=0;i<n-1;i++){
        a[s[i]-'0']++;
    }
    for(ll i=n-1;i<s.size();i++){
        a[s[i]-'0']++;
        if(a[1]>0 && a[2]>0 && a[3]>0)
        return true;
        a[s[i-n+1]-'0']--;
    }
    return false;
}*/


/*ll binarySearch(ll n,ll a[],ll x){
    ll low=0,high=n-1,mid,ans=-1;
    while(low<=high){
        mid=low+(high-low)/2;
        if(a[mid]>=x){

            high=mid-1;
        }
        else{
                ans=mid;
            low=mid+1;
        }
    }
    return a[ans];
}*/




/*bool subseq(string s,string t){
    ll y=0;
    for(ll i=0;y<s.size()&& i<t.size();i++){
        if(s[y]==t[i]){
            y++;
        }
    }
        if(y==s.size())
            return true;
        else  return false;
}*/
/*ll x=1000000001;
vector<bool>p(x,false);
void prime(){
    p[2]=true;
    for(ll i=3;i<x;i=i+2)
        p[i]=true;
    for(ll i=0;i<x;i=i+2){
        if(p[i]){
            for(ll j=i*i;j<x;j=j+i)
                p[j]=false;
        }
    }
}*/
/*vector<ll> divisor(ll n){
    vector<ll> d;
    for(ll i=1;i<=sqrt(n);i++){
        if(n%i==0){
        d.push_back(i);
        d.push_back(n/i);
        }
    }
    sort(d.begin(),d.end(),greater<ll>());
    return d;
}*/
/*bool bs(ll n,string s){
    ll a[4]={0};
    for(ll i=0;i<n-1;i++){
        a[s[i]-'0']++;
    }
    for(ll i=n-1;i<s.size();i++){
        a[s[i]-'0']++;
        if(a[1]>0 && a[2]>0 && a[3]>0)
        return true;
        a[s[i-n+1]-'0']--;
    }
    return false;
}*/


/*ll binarySearch(ll n,ll a[],ll x){
    ll low=0,high=n-1,mid,ans=-1;
    while(low<=high){
        mid=low+(high-low)/2;
        if(a[mid]>=x){

            high=mid-1;
        }
        else{
                ans=mid;
            low=mid+1;
        }
    }
    return a[ans];
}*/

string solve(ll n){


}

int main() {
    char c;
    cin>>c;
    if(c>='a' && c<='z')
        cout<<"a";
    else cout<<"A";
}


Measured memory_bytes: 3628
#include<iostream>
#include<string>
using namespace std;
int main (void){

    string s;
    int a = 0;


      cin >> s;

    for(int i = 1;i < 4;i++ ){
        
        
        if(s[i] == s[i - 1])
        {
        a = 1;
        break;
        }
        
        
    } 

    if(a == 1)
    cout << "Bad" << endl;
    else if(a == 0) 
    cout << "Good" << endl; 



    return 0;
}

Measured memory_bytes: 256
//B
#include<bits/stdc++.h>
using namespace std;
 
#define MAX 320
int n;
int m;
deque<int> d[MAX];
 
bool ng[MAX];
 
int ar[MAX];
 
pair<int, int> calc(){
	memset(ar, 0, sizeof(ar));
	for (int i = 0; i < n; i++){
		while (ng[d[i].front()]){
			d[i].pop_front();
		}
		ar[d[i].front()]++;
	}
	pair<int, int> r = make_pair(-1, -1);
	for (int i = 0; i < m; i++){
		r = max(r, make_pair(ar[i], i));
	}
	return r;
}
 
int main(){
	cin >> n >> m;
	for (int i = 0; i < n; i++){
		for (int j = 0; j < m; j++){
			int b;
			scanf("%d", &b);
			b--;
			d[i].push_back(b);
		}
	}
	int ans = INT_MAX;
	for (int i = 0; i < m; i++){
		auto f = calc();
		ng[f.second] = true;
		ans = min(ans, f.first);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 768
#include <iostream>
#include <stack>
#include <queue>
#include <list>
#include <string>
#include <cstdlib>
#include <algorithm>
using namespace std;

int main()
{
	list<int> L;
	int n, a;
	string s;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> s;
		if (s[0] == 'i') {
			cin >> a;
			L.push_front(a);
		}
		else if (s.length() > 6) {
			if (s[6] == 'F') {
				L.pop_front();
			}
			else if (s[6] == 'L') {
				L.pop_back();
			}
		}
		else{
			cin >> a;
			for (list<int>::iterator it = L.begin(); it != L.end(); it++ ){
				if (*it == a) {
					L.erase(it);
					break;
				}
			}
		}
	}
	cout << L.front();
	L.pop_front();
	while(!L.empty()){
		cout << " " << L.front();
		L.pop_front();
	}
	cout << endl;
}


Measured memory_bytes: 34360
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long LL;
int main()
{
	int a,b,n;
	scanf("%d%d%d",&n,&a,&b);
	LL l,r;
	l=1ll*a*(n-1)+b; r=1ll*b*(n-1)+a;
	if(l>r) printf("0");
	else printf("%lld",r-l+1);
	return 0;
}

Measured memory_bytes: 128
n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
a.sort()
gap = a[n-1] - a[0]
for i in range(1,n // 2):
    gap += a[-(i + 1)] - a[i - 1]
    gap += a[-i] - a[i]
if len(a) % 2 == 1:
    gap += max(a[n//2] - a[n//2 - 1], a[n//2 + 1] - a[n//2])
print(gap)

Measured memory_bytes: 7388
import java.util.*;

class Main{
    void solve(){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        boolean[] A = new boolean[N+1];
        boolean[] B = new boolean[N+1];
        boolean[] C = new boolean[N+1];
        for ( int i = 1; i <= N; i++ ) A[i] = B[i] = C[i] = false;

        int k;
        k = sc.nextInt();
        for ( int i = 0; i < k; i++ ) A[sc.nextInt()] = true;
        k = sc.nextInt();
        for ( int i = 0; i < k; i++ ) B[sc.nextInt()] = true;
        k = sc.nextInt();
        for ( int i = 0; i < k; i++ ) C[sc.nextInt()] = true;

        int ans = 0;
        for ( int i = 1; i <= N; i++ ){
            if (!A[i] && C[i] || B[i] && C[i]) ans++;
        }

        System.out.println(ans);
    }

    public static void main(String[] a){
        new Main().solve();
    }
}




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

#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define repr(i,n) for(int i=(n);i>=0;--i)
#define int long long
#define itn int
#define pb push_back
#define m_p make_pair
#define m_t meke_tuple
#define p_p(a,b) pb(m_p(a,b))
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(all(a));reverse(all(a))
#define UNIQUE(a) a.erase(unique(all(a)),a.end())
#define SZ(a) a.size()
#define ENDL cout<<endl
#define debg(a) cout<<#a<<" "<<a<<endl;
#define call(a) for(auto i:a)cout<<i<<" ";cout<<endl
#define show(a) rep(ghf,SZ(a)){rep(kjh,SZ(a[ghf])){cout<<(a[ghf][kjh]<10?" ":"")<<a[ghf][kjh]<<" ";}ENDL;}
#define out(a) cout<<(a)<<endl
#define fi first
#define se second
#define Vec vector
#define P pair
typedef long long ll;
typedef string str;
typedef vector<ll> V;
typedef pair<ll,ll> Pi;
typedef vector<Pi> VP;
const long long INF = 1LL<<60;
const long long MOD = 1e9+7;
int gcd(int a,int b){if(b==0)return a;return gcd(b,a%b);}
int lcm(int a,int b){return a/gcd(a,b)*b;}
int max(int a,int b){if(a>b)return a; return b;}
int min(int a,int b){if(a>b)return b; return a;}
void Yes(){cout<<"Yes"<<endl;}
void No(){cout<<"No"<<endl;}
void YN(bool b){cout<<(b?"Yes":"No")<<endl;}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n;
  cin>>n;
  V a(n);
  rep(i,n)cin>>a[i];
  
  //���E����ݐ�GCD
  V l(n+1,0),r(n+1,0);
  rep(i,n)l[i+1]=gcd(l[i],a[i]);
  repr(i,n-1)r[i]=gcd(r[i+1],a[i]);

  int res=1;
  rep(i,n){
    chmax(res,gcd( l[i],r[i+1] ));
  }
  out(res);
  
  return 0;
}



Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007 
#define all(n)      (n).begin(), (n).end()
#define ll long long 

void solve(){
	int n,m; cin >> n >> m;
	int a[101];

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

	ll sum = 0;

	for(int i = 0; i < n; i++){
		sum += a[i];
	}

	int cnt = 0;

	for(int i = 0; i < n; i++){
		if(a[i] >= (sum/(m*4.0))){
			cnt++;
			if(cnt == m){
				cout << "Yes" << '\n';
				return ;
			}
		}
	}
	
	cout << "No" << '\n';
	
	

}


int main (){
	
	
		solve();
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
const int mod = 1000000007;

int main() {
  int n, m;
  cin >> n >> m;
  int sum = 0;
  vector<int> a(n);
  rep(i, n) {
    int t;
    cin >> t;
    a[i] = t;
    sum += t;
  }

  sort(a.rbegin(), a.rend());
  if(a[m - 1] * 4 * m >= sum) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define MAX_N 100001
#define INF_INT 2147483647
#define INF_LL 9223372036854775807
#define REP(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
void init(int n);
int find(int n);
void unite(int x,int y);
bool same(int x, int y);
ll bpow(ll,ll,ll);
typedef vector<int> vec;
typedef vector<vec> mat;
mat mul(mat &A,mat &B);
mat pow(mat A,ll n);
int dx[3] = {1,0,-1};
int dy[3] = {1,0,-1};
const int MOD = 1000000007;

bool cmp_P(const P &a,const P &b){
  return a.second < b.second;
}
int main()
{
  char turn='a',bt='a';
  queue<char> A,B,C;
  string SA,SB,SC;
  int f = 1;
  cin >> SA >> SB >> SC;
  REP(i,SA.size())A.push(SA[i]);
  REP(i,SB.size())B.push(SB[i]);
  REP(i,SC.size())C.push(SC[i]);
  while(f){
    switch(turn){
    case 'a':
      if(A.empty()){
        cout << "A" << endl;
        return 0;
      }
      turn = A.front();A.pop();
      
      break;
    case 'b':
      if(B.empty()){
        cout << "B" << endl;
        return 0;
      }
      turn = B.front();B.pop();
      break;
    case 'c':
      if(C.empty()){
        cout << "C" << endl;
        return 0;
      }
      turn = C.front();C.pop();
      break;
    }
  }  
  return 0;  
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main(){
    int a;
    int b;
    int c;

    cin >> a;
    cin >> b;
    cin >> c;

    if((c >= a && c <= b) || (c >= b && c <= a)){
        cout << "Yes";
    }else{
        cout << "No";
    }
    cout << endl;
    
    return 0;
}

Measured memory_bytes: 256
# 2019-11-10 15:45:20(JST)
import sys
# import collections
# import math
# from string import ascii_lowercase, ascii_uppercase, digits
# from bisect import bisect_left as bi_l, bisect_right as bi_r
# import itertools
# from functools import reduce
# import operator as op
# from scipy.misc import comb # float
# import numpy as np 

def main():
    nums = sys.stdin.readline().split()
    nums.sort(reverse=True)
    ans = int(''.join(nums[:2])) + int(nums[2])
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0;}

const long long INF = 1LL << 60;

struct Edge {
    long long from;
    long long to;
    long long cost;
    Edge(int s, int d) : to(s),cost(d) {}
};

using Graph = vector<vector<Edge>>;
using Edges = vector<Edge>;
 
/* dijkstra(G,s,dis)
    入力：グラフ G, 開始点 s, 距離を格納する dis
    計算量：O(|E|log|V|)
    副作用：dis が書き換えられる
*/
void dijkstra(const Graph &G, int s, vector<long long> &dis) {
    int N = G.size();
    dis.resize(N, INF);
    priority_queue<P, vector<P>, greater<P>> pq;  // 「仮の最短距離, 頂点」が小さい順に並ぶ
    dis[s] = 0;
    pq.emplace(dis[s], s);
    while (!pq.empty()) {
        P p = pq.top();
        pq.pop();
        int v = p.second;
        if (dis[v] < p.first) {  // 最短距離で無ければ無視
            continue;
        }
        for (auto &e : G[v]) {
            if (dis[e.to] > dis[v] + e.cost) {  // 最短距離候補なら priority_queue に追加
                dis[e.to] = dis[v] + e.cost;
                pq.emplace(dis[e.to], e.to);
            }
        }
    }
}    
 
/* bellman_ford(Es,s,t,dis)
    入力: 全ての辺Es, 頂点数V, 開始点 s, 最短経路を記録するdis
    出力: 負の閉路が存在するなら ture
    計算量：O(|E||V|)
    副作用：dis が書き換えられる
*/
bool bellman_ford(const Edges &Es, int V, int s, vector<long long> &dis) {
    dis.resize(V, INF);
    dis[s] = 0;
    int cnt = 0;
    while (cnt < V) {
        bool end = true;
        for (auto e : Es) {
            if (dis[e.from] != INF && dis[e.from] + e.cost < dis[e.to]) {
                dis[e.to] = dis[e.from] + e.cost;
                end = false;
            }
        }
        if (end) break;
        cnt++;
    }
    return (cnt == V);
}

int main() {
    int n,k;
    cin >> n >> k;
    vector<int>p(n);
    rep(i,n) cin >> p[i];
    sort(p.begin(),p.end());
    int ans = 0;
    rep(i,k) {
        ans += p[i];
    }
    cout << ans << endl;
}

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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

string s;
int b[26];

int main() {
	cin >> s;
	
	if(s == "zyxwvutsrqponmlkjihgfedcba") { cout << -1 << endl; }
	else if(s.size() < 26) {
		inc(i, s.size()) { b[s[i] - 'a']++; }
		inc(i, 26) { if(b[i] == 0) { s += ('a' + i); break; } }
		cout << s << endl;
	} else {
		string t = s, u = s;
		next_permutation(ALL(t));
		while(s < t) { u = t; t.pop_back(); }
		cout << u << endl;
	}
	
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
//This code is written by Itst
using namespace std;

namespace flow{
	const int MAXN = 403 , MAXM = 1e6 + 7;
	struct Edge{int end , upEd , f , c;}Ed[MAXM];
	int head[MAXN] , S , T , cntEd = 1;	queue < int > q;
	
	void addEd(int a , int b , int c , int d = 0){
		Ed[++cntEd].end = b;
		Ed[cntEd].upEd = head[a];
		Ed[cntEd].f = c;
		Ed[cntEd].c = d;
		head[a] = cntEd;
	}

	void addE(int a , int b , int c , int d = 0 , bool f = 0){
		addEd(a , b , c , d); addEd(b , a , c * f , -d);
	}

	int cur[MAXN] , dep[MAXN];

	bool bfs(){
		while(!q.empty()) q.pop();
		q.push(S);
		memset(dep , 0 , sizeof(dep));
		dep[S] = 1;
		while(!q.empty()){
			int t = q.front(); q.pop();
			for(int i = head[t] ; i ; i = Ed[i].upEd)
				if(Ed[i].f && !dep[Ed[i].end]){
					dep[Ed[i].end] = dep[t] + 1;
					if(Ed[i].end == T){
						memcpy(cur , head , sizeof(head));
						return 1;
					}
					q.push(Ed[i].end);
				}
		}
		return 0;
	}

	int dfs(int x , int mF){
		if(x == T)
			return mF;
		int sum = 0;
		for(int &i = cur[x] ; i ; i = Ed[i].upEd)
			if(Ed[i].f && dep[Ed[i].end] == dep[x] + 1){
				int t = dfs(Ed[i].end , min(mF - sum , Ed[i].f));
				if(t){
					Ed[i].f -= t;
					Ed[i ^ 1].f += t;
					sum += t;
					if(sum == mF)
						break;
				}
			}
		return sum;
	}

	int Dinic(int s , int t){
		int ans = 0;
		S = s; T = t;
		while(bfs())
			ans += dfs(S , INF);
		return ans;
	}

	void clear(){memset(head , 0 , sizeof(int) * (T + 1)); cntEd = 1;};
}using flow::addE;

int N , M , arr[103][103];
	
int main(){
	cin >> N >> M;
	for(int i = 1 ; i <= N ; ++i)
		for(int j = 1 ; j <= M ; ++j)
			cin >> arr[i][j];
	for(int i = 1 ; i <= M ; ++i){
		flow::clear();
		for(int j = 1 ; j <= N ; ++j){
			flow::addE(0 , j , 1);
			bool vis[103] = {};
			for(int k = i ; k <= M ; ++k)
				if(!vis[(arr[j][k] - 1) / M]){
					vis[(arr[j][k] - 1) / M] = 1;
					flow::addE(j , N + (arr[j][k] - 1) / M + 1 , 1);
				}
		}
		for(int j = 1 ; j <= N ; ++j) flow::addE(N + j , N + N + 1 , 1);
		assert(flow::Dinic(0 , N + N + 1) == N);
		for(int j = 1 ; j <= N ; ++j)
			for(int k = flow::head[j] ; k ; k = flow::Ed[k].upEd)
				if(flow::Ed[k].end > N && !flow::Ed[k].f){
					int pos = flow::Ed[k].end - N;
					for(int l = i ; l <= M ; ++l)
						if((arr[j][l] - 1) / M + 1 == pos){
							swap(arr[j][i] , arr[j][l]);
							break;
						}
					break;
				}
	}
	for(int i = 1 ; i <= N ; ++i)
		for(int j = 1 ; j <= M ; ++j)
			cout << arr[i][j] << (j == M ? '\n' : ' ');
	for(int j = 1 ; j <= M ; ++j)
		for(int i = 1 ; i <= N ; ++i)
			for(int k = i ; k <= N ; ++k)
				if((arr[k][j] - 1) / M + 1 == i){
					swap(arr[k][j] , arr[i][j]); break;
				}
	for(int i = 1 ; i <= N ; ++i)
		for(int j = 1 ; j <= M ; ++j)
			cout << arr[i][j] << (j == M ? '\n' : ' ');
	return 0;
}


Measured memory_bytes: 768
#include <stdio.h>

int main(void)
{
	int a, b, c;
	int ii, cnt;

	cnt = 0;
	scanf("%d %d %d", &a, &b, &c);
	for (ii = a; ii <= b; ii++) {
		if ((c / ii) * ii == c) {
			cnt++;
		}
	}

	printf("%d\n", cnt);

	return 0;
}

Measured memory_bytes: 596
def main():
    N = int(input())
    words = [input() for _ in range(N)]
    past = [words[0]]
    for i in range(1, N):
        prev, now = words[i-1], words[i]
        if (now in past or prev[-1] != now[0]):
            print("No")
            return
        else:
            past.append(now)
    print("Yes")


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
#include<iostream>
using namespace std;
int main(){
		int a,b;
		cin>>a>>b;
		if(a<=0 && b>=0)
				cout<<"Zero\n";
		else if(a>0)
				cout<<"Positive\n";
		else if((b-a+1)%2==0)
						cout<<"Positive\n";
				else if((b-a+1)%2==1)
						cout<<"Negative\n";
		return 0;
		}

Measured memory_bytes: 256
from collections import defaultdict
import bisect

def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()

n = readInt()
a = readInts()
ans = 0
for i in range(n):
	while 1:
		if a[i]%2==0:
			a[i]=a[i]//2
			ans+=1
		else:
			break

print(ans)

Measured memory_bytes: 10492
N, M, X = map(int, input().split())
A = []
for i in range(N):
    a = list(map(int, input().split()))
    A.append(a)
ans = 100000000
for i in range(2**N):
    n = i
    al = [0] * M
    pr = 0
    for j in range(N):
        if n % 2 == 1:
            pr += A[j][0]
            for k in range(M):
                al[k] += A[j][k+1]
        n //= 2
    tes = 0
    for j in range(M):
        if al[j] < X:
            tes = 1

    if tes == 0:
        ans = min([ans, pr])

if ans == 100000000:
    print(-1)
else:
    print(ans)

Measured memory_bytes: 68400
//
//  main.cpp
//  procon
//
//  Created by ???????????? on 2015/05/21.
//  Copyright (c) 2015??´ y. inoue. All rights reserved.
//

#include <iostream>

int main(int argc, const char * argv[]) {
    while (true) {
        int N;
        std::cin >> N;

        if (N == 0) break;

        bool t[21][21];
        for (int i = 0; i < 21; i++) {
            for (int j = 0; j < 21; j++) {
                t[i][j] = false;
            }
        }
        for (int i = 0; i < N; i++) {
            int x, y;
            std::cin >> x >> y;
            t[y][x] = true;
        }

        int M;
        std::cin >> M;
        int get = 0;
        int x = 10, y = 10;
        for (int i = 0; i < M; i++) {
            char dir;
            int dis;
            std::cin >> dir >> dis;
            for (int j = 0; j < dis; j++) {
                switch (dir) {
                    case 'N':
                        y++;
                        break;

                    case 'S':
                        y--;
                        break;

                    case 'E':
                        x++;
                        break;

                    case 'W':
                        x--;
                        break;

                    default:
                        break;
                }

                if (t[y][x]) {
                    get++;
                    t[y][x] = false;
                }
            }
        }
        
        if (N == get) {
            std::cout << "Yes" << "\n";
        } else {
            std::cout << "No" << "\n";
        }
    }
}

Measured memory_bytes: 1120