akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pcc pair<char,char>
#define vi vector <int>
#define vl vector <ll>
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d",x)
#define plld(x) printf("%lld",x)
#define pds(x) printf("%d ",x)
#define pllds(x) printf("%lld ",x)
#define pdn(x) printf("%d\n",x)
#define plldn(x) printf("%lld\n",x)
#define INF 2e9
#define INFLL 4e18
using namespace std;
ll powmod(ll base,ll exponent,ll mod){ // with mod < 1e9
	ll ans=1;
	while(exponent){
		if(exponent&1)ans=(ans*base)%mod;
		base=(base*base)%mod;
		exponent/=2;
	}
	return ans;
}
ll gcd(ll a, ll b){
	if(b==0) return a;
	else return gcd(b,a%b);
}
const int upperlimit = 1e6+1;
const int mod = 1e9+7;
int etf[upperlimit];
int nfac[upperlimit];
int main() {
	for(int i = 1; i < upperlimit; i++) etf[i]=i;
	for(int i = 2; i < upperlimit; i++){
		if(etf[i]<i) continue;
		for(int j = i; j < upperlimit; j+=i){
			etf[j]/=i;
			etf[j]*=i-1;
		}
	}
	int n,k=3;
	sd(n);
	for(int i = 1; i <= n; i++) nfac[i]=n/i;
	ll ans=0;
	for(int i = 1; i <= n; i++){
		ll temp=powmod(nfac[i],k,mod);temp*=etf[i];temp%=mod;
		ans+=temp;ans%=mod;
	}
	plld(ans);
	return 0;
}

Measured memory_bytes: 7700
#include<iostream> 
#include<cstring> 
#include<cstdlib> 
using namespace std; 
int L[3001][3001]; 
void lcs( char *X, char *Y, int m, int n ) 
{ 
for (int i=0; i<=m; i++) { 
	for (int j=0; j<=n; j++) 
	{ 
	if (i == 0 || j == 0) 
		L[i][j] = 0; 
	else if (X[i-1] == Y[j-1]) 
		L[i][j] = L[i-1][j-1] + 1; 
	else
		L[i][j] = max(L[i-1][j], L[i][j-1]); 
	} 
} 
int index = L[m][n]; 
char lcs[index+1]; 
lcs[index] = '\0'; 
int i = m, j = n; 
while (i > 0 && j > 0) 
{ 
	if (X[i-1] == Y[j-1]) 
	{ 
		lcs[index-1] = X[i-1];  
		i--; j--; index--;	
	}  
	else if (L[i-1][j] > L[i][j-1]) 
		i--; 
	else
		j--; 
} 
cout << lcs << endl ;
} 
int main() 
{ 
char X[3001], Y[3001] ;
scanf("%s",X) ;
scanf("%s",Y) ;
int m = strlen(X); 
int n = strlen(Y); 
lcs(X, Y, m, n); 
return 0; 
} 

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

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
void tostr(ll x,string& res){while(x)res+=('0'+(x%10)),x/=10; reverse(ALL(res)); return;}
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; }
//end



