akhauriyash/Code-Regression huggingface dataset:
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

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

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

//constant
//--------------------------------------------
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
int main(){
    string s;
    cin >> s;
    int l = s.size();
    bool flg=1;
    int i = 0;
    while(flg==1&&i<l){
        if((i+1)%2==0&&s[i]=='R') flg=0;
        else if((i+1)%2==1&&s[i]=='L') flg=0;
        i++;
        //cout << i << endl;
    }
    if(flg==1) cout << "Yes" << endl;
    else cout << "No" << endl; 
    
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>

using namespace std;
typedef long long ll;

int main(){

  int n;
  cin >> n;
  ll l[n];
  l[0] = 2;
  l[1] = 1;
  for (int i = 2; i <= n; i++){
    l[i] = l[i - 1] + l[i - 2];
  }
  cout << l[n] << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
  
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int A = sc.nextInt();
    int B = sc.nextInt();
    int C = sc.nextInt();
    int[] l = new int[N];
    for (int i = 0; i < N; i++) {
      l[i] = sc.nextInt();
    }
    
    int ans = dfs(0, l, 0, 0, 0, 0, A, B, C);

    System.out.println(ans);
  }
  
  private static int dfs(int n, int[] l, int mp,
                         int a, int b, int c,
                        int A, int B, int C) {
    if (n == l.length) {
      if (a == 0 || b == 0 || c == 0) {
        return Integer.MAX_VALUE;
      }
      return mp-30 + Math.abs(A-a) + Math.abs(B-b) + Math.abs(C-c);
    }
    int forA = dfs(n+1, l, mp+10, a+l[n], b, c, A, B, C);
    int forB = dfs(n+1, l, mp+10, a, b+l[n], c, A, B, C);
    int forC = dfs(n+1, l, mp+10, a, b, c+l[n], A, B, C);
    int nouse= dfs(n+1, l, mp, a, b, c, A, B, C);
    return Math.min(Math.min(forA, forB), Math.min(forC, nouse));
  }
}

Measured memory_bytes: 25044
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String[] str = in.readLine().split(" ");
    int a = Integer.parseInt(str[0]);
    int b = Integer.parseInt(str[1]);
    if(a+b>=3){
      if(a%3==0 || b%3==0 || (a+b)%3==0)
        System.out.println("Possible");
      else
        System.out.println("Impossible");
    } else {
      System.out.println("Impossible");
    }
  }
}

Measured memory_bytes: 32520
import java.util.*;

public class Main {

    public static void main(String[] args) {
        int N;
        int[] a, b, c;
        try (Scanner scanner = new Scanner(System.in)) {
            N = scanner.nextInt();

            a = new int[N];
            b = new int[N];
            c = new int[N];

            for (int i = 0; i < N; i++) {
                a[i] = scanner.nextInt();
                b[i] = scanner.nextInt();
                c[i] = scanner.nextInt();
            }
        }

        int result = solve(a, b, c, N);
        System.out.println(result);

        //test();
    }

    private static int solve(int[] a, int[] b, int[] c, int N) {
        int sa = 0;
        int sb = 0;
        int sc = 0;
        for (int i = 0; i < N; i++) {
            int newSa = Math.max(sb, sc) + a[i];
            int newSb = Math.max(sa, sc) + b[i];
            int newSc = Math.max(sa, sb) + c[i];
            sa = newSa;
            sb = newSb;
            sc = newSc;
        }
        return Math.max(sa, Math.max(sb, sc));
    }

    private static void test() {
        testCase(new int[] { 10, 20, 30}, new int[] {40, 50, 60},  new int[] {70, 80, 90}, 210);
        testCase(new int[] { 100 }, new int[] {10},  new int[] {1}, 100);
        testCase(new int[] { 6,8,2,7,4,2,7}, new int[] {7,8,5,8,6,3,5},  new int[] {8,3,2,6,8,4,1}, 46);
        System.out.println("DONE");
    }

    private static void testCase(int[] a, int[] b, int[] c, int expected) {
        int result = solve(a, b, c, a.length);
        if (result != expected) {
            System.out.println("FAILED a=" + Arrays.toString(a) + " b=" + Arrays.toString(b) + " c=" + Arrays.toString(c)
                    + ", was " + result + " expected " + expected);
        }
    }
}


Measured memory_bytes: 94016
#include<iostream>
#include <string>
#include <sstream>
#include <vector>
using namespace std;

