akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
//#include <iomanip>
//#include <string>
#include <vector>
#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;
//#define all(v) v.begin(),v.end()
//ll mod = 1000000007 ;
//long double pie = acos(-1) ;
//ll INF = 1000000000000 ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void fix_cout(){cout << fixed << setprecision(20) ;}

int main(){
	ll n,m ;
	cin >> n >> m ;
	vll cnt(n,0) ;
	vvll g(n) ;
	for(int i=0;i<n-1+m;i++){
		ll a,b ;
		cin >> a >> b ;
		a-- ; b-- ;
		g.at(a).push_back(b) ;
		cnt.at(b)++ ;
	}
//	for(auto i:cnt) cout << i << endl ;
	queue<int> q ;
	vll d(n,-1) ;
	int root ;
	for(int i=0;i<n;i++){
		if(cnt.at(i)==0){
			q.push(i) ;
			d.at(i) = 0 ;
			root = i ;
		}
	}
	while(!q.empty()){
		int p = q.front() ;
		q.pop() ;
//		if(d.at(p)!=-1&&p!=root) continue ;
		for(int i=0;i<g.at(p).size();i++){
			if(cnt.at(g.at(p).at(i))==1){
//				cout << p << " " << g.at(p).at(i) << " " << cnt.at(g.at(p).at(i)) << endl ;
				q.push(g.at(p).at(i)) ;
				d.at(g.at(p).at(i)) = d.at(p)+1 ;
			}
			cnt.at(g.at(p).at(i))-- ;
		}
//		cout << q.size() << endl ;
	}
	vvll ans(n) ;
	for(int i=0;i<n;i++){
		for(int j=0;j<g.at(i).size();j++){
			if(d.at(g.at(i).at(j))-d.at(i)==1){
				ans.at(i).push_back(g.at(i).at(j)) ;
			}
		}
	}
	vll par(n,-1) ;
	q.push(root) ;
	while(!q.empty()){
		int p = q.front() ;
		q.pop() ;
		for(int i=0;i<ans.at(p).size();i++){
			par.at(ans.at(p).at(i)) = p ;
			q.push(ans.at(p).at(i)) ;
		}
	}
	for(int i=0;i<n;i++) cout << par.at(i)+1 << endl ;
//	for(int i=0;i<n;i++){
//		for(int j=0;j<ans.at(i).size();j++){
//			cout << i << " " << ans.at(i).at(j) << endl ;
//		}
//	}
//	for(int i=0;i<n;i++) cout << d.at(i) << endl ;
}


Measured memory_bytes: 16412
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main()
{
    int n, m;
    cin >> n >> m;
    vector<string> a(n), b(m);
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < m; i++) cin >> b[i];

    bool exist = false;
    for (int dy = 0; dy <= n-m && !exist; dy++) {
        for (int dx = 0; dx <= n-m && !exist; dx++) {
            bool match = true;
            for (int y = 0; y < m && match; y++) {
                for (int x = 0; x < m && match; x++) {
                    if (a[y+dy][x+dx] != b[y][x]) match = false;
                }
            }
            if (match) exist = true;
        }
    }

    cout << (exist ? "Yes" : "No") << endl;
}

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

int gcd(int a, int b)
{
  return b ? gcd(b, a % b) : a;
}
int lcm(int a, int b)
{
  return a / gcd(a, b) * b;
}