int main(){
   ll n,a,b; scanf("%lld%lld%lld",&n,&a,&b);
   ll res=n/(a+b)*a+min(a,n%(a+b)); printf("%lld\n",res);
   return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <queue>
#include <list>
#include <unordered_map>
#include <algorithm>
#include <functional>
#include <iomanip> // std::std::setprecision(X)
#include <limits>  //std::numeric_limits<int>::max(), min()

typedef long long ll;

int main (void) {
  int n; std::cin >> n;
  std::cout << 3*n*n << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int> v(n, 0);
	for (int i = 0; i < n; i++) {
		cin >> v[i];
	}
	vector<int> v1 = v;
	sort(v.begin(), v.end());
	for (int i = 0; i < n; i++) {
		if (v1[i] == v.back())
			cout << v[n - 2] << endl;
		else
			cout << v.back() << endl;
	}
}


Measured memory_bytes: 4752
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vc = vector<char>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using stkll = vector<pll>;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
#define rep(i, n) for (ll i = 0; i < (n); i++)
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
#ifndef ONLINE_JUDGE
    #define debug(x) cerr << #x << ": " << x << endl;
#else
    #define debug(x)
#endif

//
// ローリングハッシュ
//
// verified:
//   ABC 141 E - Who Says a Pun?
//     https://atcoder.jp/contests/abc141/tasks/abc141_e
//

struct RollingHash {
    static const int base1 = 1007, base2 = 2009;
    static const int mod1 = 1000000007, mod2 = 1000000009;
    vector<long long> hash1, hash2, power1, power2;

    // construct
    RollingHash(const string &S) {
        int n = (int)S.size();
        hash1.assign(n+1, 0);
        hash2.assign(n+1, 0);
        power1.assign(n+1, 1);
        power2.assign(n+1, 1);
        for (int i = 0; i < n; ++i) {
            hash1[i+1] = (hash1[i] * base1 + S[i]) % mod1;
            hash2[i+1] = (hash2[i] * base2 + S[i]) % mod2;
            power1[i+1] = (power1[i] * base1) % mod1;
            power2[i+1] = (power2[i] * base2) % mod2;
        }
    }

    // get hash of S[left:right]
    inline pair<long long, long long> get(int l, int r) const {
        long long res1 = hash1[r] - hash1[l] * power1[r-l] % mod1;
        if (res1 < 0) res1 += mod1;
        long long res2 = hash2[r] - hash2[l] * power2[r-l] % mod2;
        if (res2 < 0) res2 += mod2;
        return {res1, res2};
    }

    // get lcp of S[a:] and S[b:]
    inline int getLCP(int a, int b) const {
        int len = min((int)hash1.size()-a, (int)hash1.size()-b);
        int low = 0, high = len;
        while (high - low > 1) {
            int mid = (low + high) >> 1;
            if (get(a, a+mid) != get(b, b+mid)) high = mid;
            else low = mid;
        }
        return low;
    }

    // get lcp of S[a:] and T[b:]
    inline int getLCP(const RollingHash &T, int a, int b) const {
        int len = min((int)hash1.size()-a, (int)hash1.size()-b);
        int low = 0, high = len;
        while (high - low > 1) {
            int mid = (low + high) >> 1;
            if (get(a, a+mid) != T.get(b, b+mid)) high = mid;
            else low = mid;
        }
        return low;
    }
};


int main() {
    string T, P;
    cin >> T >> P;

    // ロリハ
    RollingHash rh1(T), rh2(P);

    // 求める
    vll ans;
    ll M = P.size();
    rep(i, T.size()) {
        if(rh1.get(i, i+M) == rh2.get(0, M)) ans.push_back(i);
    }

    for(auto i : ans) cout << i << endl;
}


Measured memory_bytes: 44104
import sys

input = sys.stdin.readline


def main():
    W, H, N = map(int, input().split())
    X = [0] * N
    Y = [0] * N
    A = [0] * N
    for i in range(N):
        X[i], Y[i], A[i] = map(int, input().split())

    x_min = 0
    x_max = W
    y_min = 0
    y_max = H
    for x, y, a in zip(X, Y, A):
        if a == 1:
            x_min = max(x_min, x)
        elif a == 2:
            x_max = min(x_max, x)
        elif a == 3:
            y_min = max(y_min, y)
        else:
            y_max = min(y_max, y)

    ans = max(0, x_max - x_min) * max(0, y_max - y_min)
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9196
#include<stdio.h>

long long A[1010][8];
long long bufArray[1010];

long long Origin[1010][3];

void q_sort(long long numbers[], long long left, long long right)
{
	long long pivot;
	long long l_hold, r_hold;

	l_hold = left;
	r_hold = right;
	pivot = numbers[left];
	while (left < right)
	{
		while ((numbers[right] >= pivot) && (left < right))
			right--;
		if (left != right)
		{
			numbers[left] = numbers[right];
			left++;
		}
		while ((numbers[left] <= pivot) && (left < right))
			left++;
		if (left != right)
		{
			numbers[right] = numbers[left];
			right--;
		}
	}
	numbers[left] = pivot;
	pivot = left;
	left = l_hold;
	right = r_hold;
	if (left < pivot)
		q_sort(numbers, left, pivot - 1);
	if (right > pivot)
		q_sort(numbers, pivot + 1, right);
}

int main() {
	int N, M;
	long long sum[8] = { 0 };
	long long sumMax = 0;
	long long bufSum=0;
	scanf("%d %d", &N, &M);
	for (int i = 0; i < N; i++) {
		scanf("%lld %lld %lld", &Origin[i][0], &Origin[i][1], &Origin[i][2]);
		A[i][0] = Origin[i][0] + Origin[i][1] + Origin[i][2];
		A[i][1] = Origin[i][0] * (-1) + Origin[i][1] + Origin[i][2];
		A[i][2] = Origin[i][0] + Origin[i][1] * (-1) + Origin[i][2];
		A[i][3] = Origin[i][0] + Origin[i][1] + Origin[i][2] * (-1);
		A[i][4] = Origin[i][0] * (-1) + Origin[i][1] * (-1) + Origin[i][2];
		A[i][5] = Origin[i][0] + Origin[i][1] * (-1) + Origin[i][2] * (-1);
		A[i][6] = Origin[i][0] * (-1) + Origin[i][1] + Origin[i][2] * (-1);
		A[i][7] = Origin[i][0] * (-1) + Origin[i][1] * (-1) + Origin[i][2] * (-1);
	}
	for (int i = 0; i < 8; i++) {
		for (int j = 0; j < N; j++) {
			bufArray[j] = A[j][i];
		}
		q_sort(bufArray, 0, N - 1);
		bufSum = 0;
		for (int j = N - 1; j >= N - M; j--) {
			bufSum += bufArray[j];
		}
		if (sumMax < bufSum)sumMax = bufSum;
	}
	
	printf("%lld\n", sumMax);

	return 0;
}

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

using namespace std;

int main()
{
  int m;
  while(cin >> m, m){
    vector< vector<int> > cubes;
    for(int i = 0; i < m; i++){
      vector<int> cube;
      cube.push_back(i+1);
      cubes.push_back(cube);
    }
    int I, J;
    while(cin >> I >> J, I || J){
      int Ip = -1, Ii = -1, Jp = -1, Ji = -1;
      for(int i = 0; i < (int)cubes.size(); i++){
	for(int j = 0; j < (int)cubes[i].size(); j++){
	  if(cubes[i][j] == I) Ip = i, Ii = j;
	  if(cubes[i][j] == J) Jp = i, Ji = j;
	}
      }
      if(Ip == Jp && Ii >= Ji) continue;
      if(J == 0 && Ii == 0) continue;
      while(cubes[Ip].back() != I){
	vector<int> cube;
	cube.push_back(cubes[Ip].back());
	cubes[Ip].pop_back();	  
	cubes.push_back(cube);
      }
      for(int i = 0; i < (int)cubes.size(); i++){
	for(int j = 0; j < (int)cubes[i].size(); j++){
	  if(cubes[i][j] == J) Jp = i, Ji = j;
	}
      }
      if(J == 0){
	vector<int> cube;
	cube.push_back(cubes[Ip].back());
	cubes[Ip].pop_back();
	cubes.push_back(cube);
      } else {
	cubes[Jp].push_back(cubes[Ip].back());
	cubes[Ip].pop_back();
      }
    }
    vector<int> out;
    for(int i = 0; i < (int)cubes.size(); i++){
      if((int)cubes[i].size() != 0) out.push_back((int)cubes[i].size());
    }
    sort(out.begin(), out.end());
    for(int i = 0; i < (int)out.size(); i++) cout << out[i] << endl;
    cout << "end" << endl;
  }
  return 0;
}

Measured memory_bytes: 1244
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();

    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let k: i64 = read();
    let n: usize = read();
    let a: Vec<i64> = (0..n).map(|_| read()).collect();

    let max_d = a[..].windows(2).fold(0, |max_d, d| {
        if max_d < d[1] - d[0] {
            d[1] - d[0]
        } else {
            max_d
        }
    });

    if max_d < k - a[n - 1] + a[0] {
        println!("{}", a[n - 1] - a[0]);
    } else {
        println!("{}", k - max_d);
    }
}


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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()

int cnt(int n) {
  int ret = 0;
  for (int i = 1; i <= n; i++) {
    if (n % i == 0) ret++;
  }
  return ret;
}

void solve() {
  int n;
  cin >> n;
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    if (i % 2 && cnt(i) == 8) {
      ans++;
    }
  }
  cout << ans << '\n';
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) solve();
}


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