int getPoint(string a,string b,char c){
    if(a.find(c) != std::string::npos){
        if(b.find(c) != std::string::npos){
            return 1;
        }
    }
    return 0;
}
int main()
{
    int n;
    int point=0;
    string s;
    cin>>n>>s;
    string s1,s2;
    int maxans=0;
    for(int i=1;i<n;i++){
        s1="";
        s2="";
        point=0;
        for(int j=0;j<i;j++){
            s1=s1+s[j];
        }
        for(int j=i;j<n;j++){
            s2=s2+s[j];
            }
        point+=getPoint(s1,s2,'a');
        point+=getPoint(s1,s2,'b');
        point+=getPoint(s1,s2,'c');
        point+=getPoint(s1,s2,'d');
        point+=getPoint(s1,s2,'e');
        point+=getPoint(s1,s2,'f');
        point+=getPoint(s1,s2,'g');
        point+=getPoint(s1,s2,'h');
        point+=getPoint(s1,s2,'i');
        point+=getPoint(s1,s2,'j');
        point+=getPoint(s1,s2,'k');
        point+=getPoint(s1,s2,'l');
        point+=getPoint(s1,s2,'m');
        point+=getPoint(s1,s2,'n');
        point+=getPoint(s1,s2,'o');
        point+=getPoint(s1,s2,'p');
        point+=getPoint(s1,s2,'q');
        point+=getPoint(s1,s2,'r');
        point+=getPoint(s1,s2,'s');
        point+=getPoint(s1,s2,'t');
        point+=getPoint(s1,s2,'u');
        point+=getPoint(s1,s2,'v');
        point+=getPoint(s1,s2,'w');
        point+=getPoint(s1,s2,'x');
        point+=getPoint(s1,s2,'y');
        point+=getPoint(s1,s2,'z');
        
        if(point>maxans){
            maxans=point;
        }
            }


    cout<<maxans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define _GLIBCXX_DEBUG
#define debug(x) cerr << #x << ": " << x << '\n';

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<pair<long long, long long> > vec(n);
  // vec.first -> a, vec.second -> b;

  vector<pair<long long, long long> > check_point(m);
  // check_point.first -> a, check_point.second -> b;
  for (int i = 0; i < n; i++) {
    cin >> vec[i].first >> vec[i].second;
  }
  for (int i = 0; i < m; i++) {
    cin >> check_point[i].first >> check_point[i].second;
  }
  pair<long long, int> ans;
  ans.first = 1000000000000000000LL, ans.second = 0;
  for (int i = 0; i < n; i++) {
    long long dis = 0;
    vector<pair<long long, int> > check(m);
    for (int j = 0; j < m; j++) {
      check[j].first = abs(vec[i].first - check_point[j].first) +
                 abs(vec[i].second - check_point[j].second);
      check[j].second = 1 + j;
    }
    sort(check.begin(), check.end());
    int x = 0;
    while (check[x] == check[0]) {
      cout << check[x].second << '\n';
      x++;
    }
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int GCD(const int& a, const int& b){
   const int& _a = max(a,b);
   const int& _b = min(a,b);
   if(_a % _b == 0){
      return _b;
   }
   else{
      return GCD(_b, _a % _b);
   }
}

int LCM(const int& a, const int& b){
   const int& _a = max(a,b);
   const int& _b = min(a,b);
   return (_a*_b)/(GCD(_a, _b));
}

int main(){
   int n, k;
   cin >> n >> k;
   vector<int> x(n);
   for(int i = 0; i < n; i++){
      cin >> x[i];
   }

   int ans = 0;
   for(int i = 0; i < n; i++){
      int da = 2*x[i];
      int db = 2*(k-x[i]);
      ans += min(da, db);
   }
   cout << ans << endl;

   return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
using namespace std;
int main()
{
	string str;
	cin>>str;
	for(int i=0;i<str.size();i++)
	{
		if(str[i]==',')
		{
			cout<<" ";
		}
		else
		{
			cout<<str[i];
		}
	}
	cout<<endl;
	return 0;
} 

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

using namespace std;


int main(void){

	int n;
	string MCXI[2];
	int tmp;
	int kuri;
	int M[2],C[2],X[2],I[2];
	int am,ac,ax,ai;
	cin>>n;
	

	for(int j=0;j<n;j++){
		cin>>MCXI[0]>>MCXI[1];

		for(int i=0;i<2;i++){
			M[i]=0;
			C[i]=0;
			X[i]=0;
			I[i]=0;
		}

		for(int i=0;i<2;i++){

			tmp=MCXI[i].find('i');
			if(tmp!=-1){
				I[i]=1;
				if(tmp>0){
					if(MCXI[i][tmp-1]!='m'&&MCXI[i][tmp-1]!='c'&&MCXI[i][tmp-1]!='x'&&MCXI[i][tmp-1]!='i'){
						I[i]*=MCXI[i][tmp-1]-'0';
					}
				}
			}

			tmp=MCXI[i].find('x');
			if(tmp!=-1){
				X[i]=1;
				if(tmp>0){
					if(MCXI[i][tmp-1]!='m'&&MCXI[i][tmp-1]!='c'&&MCXI[i][tmp-1]!='x'&&MCXI[i][tmp-1]!='i'){
						X[i]*=MCXI[i][tmp-1]-'0';
					}
				}
			}

			tmp=MCXI[i].find('c');
			if(tmp!=-1){
				C[i]=1;
				if(tmp>0){
					if(MCXI[i][tmp-1]!='m'&&MCXI[i][tmp-1]!='c'&&MCXI[i][tmp-1]!='x'&&MCXI[i][tmp-1]!='i'){
						C[i]*=MCXI[i][tmp-1]-'0';
					}
				}
			}

			tmp=MCXI[i].find('m');
			if(tmp!=-1){
				M[i]=1;
				if(tmp>0){
					if(MCXI[i][tmp-1]!='m'&&MCXI[i][tmp-1]!='c'&&MCXI[i][tmp-1]!='x'&&MCXI[i][tmp-1]!='i'){
						M[i]*=MCXI[i][tmp-1]-'0';
					}
				}
			}
		}
		am=0,ac=0,ai=0,ax=0;
		kuri=0;
		ai=(I[0]+I[1]+kuri)%10;
		kuri=(I[0]+I[1]+kuri)/10;
		ax=(X[0]+X[1]+kuri)%10;
		kuri=(X[0]+X[1]+kuri)/10;
		ac=(C[0]+C[1]+kuri)%10;
		kuri=(C[0]+C[1]+kuri)/10;
		am=(M[0]+M[1]+kuri)%10;
		kuri=(M[0]+M[1]+kuri)/10;

		if(am!=0){
			if(am!=1) cout<<am<<"m";
			else cout<<"m";
		}
		if(ac!=0){
			if(ac!=1) cout<<ac<<"c";
			else cout<<"c";
		}
		if(ax!=0){
			if(ax!=1) cout<<ax<<"x";
			else cout<<"x";
		}
		if(ai!=0){
			if(ai!=1) cout<<ai<<"i";
			else cout<<"i";
		}
		cout<<endl;
	}

	return 0;
}

Measured memory_bytes: 1208
import math
a = input()
b = input()
c = input()
d = input()
e = input()
l = []
if a[-1] != '0': l.append(a[-1])
if b[-1] != '0': l.append(b[-1])
if c[-1] != '0': l.append(c[-1])
if d[-1] != '0': l.append(d[-1])
if e[-1] != '0': l.append(e[-1])
if l == []:
  print(int(a)+int(b)+int(c)+int(d)+int(e))
else:
  min_l = min(l)
  p = [ a,b,c,d,e ]
  o = []
  len_p = len(p)
  tmp_p = ''
  for i in range(0, len_p):
    if p[i][-1] == min_l:
      tmp_p = int(p.pop(i))
      break
  new_p = 0
  for i in p:
    new_p += math.ceil(int(i)/10)*10
  print(new_p+tmp_p)

Measured memory_bytes: 3064
#
# abc060 c
#
import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """2 4
0 3"""
        output = """7"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """2 4
0 5"""
        output = """8"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """4 1000000000
0 1000 1000000 1000000000"""
        output = """2000000000"""
        self.assertIO(input, output)

    def test_入力例_4(self):
        input = """1 1
0"""
        output = """1"""
        self.assertIO(input, output)

    def test_入力例_5(self):
        input = """9 10
0 3 5 7 100 110 200 300 311"""
        output = """67"""
        self.assertIO(input, output)


def resolve():
    N, T = map(int, input().split())
    t = list(map(int, input().split()))

    ans = T
    for i in range(N-2, -1, -1):
        ans += min(T, t[i+1]-t[i])

    print(ans)


if __name__ == "__main__":
    # unittest.main()
    resolve()


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

using namespace std;
typedef long long ll;

int main()
{
    ios_base::sync_with_stdio(0);

    int N, K;
    cin >> N >> K;

    int ans = 0;
    while (N)
    {
        ans++;
        N /= K;
    }
    cout << ans << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#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)
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;

int n, m, q;
VVI perm;
VVI rest2;
ll maxi = 0;

void dfs(VI hist) {
  if ((int)hist.size() == n) {
    ll maxtmp = 0;
    rep(i, q) {
      int a = rest2.at(i).at(0);
      int b = rest2.at(i).at(1);
      a--;
      b--;
      int c = rest2.at(i).at(2);
      int d = rest2.at(i).at(3);
      if (hist.at(b) - hist.at(a) == c) {
        maxtmp += d;
      }
    }
    maxi = max(maxi, maxtmp);
    return;
  }
  for (int i = hist.back(); i < m + 1; i++) {
    VI hist2(hist.size());
    copy(hist.begin(), hist.end(), hist2.begin());
    hist2.push_back(i);
    dfs(hist2);
  }
}

int main() {
  cin >> n >> m >> q;
  VVI rest(q, VI(4));
  rep(i, q) {
    cin >> rest.at(i).at(0) >> rest.at(i).at(1) >> rest.at(i).at(2) >>
        rest.at(i).at(3);
  }
  swap(rest, rest2);

  rrep(j, m) { dfs({j}); }
  cout << maxi << endl;
  // for (auto per : perm) {
  //   for (auto pe : per) {
  //     cout << pe << " ";
  //   }
  //   cout << endl;
  // }
  return 0;
}


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


int main(){
  string s;
  cin >> s;
  if (s.at(2) == s.at(3) && s.at(4) == s.at(5))
  {
    cout << "Yes" << endl;
    return 0;
  }
  cout << "No" << endl;
  return 0;
}

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

#define loop(s, e, i) for (int i = s; i < e; ++i)
#define print(s) cout << s << endl;
#define DIV 1000000007
#define ll long long
using namespace std;

/*
浮動小数点の入力
cout << fixed << setprecision(9) << endl;
*/

int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<int>> A(M, vector<int>(N));
  loop(0, M, i) {
    int K;
    cin >> K;
    loop(0, K, j) {
      int tmp;
      cin >> tmp;
      tmp--;
      A[i][tmp] = 1;
    }
  }
  vector<int> P(M);
  loop(0, M, i) cin >> P[i];

  int c = 0;
  for(int bit=0; bit<(1<<N); bit++) {
    vector<int> COUNT(M);
    for (int i=0; i<N; i++) {
      if (!(bit & 1<<i)) continue;
      loop(0, M, j) {
        if (A[j][i] == 1) COUNT[j]++;
      } 
    }
    bool result = true;
    loop(0, M, i) {
      if (COUNT[i]%2 != P[i]) {
        result = false;
        break;
      }
    }
    if (result) {
      c++;
    }
  }
  print(c);
}


Measured memory_bytes: 3632
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
template<typename T, typename U> static void amin(T &x, U y) { if (y < x) x = y; }
template<typename T, typename U> static void amax(T &x, U y) { if (x < y) x = y; }

int main() {
	int N;
	while (~scanf("%d", &N)) {
		vector<int> a(N);
		for (int i = 0; i < N; ++ i)
			scanf("%d", &a[i]);
		int n2 = 0, n1 = 0, n0 = 0;
		for (int x : a) {
			if (x % 4 == 0) {
				++ n2;
			} else if (x % 2 == 0) {
				++ n1;
			} else {
				++ n0;
			}
		}
		bool ans = n2 >= n0;
		ans |= n1 == 0 && n0 == n2 + 1;
		puts(ans ? "Yes" : "No");
	}
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<int> vec;
int main()
{
   int n,ar[200],i,j;
   cin>>n;
   for(i=1; i<n; i++)
   {
   	 cin>>ar[i];
   }
   vec.push_back(ar[1]);
   for(i=2; i<n; i++)
   {
   	 j=min(ar[i-1],ar[i]);
   	 vec.push_back(j);
   }
   vec.push_back(ar[n-1]);

   ll sum=0;;
   int sz=vec.size();
   for(i=0; i<sz; i++)
   {
   	 sum+=vec[i];
   }
   cout<<sum<<endl;
   return 0;
}

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

using namespace std;

#define sz(x) (int)((x).size())
#define forn(i,n) for (int i=0; i < n; i++)
#define forse(i,s,e) for (int i=s; i < e; i++)
#define pb push_back
#define fi first
#define se second
#define all(vec) vec.begin(), vec.end()
#define time() ((double)clock() / CLOCKS_PER_SEC)

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

//Debug
string to_string(const string& s) { return '"' + s + '"';}
string to_string(const char* s) { return to_string((string) s);}
string to_string(bool b) { return (b ? "true" : "false");}
template <typename A, typename B>
string to_string(pair<A, B> p) {return "("+to_string(p.fi)+", "+to_string(p.se)+")";}
template <typename A>
string to_string(A v) {
	if(v.begin()==v.end()) return "";
	return accumulate(++v.begin(), v.end(), "{"+to_string(*v.begin()),
			[](const string& a, auto b){ return a + ", " + to_string(b);})+"}";
}
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(...) false
#endif


double PI=3.141592653589793;

void solve(){
	int x,y;
	cin >> x >> y;
	if((y&1)||(x>(y/2)||(2*x-(y/2)<0))) cout << "No";
	else cout << "Yes";
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0); 
	int T=1;
//	cin >> T;
	forse(c,1,T+1){
		//	cout << "Case #" << cid << ": ";
		solve();
	}
}


Measured memory_bytes: 3656
N=int(input())
A=[None]*N
for i in range(N):
        A[i]=int(input())
B=sorted(A)
M=B[N-1]
if B[N-1]==B[N-2]:
        for i in range(N):
                print(M)
else:
        for i in range(N):
                if A[i]==M:
                        print(B[N-2])
                else:
                        print(M)

Measured memory_bytes: 61500
#include<iostream>
#include<cstdio>
#define ll long long
using namespace std;
const int mod = 924844033, maxn = 2010;
int n, k, fac[maxn], a[maxn], cnt;
ll f[maxn][maxn][2][2];
bool vis[maxn];
int main()
{
	scanf("%d %d", &n, &k);
	fac[0] = 1;
	for(int i = 1; i <= n; i++) fac[i] = 1ll * fac[i - 1] * i % mod;
	for(int i = 1; i <= n; i++) if(!vis[i])
		for(int j = i; j <= n; j += k) vis[j] = 1, a[++cnt] = j;
	f[0][0][0][0] = 1;
	a[0] = -1e9;
	for(int i = 1; i <= n; i++) {
		f[i][0][0][0] = 1;
		for(int j = 1; j <= i; j++) {
			f[i][j][0][0] = (f[i - 1][j][1][0] + f[i - 1][j][0][0] + (a[i] - a[i - 1] == k) * f[i - 1][j - 1][0][0]) % mod;
			f[i][j][0][1] = (a[i + 1] - a[i] == k) * (f[i - 1][j - 1][1][0] + f[i - 1][j - 1][0][0]) % mod;
			f[i][j][1][0] = (f[i - 1][j][0][1] + f[i - 1][j][1][1] + (a[i] - a[i - 1] == k) * f[i - 1][j - 1][0][1]) % mod;
			f[i][j][1][1] = (a[i + 1] - a[i] == k) * (f[i - 1][j - 1][0][1] + f[i - 1][j - 1][1][1]) % mod;
		}
	} 
	int ans = 0;
	for(int i = 0; i <= n; i++) {
		int sum = (f[n][i][0][0] + f[n][i][0][1] + f[n][i][1][0] + f[n][i][1][1]) % mod;
		if(i & 1) ans = (ans - 1ll * sum * fac[n - i] % mod + mod) % mod;
			else ans = (ans + 1ll * sum * fac[n - i] % mod) % mod;
	}
	printf("%d\n", ans);
	return 0;
}

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

int main(){
  int N,M; cin >> N >> M;
  char a[N][N],b[M][M];

  rep(i,N){
    rep(j,N) cin >> a[i][j];
  }
  rep(i,M){
    rep(j,M) cin >> b[i][j];
  }

  for(int i=0;i<N-M+1;i++){
    for(int j=0;j<N-M+1;j++){
      bool check=true;
      for(int k=0;k<M;k++){
        for(int l=0;l<M;l++){
          if(a[i+k][j+l]!=b[k][l]){
            check=false;
          }
        }
      }
      if(check){
        puts("Yes");
        return 0;
      }
    }
  }
  puts("No");
}

Measured memory_bytes: 256
s = input()


def walk(s):
    ls = len(s)
    nc = 0
    sc = 0
    wc = 0
    ec = 0
    l=[]
    for i in range(ls):
        if s[i] == "W":
            wc += 1
            l.append(wc)
        elif s[i] == "E":
            ec += 1
            l.append(ec)
        elif s[i] == "N":
            nc += 1
            l.append(nc)
        else:
            sc += 1
            l.append(sc)
    if (wc>0 and ec==0) or (wc==0 and ec>0) or (nc==0 and sc>0) or (nc>0 and sc==0):
        print("No")
        return
    
    else:
        print("Yes")
        return
walk(s)


Measured memory_bytes: 8980
#include<bits/stdc++.h>
#define i64 long long
#define vi32 vector<int>
#define vi64 vector< long long>
#define  ii pair<int,int>
const  long long mod = 1e9 + 7, inf = 1e9, linf = 1 << 30; //linf = 9223372036854775807;
const long long hashmod[4] = { (int)1e9 + 2277, (int)1e9 + 5277, (int)1e9 + 8277, (int)1e9 + 9277 };
const long double EPS = 0.000000001L, pi = acos(-1);
using namespace std;
#define pb push_back
#define mp make_pair
#define N 200005
//int base = 311;
using namespace std;
int main()
{
   int n;
   cin>>n;
   double s=0;

   double t;
   while(n--)
   {
       cin>>t;
       s+=1/t;
   }
   s=1/s;
   printf("%0.5lf",s);
   return 0;


}




/* Written by a random fan of Mr.Siro 

Association of people who died from abandonment

Gb_H

*/


Measured memory_bytes: 256
#include "iostream"
#include "algorithm"
#include "string"
#include "vector"
#include "cmath"
#define lp(n) for (int i = 0; i < n; i++)
#define lop(n,i) for (int i = 0; i < n; i++)
#define INT_MAX 2147483647
#define LLINT_MAX 9223372036854775807
#define mod 1000000007
#define ll long long int
using namespace std;

int main() {
	ll n, a, b;
	cin >> n >> a >> b;
	if ((n == 1 && a != b) || a > b) {
		cout << 0 << endl;
		return 0;
	}
	cout << a+b*(n-1)-(b+a*(n-1))+1 << endl;
	return 0;
}

Measured memory_bytes: 256
def calc_diff_sum(nums, n)
  nums.inject(0) do |s, i|
    s += (i - n).abs
  end
end

def main
  n = ARGF.gets.chomp.to_i
  nums = ARGF.gets.split.map.with_index do |s, idx|
    s.to_i - idx
  end.sort

  candidates = if nums.length.odd?
                 [nums[nums.length / 2]]
               else
                 nums[nums.length / 2 - 1, 2]
               end

  min_diff_sum = candidates.map do |c|
    calc_diff_sum(nums, c)
  end.min

  puts min_diff_sum
end

if __FILE__ == $0
  main
end


Measured memory_bytes: 19080
N, X, Y = map(int, input().split())
d = {k: 0 for k in range(1, N)}
for i in range(1, N + 1):
    for j in range(i + 1, N + 1):
        m = min(j - i,
                abs(X - i) + 1 + abs(j - Y),
                abs(Y - i) + 1 + abs(j - X))
        d[m] += 1
for k in range(1, N):
    print(d[k])


Measured memory_bytes: 48860
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <climits>
#include <cmath>
#include <utility>
#include <string>
#include <cstring>
#include <functional>

using namespace std;

const int maxn = 102;
int n, sum, x[maxn];

int calc(int v) {
    int res = 0;
    for (int i = 0; i < n; ++i)
        res += (x[i] - v) * (x[i] - v);
    return res;
}

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> x[i];
        sum += x[i];
    }
    
    int avg = sum / n;
    cout << min(calc(avg), calc(avg+1)) << endl;;
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define F first
#define S second
#define int long long
#define ll long long
//#define int  unsigned long long
#define pb push_back
//#define double long double

using namespace std;
using namespace __gnu_pbds;
typedef  tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int mod = 998244353;
const int N = 1500000;
const int K = 50 ;
vector < int > g[N];
int cnt;
pair < int, int > dfs1(int v, int p = -1){
    int c = 0;
    int res = 0;
    for (auto u: g[v]){
        if (u == p) continue;
        auto x = dfs1(u, v);
        c += x.F;
        res += x.S;
    }
    res -= c / 2;
    c %= 2;
    if (c == 0 && p != -1){
        c++;
        res++;
    }
    return {c, res};
}
int dfs2(int v, int x, int p = -1){
    multiset < int > t;
    for (auto u: g[v]){
        if (u == p) continue;
        auto y = dfs2(u, x, v);
        t.insert(y);
    }
    vector < int > f1;
    while(t.size() > 1){
        auto y = t.end();
        y--;
        auto q = t.begin();
        int q1 = *q;
        q++;
        int q2 = *q;
        if (q1 + q2 > x) break;
        if (*y + *t.begin() > x){
            f1.pb(*y);
            t.erase(t.find(*y));
            continue;
        }
        auto z = t.upper_bound(x - (*y));
        while(z == t.end() || z == y || x - (*z) < (*y)) z--;
        if (z == y) z--;
        int v1 = *z;
        int v2 = *y;
        t.erase(t.find(v1));
        t.erase(t.find(v2));
        cnt--;
    }
    for (auto i: f1) t.insert(i);
    if (t.size() == 0){;
        cnt += (p != -1);
        return 1;
    }
    if (p == -1) return 0;
    if (*t.begin() + 1 > x){
        cnt++;
        return 1;
    }
    return (*t.begin()) + 1;
}
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt", "r", stdin);
    int n;
    cin >> n;
    for (int i = 1; i < n; i++){
        int u, v;
        cin >> u >> v;
        g[u].pb(v);
        g[v].pb(u);
    }
    int ans1 = dfs1(1).S;
    int l = 0;
    int r = n + 1;
    while(r - l > 1){
        int mid = (r + l) / 2;
        cnt = 0;
        dfs2(1, mid);
        if (cnt <= ans1){
            r = mid;
        } else{
            l = mid;
        }
    }
    cout << ans1 << " " << r;
}


Measured memory_bytes: 53248
#pragma warning(disable : 4996)
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include<unordered_map>
#define endl                         '\n'	
#define Ceil(x,y)             ((x+y-1)/y)
#define sz(s)               (int)s.size()
#define RT(x)           return cout<<x,0;
#define mem(x,y)    memset(x,y,sizeof(x))
#define all(v) ((v).begin()), ((v).end())
#define vi                    vector<int>
#define pii                 pair<int,int>
#define forr(i, n) for (int i =0; i <int(n); i++)
int dx[] = { 0, 0, 1, -1, 1, -1, 1, -1 };
int dy[] = { 1, -1, 0, 0, -1, 1, 1, -1 };
const double EPS = 1e-7;
const int N = 1e7 + 5, mod = 1e9 + 7;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
//ll gcd(ll x, ll y) { return (!y) ? x : gcd(y, x%y); }
//ll lcm(ll x, ll y) { return ((x / gcd(x, y))*y); }
#define ll	long long
using namespace std;

//int arr[100000];
int main()
{

	int n,c=0,a=0;
	cin >> n;
	for (int i = 1; i <= n; i++)
	{
		int y = i;
		a = 0;
		while (y > 0) a++, y /= 10;
		if (a % 2) c++;
	}
	cout << c;
}


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

int main(){
	int N;
	int ans=1;
	int a[100000],b[100000]={0};
	cin>>N;
	for( int i=0 ; i<N ; i++ ){
		cin>>a[i];
	}
	for( int i=0 ; i<N ; i++ ){
		b[a[i]]++;
	}
	for( int i=0 ; i<N ; i++ ){
		if(N%2==0){
			if(i%2==1){
				if(b[i]==2);
				else{
					ans=0;
					break;
				}
			}
		}
		else{
			if(i%2==0){
				if(i==0&&b[0]==1);
				else if(b[i]==2);
				else{
					ans=0;
					break;
				}
			}
		}
		if(i==N-1){
			for( int i=0 ; i<(N/2) ; i++ ){
				ans*=2;
				ans=ans%1000000007;
			}
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 1024
using System;
using System.Linq;
using System.Collections.Generic;
class c
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        var list = new List<int>();
        for (int i = 0; i < n; i++) list.Add(int.Parse(Console.ReadLine()));
        Console.WriteLine(list.Any(f => f % 2 == 1) ? "first" : "second");
    }
}

Measured memory_bytes: 18144
#include <bits/stdc++.h>
using namespace std;
#define rep(i, m, n) for (int i = m; i < n; ++i)
#define rem(i, m, n) for (int i = m; i > n; --i)
typedef long long ll;
#define mod 1000000007

int main() {
  int N, K;
  cin >> N >> K;
  double ans = 0;
  rep(i, 1, N + 1) {
    ll score = i;
    int n = 1;
    while(score < K) {
      score *= 2;
      n *= 2;
    }
    ans += (double)1 / n;
  }
  ans /= N;
  printf("%.15lf\n", ans);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mod 1000000007
#define mod998 998244353
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define mkp make_pair
typedef long long ll;
using namespace std;

int N;
string S;
map<string, ll>mp;
ll res;

int main() {
	cin >> N;
	for (int i = 0; i < N; ++i) {
		cin >> S;
		sort(S.begin(), S.end());
		++mp[S];
	}
	for (auto p : mp) {
		res += p.second*(p.second - 1) / 2;
	}
	cout << res << endl;
}

Measured memory_bytes: 11136
from collections import Counter

N = int(input())
*A, = map(int, input().split())
A = sorted(A)
max_A = A[-1]
cnt = Counter(A)
admissible = [True] * (max_A + 1)
checked = [False] * (max_A + 1)
ans = 0
for a in A:
    if not admissible[a] or checked[a]: continue
    ans += 1
    i = 2
    while a * i <= max_A:
        admissible[a * i] = False
        i += 1
    checked[a] = True
    if cnt[a] > 1: ans -= 1
print(ans)

Measured memory_bytes: 46308
#include <stdio.h>
 
int main()
{
  char str[16];
  
  scanf( "%s", str );
  
  if ( ( str[0] == str[1] && str[2] == str[3] && str[0] != str[2] ) ||
      (str[0] == str[2] && str[1] == str[3] && str[0] != str[1] ) ||
      (str[0] == str[3] && str[1] == str[2] && str[0] != str[1] ) ) {
    printf( "Yes\n" );
  } else {
    printf( "No\n" );
  }
  
}

Measured memory_bytes: 128
"""考え方
ブロックとそのブロック内の人数を調べることで、「現時点での幸福度」を調べる。
一回変換するごとに幸福度が2向上する。

"""

N,K = map(int, input().split())
S = input()


before_s = 'a'
cnt_str_cng = 0
ans = 0
for s in S:
  if s == before_s:
    ans += 1
  else:
    cnt_str_cng += 1
  before_s = s

if cnt_str_cng - 1 <= K:
  ans = N - 1
else:
  ans += K * 2

if ans >= N:
  ans = N - 1

print(ans)

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



public class Main{
	public static void main(String[] args){
		Scanner scan=new Scanner(System.in);
		int n=scan.nextInt();
		int m=scan.nextInt();
		int l=scan.nextInt();

		int[][] matrix_nm=new int[n][m];
		int[][] matrix_ml=new int[m][l];
		long[][] matrix_nl=new long[n][l];

		for(int i=0;i<n;i++){
		Arrays.fill(matrix_nl[i], 0);
		}//???????????????0??§?????????

		for(int i=0;i<n;i++){
			for(int j=0;j<m;j++){
				matrix_nm[i][j]=scan.nextInt();
			}
		}

		for(int i=0;i<m;i++){
			for(int j=0;j<l;j++){
				matrix_ml[i][j]=scan.nextInt();
			}
		}

		for(int i=0;i<n;i++){
			for(int j=0;j<l;j++){
				for(int k=0;k<m;k++){
				matrix_nl[i][j]+=(matrix_nm[i][k])*(matrix_ml[k][j]);//??£??\??????????????°????????????
				}
			}
		}

		for(int i=0;i<n;i++){
			for(int j=0;j<l;j++){
				System.out.print(matrix_nl[i][j]);
				if(j<l-1){System.out.print(" ");}
			}System.out.println();
		}


		scan.close();
}


}

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

using namespace std;
typedef pair<int, int> P;
typedef long long int ll;
const int INF = 1<<30;

int main(){
  int n;cin>>n;
  vector<int> a(n*3);
  for(int i=0;i<n*3;i++){
  	cin>>a[i];
  }
  sort(a.begin(), a.end());
  ll ans=0;
  for(int i=n*3-2;i>=n;i-=2){
  	ans+=(ll)a[i];
  }
  cout<<ans<<endl;
}


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

int D;
const int M = 26;
vector<int> C;
vector<vector<int>> S;
vector<int> T;

const int INF = 1<<30;

template<class T> inline bool chmax(T &a, T b)
{
    if(a < b)
    {
        a = b;
        return true;
    }
    return false;
}

std::mt19937 mt{ std::random_device{}() };

int randint(int lower, int upper)
{
    std::uniform_int_distribution<int> dist(lower, upper);
    return dist(mt);
}

int calc_score(int N=D)
{
    assert(N <= D);
    int ans = 0;
    vector<int> last(M, -1);
    for(int i=0; i<N; i++)
    {
        if(T[i] != -1)
        {
            ans += S[i][T[i]];
            last[T[i]] = i;
        }
        for(int j=0; j<M; j++)
        {
            ans -= C[j] * (i - last[j]);
        }
    }
    return ans;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> D;
    C.resize(M);
    for(int i=0; i<M; i++) cin >> C[i];
    S.resize(D);
    for(int i=0; i<D; i++)
    {
        S[i].resize(M);
        for(int j=0; j<M; j++)
        {
            cin >> S[i][j];
        }
    }

    int fscore = -INF;
    vector<int> ans;
    for(int k=0; k<=26; k++)
    {
        T.assign(D, -1);
        for(int i=0; i<D; i++)
        {
            int score = -INF;
            int idx = -1;
            for(int j=0; j<M; j++)
            {
                T[i] = j;
                int nscore = calc_score(min(i+1 + k, D));
                if(chmax(score, nscore)) idx = j;
            }
            T[i] = idx;
        }
        int score = calc_score();
        if(chmax(fscore, score)) ans = T;
    }
    for(int i=0; i<D; i++)
    {
        cout << T[i] + 1 << '\n';
    }
    return 0;
}


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

void fnInput(int &a_riElementCnt, vector<int> &a_rviElement, 
             int &a_riTargetCnt , vector<int> &a_rviTarget )
{
  cin >> a_riElementCnt;

  a_rviElement.resize(a_riElementCnt);
  for (int i = 0; i < a_riElementCnt; i++)
    cin >> a_rviElement[i];

  cin >> a_riTargetCnt;

  a_rviTarget.resize(a_riTargetCnt);
  for (int i = 0; i < a_riTargetCnt; i++)
    cin >> a_rviTarget[i];
}

int fnRcsSearch(int a_iPos, int a_iTarget, const vector<int> &a_cnrviElement,
                vector<vector<int>> &a_rvviOK)
{
  if (!a_iTarget)    return 1;
  if (a_iTarget < 0) return 0;
  if (a_iPos == a_cnrviElement.size())  return 0;
  if (a_rvviOK[a_iPos][a_iTarget] != -1)
    return a_rvviOK[a_iPos][a_iTarget];

  int iRtn;
  int iSmallTarget;

  iRtn = fnRcsSearch(a_iPos + 1, a_iTarget, a_cnrviElement, a_rvviOK);
  a_rvviOK[a_iPos + 1][a_iTarget] = iRtn;
  if (iRtn)  return iRtn;

  iSmallTarget = a_iTarget - a_cnrviElement[a_iPos];
  iRtn = fnRcsSearch(a_iPos + 1, iSmallTarget, a_cnrviElement, a_rvviOK);
  if (iSmallTarget >= 0)
    a_rvviOK[a_iPos + 1][iSmallTarget] = iRtn;
  return iRtn;
}

void fnExhSearch(const vector<int> &a_cnrviElement, const vector<int> &a_cnrviTarget)
{
  vector<vector<int>> vviOK(21, vector<int>(2001, -1));
  
  for (int i = 0; i < a_cnrviTarget.size(); i++)
  {
    int iTarget = a_cnrviTarget[i];
    int iRtn;

    if (iRtn = fnRcsSearch(0, iTarget, a_cnrviElement, vviOK))
      cout << "yes" << endl;
    else
      cout << "no" << endl;

    vviOK[0][iTarget] = iRtn;
  }
}

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

  int iElementCnt, iTargetCnt;
  vector<int> viElement, viTarget;

  fnInput(iElementCnt, viElement, iTargetCnt, viTarget);
  fnExhSearch(viElement, viTarget);

  return 0;
}

Measured memory_bytes: 1340
n,k = map(int,input().split())
a = list(map(int,input().split()))
mod = 10**9+7
a.sort()
mi = []
pl = []
if n == k:
    ans = 1
    for i in a:
        ans *= i
        ans %= mod
    print(ans)
    exit()
for i in a:
    if i < 0:
        mi.append(i)
    else:
        pl.append(i)
if pl == []:
    ans = 1
    count = 0
    if k%2:
        while count < k:
            ans *= a[-1-count]
            ans %= mod
            count += 1
    else:
        while count < k:
            ans *= a[count]
            ans %= mod
            count += 1
    print(ans)    
    exit()
pl = sorted(pl,reverse=True)
ip = 0
im = 0
if k%2:
    count = pl[0]
    k -= 1
    ip += 1
else:
    count = 1
while k > 0:
    check1 = True
    check2 = True
    if ip+2 <= len(pl):
        x = pl[ip]*pl[ip+1]    
    else:
        x = 1
        check1 = False
    if im+2 <= len(mi):
        y = mi[im]*mi[im+1]
    else:
        y = 1
        check2 = False
    if x > y or (check1 and not check2):
        ip += 2
        count = (x*count)%mod
    else:
        if check2:
            im += 2
            count = (y*count)%mod
    if check1 == False and check2 == False:
        break
    k -= 2

print(count%mod)

Measured memory_bytes: 33160
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define int long long
#define w(t) int t;cin>>t;while(t--)
#define pb push_back
#define mk make_pair
#define ascSort(v) sort(v.begin(), v.end())
#define descSort(v) sort(v.begin(), v.end(), greater<int>())
#define ff first
#define ss second
#define pi pair<int,int>
#define vi vector<int>
#define umapi unordered_map<int,int>
#define INF 1000000007
const int mod=998244353;
using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>PBDS;

void FIO(){
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);	
}
double dp[3000][3000];
double solve(vector<double>& p, int n, int max){
	if(max==0)
		return 1.00;
	if(n==0)
		return 0.00;
	
	if(dp[n][max]>-0.99)
		return dp[n][max];
	else
		return dp[n][max]=p[n-1]*solve(p,n-1,max-1)+(1.00-p[n-1])*solve(p,n-1,max);
}

int32_t main(){
	
	//FIO();
	int n;cin>>n;
	vector<double> p(n);
	for(int i=0; i<n; i++){
		cin>>p[i];
	}
	for(int i=0; i<=n; i++){
		for(int j=0; j<=n; j++){
			dp[i][j]=-1.00;
		}
	}
	double ans=solve(p,n,n/2+1);
	cout<<fixed<<setprecision(10)<<ans<<"\n";
	return 0;
		
}
		
		



Measured memory_bytes: 74336
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <cstdio>
using namespace std;
#define F first
#define S second
typedef long long ll;
typedef pair<ll,ll> P;
int n,ans;
int p[105];
int main(void){
    cin>>n;
    for(int i=0;i<n;i++)cin>>p[i];
    sort(p,p+n,greater<int>());
    for(int i=0;i<n;i++){
        if(p[i]>=i+1)ans=i+1;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3160
#include <iostream>
#include <set>
using namespace std;
string s;
int main()
{
	ios_base::sync_with_stdio(0);cin.tie();cout.tie();
	cin>>s;
	if ((int)s.length()<26)
	{
		for (char c='a';c<='z';++c)
		{
			if (s.find(c)==-1)
			{
				cout<<s<<c<<endl;
				return 0;
			}
		}
	}
	else
	{
		set <char> x;
		while (!s.empty())
		{
			char c=s.back();
			x.insert(c);
			s.pop_back();
			if (c!=*x.rbegin())
			{
				cout<<s<<*x.upper_bound(c)<<endl;
				return 0;
			}
		}
		cout<<"-1\n";
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#define mod 1000000007
using namespace std;
int main(){
    int h,w;
    cin>>h>>w;
    char a[h][w];
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin>>a[i][j];
        }
    }
    int dp[h+1][w+1];
    for(int i=0;i<=h;i++){
        for(int j=0;j<=w;j++){
            if(j==0 || i==0){
                dp[i][j]=0;
            }
            else if(a[i-1][j-1]=='#'){
                dp[i][j]=0;
            }
            else if(j==1 && i==1){
                dp[i][j]=1;
            }
            else{
                dp[i][j]=(dp[i-1][j]+dp[i][j-1])%mod;
            }
        }
    }
    cout<<dp[h][w]%mod<<endl;


}
  

Measured memory_bytes: 5120
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
typedef pair<string,string> Ps;
const ll INF=1000000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};
struct pos{
	// 1 変数を入れる;
	int x,y,sx,sy,cost;
};
int main() {

	string s,t;
	cin>>s;
	cin>>t;

	ll a=0;
	rep(i,s.size()){
		if(s[i]!=t[i])a++;
	}
	cout<<a<<endl;

	return 0;
}


Measured memory_bytes: 3916
#include <iostream>
#include <math.h>

using namespace std;

int main()
{
    int N, K;
    cin >> N >> K;

    int a = N / K; // 等分できる数
    int b = N % K; // 余り

    if (b != 0){
        cout << '1' << endl;
    }else{
        cout << '0' << endl;
    }
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
    
    public void solve(){
       Scanner sc = new Scanner(System.in);
	   int ninzu,k;
	   int ban;
	   for(int i=0;i<4;i++){
	   	ban = sc.nextInt();
		if(ban == 1){
			k = 6000;
		}else if(ban == 2){
			k = 4000;
		}else if(ban == 3){
			k = 3000;
		}else{
			k = 2000;
		}
		ninzu = sc.nextInt();
		int uriage = k*ninzu;
		System.out.println(uriage);
	   }
    }
    public static void main(String[] args){
        Main obj = new Main();
        obj.solve();
    }
}

Measured memory_bytes: 17356
def insertion_sort(a,n,g,cnt):
    for i in range(g,n):
        v = a[i]
        j = i-g
        while j >= 0 and a[j] > v:
            a[j+g] = a[j]
            j -= g
            cnt+=1
        a[j+g] = v
    return a,cnt

def shell_sort(a,n,G):
    cnt=0
    for g in G:
        a,cnt = insertion_sort(a,n,g,cnt)
    return a,cnt

n = int(raw_input())
a = []
for i in range(n):
    a.append(int(raw_input()))

g = 1
G = [g]
while True:
    g = 3*g + 1
    if g > n:
        break
    G.append(g)

G = sorted(G,reverse=True)

a,cnt = shell_sort(a,n,G)
print len(G)
print ' '.join([str(v) for v in G])
print cnt
for v in a:
    print v

Measured memory_bytes: 77644
#include "bits/stdc++.h"
#define Rep(i,n) for(int i=0;i<n;i++)
#define For(i,n1,n2) for(int i=n1;i<n2;i++)
#define REP(i,n) for(ll i=0;i<n;i++)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define put(a) cout<<a<<endl;
#define all(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define TDARRAY(int,a,n,m) vector<vector<int>> a(n,vector<int>(m,0));
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
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;}

int n;
string s;

int main(){
    cin >> n >> s;
    int r=0,b=0;
    REP(i,n){
        if(s[i]=='R')r++;
        else b++;
    }
    if(r>b){
        put("Yes");
    }else{
        put("No");
    }
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#define LEN 100005

typedef struct pp
{
    char name[100];
    int t;
} P;

P Q[LEN];
int head, tail, n;

void enqueue(P x)
{
    Q[tail] = x;
    tail = (tail + 1) % LEN;
}

P dequeue()
{
    P x = Q[head];
    head = (head + 1) % LEN;
    return x;
}

int min(int a, int b){ return a < b ? a : b; }

int main()
{
    int elaps = 0, c;
    int i, q;
    P u;
    scanf("%d %d", &n, &q);

    for ( i = 1; i <= n ; i++)
    {
        scanf("%s", Q[i].name);
        scanf("%d", &Q[i].t);
    }
    head = 1; tail = n + 1;
    
    while (head != tail)
    {
        u = dequeue();
        c = min(q, u.t);
        elaps += c;
        u.t -= c; 
        if ( u.t > 0)
        {
            enqueue(u);
        }
        else
        {
            printf("%s %d\n", u.name, elaps);
        }
    }

    return 0;
}


Measured memory_bytes: 11852
import math
from fractions import Fraction

NK = [int(i) for i in input().split()]
answer = [0.0] * NK[0]

for i in range(NK[0]):
    f = float(math.log2(NK[1]) - math.log2(i+1))
    if(f.is_integer()):
        value = int(math.log2(NK[1]) - math.log2(i+1))
    elif(i+1 >= NK[1]):
        value = 0
    else:
        value = int(math.log2(NK[1]) - math.log2(i+1)) + 1
    if(value < 0):
        value = 0
    answer[i] = Fraction(1, (NK[0] * (2**value)))
print(float(sum(answer)))

Measured memory_bytes: 14460
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<queue>

using namespace std;

int main()
{
	char a[105],b[105];
	int i;
	scanf("%s",a);
	scanf("%s",b);
	if(strlen(a) > strlen(b)) printf("GREATER");
	else if(strlen(a) < strlen(b)) printf("LESS");
	else{
		for(i = 0; i <= strlen(a) - 1; i++){
			if(a[i] > b[i]){ printf("GREATER"); break;}
 			else if(a[i] < b[i]){ printf("LESS"); break;}
		}
		if(i == strlen(a)) printf("EQUAL");
	}
	return 0;
}

Measured memory_bytes: 128
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

void main() {
    readint;
    auto ab = readints;
    int a = ab[0], b = ab[1];
    auto ps = readints;

    int x = 0, y = 0, z = 0;
    foreach (p; ps) {
        if (p <= a) x++;
        else if (p <= b) y++;
        else z++;
    }
    writeln(min(x, y, z));
}


Measured memory_bytes: 256
using System;

class main
{
    static void Main(string[] args)
    {
        string s1, s2, s7, a4;
        s7 = Console.ReadLine();
        int c = int.Parse(s7);
        for (int m = 0; m < c; m++)
        {
            s1 = Console.ReadLine();
            s2 = Console.ReadLine();
            a4 = string.Empty;
            ulong a1 = 0, a2 = 0;
            string[] s3 = new string[5];
            string[] s4 = new string[5];
            string[] s5 = new string[5];
            ulong[] a3 = new ulong[5];
            if (s1.Length > 80 || s2.Length > 80)
            {
                Console.WriteLine("overflow");
                goto end;
            }
            s1 = s1.PadLeft(80, '0');
            s2 = s2.PadLeft(80, '0');
            for (int i = 0; i < 5; i++)
            {
                s3[i] = s1.Substring(16 * i, 16);
                s4[i] = s2.Substring(16 * i, 16);
            }
            for (int j = 4; j >= 0; j--)
            {
                a1 = ulong.Parse(s3[j]);
                a2 = ulong.Parse(s4[j]);
                a3[j] += a1 + a2;
                if (a3[j].ToString().Length == 17)
                {
                    if (j == 0)
                    {
                        Console.WriteLine("overflow");
                        goto end;
                    }
                    a3[j] -= 10000000000000000;
                    a3[j - 1] += 1;
                }
                s5[j] = a3[j].ToString().PadLeft(16, '0');
            }
            a4 = string.Join("", s5);
            while (a4.StartsWith("0"))
            {
                a4 = a4.TrimStart('0');
                if (a4 == "")
                {
                    Console.WriteLine(0);
                    goto end;
                }
            }
            Console.WriteLine(a4);
        end: ;
        }
    }
}

Measured memory_bytes: 6360