akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
import java.util.*;

public class Main {

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

		ArrayList<MyList> list = new ArrayList<>();

		int n = in.nextInt(), query = in.nextInt();
		for(int i = 0; i < n; i++) {
			MyList ls = new MyList();
			list.add(ls);
		}

		for(int i = 0; i < query; i++) {
			int odr = Integer.parseInt(in.next()), index = Integer.parseInt(in.next());

			switch(odr) {
				case 0:
					list.get(index).add(Integer.parseInt(in.next()));
					break;

				case 1:
					list.get(index).dump(out);
					break;

				case 2:
					list.get(Integer.parseInt(in.next())).splice(list.get(index));
					break;
			}
		}
		out.flush();
		in.close();
	}


	static class ListNode{
		int value;
		ListNode next;

		ListNode(int v){
			this.value = v;
		}
	}

	static class MyList{
		ListNode END, TAIL;
		int size;

		MyList(){
			END  = new ListNode(0);
			TAIL = END;
			size = 0;
		}

		void add(int x) {
			ListNode NEW = new ListNode(x);
			NEW.next = END;
			TAIL.next = NEW;

			TAIL = NEW;
			size++;
		}

		void clear() {
			END.next = END;
			TAIL = END;
			size = 0;
		}

		void dump(PrintWriter out) {
			ListNode NOW = END;

			for(int i = 0; i < size-1; i++) {
				NOW = NOW.next;
				out.print(NOW.value + " ");
			}
			if(TAIL != END) {
				NOW = NOW.next;
				out.println(NOW.value);
			}
			else out.println();
		}

		void splice(MyList list) {
			TAIL.next = list.END.next;
			list.TAIL.next = this.END;
			this.TAIL = list.TAIL;

			size += list.size;

			list.clear();
		}
	}
}



Measured memory_bytes: 189016
#include <bits/stdc++.h>
//#include <unordered_map>
#define N 111
#define ID(x, y) (pre[(x)-1]+(y-1))
#define CHECK(x, y) ((x)>0 && (x)<= 2 * n - 1 && (y)>0 && (y)<=(linelimit))
using namespace std;
long long n, mod, m, l;
long long a[N][N], b[N][N], c[N][N], mat[N][N], pre[N];
void mul(long long A[N][N],long long B[N][N],long long t[N][N],long long n,long long m,long long l)
{
    long long tmp[N][N];
    for(long long i=0;i<n;i++)
        for(long long j=0;j<l;j++){
            tmp[i][j]=0;
            for(long long k=0;k<m;k++)
                tmp[i][j]=(tmp[i][j]+A[i][k]*B[k][j]%mod)%mod;
        }
    for(long long i=0;i<n;i++)
        for(long long j=0;j<l;j++)
            t[i][j]=tmp[i][j];
}
void expo(long long p[N][N],long long e[N][N],long long k,long long n)
{
    if(k!=1){
        for(long long i = 0; i < n; ++i)
            for(long long j = 0; j < n; ++j)
                e[i][j] = (i == j);
        while(k){
            if(k&1)
                mul(e,p,e,n,n,n);
            mul(p,p,p,n,n,n);
            k>>=1;
        }
    }else {
        for(long long i=0;i<n;i++)
            for(long long j=0;j<n;j++)
                e[i][j]=p[i][j];
    }
}
void addOneP(long long idx, long long x, long long y, long long linelimit)
{
    if(CHECK(x, y)) b[ID(x, y)][idx] = 1;
}
int main()
{
    long long cas = 1;
    while(~scanf("%lld%lld%lld", &n, &mod, &l) && (n || mod || l))
    {
        m = n;
        long long add = 1;
        long long num = 0;
        pre[0] = 0;
        for(long long i=1; i <= 2 * n -1; i++){
            pre[i] = m + pre[i-1];
            for(long long j=1;j<=m;j++)
                scanf("%lld", &mat[i][j]), a[0][num++] = mat[i][j]%mod;
            if(i == n) add = -1;
            m += add;
        }
        memset(b, 0, sizeof(b));
        m = n, add = 1;
        for(long long i=1; i <= 2 * n -1; i++){
            for(long long j=1;j<=m;j++)
            {
                addOneP(ID(i, j), i, j, m);
                addOneP(ID(i, j), i, j - 1, m);
                addOneP(ID(i, j), i, j + 1, m);
                addOneP(ID(i, j), i - 1, j, m - add);
                addOneP(ID(i, j), i + 1, j, m + (i < n ? 1 : -1));
                if(i < n) addOneP(ID(i, j), i - 1, j - 1, m - 1), addOneP(ID(i, j), i + 1, j + 1, m + 1);
                if(i == n) addOneP(ID(i, j), i - 1, j - 1, m - 1), addOneP(ID(i, j), i + 1, j - 1, m - 1);
                if(i > n) addOneP(ID(i, j), i - 1, j + 1, m + 1), addOneP(ID(i, j), i + 1, j - 1, m - 1);
            }
            if(i == n) add = -1;
            m += add;
        }
        expo(b, c, l, num);
        mul(a, c, b, 1, num, num);
        long long ans = 0;
        for(long long i=0;i<num;i++)
            ans += b[0][i];
        printf("Case %lld: %lld\n", cas++, ans);
    }
    return 0;
}

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

int main(){
    int n,k;cin>>n;
    for(int i=1;i<pow(10,5);i++){
        if(n<pow(i,2)){
            k=pow(i-1,2);
            break;
        }
    }
    cout<<k<<endl;
}

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

using namespace std;

struct proc {
	string pid;
	int procTime;
};

const int MAX = 100001;
proc queueArr[MAX];
int head, tail;

void inc(int* a) {
	if (*a == MAX - 1)
		*a = 0;
	else
		(*a)++;
}

bool isFull() {
	int a = tail;
	inc(&a);
	return a == head;
}

bool isEmpty() {
	return head == tail;
}

void push(proc p) {
	if (isFull()) {
		cout << "queue is full" << endl;
		return;
	}
	inc(&tail);
	queueArr[tail] = p;
}

proc pop() {
	if (isEmpty()) {
		cout << "queue is empty" << endl;
	}
	inc(&head);
	return queueArr[head];
}