#ifdef LOCAL
#include <debug.hpp>
#else
#define debug(...) void()
#endif

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int h, w, sy, sx, gy, gx;
  cin >> h >> w >> sy >> sx >> gy >> gx;
  sy--, sx--, gy--, gx--;
  vector<string> a(h);
  for (int i = 0; i < h; i++) {
    cin >> a[i];
  }
  deque<pair<int, int>> q;
  q.push_front({sy, sx});
  vector<vector<int>> cost(h, vector<int>(w, -1));
  cost[sy][sx] = 0;
  int dy[4] = {1, -1, 0, 0}, dx[4] = {0, 0, 1, -1};
  while (!q.empty()) {
    auto p = q.front();
    q.pop_front();
    int y = p.first, x = p.second;
    for (int i = 0; i < 4; i++) {
      int ny = y + dy[i];
      int nx = x + dx[i];
      if (ny < 0 || ny >= h || nx < 0 || nx >= w) continue;
      if (cost[ny][nx] != cost[y][x] && a[ny][nx] == '.') {
        q.push_front({ny, nx});
        cost[ny][nx] = cost[y][x];
      }
    }
    for (int i = -2; i <= 2; i++) {
      for (int j = -2; j <= 2; j++) {
        int ny = y + i, nx = x + j;
        if (ny < 0 || ny >= h || nx < 0 || nx >= w) continue;
        if (cost[ny][nx] == -1 && a[ny][nx] == '.') {
          q.push_back({ny, nx});
          cost[ny][nx] = cost[y][x] + 1;
        }
      }
    }
  }
  cout << cost[gy][gx] << '\n';
  return 0;
}

Measured memory_bytes: 8644
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
#define x first
#define y second
int dx[]={1,-1,0,0};
int dy[]={0,0,1,-1};
char a[52][52];
bool vis[52][52];
int dist[52][52];
int n,m;
bool ok(int i, int j)
{
	return (i>=0 and j>=0 and j<m and i<n);
}
int32_t main()
{
	#ifndef ONLINE_JUDGE
	freopen("in","r",stdin);
	freopen("out","w",stdout);
	#endif
	cin>>n>>m;
	int b=0;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
		{
			dist[i][j]=1e9;
			cin>>a[i][j];
			if(a[i][j]=='#')b++;
		}
	}
	queue<pair<int,int>> q;
	q.push({0,0});
	vis[0][0]=1;dist[0][0]=0;

	while(!q.empty())
	{
		auto p=q.front();
		q.pop();
		for(int k=0;k<4;k++)
		{
			int u=p.x+dx[k];int v=p.y+dy[k];

			if(!ok(u,v))continue;
			if(a[u][v]=='#')continue;
			if(vis[u][v])continue;
			dist[u][v]=min(dist[u][v], 1+dist[p.x][p.y]);
			vis[u][v]=1;
			q.push({u,v});

		}
	}

	if(dist[n-1][m-1]==1e9)puts("-1");
	else 
		cout<<(n*m)-(b+dist[n-1][m-1])-1;


}

Measured memory_bytes: 3644
import java.util.Scanner;
public class Main {
    static Scanner sc = new Scanner(System.in);
    public static int gcd (int a, int b) {
      int temp;
      while((temp = a%b)!=0) {
        a = b;
        b = temp;
      }
      return b;
    }
    public static void main(String[] args) {
      int N = sc.nextInt();
      int answer = 0;
      int x = 0; int y = 0;
      for(int i = 1; i <= N; i++){
        for(int j = 1; j <= N; j++){
          for(int k = 1; k <= N; k++){
            x = gcd(i,j);
            y = gcd(x,k);
            answer += y;
          }
        }
      }
      System.out.println(answer);
      }
}

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

using namespace std;

using i64 = long long;

const i64 MOD = i64(1e9) + 7;
const i64 INF = i64(1e18) + 7;


signed main(){

    int sx, sy, gx, gy;
    cin >> sx >> sy >> gx >> gy;
    int n;
    cin >> n;
    vector<int> px(n), py(n);
    for(int i = 0; i < n; ++i)
        cin >> px[i] >> py[i];
    int absx, absy;
    cin >> absx >> absy;

    sx += absx;
    sy += absy;
    gx += absx;
    gy += absy;
    for(int i = 0; i < n; ++i){
        px[i] += absx;
        py[i] += absy;
    }
    int b_absx = absx;
    int b_absy = absy;
    absx *= 2;
    absx += 4;
    absy *= 2;
    absy += 4;

    vector<vector<int>> dx{{0, 1, 1, 0, -1, -1, 0}, {0, 1, 1, 0, -1, -1, 0}};
    vector<vector<int>> dy{{1, 0, -1, -1, -1, 0, 0}, {1, 1, 0, -1, 0, 1, 0}};

    vector<vector<vector<int>>> dp(absx, vector<vector<int>>(absy, vector<int>(6, MOD)));
    dp[sx][sy][0] = 0;
    vector<bitset<210>> bs(210);
    for(int i = 0; i < n; ++i)
        bs[px[i]].set(py[i]);

    using TP = tuple<int,int,int,int>;
    priority_queue<TP, vector<TP>, greater<TP>> que;
    que.emplace(0, sx, sy, 0);
    while(!que.empty()){
        int x, y, cnt, di;
        tie(cnt, x, y, di) = que.top();
        que.pop();
        if(dp[x][y][di] != cnt)
            continue;

        int tx = x - b_absx;
        int ty = y - b_absy;
        bool fl = tx % 2;

        int dir = abs(tx * ty * di) % 6;
        for(int d = 0; d < 7; ++d){
            int nx = x + dx[fl][d];
            int ny = y + dy[fl][d];
            int nex = cnt + (dir != d);
            if(abs(nx - b_absx) > b_absx || abs(ny - b_absy) > b_absy || bs[nx][ny])
                continue;
            if(dp[nx][ny][(di + 1) % 6] > nex){
                dp[nx][ny][(di + 1) % 6] = nex;
                que.emplace(nex, nx, ny, (di + 1) % 6);
            }
        }
    }

    int ans = MOD;
    for(int j = 0; j < 6; ++j)
        ans = min(ans, dp[gx][gy][j]);
    cout << (ans == MOD ? -1 : ans) << endl;
}




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

using namespace std;
typedef long long ll;
#define MOD 1000000007

int main()
{

  ll a, b, x;
  long double theta;
  cin >> a >> b >> x;
  ll mass = a * a * b / 2;
  if (mass < x)
  {
    // 半分以上
    theta = atan(2 * double(a * a * b - x) / (a * a * a));
  }
  else
  {
    theta = atan(double(a * b * b) / (2 * x));
  }

  cout << setprecision(10) << theta * 180.0 / M_PI << endl;

  return 0;
}