int main()
{
  ll n, m;
  cin >> n >> m;
  string s, t;
  cin >> s >> t;
  if (n < m)
  {
    swap(n, m);
    swap(s, t);
  }
  int g = gcd(n, m);
  for (int i = 0, j = 0; i < n; i += n / g, j += m / g)
  {
    if (s[i] != t[j])
    {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << n / g * m << endl;

  return 0;
}


Measured memory_bytes: 512
#include <memory.h>

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>

using namespace std;

#define MOD 998244353
#define INIT -1

class UF
{
private:
   int n;
   vector<int> root;
   vector<int> size;

public:
   UF(int k)
   {
      n = k;
      root = vector<int>(n, -1);
      size = vector<int>(n, 1);
   }
   int getRoot(int x)
   {
      if (root[x] == -1)
         return x;
      else
         return root[x] = getRoot(root[x]);
   }
   void connect(int x, int y)
   {
      x = getRoot(x);
      y = getRoot(y);
      if (x == y)
         return;
      if (y < x)
         swap(x, y);
      root[y] = x;
      size[x] += size[y];
   }
   int getSize(int x)
   {
      return size[getRoot(x)];
   }
};

int main()
{
   int n, k, l;
   cin >> n >> k >> l;
   UF road(n), rail(n);
   for (int i = 0; i < k; i++)
   {
      int p, q;
      cin >> p >> q;
      p--;
      q--;
      road.connect(p, q);
   }
   for (int i = 0; i < l; i++)
   {
      int p, q;
      cin >> p >> q;
      p--;
      q--;
      rail.connect(p, q);
   }
   map<pair<int, int>, int> cnt;
   for (int i = 0; i < n; i++)
   {
      auto p = make_pair(road.getRoot(i), rail.getRoot(i));
      if (cnt.find(p) == cnt.end())
         cnt[p] = 0;
      cnt[p]++;
   }

   for (int i = 0; i < n; i++)
   {
      auto p = make_pair(road.getRoot(i), rail.getRoot(i));
      cout << cnt[p];
      if (i == n - 1)
         cout << endl;
      else
         cout << " ";
   }
}

Measured memory_bytes: 17600
#include <stdio.h>
int main(void)
{
	int num[10000],i;
	

	for (i = 0; i < 10000; i++)
	{
		scanf("%d", &num[i]);

		if (num[i]!=0)
		{
			printf("Case %d: %d\n", i + 1, num[i]);
		}

		else
		{
			break;
		}
	}

	return 0;
}


Measured memory_bytes: 1924
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define deb(x) cout<< #x << " " << x << "\n";
#define MAX 9223372036854775807
#define MIN -9223372036854775807
#define PI 3.141592653589
#define setbits(n) __builtin_popcountll(n)
const ll mod=1e9+7;

const int N=3001;
int dp[N][N];
string s,t;

int go(int pos1, int pos2){
    if(pos1==s.size() || pos2==t.size()) return 0;
    if(dp[pos1][pos2]!=-1)
        return dp[pos1][pos2];
    int ans=0;
    ans=max(0,max(go(pos1,pos2+1),go(pos1+1,pos2)));
    if(s[pos1]==t[pos2])
        ans=max(ans,1+go(pos1+1,pos2+1));
    return dp[pos1][pos2]=ans;
}

int main() {
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll T=clock();
    
    cin>>s>>t;
    for(ll i=0;i<N;i++)
        for(ll j=0;j<N;j++)
            dp[i][j]=-1;
    ll z=go(0,0);
    //cout<<z;
    ll n=s.size(), m=t.size();
    ll i=0,j=0;
    string ans;
    while(i<n && j<m){
        if(s[i]==t[j]){
            ans+=s[i];
            i++,j++;
        }
        else if(dp[i+1][j]>dp[i][j+1])
            i++;
        else
            j++;
    }
    cout<<ans;

    cerr<<"\n\nTIME: "<<(double)(clock()-T)/CLOCKS_PER_SEC<<" sec\n";
    T = clock();
    return 0;
}

Measured memory_bytes: 39412
#include <iostream>
#include <unordered_map>

int main(int argc, char **argv)
{
	int n = 0;
	int a = 0;
	std::unordered_map<int, int> amap;
	int duplicate = 0;
	int remains = 0;

	std::cin >> n;
	for (int i = 0; i < n; i++) {
		std::cin >> a;
		if (amap.find(a) == amap.end()) {
			amap[a] = 1;
		}
		else {
			amap[a]++;
			if (amap[a] > 1) {
				duplicate++;
			}
		}
	}

	if (duplicate % 2 > 0) {
		duplicate++;
	}

	remains = n - duplicate;
	std::cout << remains;

	return 0;
}

Measured memory_bytes: 4388
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mkp make_pair
#define f(i,l,h) for(ll i=l;i<h;i++)
#define fr(i,h,l) for(ll i=h;i>=l;i--)

using namespace std;

typedef pair<ll,ll> pll;
const ll INF=(ll)(1e9+7);
typedef vector<ll> vll;

int main()
{
    ll n,k;
    cin>>n>>k;
    ll snuke[n+1];
    memset(snuke,0,sizeof(snuke));

    for(ll i=0;i<k;i++){
        ll d;
        cin>>d;
        ll temp;
        for(ll i=0;i<d;i++){
            cin>>temp;
            snuke[temp]++;
        }
    }
    ll cnt=0;
    for(ll i=1;i<=n;i++){
        if(snuke[i]==0) cnt++;
    }
    cout<<cnt<<endl;

}


Measured memory_bytes: 3640
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#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 pi M_PI
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

bool check(int x){
    int p = x % 10;
    x /= 10;
    bool f = 1;
    while (x) {
        if (x % 10 != p - 1) f = 0;
        x /= 10;
        p--;
    }
    return f;
}

int main() {
    int n;
    cin >> n;
    VI a(n);
    REP(i,n) cin >> a[i];

    int ans = -1;
    REP(i,n-1) FOR(j,i+1,n-1){
        int x = a[i]*a[j];
        if (check(x)) ans = max(ans, x);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3048
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
constexpr int MOD = 1000000007;
constexpr int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const double PI = acos(-1.0);
// cout << fixed << setprecision(14);
 
 
signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);

    int N;
    cin >> N;
    char c[2][N];
    rep(i,2){
        rep(j,N){
            cin >> c[i][j];
        }
    }
    int num;
    int ans = 1;
    int tmp;
    if(c[0][0] != c[1][0]){
        ans *= 6;
        num = 1;
        tmp = 2;
    }
    else{
        ans *= 3;
        num = 0;
        tmp = 1;
    }
    while(tmp < N){
        if(c[0][tmp] != c[1][tmp]){
            if(num == 1){
                ans *= 3;
            }
            else{
                ans *= 2;
            }
            num = 1;
            tmp += 2;
        }
        else{
            if(num == 0){
                ans *= 2;
            }
            num = 0;
            tmp++;
        }
        ans %= MOD;
    }
    cout << ans << endl;
}

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

# define C continue;
# define R return

# define D double
# define I insert
# define ll long long
# define ld long double

# define ull unsigned long long
# define ui unsigned int

# define pb push_back
# define pf push_front

# define vi vector < ll >
# define vc vector < char >
# define vs vector < string >
# define vb vector < bool >
# define vd vector < D >
# define vll vector < ll >
# define vull vector < ull >
# define vld vector < ld >

# define vvi vector < vector < ll > >
# define vvb vector < vector < bool > >
# define vvc vector < vector < char > >
# define vvll vector < vector < ll > >
# define vvd vector < vector < D > >
# define vvld vector < vector < ld > >

# define all(v) (v).begin() , (v).end()
# define allrev(v) (v).rbegin() , (v).rend()
# define allcomp(v) v.begin() , v.end() , comp
# define allrevcomp(v) v.rbegin() , v.rend() , comp

# define pii pair < ll , ll >
# define pll pair < ll , ll >
# define pld pair < ld , ld >
# define pDD pair < D , D >

# define vpld vector < pld >
# define vpii vector < pii >
# define vpll vector < pll >
# define vpDD vector < pDD >

# define vvpii vector < vector < pii > >
# define F first
# define S second
# define mp make_pair

# define dist(a,b,p,q) sqrt((p-a)*(p-a) + (q-b)*(q-b))

# define pp(n) printf("%.10Lf",n);
# define line cout<<"\n";
# define fast ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0);

string vow = "aeiou";

const ll dxhorse[] = {-2, -2, -1, -1, 1, 1, 2, 2};
const ll dyhorse[] = {1, -1, 2, -2, 2, -2, 1, -1};

const ll dx[] = { -1 , 0 , 0 , 1 } ;
const ll dy[] = { 0 , -1 , 1 , 0 } ;

const ld pie = 3.14159265358979 ;
const ll mod = 1e9 + 7 ;

void solve ( ll test_case )
{
    ll n ; cin >> n ;
    vi bit ( 62 ) ;

    for ( ll i=0 ; i < n ; i ++ )
    {
        ll val ; cin >> val ;

        for ( ll j = 0 ; j < 62 ; j++ )
        {
            ll temp = (val&1) ;
            val >>= 1 ;

            if ( temp )
                bit[j] ++ ;
        }
    }

    ll f = 1 ;
    ll ans = 0 ;

    for ( ll j = 0 ; j < 62 ; j ++ )
    {
        ll one = bit[j] ;
        ll zero = n - one ;

        ll temp = one * f ;
        temp %= mod ;

        temp *= zero ;
        temp %= mod ;

        ans += temp ;
        ans %= mod ;

        f <<= 1 ;
        f %= mod ;
    }

    cout << ans ; line
}

int main()
{
    ll t = 1;
    // cin >> t;

    for ( ll i=0 ; i < t ; i++ ) solve(i);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
    int N;
    long long M;
    while(cin>>N>>M&&N+M){
        vector<int> line(N+1);
        for(int i=0;i<N;++i){
            cin>>line[i];
        }
        line[N]=0;
        vector<int> data;
        for(int i=0;i<=N;++i){
            for(int j=0;j<=N;++j){
                data.push_back(line[i]+line[j]);
            }
        }
        sort(data.begin(),data.end());
        int right = data.size()-1;
        int ans = 0;
        for(int left = 0;left<data.size();++left){
            while(right>0&&(long long)data[right]+data[left]>M){
                --right;
            }
            if((long long)data[right]+data[left]<=M){
                ans = max(ans,data[right]+data[left]);
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}


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

int main() {

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

  int num, max = 0;
  for (int i = 0; i < s.size() - t.size() + 1; i++) {
    num = 0;
    for (int j = 0; j < t.size(); j++) {
      if (s[i+j] == t[j]) num++;
      if (num > max) max = num;
    }
  }

  cout<<t.size() - max<<endl;
  return 0;
}

Measured memory_bytes: 3644
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
int PN[1000000];
bool isPrime[1300000];
int Index=0;
void Init(){
  for(int i=0;i<1300000;i++){
    isPrime[i] = false;
  }
  for(int i=3;i<1300000;i+=2)isPrime[i] = true;
  isPrime[2] = true;

  int lim = sqrt(1300000.0)+1;
  for(int i=3;i<=lim;i+=2){
    if(!isPrime[i])continue;
    for(int j=i+i;j<=1300000;j+=i){
      isPrime[j] = false;
    }
  }

  for(int i=2;i<1300000;i++){
    if(isPrime[i])PN[Index++] = i;
  }
}

int main(){
  int k;
  Init();
  while(cin >> k && k){
    if(isPrime[k]){
      cout << "0" << endl;
      continue;
    }
    int A = *(lower_bound(PN,PN+Index,k)-1);
    int B = *(upper_bound(PN,PN+Index,k));
    cout << B-A << endl;

  }
  return 0;
}

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

int main() {
  int h,n;
  cin>>h>>n;
  vector<int> dp(h+1,100000005);
  dp[0] = 0;
  rep(i,n){
    int a,b;
    cin>>a>>b;
    rep(j,h+1){
      int nj = min(h,j+a);
      dp[nj] = min(dp[j]+b,dp[nj]);
    }
    
  }
  cout << dp[h] << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s;
	cin>>s;
	int cnt=0;
	string s1="",s2="";
	for(int i=0;i<s.size();i++){
		s1+=s[i];
		if(s1!=s2){
			cnt++;
			s2=s1;
			s1="";
		}
	}
	printf("%d",cnt);
	return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>

typedef long long t_long;

int main()
{
	t_long A,B,C;
	scanf("%lld%lld%lld", &A,&B,&C);
	t_long K;
	scanf("%lld", &K);
	if (llabs(A - B) == 0)
	{
		printf("0\n");
		return 0;
	}
	if (K % 2)
	{
		printf("%lld\n", B - A);
	}
	else
	{
		printf("%lld", A - B);
	}
	return (0);
}

Measured memory_bytes: 128
class Fib:
    def __init__(self):
        self.memo = {0: 1, 1: 1}
    
    def calc_fib(self, n):
        if n in self.memo.keys():
            return self.memo[n]
        
        self.memo[n] = self.calc_fib(n - 2) + self.calc_fib(n - 1)
        return self.memo[n]
    
fib = Fib()
print(fib.calc_fib(int(input())))


Measured memory_bytes: 5600
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {
		// TODO ?????????????????????????????????????????????
		Scanner scan = new java.util.Scanner(System.in);

		InputStreamReader input = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(input);

		StringBuilder sb = new StringBuilder();

		int n = Integer.parseInt( br.readLine() );
		String[] xVec = br.readLine().split(" ");
		String[] yVec = br.readLine().split(" ");

		double[] x = new double[n];
		double[] y = new double[n];
		for (int i = 0; i < n; i++) {
			x[i] = Double.parseDouble(xVec[i]);
			y[i] = Double.parseDouble(yVec[i]);
		}

		double dxy1 = 0;
		for (int i = 0; i < n; i++ ) {
			dxy1 += Math.abs(x[i] - y[i]);
		}

		double dxy2 = 0;
		for (int i = 0; i < n; i++) {
			dxy2 += (x[i] - y[i]) * (x[i] - y[i]);
		}
		dxy2 = Math.sqrt(dxy2);

		double dxy3 = 0;
		for (int i = 0; i < n; i++) {
			//dxy3 += (x[i] - y[i]) * (x[i] - y[i]) * (x[i] - y[i]);
			dxy3 += Math.pow( Math.abs(x[i] - y[i]), 3 );
		}
		dxy3 = Math.cbrt(dxy3);

		double dxyinf = 0;
		for (int i = 0; i < n; i++) {
			if ( dxyinf < Math.abs(x[i] - y[i]) ) {
				dxyinf = Math.abs(x[i] - y[i]);
			}
		}

		System.out.println(dxy1);
		System.out.println(dxy2);
		System.out.println(dxy3);
		System.out.println(dxyinf);
	}

}

Measured memory_bytes: 26368
program frequency
  implicit none
  integer :: n, a(100001,2), m, i
  integer(8) :: s(100000)
  a = 0
  s = 0_8
  read(*,*) n
  read(*,*) a(1:n,1)
  do i = 1, n
    a(i,2) = i
  end do
  call merge_sort(a(1:n,1:2))
  m = n+1
  do i = 1, n
    m = min(m,a(i,2))
    s(m) = s(m)+int(i,8)*int(a(i,1)-a(i+1,1),8)
  end do
  do i = 1, n
    write(*,'(i0)') s(i)
  end do
  stop
contains
  subroutine merge_sort(c)
    implicit none
    integer, intent(inout) :: c(:,:)
    integer :: n, m, l, u, i
    n = size(c(:,1))
    m = n
    l = 1
    do while (m.gt.1)
      do i = 1, m/2
        u = min(2*i*l,n)
        call merger(c(2*(i-1)*l+1:(2*i-1)*l,:),c((2*i-1)*l+1:u,:))
      end do
      l = 2*l
      m = (m+1)/2
    end do
    return
  end subroutine merge_sort
  subroutine merger(c1,c2)
    implicit none
    integer, intent(inout) :: c1(:,:), c2(:,:)
    integer :: c(size(c1(:,1))+size(c2(:,1)),size(c2(1,:)))
    integer :: i1, i2, n1, n2
    i1 = 1
    i2 = 1
    n1 = size(c1(:,1))
    n2 = size(c2(:,1))
    do while ((i1.le.n1).and.(i2.le.n2))
      if (c1(i1,1).gt.c2(i2,1)) then
        c(i1+i2-1,:) = c1(i1,:)
        i1 = i1+1
      else if (c1(i1,1).lt.c2(i2,1)) then
        c(i1+i2-1,:) = c2(i2,:)
        i2 = i2+1
      else if (c1(i1,2).gt.c2(i2,2)) then
        c(i1+i2-1,:) = c1(i1,:)
        i1 = i1+1
      else
        c(i1+i2-1,:) = c2(i2,:)
        i2 = i2+1
      end if
    end do
    if (i1.le.n1) then
      c(i1+i2-1:n1+n2,:) = c1(i1:n1,:)
    else if (i2.le.n2) then
      c(i1+i2-1:n1+n2,:) = c2(i2:n2,:)
    end if
    c1 = c(1:n1,:)
    c2 = c(n1+1:n1+n2,:)
    return
  end subroutine merger
end program frequency

Measured memory_bytes: 3432
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#define rg register
using namespace std;
int n,K;
inline int read()
{
	rg int save=0,w=1;rg char q=getchar();
	while(q<'0'||q>'9'){if(q=='-')w=-1;q=getchar();}
	while(q>='0'&&q<='9')save=(save<<3)+(save<<1)+q-'0',q=getchar();
	return save*w;
}
int main()
{
	n=read(),K=read();
	if(K&1)
	{
		int num=n/K;
		printf("%lld\n",1ll*num*1ll*num*1ll*num);
	}
	else
	{
		int half=K>>1;
		int num1=n/K;
		int num2=((n+half)>>1)/half;
		printf("%lld\n",1ll*num1*1ll*num1*1ll*num1+1ll*num2*1ll*num2*1ll*num2);
	}
	return 0;
}


Measured memory_bytes: 256
import java.io.*;
public class Main {

	static int n, m;
	static int[] dx = {0,0,-1,1}, dy = {-1,1,0,0};
	static boolean[][] map, check;

	public static int dfs(int y, int x) {
		int ret = 0;
		for (int d = 0 ; d < 4 ; d++) {
			int nextX = x + dx[d];
			int nextY = y + dy[d];
			if (0 <= nextX && nextX < m &&
					0 <= nextY && nextY < n &&
					map[nextY][nextX] &&
					!check[nextY][nextX]) {

					check[nextY][nextX] = true;
					ret = Math.max(dfs(nextY,nextX) + 1,ret);
					check[nextY][nextX] = false;
				}
		}
		return ret;
	}

	public static void main(String[] args) throws IOException {
		BufferedReader s = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter out = new PrintWriter(System.out);
		while (true) {
			m = Integer.valueOf(s.readLine());
			n = Integer.valueOf(s.readLine());
			if (m == 0 && n == 0) break;
			map = new boolean[n][m];
			for (int i = 0 ; i < n ; i++) {
				String[] data = s.readLine().split(" ");
				for (int j = 0 ; j < m ; j++)
					map[i][j] = Integer.valueOf(data[j]) == 1;
			}
			int max = 0;
			for (int i = 0 ; i < n ; i++) {
				for (int j = 0 ; j < m ; j++) {
					if (map[i][j]) {
						check = new boolean[n][m];
						max = Math.max(max, dfs(i, j));
					}
				}
			}
			out.println(max);
		}
		out.flush();
	}
}

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

int f(int n) {
  int res = 0;
  while (n > 0) {
    res += n % 10;
    n /= 10;
  }
  return res;
}

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

  int fx = f(N);
  if (N % fx == 0)
    puts("Yes");
  else
    puts("No");
}

Measured memory_bytes: 256
//============================================================================
// Name        : JOI.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <vector>
using namespace std;
typedef long long ll;
ll A,B,C,D;

int main() {

	cin>>A>>B>>C>>D;

	ll total=0;
	if(A>B)total+=B;
	else total+=A;
	if(C>D)total+=D;
	else total+=C;
	cout<<total<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdbool.h>

int main(void){
        char s[10];
        int l = 0, i, cnt = 0;
        bool ok = true;
        while((s[l]=getchar())!='\n') l++;
        for(i=0; i<l; i++){
                if('a'<=s[i] && s[i]<='z') cnt++;
                else if(s[i]=='C') ok &= (1<i && i<l-1);
                else if(s[i]=='A') ok &= (i==0);
                else ok = false;
        }
        if(ok && cnt==l-2) puts("AC");
        else puts("WA");
        return 0;
}

Measured memory_bytes: 128
import sys
readline = sys.stdin.readline
N = int(readline())
A = list(map(int, readline().split()))

L = list(range(N))
L.sort(key = lambda x: A[x], reverse = True)

dp = [[0]*(N+1) for _ in range(N+1)]

for s in range(N):
    l = L[s]
    a = A[l]
    for i in range(s+1):
        j = s-i
        dp[i+1][j] = max(dp[i+1][j], dp[i][j]+a*abs(l-i))
        dp[i][j+1] = max(dp[i][j+1], dp[i][j]+a*abs(l-(N-s+i-1)))
ans = 0
for i in range(N+1):
    ans = max(ans, dp[i][N-i])
print(ans)

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

int main() {
	int x;
	cin >> x;
	if (x >= 30) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 3632
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <chrono>
#include <random>

const int INF = 1000000009;
const long LINF = 1123456789012345678;

long n;
double sum;

int main(){
	scanf("%ld", &n);
	for(int i = 0; i < n; i++){
		double x;
		char s[3];
		scanf("%lf %s", &x, s);
		if(s[0] == 'J'){
			sum += x;
		}else{
			sum += x * 380000.0;
		}
	}
	printf("%lf\n", sum);
	return 0;
}


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

using namespace std;

int A[100010],S[100010];

int main()
{
	int N;
	scanf("%d",&N);
	for (int i=1;i<=N;i++)
	{
		scanf("%d",&A[i]);
		int tmp = -1; //(N-X) - (X-1) = A[i]  X = N-1-A[i]
		if ((N+1-A[i])%2!=0)
		{
			puts("0");
			return 0;
		}
		else S[(N+1-A[i])/2]++;
	}
	//for (int i=1;i<=N;i++)printf("%d\n",S[i]);
	if ((N&1) && S[N/2+1]!=1)
	{
		puts("0");
		return 0;
	}
	int ans = 1;
	for (int i=1;i<=N/2;i++)
	{
		if (S[i] < 1 || S[i] > 2) 
		{
			puts("0");
			return 0;
		}
		ans *= S[i];
		ans %= 1000000007;
	}
	printf("%d\n",ans);
}

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


#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define pii pair<int,int>
#define pli pair<long long,int>
#define pil pair<int,long long>
#define ll long long
#define el '\n'

using namespace std;

ll x;
ll ans;

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

    cin >> x;
    ans += (x / 500) * 1000;
    x %= 500;
    ans += (x / 5) * 5;
    cout << ans << el;

    return 0;
}

Measured memory_bytes: 256
//#include"bits/stdc++.h"
#include<algorithm>
#include<cassert>
#include<cmath>
#include<climits>
#include<iostream>
#include<map>
#include<set>
#include<vector>
using namespace std;
#define ll long long
#define FOR(i, j, k, in) for (int i=j ; i<k ; i+=in)
#define rep(i, j) FOR(i, 0, j, 1)
#define MP make_pair
#define PB push_back
#define endl "\n"
#define MOD 1000000007
#define DEB(x) cout<<"##"<<x<<"##"<<endl
const int INF=(int)2e9+9;
const int SIZE=(int)2e5+5;
//Brute force answers(BINARY SEARCH) symmetry
//Change perspective
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    int n,ans=0;
    ll d;
    cin>>n>>d;
    rep(i,n){
        ll x,y;
        cin>>x>>y;
        if(x*x+y*y<=d*d){
            ans++;
        }
    }
    cout<<ans;

} 

Measured memory_bytes: 3632
#include <algorithm>
#include <complex>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;
#define SAY_YES cout << "YES" << endl;
#define SAY_Yes cout << "Yes" << endl;
#define SAY_NO cout << "NO" << endl;
#define SAY_No cout << "No" << endl;
#define IFYES(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "YES" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "NO" << endl;  \
    }
#define IFYes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "Yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "No" << endl;  \
    }
#define IFyes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "no" << endl;  \
    }
#define DEBUG_OUTPUT_ARRAY(XXX, ONE)                            \
    for (int i = 0; i < (ONE); i++)                             \
    {                                                           \
        cout << "DEBUG: i = " << i << " -> " << XXX[i] << endl; \
    }
#define DEBUG_OUTPUT_ARRAY2(XXX, ONE, TWO)                             \
    for (int i = 0; i < (ONE); i++)                                    \
    {                                                                  \
        cout << "<<< i = " << i << " >>>" << endl;                     \
        for (int j = 0; j < (TWO); j++)                                \
        {                                                              \
            cout << "DEBUG: j = " << j << " -> " << XXX[i][j] << endl; \
        }                                                              \
    }
#define DEBUG_OUTPUT_ARRAY2_BOX(XXX, ONE, TWO) \
    for (int i = 0; i < (ONE); i++)            \
    {                                          \
        cout << i << "  ";                     \
        for (int j = 0; j < (TWO); j++)        \
        {                                      \
            cout << XXX[i][j] << " ";          \
        }                                      \
        cout << endl;                          \
    }

typedef pair<long long int, long long int> pll;


const long long int mod = 1000000007;
const long long int INF = 99999999999999999;




long long int N,M,K,sum=0,res=0;
string str;

int main()
{
    cout << fixed << setprecision(18);
    
    cin>>N>>M>>K;
    if(M+K==0){cout<<0<<endl;return 0;}
    res=N/(M+K)*M+min(N%(M+K),M);
    cout<<res<<endl;
    
    
}



Measured memory_bytes: 256
# Template 1.0
import sys, re
from collections import deque, defaultdict, Counter, OrderedDict
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from heapq import heappush, heappop, heapify, nlargest, nsmallest
def STR(): return list(input())
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def list2d(a, b, c): return [[c] * b for i in range(a)]
def sortListWithIndex(listOfTuples, idx):   return (sorted(listOfTuples, key=lambda x: x[idx]))
def sortDictWithVal(passedDic):
    temp = sorted(passedDic.items(), key=lambda kv: (kv[1], kv[0]))
    toret = {}
    for tup in temp:
        toret[tup[0]] = tup[1]
    return toret
def sortDictWithKey(passedDic):
    return dict(OrderedDict(sorted(passedDic.items())))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

n,k = MAP()

a = LIST()

for i in range(k, n):
    if(a[i]>a[i-k]):
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 95416
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long N,a=1000000,b=-1000000,c=0;
    cin>>N;
    while(N--){
        long long x;
        cin>>x;
        a=min(a,x),b=max(b,x),c+=x;
    }
    cout<<a<<' '<<b<<' '<<c<<endl;
}