int main() {
	head = tail = 0;
	int n, q, tcnt = 0;
	proc p;
	cin >> n >> q;
	for (int i = 0; i < n; i++) {
		cin >> p.pid >> p.procTime;
		push(p);
	}
	while(!isEmpty()) {
		p = pop();
		if (p.procTime > q) {
			p.procTime -= q;
			push(p);
			tcnt += q;
		}
		else {
			cout << p.pid << " " << p.procTime + tcnt << endl;
			tcnt += p.procTime;
		}
	}

	return 0;
}

Measured memory_bytes: 5112
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int a = sc.nextInt();
		// スペース区切りの整数の入力
		long b = sc.nextLong();
		// 文字列の入力
		long[] d = new long[a];
		long[] e = new long[a];
		for(int i = 0; i < a; i++){
			d[i] = sc.nextLong();
			e[i] = sc.nextLong();
		} 
		int f = 0;
		
		for(int i = 0; i < a; i++){
			if(Math.sqrt(d[i] * d[i] + e[i] * e[i]) <= b){
				f++;
			}
		}
		System.out.println(f);
		
		
	}
}

Measured memory_bytes: 62536
n, m ,c =map(int, input().split())
#print(n, m, c)
b = list(map(int, input().split()))
#print(b)
y = 0
for i in range(n):
    a = list(map(int, input().split()))
    x = 0
    for j in range(m):
        x += a[j]*b[j]
    if x + c > 0:
        y +=1
print(y)




Measured memory_bytes: 3068
#include<iostream>
#include<string>
#include<vector>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

char button1[5]={'\'',',','.','!','?'};
char button2[6]={'a','b','c','A','B','C'};
char button3[6]={'d','e','f','D','E','F'};
char button4[6]={'g','h','i','G','H','I'};
char button5[6]={'j','k','l','J','K','L'};
char button6[6]={'m','n','o','M','N','O'};
char button7[8]={'p','q','r','s','P','Q','R','S'};
char button8[6]={'t','u','v','T','U','V'};
char button9[8]={'w','x','y','z','W','X','Y','Z'};

int main(){
	string s;
	while(cin>>s){
		char c;
		int cnt=0;
		vector<int> vec;
		vec.push_back(cnt);
		rep(i,s.size()){
			if(s[cnt]!=s[i]){
				vec.push_back(i);
				cnt=i;
			}
		}
		rep(i,vec.size()){
			int times;
			if(i==vec.size()-1){
				times=s.size()-vec[i];
			}else{
				times=vec[i+1]-vec[i];
			}
			if(s[vec[i]]=='1'){
				cout<<button1[times%6-1];
			}else if(s[vec[i]]=='2'){
				cout<<button2[times%7-1];
			}else if(s[vec[i]]=='3'){
				cout<<button3[times%7-1];
			}else if(s[vec[i]]=='4'){
				cout<<button4[times%7-1];
			}else if(s[vec[i]]=='5'){
				cout<<button5[times%7-1];
			}else if(s[vec[i]]=='6'){
				cout<<button6[times%7-1];
			}else if(s[vec[i]]=='7'){
				cout<<button7[times%9-1];
			}else if(s[vec[i]]=='8'){
				cout<<button8[times%7-1];
			}else if(s[vec[i]]=='9'){
				cout<<button9[times%9-1];
			}else{
				if(times!=1){
					rep(i,times-1)cout<<" ";
				}
			}
		}
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 1200
n, k = map(int, input().split())

mod = 1000000007
ans = 0
dp = [0]*(k+1)

for i in range(k, 0, -1):
    x = k//i
    dp[i] += pow(x, n, mod)
    dp[i] %= mod
    # for c in dp:
    #     print(c, end=' ')
    # print()
    ans += dp[i]*i
    ans %= mod

    j = 2
    divisor = [1]
    while j*j <= i:
        if i%j == 0:
            divisor.append(j)
            if j != i//j:
                divisor.append(i//j)
        j += 1

    for d in divisor:
        dp[d] -= dp[i]
        dp[d] = (dp[d]+mod)%mod


ans %= mod
print(ans)


Measured memory_bytes: 68992
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdint>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

#define EPS (1e-7)

int main() {
  ll N, M;
  cin >> N >> M;
  map<ll, ll> A;

  for (ll i = 0; i < N; i++) {
    ll x;
    cin >> x;
    A[x]++;
  }
  for (ll i = 0; i < M; i++) {
    auto value = rbegin(A)->first;
    auto count = rbegin(A)->second;

    if (count == 1) {
      A.erase(value);
    } else {
      A[value]--;
    }

    auto newValue = value / 2;
    A[newValue]++;
  }

  ll sum = accumulate(cbegin(A), cend(A), 0LL,
                      [](auto sum, auto x) { return sum + x.first * x.second; });
  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 6528
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int ac = 0;
		int wa = 0;
		int tle = 0;
		int re = 0;
		for (int i = 0; i <= n; i++) {
			String s = sc.nextLine();
			if (s.equals("AC")) {
				ac++;
			} else if (s.equals("WA")) {
				wa++;
			} else if (s.equals("TLE")) {
				tle++;
			} else if (s.equals("RE")) {
				re++;
			}
		}
		System.out.println("AC x " + ac);
		System.out.println("WA x " + wa);
		System.out.println("TLE x " + tle);
		System.out.println("RE x " + re);

		sc.close();
	}
}

Measured memory_bytes: 61060
#include<cstdio>
#include<cstring>
#include<map>
#include<algorithm>
using namespace std;
int n,e;
int pd(char c)
{
	if(c=='M')
		return 0;
	if(c=='F')
		return 1;
	return -1;
}
int main()
{
	scanf("%d",&n);
	printf("0\n");
	fflush(stdout);
	char s[100];
	scanf("%s",s);
	if(s[0]=='M')
		e=0;
	if(s[0]=='F')
		e=1;
	if(s[0]=='V')
		return 0;
	int l=0,r=n,jl=0;
	while(l<=r&&jl<=22)
	{
		jl++;
		int mid=(l+r)>>1;
		printf("%d\n",mid);
		fflush(stdout);
		scanf("%s",s);
		int k=pd(s[0]);
		if(k==-1)
			return 0;
		if(k!=((mid%2)^e))
			r=mid;
		else
			l=mid+1;
	}
}

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

int main(){
	int n;
	cin >> n;
	cout << 800 * n - (n / 15 * 200);
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    string S;
    cin >> S;
    
    int N = S.size();
    
    for(int i = 1; i <= N/2; i++){
        //cout << S[i-1] << " " << S[N-i] << endl;
        if(S[i-1] != S[N-i]){
            cout << "No" << endl;
            return 0;
        }
    }
    
    for(int i = 1; i <= (N-1)/2; i++){
        int mae = (N-1)/2;
        //cout << S[i-1] << " " << S[mae-i] << endl;
        if(S[i-1] != S[mae-i]){
            cout << "No" << endl;
            return 0;
        }
    }
    
    int m = N - 1;
    
    for(int i = (N-1)/2 + 1; i < N; i++){
        if(S[i] != S[m]){
            cout << "No" << endl;
            return 0;
        }
        m--;
    }
    
    cout << "Yes" << endl;

}


Measured memory_bytes: 256
import math

x = 0

while True:
    x = int(input())
    if x == 0:
        break
    ans = 1000000
    for i in range(x+1):
        if i*i*i > x:
            break
        j = math.floor(math.sqrt(x-i*i*i))
        ans = min(ans, i+j+x-i*i*i-j*j)


    print(int(ans))



Measured memory_bytes: 5680
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); ++i)
#define fi first
#define se second
#define INF 1000000009
#define lINF 1000000000000000009
using ll = long long;