Measured memory_bytes: 512
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>
#include <set>

using namespace std;
using ll = long long;
const int MOD=1000000007;


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 GCD(int a, int b) { return b ? GCD(b, a%b) : a; }



int main(int argc, char**argv){
    int a, b, c;
    cin >> a >> b >> c;
    for (int i = a; i <= max(a*100, b*100) + a; i += a){
        if (i % b == c){
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;

    return 0;
}


Measured memory_bytes: 256
N = int(input())
A = []
for i in range(N):
    A.append(int(input()))
count = 0
cur = 1
for i in range(N):
    if A[i] > cur:
        count += (A[i]-1)//cur
    elif A[i] == cur:
        cur += 1
    if cur == 1:
        cur += 1
print(count)

Measured memory_bytes: 80412
//競技プログラミング　テンプレ
//
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cstdlib> //abs() これは整数のみ

using namespace std;

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

const int max_v = 300;
const int INF = 1000000;



int main() {
	int a,b, ans=0, ten = 10;
    string s;
	cin >> a >> b;
    cin >> s;

    REP(i,a){
        if(int(s[i]) == 45) {cout << "No"  << endl; return 0;} 
    }
    if(s[a] != '-') {cout << "No" <<   endl; return 0;} 
    int aa = a+1;
    int bb = a+b;
    for(aa; aa <= bb; aa++){
        if(s[aa] == '-') {cout << "No" << endl; return 0;} 
    }
    
	cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
start = n - 1
while start >= 0:
    print(a[start],end=' ')
    start -= 2
if n % 2 == 0:
    start = 0
else:
    start = 1
while start < n:
    print(a[start],end=' ')
    start += 2


Measured memory_bytes: 104440
#include<stdio.h>
int main()
{
  int n,i,num,answer,count=0,sum=0;
  
  scanf("%d", &n);
  
  if(n!=1){
  for(i=1;i<=n;i++){
    num=i;
    while(num>0){
      if(num%2==0){
        num=num/2;
        count++;
      }else
        break;
    }
    if(sum<count){
      sum=count;
      answer=i;
    }
    count=0;
    num=0;
  }
  
  printf("%d", answer);
  }else
    printf("1");
  
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

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

    ll y500 = floor((double)n / 500.0);
    n -= y500 * 500;
    ll y5 = floor((double)n / 5.0);

    cout << (y500 * 1000) + (y5 * 5) << endl;
}

 

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
  int k,a,b,f=0;
  scanf("%d",&k);
  scanf("%d %d",&a,&b);
  int i;
  for(i=a;i<=b;i++)
  {
    if(i%k==0)
    {
      f=1;
      break;
    }
  }
  if(f==1)
    printf("OK");
  else
    printf("NG");
}



Measured memory_bytes: 1728
N = int(input())
ans = 1
mod = pow(10,9)+7

INSU = {}

#引用・改変：https://qiita.com/ym11235/items/fb01b2e84041bd2eaffd
import math
for j in range(2,N+1):
    I=j
    s=0
    R=int(I)
    L=[]
    while s==0:
        for i in range(2,R+1):
            if I%i==0:
                I=I/i
                if I==1:
                    s=1
                L.append(i)
                break
    if len(L)==1:
        #print(R ,"is a prime")
        INSU[R] = 1
    else:
        #print(L)
        for l in L: INSU[l] += 1
    ans = 1
    for insu in INSU:
        ans = (ans*(INSU[insu]+1))%mod
        
print(ans)

Measured memory_bytes: 3064
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <map>
#include <set>

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define Fst first
#define Snd second
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

const int MC = 500010;

int N,D,Q;
int d[MC];
int s[MC];
LL r[MC];
bool ans[MC];

int main(){
	scanf("%d%d" , &N , &D);
	repp(i,0,N){
		scanf("%d" , d+i);
	}
	s[0] = D;
	repp(i,0,N){
		s[i+1] = abs(s[i] - d[i]);
		if(s[i+1]>s[i]) s[i+1] = s[i];
	}
	r[N] = 0;
	repm(i,N,0){
		r[i-1] = r[i];
		if(d[i-1] <= 2 * r[i] + 1){
			r[i-1] += d[i-1];
		}
		if(r[i-1] > D) r[i-1] = D;
	}
	repp(i,1,N+1){
		ans[i] = s[i-1] > r[i];
	}
	scanf("%d" , &Q);
	repp(i,0,Q){
		int x;
		scanf("%d" , &x);
		printf("%s\n" , ans[x] ? "YES" : "NO");
	}
	return 0;
}


Measured memory_bytes: 10112
#include<bits/stdc++.h>                
using namespace std;
int N;
char C;
bool flag;
int main(){
	cin >> N;
	for(int i = 0; i < N; i++){
		scanf("%c", &C);
    if(C == 'Y')flag = true;
	}
	if(flag)cout << "Four" << endl;
	else cout << "Three" << endl;
}


Measured memory_bytes: 256
#pragma region
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <iomanip>
#include <cstdint>
#include <cstdlib>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()
#pragma endregion


int main()
{
	ll n, k; cin >> n >> k;
	vector<ll> a(n); rep(i, n)cin >> a[i];
	ll sum = 0;
	rep(i, n)sum += a[i];
	vector<ll> factors;
	for (int i = 1; i*i <= sum; ++i)
	{
		if (sum%i == 0)
		{
			factors.push_back(i);
			factors.push_back(sum / i);
		}
	}
	sort(all(factors));
	ll res = 1;
	for (ll x : factors)
	{
		vector<ll> r(n); rep(i, n)r[i] = a[i] % x;
		sort(all(r));
		vector<ll> m(n + 1), p(n + 1);
		rep(i, n)m[i + 1] = m[i] + r[i];
		rep(i, n)p[i + 1] = p[i] + (x - r[i]);
		rep(i, n + 1)
		{
			ll can = max(m[i], p[n] - p[i]);
			if (can <= k)res = x;
		}
	}
	cout << res << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
/* Author : Ravikumar Navale */
#define fastIo() ios_base :: sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)
#define pb push_back
#define endl  "\n"
typedef long long int ll;
vector<pair<ll,ll> >v1, v2, v3;
const ll MOD = 1e9 + 7;
const ll NM = 1e5 + 7;
const double peek = 1e7 ;
vector<ll> v[NM];
vector<ll> dp(NM,0);
bool  b[NM];

void dfs(ll vertex)
{
    b[vertex] =true;
    if(v[vertex].size()==0) return;
    for(auto x : v[vertex])
    {
        if(!b[x])
            dfs(x);
        dp[vertex] = max(dp[vertex] , 1 + dp[x]);
    }

}

int main()
{
    fastIo();
    ll N , M;
    cin>> N >> M;

    ll l ,r;
    
    for(ll i =0; i < M ; i++)
    {
        cin  >>l >> r;
        v[l].pb(r);
      //  dp[r] = max(dp[l] + 1, dp[r]);
    }
    memset(b,false,sizeof(b));
    for(ll i= 1; i <= N ; i++)
    {
        if(!b[i])
            dfs(i);
    }
   
    ll ANS = 0;
    for(ll i= 1; i <= N ; i++){
        ANS = max(dp[i],ANS);
      // cout <<i <<" -->" << dp[i]<<" ";
        
    }
    cout << ANS  << endl;
    
}

Measured memory_bytes: 8704
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;

/*
<url:https://abc088.contest.atcoder.jp/tasks/abc088_d>
問題文============================================================
 縦 H マス, 横 W マスに広がるマス目があり, 各マスは白または黒で塗られている.
 上から i 番目で左から j 番目のマスを (i,j) で表す.
 すぬけ君は, このマス目を使って次のようなゲームをしたい.
 ゲームの開始時点ではマス (1,1) にゲームキャラクター「けぬす君」がいる.
 プレイヤーはけぬす君を上下左右の 4 方向のいずれかに 1 マスだけ動かすことを繰り返す.
 けぬす君が白いマスだけを通って (H,W) にたどり着けばゲームクリアとなる.
 
 ゲームを開始する前に, すぬけ君はいくつかの白いマス目の色を黒に変えることができる.
 ただし, マス (1,1) と (H,W) の色を変えることはできず,
 ゲームを開始するまでにすべての色の変更を行わなければならない.
 
 ゲームをクリアしたとき, ゲームの開始前にマスの色を変えた回数がすぬけ君のスコアとなる.
 そのとき, すぬけ君が取る可能性のある最大のスコアを求めなさい.
 ただし,すぬけ君がどのようにマス目の色を変えてもけぬす君が (H,W) にたどり着くことが出来ない場合、−1 と出力しなさい.
 
 ただし, 各マスの色の情報は文字 si,j として与えられる.
 マス (i,j) が最初白で塗られている場合 si,j は .
 であり, マス (i,j) が最初黒で塗られている場合 si,j は # である.
 

=================================================================

解説=============================================================

================================================================
*/
int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
    int H,W;
    cin >> H >> W;
    vector<vector<char>> masu(H+2,vector<char>(W+2,'#'));
    int cnt = 0;
    for(int i = 1; i <= H;i++){
        for(int j = 1; j <=W;j++){
            cin >> masu[i][j];
            if(masu[i][j] == '#') cnt++;
        }
    }
    int dx[4] = {1,0,-1,0};
    int dy[4] = {0,1,0,-1};
    vector<vector<int>> G(H+1,vector<int>(W+1,INF));
    G[1][1] = 0;
    queue<pii> q; q.push(pii(1,1));
    while(!q.empty()){
        auto p = q.front(); q.pop();
        int x,y; tie(x,y) = p;
        for(int i = 0; i < 4;i++){
            int nx = x + dx[i] , ny = y + dy[i];
            if(masu[nx][ny] == '#') continue;
            if(G[nx][ny] > G[x][y] + 1){
                G[nx][ny] = G[x][y] + 1;
                q.push(pii(nx,ny));
            }
        }
    }
    
    if(G[H][W] == INF) cout << -1 << endl;
    else cout << H*W - G[H][W] - 1 - cnt << endl;
	return 0;
}


Measured memory_bytes: 256
def solve():
    n = int(input())
    s = input()
    if len(s) % 2 == 1:
        print('No')
    elif s[:len(s)//2] == s[len(s)//2:]:
        print('Yes')
    else:
        print('No')



if __name__ == '__main__':
    solve()


Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <string>
#include <utility>
#include <map>
#include <queue>
#include <list>
#include <functional>
#include <numeric>
#include <stack>
#include <tuple>

using namespace std;
int dx[4] = { -1,0,1,0 };
int dy[4] = { 0,1,0,-1 };
const int INF = 100000000;
const long long LINF = 1000000000000000000;
const long long MOD = 998244353;
const double EPS = 1e-6;
using pii = std::pair<int, int>;
using ll = long long;
using pLL = std::pair<ll, ll>;
#define SORT(v) std::sort(v.begin(), v.end())
#define RSORT(v) std::sort(v.rbegin(), v.rend())
#define PI 3.14159265358979323846264338327950L


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A, B;
    cin >> A >> B;
    int H, M;
    cin >> H >> M;
    long double rad = PI * 2 * ((long double)H / 12.0 + ((long double)M / 60.0) / 12.0 - (long double)M / 60.0);
    long double ans = (long double)(A*A + B * B) - (long double)2 * A*B*cosl(rad);
    printf("%20.20Lf\n", sqrt(ans));
    return 0;
}


Measured memory_bytes: 4120
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

#include <bits/stdc++.h>
using namespace std;

#define INF 2147483647

int m;
vector<int> A;

void update(int a,int b){
  A[m+a]=b;
  int j=(m+a)/2;
  while(j>=1){
    A[j]=min(A[2*j],A[2*j+1]);
    j/=2;
  }  
}

int find(int a,int b,int k,int l,int r){
  if(b<=l || r<=a) return INF;
  else if(a<=l && b>=r) return A[k];
  else{
    int c1=find(a,b,2*k,l,(l+r)/2);
    int c2=find(a,b,2*k+1,(l+r)/2,r);
    return min(c1,c2);
  }
}         

int main(){
  int n,q;
  cin>>n>>q;
  
  m=1;
  while(m<n){
    m*=2;
  }
  
  A=vector<int>(2*m,INF);
  
  int c,x,y;
  rep(i,q){
    cin>>c>>x>>y;
    if(c==0) update(x,y);
    else if(c==1) cout<<find(x,y+1,1,0,m)<<endl;
  }
  
  return 0;
}


Measured memory_bytes: 3892
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m;
  cin >> n >> m;
  vector<int> a(m);
  vector<int> c(m);
  for(int i=0; i<m; i++){
    cin >> a[i];
    int b;
    cin >> b;
    for(int j=0; j<b; j++){
      int tc;
      cin >> tc;
      c[i] += (1<<(tc-1));
    }
  }
  int pattern = (1<<n);
  vector<int> money(pattern);
  int INF=1000000;
  for(int i=0; i<pattern; i++){
    money[i]=INF;
  }
  money[0]=0;
  for(int i=0; i<m; i++){//until number i key. key numbers start from 0.
    for(int j=0; j<pattern; j++){
      money[(j|c[i])] = min(money[(j|c[i])],money[j]+a[i]);
    }
  }
  if(money[pattern-1]==INF)money[pattern-1]=-1;
  cout << money[pattern-1] << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include <algorithm>
#include<string>
#include <bitset>
#include <vector>
#include <functional>
#include <climits>
#include <iomanip>
#include <utility>
using namespace std;
typedef pair <int, int> pii;
int main()
{

	//int a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, g = 0, h = 0, ans = 0;
	long long a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, g = 0, h = 0, i = 0, j = 0, k = 0, l = 0, ans = 0;
	//cout << LONG_MAX << endl;
	//string s, t;
	//long long n, A[1000000000];
	long long n, m;
	//int   y[100001], z[100001], x[10001] = {};
	//pii y[100001];
	//pair<int, float> pii[100001];
	int x[100];
	cin >> a ;
	for ( b = 1; b <= a; b+=2)
	{
		d = 0;
		for ( c = 1; c <= b; c++)
		{
			if (b%c==0)
			{
				d++;
			}
		}
		if (d==8)
		{
			e++;
		}
	}


	////std::cout << std::fixed;
	//cout << std::setprecision(20) << << endl;
	//cout << d+1 << endl;

	cout << e << endl;

	return 0;
}

Measured memory_bytes: 256
/************************************************
 * Au: Hany01
 * Date: Aug 23rd, 2018
 * Prob: ARC074 E
 * Email: hany01dxx@gmail.com & hany01@foxmail.com
 * Inst: Yali High School
************************************************/

#include<bits/stdc++.h>

using namespace std;

typedef long long LL;
typedef long double LD;
typedef pair<int, int> PII;
#define rep(i, j) for (register int i = 0, i##_end_ = (j); i < i##_end_; ++ i)
#define For(i, j, k) for (register int i = (j), i##_end_ = (k); i <= i##_end_; ++ i)
#define Fordown(i, j, k) for (register int i = (j), i##_end_ = (k); i >= i##_end_; -- i)
#define Set(a, b) memset(a, b, sizeof(a))
#define Cpy(a, b) memcpy(a, b, sizeof(a))
#define x first
#define y second
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define SZ(a) ((int)(a).size())
#define INF (0x3f3f3f3f)
#define INF1 (2139062143)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define y1 wozenmezhemecaia

template <typename T> inline bool chkmax(T &a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> inline bool chkmin(T &a, T b) { return b < a ? a = b, 1 : 0; }

inline int read() {
	static int _, __; static char c_;
    for (_ = 0, __ = 1, c_ = getchar(); c_ < '0' || c_ > '9'; c_ = getchar()) if (c_ == '-') __ = -1;
    for ( ; c_ >= '0' && c_ <= '9'; c_ = getchar()) _ = (_ << 1) + (_ << 3) + (c_ ^ 48);
    return _ * __;
}

const int maxn = 305, MOD = 1e9 + 7;

int n, m, l, r, x, dp[maxn][maxn][maxn], Ans;
vector<PII> lmt[maxn];

inline void ad(int& x, int y) { if ((x += y) >= MOD) x -= MOD; }

int main()
{
#ifdef hany01
	freopen("arc074e.in", "r", stdin);
	freopen("arc074e.out", "w", stdout);
#endif

	n = read(), m = read();
	For(i, 1, m) l = read(), r = read(), x = read(), lmt[r].pb(mp(l, x));

	dp[0][0][0] = 1;
	For(i, 0, n) For(j, 0, i) For(k, 0, i) if (dp[i][j][k]) {
		rep(p, SZ(lmt[i])) {
			int sm = 1, l = lmt[i][p].x;
			if (j >= l) ++ sm;
			if (k >= l) ++ sm;
			if (sm != lmt[i][p].y) { dp[i][j][k] = 0; break; }
		}
		if (!dp[i][j][k]) continue;
		if (i == n) ad(Ans, dp[i][j][k]);
		else {
			ad(dp[i + 1][j][k], dp[i][j][k]);
			ad(dp[i + 1][i][j], dp[i][j][k]);
			ad(dp[i + 1][i][k], dp[i][j][k]);
		}
	}
	printf("%d\n", Ans);

	return 0;
}

Measured memory_bytes: 108800
#include<bits/stdc++.h>
using namespace std;
#define INF 1000000000

string f_J(string s){
    
    char c = s[0];
    for(int i = 0; i < s.size() - 1; i++){
        s[i] = s[i + 1];
    }
    s[s.size() - 1] = c;
    return s;
}

string f_C(string s){

    char c = s[s.size() - 1];
    for(int i = s.size() - 1; i > 0; i--){
        s[i] = s[i - 1];
    }
    s[0] = c;
    return s;
}

string f_E(string s){

    int n = s.size();
    if(n % 2 == 0){

        string r = "", l = "";
        for(int i = 0; i < n/2; i++){
            l = l + s[i];
        }
        for(int i = n/2; i < n; i++){
            r = r + s[i];
        }

        s = r + l;        
    }else{

        string r = "", l = "";
        for(int i = 0; i < n/2; i++){
            r = r + s[i];
        }

        for(int i = n/2 + 1; i < n; i++){
            l = l + s[i];
        }

        s = l + s[n/2] + r;
    }

    return s;
}

string f_A(string s){
    
    reverse(s.begin(), s.end());
    return s;
}

string f_P(string s){

    for(int i = 0; i < s.size(); i++){
        if('0' <= s[i] && s[i] <= '8'){
            s[i]++;
        }else if(s[i] == '9'){
            s[i] = '0';
        }
    }

    return s;
}

string f_M(string s){

    for(int i = 0; i < s.size(); i++){
        if('1' <= s[i] && s[i] <= '9'){
            s[i]--;
        }else if(s[i] == '0'){
            s[i] = '9';
        }
    }

    return s;
}

int main(){

    int n; cin >> n;
    for(int i = 0; i < n; i++){
        string t; cin >> t;
        string s; cin >> s;
        for(int j = t.size() - 1; j >= 0; j--){

            if(t[j] == 'J') s = f_C(s);
            if(t[j] == 'C') s = f_J(s);
            if(t[j] == 'E') s = f_E(s);
            if(t[j] == 'A') s = f_A(s);
            if(t[j] == 'P') s = f_M(s);
            if(t[j] == 'M') s = f_P(s);
        }

        cout << s << endl;
    }

    return 0;
}


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

bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    } else {
    	return a.first < b.first;
    }
}

int main() {
	int		a,b,c,i,j,k,n,m,x,l,y,ans = 0;
	
	cin >> n;	
	
	vector<pair<int , int>> p(n);

	for(i=0; i<n; i++) {
		cin >> x >> l;
		p[i] = make_pair(x-l, x+l);
	}
	
	sort(p.begin(), p.end(), compare_by_b);
	
	j = p[0].second;
	ans = n;
	for(i=1;i<n;i++) {
		if (j > p[i].first) {
			ans--;
		} else {
			j = p[i].second;
		}
	}
	
	cout << ans << endl;


}


Measured memory_bytes: 1024
#define DEBUG 1
#include <bits/stdc++.h>
#define loop(n) for (lint ngtkana_is_a_genius = 0; ngtkana_is_a_genius < lint(n); ngtkana_is_a_genius++)
#define rep(i, begin, end) for (lint i = lint(begin); (i) < lint(end); i++)
#define all(v) v.begin(), v.end()
#define rand(l, r) std::uniform_int_distribution<>(l, r)(mt)
using lint = long long;
auto mt = std::mt19937_64(std::random_device{}());
auto cmn = [](auto&& a, auto b){ if (a > b) {a = b; return true;} return false; };
auto cmx = [](auto&& a, auto b){ if (a < b) {a = b; return true;} return false; };
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail) { std::cerr << " " << head; debug_impl(tail...); }
#if DEBUG
#define debug(...)\
  do {\
    std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\
    debug_impl(__VA_ARGS__);\
    std::cerr << std::noboolalpha;\
  } while (false)