Measured memory_bytes: 3112
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b;
	cin>>a>>b;
	for(int i=1;i<4;i++)
	{
		if(a*b*i%2==1)
		{
			cout<<"Yes";
			return 0;
		}
	}
	cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#pragma GCC opointimize("Ofset_asc")
#pragma GCC opointimize("unroll-loops")
#pragma GCC target("avx2")
#pragma GCC opointimize("Os")
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);
#define FO cout.tie(NULL);
#define FI cin.tie(NULL);
#define IN cin>>
#define OUT cout<<
#define loop(i,a,n) for(int i=a; i<n; i++)
#define rloop(i,a,n) for(int i=a; i>=n; i--)
#define endl "\n";
#define pb push_back
#define mp make_pair
#define set_bits(a) __builtin_popcountll(a)
#define ll long long int
#define ld long double
#define vll vector<long long int>
#define pll pair<long long int, long long int>
#define mod 1000000007
#define M 998244353
using namespace std;
ll gcd(ll a, ll b)
{
    return (b?gcd(b,a%b):a);
}
ll P(ll B, ll power, ll modulo)
{
    ll ans=1LL;
    while(power>0LL)
    {
        if(power%2LL==1LL)
        {
            ans=(ans*B)%modulo;
        }
        B=(B*B)%modulo;
        power/=2LL;
    }
    return ans;
}
bool isPrime(ll n)
{
    if(n<=1LL)
    {
        return false;
    }
    if(n<=3LL)
    {
        return true;
    }
    if(n%2==0LL || n%3==0LL)
    {
        return false;
    }
    for(ll i=5LL; (i*i)<=n; i+=6LL)
    {
        if(n%i==0LL || n%(i+2LL)==0LL)
        {
            return false;
        }
    }
    return true;
}
void vok()
{
    FAST
    FO
    FI
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
        // freopen("error.txt","w",stderr);
    #endif
}
int main()
{
    vok();
    int x;
    IN x;
    int num=1;
    while(1)
    {
        if(x*num%360==0)
        {
            break;
        }
        num++;
    }
    OUT num<<endl
    return 0;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
        using namespace std;
        int main()
        {
          int n,x,i,c=0,o=0;
          cin>>n>>x;
          int a[n],b[n+1];
          b[0]=0;
             for(i=0;i<n;i++)
                 {
                   cin>>a[i];
                 }
          for(i=1;i<=n;i++)
          {
            c=c+a[i-1];
            b[i]=c;
          }
          for(i=0;i<=n;i++)
          {
            if(b[i]<=x)
              o++;
          }
          cout<<o<<endl;
        }
     

Measured memory_bytes: 256
//g++ -std=c++14 test.cpp -o test.out

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (1LL<<60);
const int INF_INT = 2147483647-1e6-1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

LL N,P;
LL A[50];

LL ans = 0;

void solve(){
	LL num[2] = {0,0};
	for(int i=0;i<N;i++) num[A[i]]++;

	vector<LL> comb(num[1]+2,1);//num[1]_C_iをcomb[i]とする
	comb[1] = num[1];
	for(int i=2;i<num[1];i++){
		comb[i] = comb[i-1]*(num[1]-(i-1));
		comb[i] /= i;
	}
	//求めたcombから求める
	for(int i=0;i<=num[1];i++){
		if(i%2==P) ans += comb[i];
	}
	ans *= (1LL<<num[0]);
}
 
int main(){
    cin >> N >> P;
    for(int i=0;i<N;i++){
    	cin >> A[i];
    	A[i]%=2;
    }
 
    solve();

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

Measured memory_bytes: 256
fn main() {
    let (a, b) = {
        let v = mylib::get_ints();
        (v[0], v[1])
    };
    println!("{}", match a + b { v if v < 10 => (a + b).to_string(), v => "error".to_string() })
}

mod mylib {
    // IO
    pub fn get_str() -> String {
        use std::io;
        let mut input = String::new();
        io::stdin().read_line(&mut input);
        input.as_str().trim().to_string()
    }
    fn split_by_space(ss:&str) -> Vec<&str> {
        ss.split_whitespace().collect()
    }
    fn str_to_int(ss:&str) -> i64 {
        ss.parse().unwrap()
    }
    pub fn get_ints() -> Vec<i64> {
        split_by_space(&get_str()).iter().map(|s:&&str| str_to_int(s)).collect()
    }
}


Measured memory_bytes: 4476
#include<bits/stdc++.h>
using namespace std;
int dp[2][16][1<<16];
signed main(){
  int r,c;
  cin>>r>>c;
  string s[r];
  for(int i=0;i<r;i++) cin>>s[i];
  memset(dp,-1,sizeof(dp));
  dp[0][0][0]=0;
  int mask=(1<<c)-1;
  for(int i=0;i<r;i++){
    bool f=i%2;
    memset(dp[!f],-1,sizeof(dp[!f]));
    for(int j=0;j<c;j++){
      for(int b=0;b<(1<<c);b++){
	if(dp[f][j][b]<0) continue;
	//cout<<i<<" "<<j<<" "<<b<<":"<<dp[f][j][b]<<endl;
	char t,u;
	t=u='$';
	int y=0;
	for(int k=j-1;k>=0;k--) if((b>>k)&1) y++;
	if(j&&(b&1)) u=s[i][y-1];

	if(i){
	  int x=s[i-1].size()-(__builtin_popcountll(b)-y);
	  if(x<(int)s[i-1].size()&&((b>>(c-1))&1)) t=s[i-1][x];
	}
	
	if(y<(int)s[i].size()){
	  int nb=((b<<1)&mask)+1;
	  int nd=dp[f][j][b]+(t==s[i][y])*2+(u==s[i][y])*2;
	  if(j+1<c)
	    dp[f][j+1][nb]=max(dp[f][j+1][nb],nd);
	  else if(y+1==(int)s[i].size())
	    dp[!f][0][nb]=max(dp[!f][0][nb],nd);
	}
	{
	  int nb=(b<<1)&mask;
	  int nd=dp[f][j][b];
	  if(j+1<c)
	    dp[f][j+1][nb]=max(dp[f][j+1][nb],nd);
	  else if(y==(int)s[i].size())
	    dp[!f][0][nb]=max(dp[!f][0][nb],nd);
	}
      }
    }
  }
  int ans=0;
  for(int b=0;b<(1<<c);b++)
    ans=max(ans,dp[r%2][0][b]);
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 11368
x = list(map(int, input().split()))
y = list(map(int, input().split()))
z = [[0, 1, 2, 3], [0, 2, 1, 1], [1, 0, 2, 1], [2, 0, 1, 0], [1, 2, 0, 0], [2, 1, 0, 1]] 
succeed = False
for i in range(6):
    order = [0, 0, 0]
    for j in range(3):
        if {x[j], x[-j-1]} != {y[z[i][j]], y[-z[i][j]-1]}:
            break
        if x[j] == y[z[i][j]]:
            order[j] = 1 
            if x[j] == x[-j-1]:
                order[j] = 2 
    else:
        if 2 in order:
            succeed = True
            break
        if (z[i][3] == 0 or z[i][3] == 3) and sum(order) % 2:
            succeed = True
            break
        if z[i][3] == 1 and not sum(order) % 2:
            succeed = True
            break
if succeed:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 7748
macro_rules! read_line {
    () => {{
        let mut input = String::new();
        std::io::stdin().read_line(&mut input).unwrap();
        input
    }};
}
pub fn read_and_parse<T: std::str::FromStr>() -> T {
    read_line!().trim().parse().ok().unwrap()
}
pub fn read_to_vec<T: std::str::FromStr>() -> Vec<T> {
    read_line!().split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
use std::cmp::max;
fn main() {
    let n: usize = read_and_parse();
    let a: Vec<i64> = read_to_vec();

    println!("{}",
        (1..=n).zip(&a).fold([[-a[0], 0], [0, 0]], |status, (i, a)|
            [
                status[1],
                [
                    max(status[0][0] + a, status[1][i % 2]),
                    if i % 2 == 1 {status[0][1] + a} else {max(status[0][1] + a, status[1][1])}
                ]
            ]
        )[1][(n + 1) % 2]
    );
}


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

int main(void) {
  long long N, sum;

  while (1) {
    cin >> N;
    if (N == 0) break;
    sum = 1;

    for (long long i = 2; i*i <= N; i++) {
      if (N % i == 0) {
        long long tmp = N / i;
        sum += i;
        if (i != tmp) {
          sum += tmp;
        }
      }
      if (sum > N) {
        cout << "abundant number" << endl;
        break;
      }
    }

    if (N == 1 || sum < N) {
      cout << "deficient number" << endl;
    } else if (sum == N) {
      cout << "perfect number" << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 1156
# coding: utf-8
import array, bisect, collections, copy, heapq, itertools, math, random, re, string, sys, time

sys.setrecursionlimit(10 ** 7)
INF = 10 ** 20
MOD = 10 ** 9 + 7


def II(): return int(input())
def ILI(): return list(map(int, input().split()))
def IAI(LINE): return [ILI() for __ in range(LINE)]
def IDI(): return {key: value for key, value in ILI()}


def read():
    N = II()
    x, y = [], []
    for i in range(N):
        _x, _y = ILI()
        x.append((i, _x))
        y.append((i, _y))
    return N, x, y


class UnionFind(object):
    def __init__(self, number_of_nodes):  # 初期化
        self.par = array.array("L", range(number_of_nodes))
        self.rank = array.array("L", (0 for i in range(number_of_nodes)))

    def root(self, node):  # 根を求める
        if self.par[node] == node:
            return node
        else:
            r = self.root(self.par[node])
            self.par[node] = r  # 経路圧縮
            return r

    def in_the_same_set(self, node1, node2):  # 同じ集合に属するか
        return self.root(node1) == self.root(node2)

    def unite(self, node1, node2):  # 属する集合を併合
        x = self.root(node1)
        y = self.root(node2)
        if x == y:
            pass
        elif self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1


def solve(N, x, y):
    edges = []
    x.sort(key=lambda x: x[1])
    y.sort(key=lambda x: x[1])
    for i in range(N - 1):
        x_s, x_e = x[i], x[i + 1]
        y_s, y_e = y[i], y[i + 1]
        edges.append((x_s[0], x_e[0], x_e[1] - x_s[1]))
        edges.append((y_s[0], y_e[0], y_e[1] - y_s[1]))

    edges.sort(key=lambda x: x[2])
    union_find = UnionFind(N)
    ans = 0
    for edge in edges:
        if not union_find.in_the_same_set(edge[0], edge[1]):
            union_find.unite(edge[0], edge[1])
            ans += edge[2]

    return ans


def main():
    params = read()
    print(solve(*params))


if __name__ == "__main__":
    main()


Measured memory_bytes: 54000
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
typedef unsigned int ui;
int main(){
	int n; ll a;
	cin >> n;
	ll sum = 0;
	bool f = false;
	for (int i = 0; i < n; i++) {
		cin >> a;
		if (f&&a>0) {
			sum++; a--;
		}
		sum += a / 2;
		f = false;
		if (a % 2 == 1)f = true;
	}
	cout << sum << endl;
	char nyaa;
	cin >> nyaa;
	return 0;
}

Measured memory_bytes: 256
from sys import stdin
def main():
    readline=stdin.readline
    N,M=map(int,readline().split())
    s=[0]*M
    c=[0]*M
    for i in range(M):
        a,b=map(int,readline().split())
        s[i]=a
        c[i]=b

    res=[0]*N
    res[0]=-1
    flag=[False]*N
    for i in range(M):
        if flag[s[i]-1]==False:
            flag[s[i]-1]=True
            res[s[i]-1]=c[i]
        else:
            if res[s[i]-1]!=c[i]:
                print(-1)
                break
    else:
        for i in range(M):
            res[s[i]-1]=c[i]
        if res[0]==-1 and N!=1:
            res[0]=1
            print("".join(map(str,res)))
        elif res[0]==-1 and N==1:
            print(0)
        elif res[0]==0 and N!=1:
            print(-1)
        else:
            print("".join(map(str,res)))

if __name__=="__main__":
    main()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int K;
  string S;
  cin >> K >> S;
  if(S.size() <= K) {
    cout << S << endl;
  }
  else {
    cout << S.substr(0, K) << "..." << endl;
  }
}

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

//////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////// ここからコピペ ////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////

////////////
// 行列型 //
///////////

// 加算、減算、乗算をもつN*M型行列
// N=Mで環をつくる
template<typename T = int64_t>
class Matrix {
private:
	using RowVector = std::vector<T>;

	std::vector<RowVector> container_;

public:
	const int N, M;

	Matrix(const int row_size, const int column_size)
		: N(row_size), M(column_size), container_(row_size, RowVector(column_size)){}
	Matrix(Matrix<T>&& mat)
		: N(mat.N), M(mat.M), container_(std::move(mat.container_)){}
	Matrix(Matrix<T>& mat)
		: N(mat.N), M(mat.M), container_(mat.container_){}

	// 要素アクセス
	RowVector& operator[](const int r) { return container_[r]; }
	const RowVector& operator[](const int r) const { return container_[r]; }
	// イテレータ
	typename decltype(container_)::iterator begin(){ return container_.begin(); }
	typename decltype(container_)::iterator end(){ return container_.end(); }

	// 環の演算
	Matrix<T> operator+(const Matrix<T>& mat) const
	{
		Matrix<T> ret{*this};
		for (int r_i{}; r_i < N; r_i++)
			for (int c_i{}; c_i < M; c_i++)
				ret[r_i][c_i] += mat[r_i][c_i];
		return std::move(ret);
	}
	Matrix<T> operator-(const Matrix<T>& mat) const
	{
		Matrix<T> ret{*this};
		for (int r_i{}; r_i < N; r_i++)
			for (int c_i{}; c_i < M; c_i++)
				ret[r_i][c_i] -= mat[r_i][c_i];
		return std::move(ret);
	}
	Matrix<T> operator*(const Matrix<T>& mat) const
	{
		Matrix<T> ret(this->N, mat.M);
		for (int r_i{}; r_i < this->N; r_i++)
			for (int c_i{}; c_i < mat.M; c_i++)
				for (int l_i{}; l_i < this->M; l_i++)
					ret[r_i][c_i] += (*this)[r_i][l_i] * mat[l_i][c_i];
		return std::move(ret);
	}
	std::vector<T> operator*(const std::vector<T>& vec) const
	{
		std::vector<T> ret(N);
		for (int r_i{}; r_i < N; r_i++)
			for (int c_i{}; c_i < M; c_i++)
				ret[r_i] += (*this)[r_i][c_i] * vec[c_i];
		return std::move(ret);
	}

	// 代入演算子
	Matrix<T>& operator+=(const Matrix& mat)
	{
		*this = *this + mat;
		return *this;
	}
	Matrix<T>& operator-=(const Matrix& mat)
	{
		*this = *this - mat;
		return *this;
	}
	Matrix<T>& operator*=(const Matrix& mat)
	{
		*this = *this * mat;
		return *this;
	}
};

//////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////// ここまでコピペ ////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=3035
int main()
{
	int n, m, l;
	scanf("%d%d%d", &n, &m, &l);
	Matrix<> A(n, m), B(m, l);
	for (auto& e: A)
		for (auto& f: e)
			scanf("%lld", &f);
	for (auto& e: B)
		for (auto& f: e)
			scanf("%lld", &f);
	Matrix<> C(A * B);
	for (int i{}; i < n; i++)
		for (int j{}; j < l; j++)
			printf("%lld%c", C[i][j], j == l - 1? '\n': ' ');
	return 0;
}


Measured memory_bytes: 3416
#include <iostream>
#include <vector>
#include <functional>
using namespace std;
int main(){
  long long int a, b, n;
  cin >> a >> b >> n;
  long long int x = b-1 > n ? n : b-1;
  cout << (a * x) / b - a * (x/b) << endl;
  return 0;
}

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

int cnt[1000000], cntid[50];
ll c[51][51], cc[51][51];

int main() {
  int n, k, s, t;
  cin >> n >> k >> s >> t;
  rep(i, 1000000) {
    cnt[i] = 0;
  }
  vector<int> atmp(n);
  rep(i, n) cin >> atmp[i];

  rep(i, n + 1) rep(j, n + 1) c[i][j] = 0;
  rep(i, n + 1) {
    c[i][0] = 1;
    for (int j = 1; j <= i; j++) {
      c[i][j] = c[i - 1][j] + c[i - 1][j - 1];
    }
  }
  rep(i, n + 1) {
    cc[i][0] = 0;
    for (int j = 1; j <= n; j++) {
      cc[i][j] = cc[i][j - 1] + c[i][j];
    }
  }

  // if si = 1 and ti = 0, no set meets the condition;
  // if si = 0 and ti = 1, the i-th bit is to be considered;
  vector<int> bit; int maxb = -1;
  rep(i, 20) {
    int si = (s>>i) & 1, ti = (t>>i) & 1;
    if (si == 1 && ti == 0) { cout << 0 << endl; return 0; }
    else if (si == 0 && ti == 1) { bit.push_back(i); maxb++; }
  }

  // if aij = 0 and sj = 1 or aij = 1 and tj = 0, ai is not included in any set;
  // only bits included in bit are added to a;
  vector<int> a;
  rep(i, n) {
    int ai = atmp[i];
    bool flug = true;
    rep(j, 20) {
      int aij = (ai>>j) & 1, sj = (s>>j) & 1, tj = (t>>j) & 1;
      if ((aij == 0 && sj == 1) || (aij == 1 && tj == 0)) { flug = false; }
    }
    if (flug) {
      a.push_back(0);
      rep(j, bit.size()) {
        int aij = ai & (1<<bit[j]);
        if (aij) {
          maxb = max( maxb, j );
          a[a.size() - 1] += 1<<j;
        }
      }
    }
  }
  if (a.size() == 0) { cout << 0 << endl; return 0; }
/*
cout << "bit";
rep(i, bit.size()) cout << " " << bit[i]; cout << endl;
cout << "a ";
rep(i, a.size()) cout << a[i] << " "; cout << endl; cout << "maxb " << maxb << endl;
*/
  ll ans = 0;
  rep(i, 1<<(maxb + 1)) {
    int one = 0;
    rep(l, maxb + 1) one += (i>>l) & 1;
//cout << "one " << one << endl;
    rep(l, a.size()) {
      int ani = a[l]&i;
      cnt[ani]++;
      cntid[l] = ani;
    }
//cout << "i:" << i << ":"; rep(l, 1<<(maxb + 1)) cout << " " << cnt[l]; cout << endl;
    ll co = (one % 2 == 0) ? 1 : -1;
    rep(l, a.size()) {
      // choose at most k element from a set of size cnt[cntid[l]];
      ans += co * cc[cnt[cntid[l]]][k];
      cnt[cntid[l]] = 0;
    }
  }

  cout << ans << endl;

  return 0;
}

/*
*/


Measured memory_bytes: 7548
#include<bits/stdc++.h>
#define ll long long 
#define ld long double
#define pb push_back
#define vl vector
#define ff first
#define ss second
using namespace std;
int main()
{
    ll a,b,i,j,n,t,c,m;
    cin>>n;
    ll arr[n];
    for(i=0;i<n;i++) cin>>arr[i];
    ll sum[n];
    ll temp=arr[n-1];
    for(i=n-1;i>=1;i--)
    {
        sum[i]=temp;
        temp+=arr[i-1];
    }
    sum[0]=0;
    //for(i=0;i<n;i++) cout<<sum[i]<<" ";
    ll ans=0;
    for(i=0;i<n-1;i++)
    {
        ans+=((arr[i]%1000000007)*(sum[i+1]%1000000007))%1000000007;
    }
    cout<<ans%1000000007;
    
}

Measured memory_bytes: 6696