int main(){
  int a[]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int k;
  cin>>k;
  cout<<a[k-1]<<endl;
  return(0);
}


Measured memory_bytes: 256
def factorial_(a):
    mem = 1
    for i in range(1, a+1):
        mem = (mem*i)%(10**9 + 7)
    return mem

N, M = map(int, input().split())
a = max([N, M])
b = min([N, M])

if abs(N - M) > 1:
    print(0)
else:
    print((factorial_(a) * (b-a+2) * factorial_(b))%(10**9 + 7))

Measured memory_bytes: 38512
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);
		String input = scanner.nextLine();

		switch(input) {
	        case "Sunny":
	            System.out.println("Cloudy");
	            break;
	        case "Cloudy":
	            System.out.println("Rainy");
	            break;
	        case "Rainy":
	            System.out.println("Sunny");
	            break;
		}
	}
}

Measured memory_bytes: 20688
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#define debug(x) cerr << #x << ':' << x << endl
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
using namespace std;
typedef long long ll;

int main(){
    int n,k;
    cin >> n >> k;
    int mi=1e9, arg;
    REP(i,n){
        int ai;
        cin >> ai;
        if(ai<mi)mi=ai, arg=i;
    }
    int ans=1;
    int x=n;
    x-=k;
    if(x%(k-1)==0) ans+=x/(k-1);
    else ans+=x/(k-1)+1;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <algorithm>

#define int long long
#define MOD7 1000000007
#define MOD9 1000000009

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

using namespace std;

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

int nextInt() {int a; cin >> a; return a;}
char nextChar() {char a; cin >> a; return a;}
double nextDouble() {double a; cin >> a; return a;}
string nextString() {string a; cin >> a; return a;}

void inputVector(vector<int> &v, int &n) {rep(i,n){v.push_back(nextInt());}}
void inputVector(vector<double> &v, int &n) {rep(i,n){v.push_back(nextDouble());}}
void inputVector(vector<string> &v, int &n) {rep(i,n){v.push_back(nextString());}}

int dp[1<<17];
int t[16][17];

signed main() {
    int n;
    while (cin >> n) {
	if (n == 0) break;

	rep(i, n) {
	    rep(j, n+1) {
		cin >> t[i][j];
	    }
	}

	rep(i, 2 << (n - 1)) dp[i] = INT_MAX;
	dp[0] = 0;

	rep(i, 2 << (n - 1)) {
	    rep(j, n) {
		int bit = 1 << j;
		if (i & bit) continue;

		int cost = t[j][0];
		rep(k, n) {
		    if (((1 << k) & i) == 0) continue;
		    cost = min(cost, t[j][k + 1]);
		}
		
		dp[i + bit] = min(dp[i + bit], dp[i] + cost);
	    }
	}

	cout << dp[(2 << (n - 1)) - 1] << endl;
    }

    return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<ll,ll>;
#define For(i,a,b)  for(int i=a;i<=b;i++)
#define Forr(i,a,b) for(int i=a;i>=b;i--)
#define F first
#define S second
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define bpc __builtin_popcount
#define MOD (ll)(1e9+7)
#define INF (1e18)
#define EPS (1e-6)
#define NATHANLEE_IS_EVIL_AND_ELECTRIC true
#define int ll
#ifdef LOCAL_TEST
#define debug(...) do{\
	cerr<<__PRETTY_FUNCTION__<<" - "<<__LINE__<<\
	" : ("#__VA_ARGS__<<") = ";\
	_OUT(__VA_ARGS__);\
}while(0)
template<typename T>void _OUT(T x){cerr<<x<<"\n";}
template<typename T,typename...I>void _OUT(T x,I ...tail){cerr<<x<<", ";_OUT(tail...);}
#else
#define debug(...)
#endif
void INIT(){
#ifdef LOCAL_TEST
	freopen("D:\\input.in","r",stdin);
	freopen("D:\\output.out","w",stdout);
	freopen("D:\\error.out","w",stderr);
#endif
	ios::sync_with_stdio(!NATHANLEE_IS_EVIL_AND_ELECTRIC);
	cin.tie(0);
}

ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }
ll lcm(ll a,ll b) { return a/gcd(a,b)*b; }
ll fpow(ll b,ll p){
	b%=MOD;
	ll ans=1;
	while(p>0){
		if(p&1) ans=(ans*b)%MOD;
		p/=2;
		b=(b*b)%MOD;
	}
	return ans;
}

int ans[50][50];
int mat[50][50];
int tmp[50][50];

inline void mult(int n,int a[50][50],int b[50][50]){
	For(i,0,n-1) For(j,0,n-1){
		tmp[i][j]=0;
		For(k,0,n-1) tmp[i][j]=(tmp[i][j]+a[i][k]*b[k][j])%MOD;
	}
	For(i,0,n-1) For(j,0,n-1) b[i][j]=tmp[i][j];
}

int32_t main() {
	INIT();
	//code...
	int n,k; cin>>n>>k;
	For(i,0,n-1) For(j,0,n-1){
		cin>>mat[i][j];
		ans[i][j]=(i==j);
	}
	For(p,0,60){
		if(k&(1ll<<p)) mult(n,mat,ans);
		mult(n,mat,mat);
	}
	int a=0;
	For(i,0,n-1) For(j,0,n-1) a=(a+ans[i][j])%MOD;
	cout<<a<<"\n";
	return 0;
}