#else
#define debug(...) {}
#endif

int main() {
  std::cin.tie(0); std::cin.sync_with_stdio(false);
  int n; std::cin >> n;
  std::string s; std::cin >> s;
  int ans = 0;
  rep(i,0,n) {
    ans += s.substr(i,3) == "ABC";
  }
  std::cout << ans << std::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);
        String[] array = sc.nextLine().split(" ");
        if (Integer.parseInt(array[0]) % Integer.parseInt(array[1]) == 0) {
        	System.out.println("0");
        } else {
        	System.out.println("1");  
        }  
    }
}

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

int main() {
string S;
cin >> S;
int count = 0;
string Sdash = S;
reverse(S.begin(), S.end());
for (int i = 0; i < S.size(); i++) {
    if (S.at(i) !=Sdash.at(i)) {
        count++;
    }
}
cout << count / 2 << endl;
}

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

#define DBG(a)	cerr << #a << " = " << a << endl;

int main(){
	int n, k;	cin >> n >> k;
	int p[n];
	double expec[n];
	for (int i = 0; i < n; ++i){
		cin >> p[i];
		expec[i] = (p[i]+1.0)/2.0;
	}
	double sum = 0;
	for (int i = 0; i < k; ++i){
		sum += expec[i];
	}
	double ans = sum;
	for (int i = k; i < n; ++i){
		sum += expec[i];
		sum -= expec[i-k];
		ans = max(ans, sum);
	}
	printf("%0.15lf\n", ans);
	return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define in ({int x=0;int c=getchar(),n=0;for(;!isdigit(c);c=getchar()) n=(c=='-');for(;isdigit(c);c=getchar()) x=x*10+c-'0';n?-x:x;})
#define forinc(i,a,b) for(int i=a;i<=b;i++)
#define fordec(i,a,b) for(int i=a;i>=b;i--)
#define pii pair<int,int>
#define int long long
#define fi first
#define se second

const int maxn=405;
int n,a[maxn];
int f[maxn][maxn],s[maxn];
int calc(int l,int r)
{
    if(l>=r) return 0;
    if(f[l][r]!=-1) return f[l][r];
    int ret=1e16;
    forinc(i,l,r-1)
    {
        ret=min(ret,calc(l,i)+calc(i+1,r)+s[r]-s[l-1]);
    }
    return f[l][r]=ret;
}
main()
{
    cin>>n;
    forinc(i,1,n) {cin>>a[i];s[i]=s[i-1]+a[i];}
    memset(f,-1,sizeof f);
    cout<<calc(1,n);
}


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

using namespace std;

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

vector<int> x;

void init(){
  x.clear();
}
bool input(){
  int n;
  cin>>n;
  if(n==0)return false; 
 rep(i,n){
    int a;
    cin>>a;
    x.push_back(a);
  }
  return true;
}

int solve(){
  sort(x.begin(),x.end());
  int sum = 0;
  reps(i,1,x.size()-1)sum+=x[i];
  return sum/(x.size()-2);
}
int main(){
  while(init(),input()){
    printf("%d\n",solve());
  }
}

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


#include <bits/stdc++.h>

#define MOD 1e9+7

using namespace std;

class DLine {
public:
  static void solve(std::istream &cin, std::ostream &cout) {
    int64_t n, x, y;
    cin >> n >> x >> y;
    vector<vector<int>> g(n, vector<int>());
    g[0].emplace_back(1);
    g[n - 1].emplace_back(n - 2);
    for (int i = 1; i < n - 1; ++i) {
      g[i].emplace_back(i + 1);
      g[i].emplace_back(i - 1);
    }
    g[x - 1].emplace_back(y - 1);
    g[y - 1].emplace_back(x - 1);
    vector<int> ans(n, 0);
    for (int i = 0; i < n; ++i) {
      vector<bool> visited(n, false);
      visited[i] = true;
      queue<pair<int, int>> q;
      q.push(make_pair(i, 0));
      while (!q.empty()) {
        auto p = q.front();
        q.pop();
        for (const auto &item : g[p.first]) {
          if (visited[item])continue;
          visited[item] = true;
          ans[p.second + 1]++;
          q.push(make_pair(item, p.second + 1));
        }
      }
    }
    for (int i = 1; i < n; ++i) {
      cout << ans[i] / 2 << endl;
    }
  }
};


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


Measured memory_bytes: 384
N = int(input())
d = [int(input()) for i in range(N)]

# 餅を太い順に置けるので太い順にソートする
d.sort(reverse=True)
# 同じ直径の餅は2枚以上置けないので重複を除く
dUnique = set(d)


print(len(dUnique))


Measured memory_bytes: 9072
int main(){
  int n,m,a[1000],c=0,d=0;
  scanf("%d%d",&n,&m);
  for(int i=0;i<n;i++){
    scanf("%d",&a[i]);
    c+=a[i];
  }
  for(int i=0;i<n;i++){
    if(a[i]*4*m>=c) d++;
  }
  if(d<m) printf("No");
  else printf("Yes");
  return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<queue>
using namespace std;
int cnt = 0;
vector<int> bubble(vector<int> a){
  bool f = true;
  while( f ){
    f = false;
    for(int i=a.size()-1; i>0; i--){
      if( a[i] < a[i-1] ){
        swap(a[i], a[i-1]);
        f = true;
        cnt++;
      }
    }
  }
  return a;
}

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

  a = bubble(a);
  for(int i=0; i<n-1; i++) cout << a[i] << " ";
  cout << a[n-1] << endl;
  cout << cnt << endl;

  return 0;
}

Measured memory_bytes: 3108
import java.util.Scanner;
import java.util.TreeSet;
import java.util.Arrays;
public class Main {
 
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n;
       n= sc.nextInt();
       int [] a=new int[n];
       for(int i=0;i<n;i++){
           a[i]=sc.nextInt();
       }
       int count=0;
       for(int i=0;i<n-1;i++){
           for(int j=0;j<n-1-i;j++){
                if(a[j]>a[j+1]){
                    int tmp=a[j];
                    a[j]=a[j+1];
                    a[j+1]=tmp;
                    count++;
                }
           }
       }

       for(int i=0;i<n;i++){
        if(i!=(n-1))System.out.print(a[i]+" ");
        else  System.out.println(a[i]);
       }
       System.out.println(count);
}
}