Measured memory_bytes: 3676
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
		String s = sc.next();
        String t = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        String ans = " ";
        for(int i=0;i<s.length();i++){
          for(int j=0;j<26;j++){if(s.charAt(i)==t.charAt(j))
          {ans+=t.substring((j+a)%26,(j+a)%26+1);break;}                                                           
                               }
                                     }
        System.out.println(ans);
	}
}


Measured memory_bytes: 149424
while True:
    k = [int(i) for i in input().split()]
    if k[0] == -1 and k[1] == -1 and k[2] == -1:
        break
    elif k[0] == -1 or k[1] == -1:
        print("F")
    elif k[0] + k[1] >= 80:
        print("A")
    elif k[0] + k[1] < 80 and k[0] + k[1] >= 65:
        print("B")
    elif k[0] + k[1] < 65 and k[0] + k[1] >= 50:
        print("C")        
    elif k[0] + k[1] < 50 and k[0] + k[1] >= 30:
        if k[2] >= 50:
            print("C")
        else:
            print("D")
    else:
        print("F")
    


Measured memory_bytes: 5604
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int[] x = new int[6];
    for(int i=0; i<6; i++){
      x[i] = sc.nextInt();
    }
    if(x[4]-x[0]<=x[5]){
      System.out.println("Yay!");
    }else{
      System.out.println(":(");
    }
  }
}

Measured memory_bytes: 23248
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
int n;
int a[200005];
int aa[200005];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> n;
  REP(i, n) {
    cin >> a[i];
    aa[i] = a[i] - (i + 1);
  }

  sort(aa, aa + n);
  int t = aa[n / 2];

  ll ans = 0;
  REP(i, n) {
    ans += (ll)abs(a[i] - (t + (i + 1)));
  }

  cout << ans << endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<pair<string,int>> prvec;
  map<int,int> mp;
  string s;
  int a;
  for(int i = 0;i<n;i++){
    cin >> s >> a;
    prvec.push_back(make_pair(s,-a));
    mp[-a] = i+1;
  }
  sort(prvec.begin(),prvec.end());
  for(int i = 0;i<n;i++){
    cout << mp[prvec[i].second] << endl;
  }
}


Measured memory_bytes: 256
def resolve():
	N,M=map(int,input().split())
	L=[]
	for i in range(N):
		a,b=map(int,input().split())
		L.append([a,b])
	D=sorted(L,key=lambda x:x[0])
	ans=0
	cnt=M
	for i in D:
		if i[1]<cnt:
			ans+=i[0]*i[1]
			cnt-=i[1]
		else:
			ans+=i[0]*cnt
			break
	print(ans)
resolve()

Measured memory_bytes: 64344
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace ABC086A
{
	class Program
	{
		static void Main(string[] args)
		{
			string[] n = Console.ReadLine().Split(' ');
			int a = int.Parse(n[0]);
			int b = int.Parse(n[1]);
 
			if ((a * b) % 2 == 0)
				Console.WriteLine("Even");
 
			else
				Console.WriteLine("Odd");
 
			Console.ReadKey();
		}
	}
}

Measured memory_bytes: 13140
#include<bits/stdc++.h>
#define fr(i,c,b) for(int i=c;i<b;i++)
#define si(x) int x; scanf("%d", &x)
#define sll(x) ll x; scanf("%lld", &x)
#define pi(x) printf("%d", x)
#define pll(x) printf("%lld", x)
#define nl printf("\n")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define MAX 1000001

typedef long long int ll;

using namespace std;

int main()
{
    si(n);
    int a[n];
    fr(i,0,n)
        cin>>a[i];
    sort(a,a+n);
    int count=0;
    bool flag=false;
    fr(i,0,n-2)
    {
        int k=i+2;
        fr(j,i+1,n)
        {
            while (k < n && a[i] + a[j] > a[k])  
                ++k;
            if(k > j)  
                count += k - j - 1;  

        }
    }
    cout<<count;
}

Measured memory_bytes: 256
import sys
S = int(input())
if S < 3:
    print(0)
    sys.exit()