Measured memory_bytes: 26352
# coding: utf-8
# Your code here!
N=int(input())
dp=[[0]*3 for i in range(N)]

if N==1:
    print(max(list(map(int,input().split()))))
else:
    for i in range(0,N):
        l=list(map(int,input().split()))
        if i==0:
            dp[0]=l
        else:
            for j in range(3):
                index_l=[0,1,2]
                index_l.pop(j)
                for index in index_l:
                    #print(i,j,int(index))
                    dp[i][index]=max(dp[i-1][j]+l[index],dp[i][index])

    print(max(dp[N-1]))

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

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

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2018/02/24  Problem: code-festival-2017-qual-c_c / Link: https://code-festival-2017-qualc.contest.atcoder.jp/tasks/code_festival_2017_qualc_c?lang=en  ----- */
/* ------問題------

英小文字のみからなる文字列 s があります。 すぬけ君は、次の操作を繰り返し行うことができます。
s の任意の位置 (先頭および末尾を含む) をひとつ選び、英小文字 x をひとつ挿入する。
すぬけ君の目標は、s を回文にすることです。 すぬけ君の目標が達成可能か判定し、達成可能ならば必要な操作回数の最小値を求めてください。
注釈
回文とは、前後を反転しても変わらない文字列のことです。 例えば、a, aa, abba, abcba は回文ですが、ab, abab, abcda は回文ではありません。

-----問題ここまで----- */
/* -----解説等-----

xについてばあいわけすればよい

----解説ここまで---- */

LL N;

LL ans = 0LL;

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


	string s; cin >> s;
	int l = 0;
	int r = SZ(s) - 1;
	while (l < r) {
		if (s[l] != s[r]) {
			if (s[l] == 'x') {
				ans++;
				l++;
			}
			else if (s[r] == 'x') {
				ans++;
				r--;
			}
			else {
				ans = -1;
				break;
			}
		}
		else {
			l++;
			r--;
		}
	}


	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 512
n = int(input())
a = list(map(int, input().split()))
a.sort()
c = 0
e = 0
i = 0
while True:
    c += 1
    cai = 1
    while i != n - 1 and a[i] == a[i + 1]:
        cai += 1
        if i != n - 1:
            i += 1
        else:
            break
    if cai % 2 == 0:
        e += 1
    if i != n - 1:
        i += 1
    else:
        break
ans = c - (e % 2)
print(ans)


Measured memory_bytes: 14388
from itertools import combinations

N = int(input())
xyss = [[tuple(map(int, input().split())) for _ in range(int(input()))] for _ in range(N)]

def check(mask):
    m = [None] * N
    for i, xys in enumerate(xyss):
        if i in mask:
            continue
        for x, y in xys:
            x -= 1
            if m[x] != None and m[x] != y:
                # 矛盾が生じている
                return False
            elif  y == 1 and x in mask or y == 0 and x not in mask:
                # 矛盾が生じている
                return False
            else:
                m[x] = y
    return True