MOD = 10 ** 9 + 7
ans = 0
dp = [[0 for j in range(S+1)]for i in range(S//3)]
for j in range(3, S+1):
    dp[0][j] = 1
for i in range(1, S//3):
    cusum = 0
    for j in range(3*(i+1), S+1):
        cusum = (cusum + dp[i-1][j-3]) % MOD
        dp[i][j] = cusum
for i in range(S//3):
    ans = (ans + dp[i][S]) % MOD
print(ans)

Measured memory_bytes: 79220
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#ifndef FAST_IO
 #define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);
#endif

#define FILE_IO freopen("input.txt","r",stdin)
#define int long long
#define f first
#define s second
#define endl '\n'
#define all(c) c.begin(),c.end()
#define debug(x) cerr << #x << " = " << x << endl;

const int MOD = 1e9 + 7;
const int INF = 1<<29;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T>void print(T t){for(auto &it:t)cout<<it<<" ";}
inline int powerexp(int a,int b,int m = MOD){int res=1;while(b){if(b&1)res=res*a%m;a=a*a%m,b>>=1;}return res%m;}
inline int modinv(int a){return powerexp(a,MOD-2,MOD);}
inline int lcm(int a,int b){int g=__gcd(a,b);return a/g*b;}

//-------------------< start here >-------------------------// 
void solve(){
   int k, s;
   cin >> k >> s;
   int cnt = 0;
   for (int i = 0; i <= k; i++){
	  for (int j = 0; j <= k; j++){
			   int ret = s - i - j;
			   if (ret >= 0 && ret <= k) cnt++;			
		 }  
	 }
	cout << cnt << endl;
}
//-----------------------------
//comment from here for TOPCODER 
int32_t main(){
   IOS;
   solve();
   //find();
   #ifdef LOCAL_DEFINE
   cerr<<"time elapsed "<<(double)clock()/CLOCKS_PER_SEC<<endl;
   #endif
}


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

using namespace std;

#define int long long
#define FR first
#define SC second
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define per(i, n) for(int i = (int)(n); i >= 0; i--)
#define reps(i, f, n) for(int i = (int)(f); i < (int)(n); i++)
#define each(a, b) for(auto& a : b)

typedef pair<int, int> P;

const int inf = 1LL << 55;

int dp[370][370];

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int N;
  while(cin >> N, N) {
    vector< tuple<int, int, int> > app;
    rep(i, N) {
      int a, b, w; cin >> a >> b >> w;
      app.emplace_back(a, b+1, w);
    }

    sort(all(app));

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

    rep(i, N) {
      int a, b, w; tie(a, b, w) = app[i];
      per(j, 370-1) per(k, 370-1) {
	if(j <= a) dp[b][k] = max(dp[b][k], dp[j][k] + w);
	if(k <= a) dp[j][b] = max(dp[j][b], dp[j][k] + w);
      }
    }

    int ans = 0;
    rep(i, 370) rep(j, 370) ans = max(ans, dp[i][j]);

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

Measured memory_bytes: 4244
#!/usr/bin/env python3
#AGC3 A

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

s = input()
n = len(s)
N,W,S,E = 0,0,0,0
for i in range(n):
    if s[i] == 'N':
        N = 1
    elif s[i] == 'W':
        W = 1
    elif s[i] == 'S':
        S = 1
    elif s[i] == 'E':
        E = 1
if N & S and W & E:
    print('Yes')
elif (N==0 and S==0) and W&E:
    print('Yes')
elif N&S and (W==0 and E==0):
    print('Yes')
else:
    print('No')


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

using namespace std;
#define CK(N, A, B) (A <= N && N < B)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define RREP(i, a, b) for (int i = (b - 1); a <= i; i--)
#define F first
#define S second
typedef long long ll;

const int INF = 1e9 + 7;
const long long LLINF = 1e18;

ll n;
ll a[100001], b[100001];
int main()
{
	cin >> n;
	REP(i, 0, n) cin >> a[i] >> b[i];

	ll ans = 0;
	RREP(i, 0, n) {
		ll mod = (a[i] + ans) % b[i];
		if (mod != 0) {
			ans += b[i] - mod;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h> 
using namespace std;  
#define ll   long long int
#define INF 1000000007

int main()
{
	ll n;
	cin>>n;
	ll count = 0;
	for(ll i =1;i<=n;i++)
	{
		ll x;
		cin>>x;
		if(i%2!=0)
		{
			if(x%2!=0)
			{
				count++;
			}
		}
	}
	cout<<count<<endl;
}


Measured memory_bytes: 3592
# author:  Taichicchi
# created: 21.09.2020 20:00:43

import sys

S = input()

Q = int(input())

rev = 0

front = []
end = []

for q in range(Q):
    query = input().split()
    if query[0] == "1":
        rev = 1 - rev
    else:
        if ((rev == 0) & (query[1] == "1")) | ((rev == 1) & (query[1] == "2")):
            front.append(query[2])
        else:
            end.append(query[2])

front = "".join(front)
end = "".join(end)


if rev:
    print(end[::-1] + S[::-1] + front)
else:
    print(front[::-1] + S + end)


Measured memory_bytes: 10692
# from math import sqrt
# from heapq import heappush, heappop
# from collections import deque
from operator import mul
from functools import reduce
# a, b = [int(v) for v in input().split()]


def main():

    mod = 1000000007
    n, a, b = map(int, input().split())

    def combi(n, r):
        if r < 0 or r > n:
            return 0
        r = min(n - r, r)

        over = 1
        under = 1

        for i in range(n - r + 1, n + 1):
            over = over * i % mod

        for i in range(1, r + 1):
            under = under * i % mod

        return over * modpow(under, mod-2) % mod

    def modpow(n, r):
        if r == 0:
            return 1

        v = modpow(n, r // 2)
        v = v * v % mod
        if r % 2 != 0:
            v = v * n % mod
        return v

    ans = modpow(2, n) - 1
    ans -= combi(n, a)
    ans -= combi(n, b)

    while ans < 0:
        ans += mod

    print(ans)


main()


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

int main() {
  ll A, B;
  double x;
  cin >> A >> x;
  B = x * 100 + 0.5;

  ll ans = A * B / 100;
  cout << ans << endl;
  return 0;
}

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

int a, b, c;

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

    cin >> a >> b >> c;

    int count = 0;

    for (int i = a; i < b + 1; i++) {
        if (c % i == 0) {
            count++;
        }
    }

    cout << count << '\n';
    return 0;
}


Measured memory_bytes: 3216
#include<stdio.h>

int main(){
	int n, a, b;
	scanf("%d %d %d", &n, &a, &b);
	int tota = n-a;
	if(tota<0){
		tota*=-1;
	}
	int totb = n-b;
	if(totb<0){
		totb*=-1;
	}
	if(tota<totb){
		printf("A\n");
	}
	else if(totb<tota){
		printf("B\n");
	}
	return 0;
}

Measured memory_bytes: 1548
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
#define INF 1007654321
#define PI 3.14159265358979
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repp(i, s, e) for(int i = (s); i <= (e); ++i)
#define sz(x) ((int)x.size())
#define all(x) x.begin(), x.end()
#define FAST_IO() ios::sync_with_stdio(0); cin.tie(0)
template<typename T>
ostream& operator<<(ostream &os, const vector<T> &v) { for (auto x : v) os << x << " "; return os << "\n"; }
template<typename U, typename V>
ostream& operator<<(ostream &os, const pair<U, V> &p) { return os << "(" << p.first << "," << p.second << ")";}

int main() {
    int N, Z, W; cin >> N >> Z >> W;
    vector<int> A(N);
    rep(i, N) cin >> A[i];
    vector<int> X(N), Y(N);
    int ans = abs(A[N-1] - W);
    for(int i = N - 2; i >= 0; --i) {
        X[i] = abs(A[i] - A[N-1]);
        for(int j = i + 1; j <= N - 2; ++j) {
            X[i] = min(X[i], Y[j]);
        }
        int qy = abs(A[i] - A[N-1]);
        for(int j = i + 1; j <= N - 2; ++j) {
            Y[i] = max(Y[i], Y[j]);
        }
    }
    for(int i = 0; i <= N - 2; ++i) {
        ans = max(ans, X[i]);
    }
    cout << ans << endl;
}

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

const double PI = 3.14159265358979323846;
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
//typedef pair<ll, ll> P;
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

std::istream &operator>>(std::istream &in, set<int> &o) {
    ll a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

//const ll mod = 1e10;
typedef priority_queue<string, vector<string>, greater<string> > PQ_ASK;

#include <iostream>
#include <vector>

using namespace std;

const int mod = 1000000007;


int main() {
    string s;
    cin >> s;
    if (s[2] == s[3] && s[4] == s[5]) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


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();
        long k = sc.nextLong();       
		int [] in = new int [n];
        long [] count = new long [n];       
        for(int i=0;i<n;i++){
                             in[i] = sc.nextInt();
                            }
        count[0]=1;
        long mod = 0;
        int a = 0;
        int point = 1;
        long ans = 0;
        while(a<1){point=in[point-1];
                  count[point-1]++;
                   mod++;
                  if(count[point-1]==2){a=1;}}
        if(k<=mod){point=1;for(long i=0;i<k;i++){point=in[point-1];
                                                        }
                   ans=point;}
 else{long count1=0;
     int point2=1;while(point!=point2){point2=in[point2-1];k--;count1++;}
     for(long i=0;i<k%(mod-count1);i++){point2=in[point2-1];}
     ans=point2;}         
		System.out.println(ans);
}
}


Measured memory_bytes: 61284
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include<algorithm>
#include<sstream>
#include<iomanip>
#include<deque>
#include<list>


using namespace std;

typedef long long ll;

typedef pair<ll, ll> pll;

const ll MOD_CONST = 1000000007;
const ll BIG_NUM = 1000000000000000000;
const int BIG_INT = 1000000000;


int main() {
	int n, m;
	ll l;
	cin >> n >> m >> l;
	vector<vector<ll>> adj(n, vector<ll>(n,BIG_NUM));
	for (int i = 0; i < m;i++) {
		int a, b, c;
		cin >> a >> b >> c;
		a--;
		b--;
		adj[a][b] = c;
		adj[b][a] = c;
	}

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

	for (int k = 0; k < n;k++) {
		for (int i = 0; i < n;i++) {
			for (int j = 0; j < n; j++) {
				adj[i][j] = min(adj[i][j], adj[i][k] + adj[k][j]);
			}
		}
	}

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

		adj[i][i] = 0;


	}

	for (int k = 0; k < n;k++) {
		for (int i = 0; i < n;i++) {
			for (int j = 0; j < n; j++) {
				adj[i][j] = min(adj[i][j], adj[i][k] + adj[k][j]);
			}
		}
	}
	vector<vector<int>> d(n, vector<int>(n, BIG_INT));

	for (int i = 0; i < n;i++) {
		for (int j = 0; j < n; j++) {
			if (adj[i][j] <= l) {
				d[i][j] = 1;
			}
		}

		d[i][i] = 0;
	}

	for (int k = 0; k < n;k++) {
		for (int i = 0; i < n;i++) {
			for (int j = 0; j < n; j++) {
				d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
			}
		}
	}

	int q;
	cin >> q;
	for (int i = 0; i < q;i++) {
		int s, t;
		cin >> s >> t;
		s--;
		t--;
		if (d[s][t] == BIG_INT) {
			cout << -1 << endl;

		}
		else {
			cout << d[s][t]-1 << endl;
		}
	}
}



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

template <int mod = (int)(998244353)>
struct ModInt {
  int x;
  constexpr ModInt() : x(0) {}
  constexpr ModInt(int64_t y)
      : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
  constexpr ModInt &operator+=(const ModInt &p) noexcept {
    if ((x += p.x) >= mod) x -= mod;
    return *this;
  }
  constexpr ModInt &operator-=(const ModInt &p) noexcept {
    if ((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }
  constexpr ModInt &operator*=(const ModInt &p) noexcept {
    x = (int)(1LL * x * p.x % mod);
    return *this;
  }
  constexpr ModInt &operator/=(const ModInt &p) noexcept {
    *this *= p.inverse();
    return *this;
  }
  constexpr ModInt operator-() const { return ModInt(-x); }
  constexpr ModInt operator+(const ModInt &p) const noexcept {
    return ModInt(*this) += p;
  }
  constexpr ModInt operator-(const ModInt &p) const noexcept {
    return ModInt(*this) -= p;
  }
  constexpr ModInt operator*(const ModInt &p) const noexcept {
    return ModInt(*this) *= p;
  }
  constexpr ModInt operator/(const ModInt &p) const noexcept {
    return ModInt(*this) /= p;
  }
  constexpr bool operator==(const ModInt &p) const noexcept { return x == p.x; }
  constexpr bool operator!=(const ModInt &p) const noexcept { return x != p.x; }
  constexpr ModInt inverse() const noexcept {
    int a = x, b = mod, u = 1, v = 0, t = 0;
    while (b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }
  constexpr ModInt pow(int64_t n) const {
    ModInt res(1), mul(x);
    while (n) {
      if (n & 1) res *= mul;
      mul *= mul;
      n >>= 1;
    }
    return res;
  }
  friend constexpr ostream &operator<<(ostream &os, const ModInt &p) noexcept {
    return os << p.x;
  }
  friend constexpr istream &operator>>(istream &is, ModInt &a) noexcept {
    int64_t t = 0;
    is >> t;
    a = ModInt<mod>(t);
    return (is);
  }
  constexpr int get_mod() { return mod; }
};

int n;
string x;
vector<int> v;
vector<ModInt<>> cnt;
vector<vector<ModInt<>>> dp;

ModInt<> solve();

int main() {
  cin >> n >> x;
  cout << solve() << endl;
  return 0;
}

ModInt<> solve() {
  ModInt<> res;
  dp.assign(n + 1, vector<ModInt<>>(2, 0));
  dp[0][0] = 1;
  for (int i = 0; i < n; ++i) {
    dp[i + 1][1] += dp[i][1] * 2;
    if (x[i] - '0') dp[i + 1][0] += dp[i][0];
    dp[i + 1][x[i] - '0'] += dp[i][0];
  }
  res = (dp[n][0] + dp[n][1]) * 2 * n;
  // search divisor
  {
    for (int i = 1; i * i <= n; ++i)
      if (n % i == 0) {
        if ((n / i) & 1) v.push_back(i);
        if (i * i != n && (i & 1) && i != 1) v.push_back(n / i);
      }
    sort(v.begin(), v.end());
  }
  cnt.assign(n + 1, 0);
  for (auto p : v) {
    cnt[p] += dp[p][1];
    {
      int cycle = n / p;
      string now;
      for (int i = 0; i < cycle; ++i)
        for (int j = 0; j < p; ++j) now += '0' + ((x[j] - '0') ^ (i & 1));
      if (now <= x) cnt[p] += 1;
    }
    res -= cnt[p] * 2 * (n - p);
    for (int i = 2; i * p <= n; ++i) cnt[i * p] -= cnt[p];
  }
  return res;
}


Measured memory_bytes: 15652
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;

constexpr int MAX_N = 30;

int ans;
int n, m;
int cover[30];
int used;
int ok;
vector<vector<int>> edges;

void dfs(int idx, int sum) {
	if(sum >= ans) return;
	if(used == ok) {
		ans = sum;
		return;
	}
	if(idx == n) return;

	dfs(idx + 1, sum);
	const int tmp = used;
	used |= cover[idx];
	dfs(idx + 1, sum + 1);
	used = tmp;
}

int solve() {
	used = 0;
	int cnt = 0;
	for(int i = 0; i < n; ++i) {
		if(edges[i].size() == 0) {
			used |= (1 << i);
			++cnt;
		}
		else if(edges[i].size() == 1) {
			const int neighbor = edges[i][0];
			if(used & (1 << neighbor)) continue;
			used |= cover[neighbor];
			++cnt;
		}
	}

	ok = (1 << n) - 1;
	ans = n - __builtin_popcount(used) + cnt;
	dfs(0, cnt);
	return ans;
}

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

	while(cin >> n >> m && n) {
		memset(cover, 0, sizeof(cover));
		for(int i = 0; i < n; ++i) {
			cover[i] = (1 << i);
		}

		edges.assign(n, vector<int>());
		for(int i = 0; i < m; ++i) {
			int a, b;
			cin >> a >> b;
			cover[a] |= (1 << b);
			cover[b] |= (1 << a);
			edges[a].emplace_back(b);
			edges[b].emplace_back(a);
		}

		cout << solve() << endl;
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1216
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <iomanip>
#include <set>
using namespace std;

#define rep(i, s) for (int i = 0; i < s; ++i)
#define all(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define VEC(a, n) vector<int>a(n)
#define PQ(a) priority_queue<int>a
#define PQmin(a) priority_queue< int, :vector<int>, greater<int> >a
#define PAIR pair<int, int>
/*
sort(sp.begin(), sp.end(), [](PAIR l, PAIR r){
        return l.first<r.first || (l.first==r.first && l.second > r.second);
        });
*/

typedef long long  ll;

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

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


int main() {
    string s;
    cin>>s;
    for(int i=0;i<s.size();i++){
        if(s.at(i)!=s.at(s.size()-1-i)){
            cout<<"No"<<endl;
            return 0;
        }
    }
    for(int i=0;i<(s.size()-1)/2-1;i++){
        if(s.at(i)!=s.at(s.size()-1-i)){
            cout<<"No"<<endl;
            return 0;
        }
    }
    int j=0;
    for(int i=(s.size()+3)/2-1;i<s.size();i++){
        if(s.at(i)!=s.at(s.size()-1-j)){
            cout<<"No"<<endl;
            return 0;
        }
        j++;
    }
    cout<<"Yes"<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

int main(void){
    // input
    lint N;
    cin >> N;
    vector<double> x(N);
    vector<double> y(N);

    for (int i = 0; i < N; ++i) {
        cin >> x[i] >> y[i];
    }

    vector<int> v(N);
    iota(v.begin(), v.end(), 0);       // v に 1, 2, ... N を設定
    double distance = 0;
    double sub = 0;
    do {
        for (int i = 0; i < N-1; ++i) {
            int from, to; from = v[i]; to = v[i+1];
            distance += sqrt(pow((x[from] - x[to]),2) + pow((y[from] - y[to]),2));
        }
        ++sub;
    } while( next_permutation(v.begin(), v.end()) );     // 次の順列を生成

    cout << fixed << setprecision(15) << distance / sub << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using  namespace std;
typedef long long ll;
int main()
{
    int k;
    cin>>k;
    ll n=7;
    int f=0;
    for(int i=1; i<=10000005&&f==0; i++)
    {
        if(n%k==0)
        {
            cout<<i<<endl;
            f=1;
        }
        else
        {
            n=n*10+7;
            n%=k;
        }
    }
    if(f==0)
        cout<<"-1"<<endl;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
#include<vector>
using namespace std;
typedef long long ll; 
const ll mod=1e9+7;
ll fact[300005]={0};
ll qpow(ll a,ll b)
{
	if(b==0)
	{
		return 1;
	}
	else if(b==1)
	{
		return a;
	}
	else if(b%2==0)
	{
		ll c=qpow(a,b/2);
		return c*c%mod;
	}
	else
	{
		ll c=qpow(a,b/2);
		return ((c*c)%mod*a)%mod;
	}
}
ll cnk(ll n,ll k)
{
	ll b=fact[n-k]*fact[k];
	b%=mod;
	return fact[n]*qpow(b,mod-2)%mod;
}
int main(void)
{
	ll n,k;
	scanf("%lld%lld",&n,&k);
	if(k>=n)
	{
		k=n-1;
	}
	fact[0]=fact[1]=1;
	for(ll i=2;i<=n+100000;i++)
	{
		fact[i]=fact[i-1]*i;
		fact[i]%=mod;
	}
	ll ans=0;
	for(ll i=0;i<=k;i++)
	{
		ans+=cnk(n,i)*cnk(n-1,i);
//		printf("%lld %lld %lld %lld\n",n,i,cnk(n,i),cnk(n-1,i));
		ans%=mod;
	}
	printf("%lld",ans);
}

Measured memory_bytes: 2560
#include<stdio.h>
#pragma GCC optimize("O2")
#pragma GCC optimize("O3")
#pragma GCC target("avx")
#define rep(i,N) for(int i=0;i<(int)N;i++)
const int MOD=1e9+7,MAX=1e6;
static inline int IN(void)
{
  int x=0,f=0,c=getchar();while(c<48||c>57){f^=c==45,c=getchar();}
  while(c>47&&c<58){x=x*10+c-48,c=getchar();}return f?-x:x;
}
typedef struct{int SPF[1000001];int Primes[1000001];int sz;}Template;
struct T{int fact[1000001],inv[1000001];};
Template P;struct T MODINV;
static inline int MPow(int a,int b){return b?1l*MPow(1l*a*a%MOD,b>>1)*(b&1?a:1)%MOD:1;}
static inline void ready(void)
{
  *P.SPF=1,*P.Primes=2,P.sz=1;
  rep(i,MAX/2)P.SPF[2*(i+1)]=2,P.SPF[2*(i+1)-1]=2*(i+1)-1;
  rep(i,MAX/2-1)
  {
    int x=2*(i+1)+1;if(P.SPF[x]==x)P.Primes[P.sz++]=x;
    rep(j,P.sz){if(P.Primes[j]<=P.SPF[x]&&x*P.Primes[j]<=MAX)P.SPF[x*P.Primes[j]]=P.Primes[j];else break;}
  }
}
static inline void init(void)
{
  MODINV.fact[0]=1;rep(i,MAX)MODINV.fact[i+1]=1l*MODINV.fact[i]*(i+1)%MOD;
  MODINV.inv[MAX]=MPow(MODINV.fact[MAX],MOD-2);
  rep(i,MAX)MODINV.inv[MAX-1-i]=1l*MODINV.inv[MAX-i]*(MAX-i)%MOD;
}
int main(void)
{
  int N=IN(),A=0,flag=0,invsum=0,k=0,lcm=1,x=0,temp[10000],box[168]={};ready();init();
  rep(i,N)
  {
    A=IN();invsum=(invsum+1l*MODINV.fact[A-1]*MODINV.inv[A]%MOD)%MOD;
    rep(j,168){x=0;while(A%P.Primes[j]==0){A/=P.Primes[j];if(box[j]<++x)box[j]=x;}}
    if(A&&A!=1){rep(j,k){if(temp[j]==A)flag=1;}if(!flag)temp[k++]=A;}flag=0;
  }
  rep(i,168){rep(j,box[i]){lcm=1l*lcm*P.Primes[i]%MOD;}}
  rep(i,k){lcm=1l*lcm*temp[i]%MOD;}
  x=1l*lcm*invsum%MOD;return printf("%d\n",x),0;
}

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

typedef long long LL;

const int maxn = 10010;

const LL mod = 1e9 + 7;

int qpow(int a, int n){
    int ret = 1;
    while(n > 0){
        if(n & 1){
            ret = 1LL * ret * a % mod;
        }
        a = 1LL * a * a % mod;
        n >>= 1;
    }
    return ret;
}
LL dp1[maxn/2][maxn/2];
int n;
char s[maxn];
int main(){
    memset(dp1, 0, sizeof(dp1));
    dp1[0][0] = 1;
    cin >> n;
    scanf("%s", s + 1);
    int m = strlen(s + 1);
    for(int i = 1;i <= n;i++){
        for(int j = 0;j <= i;j++){
            if(j > 0){
                dp1[i][j] = (dp1[i][j] + 2LL * dp1[i - 1][j - 1]) % mod;
            }
            dp1[i][j] = (dp1[i][j] + dp1[i - 1][j + 1]) % mod;
        }
        dp1[i][0] = (dp1[i][0] + dp1[i - 1][0]) % mod;
    } 
    LL ans = dp1[n][m];
    LL tmp = qpow(2, m) % mod;
    ans = ans * qpow(tmp, mod - 2) % mod;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 195968
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
template <class T> void corner(bool flg, T hoge) {
    if(flg) {
        cout << hoge << endl;
        exit(0);
    }
}
#define all(v) v.begin(), v.end()
#define inputv(v, n)                                                           \
    vl v;                                                                      \
    rep(i, n) {                                                                \
        ll x;                                                                  \
        cin >> x;                                                              \
        v.push_back(x);                                                        \
    }
const ll INF = 999999999999999;
const ll MOD = 1000000007;
ll a, b, c, d, e, f, p, t, x, y, z, q, m, n, r, h, k, w, l, ans = 0;
#include <cstdint>

template <std::uint_fast64_t Modulus> class modint {
    using u64 = std::uint_fast64_t;

  public:
    u64 a;

    constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {}
    constexpr u64 &value() noexcept { return a; }
    constexpr const u64 &value() const noexcept { return a; }
    constexpr modint operator+(const modint rhs) const noexcept {
        return modint(*this) += rhs;
    }
    constexpr modint operator-(const modint rhs) const noexcept {
        return modint(*this) -= rhs;
    }
    constexpr modint operator*(const modint rhs) const noexcept {
        return modint(*this) *= rhs;
    }
    constexpr modint operator/(const modint rhs) const noexcept {
        return modint(*this) /= rhs;
    }
    constexpr modint &operator+=(const modint rhs) noexcept {
        a += rhs.a;
        if(a >= Modulus) {
            a -= Modulus;
        }
        return *this;
    }
    constexpr modint &operator-=(const modint rhs) noexcept {
        if(a < rhs.a) {
            a += Modulus;
        }
        a -= rhs.a;
        return *this;
    }
    constexpr modint &operator*=(const modint rhs) noexcept {
        a = a * rhs.a % Modulus;
        return *this;
    }
    constexpr modint &operator/=(modint rhs) noexcept {
        u64 exp = Modulus - 2;
        while(exp) {
            if(exp % 2) {
                *this *= rhs;
            }
            rhs *= rhs;
            exp /= 2;
        }
        return *this;
    }
};

using mint = modint<MOD>;
int main() {
    cin >> n >> m >> k;
    vl v1, v2, v(200100, 0);
    vector<mint> kaijo(n * m + 1);

    kaijo[0] = 1;
    rep(i, n * m) { kaijo[i + 1] = kaijo[i] * (i + 1); }
    rep(i, n) { v1.push_back(n - i); }
    rep(j, m) { v2.push_back(m - j); }

    rep(i, n) {
        rep(j, m) {
            if(i * j == 0) {
                v[i + j] += v1[i] * v2[j];
            } else {
                v[i + j] += v1[i] * v2[j] * 2;
            }
            v[i+j]%=MOD;
        }
    }

    mint ans=0,x;
    x=kaijo[n*m-2]/(kaijo[n*m-k]*kaijo[k-2]);
    rep(i,m+n){
        ans+=x*(v[i]*i);
    }

    cout << ans.a << endl;
}

Measured memory_bytes: 5492