for i in range(N + 1):
    for k in combinations(range(N), i):
        mask = set(k)
        if check(mask):
            print(N - i)
            break
    else:
        continue
    break

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <math.h>
#define FOR(i,b,e) for(int i=b;i<e;i++)
#define REP(i,n) FOR(i,0,n)
using namespace std;

struct Point { double x, y; };

void koch(int d, Point p1, Point p2) {
  if (d == 0) return;

  Point s, t, u;
  double th = M_PI / 3.0;
  
  s.x = (2 * p1.x + 1 * p2.x) / 3.0;
  s.y = (2 * p1.y + 1 * p2.y) / 3.0;

  u.x = (1 * p1.x + 2 * p2.x) / 3.0;
  u.y = (1 * p1.y + 2 * p2.y) / 3.0;

  t.x = s.x + (u.x - s.x) * cos(th) - (u.y - s.y) * sin(th);
  t.y = s.y + (u.x - s.x) * sin(th) + (u.y - s.y) * cos(th);

  koch(d - 1, p1, s);
  cout << s.x << " " << s.y << endl;
  koch(d - 1, s, t);
  cout << t.x << " " << t.y << endl;
  koch(d - 1, t, u);
  cout << u.x << " " << u.y << endl;
  koch(d - 1, u, p2);
}

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

  int n;
  Point l, r;
  l.x = 0.0; l.y = 0.0;
  r.x = 100.0; r.y = 0.0;

  cin >> n;

  cout << l.x << " " << l.y << endl;
  koch(n, l, r);
  cout << r.x << " " << r.y << endl;
}

Measured memory_bytes: 3280