akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(x) (x).begin(),(x).end()
#define dup(x,y) (((x)+(y)-1)/(y))
#define sz(x) (int)(x).size()
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main(){
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll cd = c*d;
    ll c1 = c;
    ll d1 = d;
    if(c1<d1) swap(c1,d1);
    ll r = c1%d1;
    while(r!=0){
        c1 = d1;
        d1 = r;
        r = c1%d1;
    }
    ll lcm = cd/d1;
    ll e = b/c;
    ll f = b/d;
    ll g = b/lcm;
    ll x = e+f-g;
    ll h = (a-1)/c;
    ll i = (a-1)/d;
    ll j = (a-1)/lcm;
    ll y = h+i-j;
    cout << (b-a+1)-(x-y) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>ordered_set;
*/
/////////////////// TYPES & MACROS ///////////////////////////////
#define mp make_pair
#define eb emplace_back
#define pb push_back
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define vv vector
#define exist(s,e) (s.find(e)!=s.end())
using ll=long long int; using dd=double;
using pii=pair<int,int>; using pll=pair<ll,ll>;
typedef vector<int> vi;
const ll INFLL=(ll)2e18, MOD=1'000'000'007;
const int INF=0x3f3fffff ;
/////////////////// DEBUG /////////////////////////////////////////
#define D(x) cerr<<#x<<" is: "<<x<<'\n';
#define DD(x,y) cerr<<"("<<#x<<","<<#y<<") are: "<<x<<" "<<y<<'\n';
/////////////////// VARIABLES & FUNCTIONS//////////////////////////
vector<vector<pll>> adj; vector<int> vis;
int dx8[]={0,1,1,1,0,-1,-1,-1}, dy8[]={1,1,0,-1,-1,-1,0,1},dx4[]={0,1,0,-1}, dy4[]={1,0,-1,0};
inline ll mexp(ll x,ll n,ll m){ll res=1;while(n){if(n&1)res=(res*x)%m;n>>=1;x=((x%m)*(x%m))%m;}return res;}
bool ispow2(ll x){ return x && (!(x&(x-1)));}
ll gcd(ll x, ll y){ pll p{x,y}; while(p.ss) p={p.ss,p.ff%p.ss}; return p.ff;}

/////////////////// MAIN STARTS //////////////////////////////////
int main(){
  ios::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);
  cout<<fixed;cerr<<fixed; cout<<setprecision(10); cerr<<setprecision(3);
  random_device rd; mt19937 genr(rd());

#ifdef DEBUG
  auto tStart = chrono::system_clock::now();
  //freopen("op.txt","w",stdout);
#endif

string s,t; cin>>s>>t;
for(int i=0;i<s.size();++i){
  if(t==s.substr(i,s.size()-i)+s.substr(0,i)){
    cout<<"Yes"<<"\n";
    return 0;
  }
}
cout<<"No"<<"\n";

#ifdef DEBUG
  auto diff=chrono::system_clock::now()-tStart;
	cerr<<"\nExecution time: "<<chrono::duration<dd,milli>(diff).count()<<" ms.\n";
#endif
return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;
import java.lang.*;

public class Main {

	public static void main(String[] args) {
		FastReader in = new FastReader();
		PrintWriter out = new PrintWriter(System.out);
		int MOD = (int)(1e9+7);
		int n = in.nextInt();
		int[] arr = in.readArray(n);
		int[] freq = new int[n];
		freq[n-1] = arr[n-1];
		for(int i=n-2;i>=0;i--) freq[i]=(freq[i+1]+arr[i])%MOD;
		long ans =0;
		for(int i=0;i<n-1;i++) ans=(ans+(long)arr[i]*freq[i+1])%MOD;
		out.println(ans);
		//out.println(Arrays.toString(freq));
		out.close();
	}

	static final Random random=new Random();
	//	static void ruffleSort(Pair[] a) {
	//		int n=a.length;//shuffle, then sort 
	//		for (int i=0; i<n; i++) {
	//			int oi=random.nextInt(n);
	//			Pair temp=a[oi];
	//			a[oi]=a[i]; a[i]=temp;
	//		}
	//		Arrays.sort(a);
	//	}
	static void ruffleSort(int[] a) {
		int n=a.length;//shuffle, then sort 
		for (int i=0; i<n; i++) {
			int oi=random.nextInt(n), temp=a[oi];
			a[oi]=a[i]; a[i]=temp;
		}
		Arrays.sort(a);
	}
	static void ruffleSort(char[] a) {
		int n=a.length;//shuffle, then sort 
		for (int i=0; i<n; i++) {
			int oi=random.nextInt(n);
			char temp=a[oi];
			a[oi]=a[i]; a[i]=temp;
		}
		Arrays.sort(a);
	}
	static class FastReader 
	{ 
		BufferedReader br; 
		StringTokenizer st; 

		public FastReader() 
		{ 
			br = new BufferedReader(new
					InputStreamReader(System.in)); 
		} 

		String next() 
		{ 
			while (st == null || !st.hasMoreElements()) 
			{ 
				try
				{ 
					st = new StringTokenizer(br.readLine()); 
				} 
				catch (IOException  e) 
				{ 
					e.printStackTrace(); 
				} 
			} 
			return st.nextToken(); 
		} 

		int nextInt() 
		{ 
			return Integer.parseInt(next()); 
		} 

		long nextLong() 
		{ 
			return Long.parseLong(next()); 
		} 

		double nextDouble() 
		{ 
			return Double.parseDouble(next()); 
		} 

		String nextLine() 
		{ 
			String str = ""; 
			try
			{ 
				str = br.readLine(); 
			} 
			catch (IOException e) 
			{ 
				e.printStackTrace(); 
			} 
			return str; 
		} 

		int[] readArray(int n) {
			int[] a=new int[n];
			for (int i=0; i<n; i++) a[i]=nextInt();
			return a;
		}
	}
}

//class Pair implements Comparable<Pair>{
//    int a;
//    int b;
//    public Pair(int a, int b) {
//        this.a = a;
//        this.b = b;
//    }
//    public int compareTo(Pair o) {
//        if(this.a==o.a)
//            return this.b - o.b;
//        return this.a - o.a;
//    }   
//}

Measured memory_bytes: 55212
n = int(input())
tlist = [0]
xlist = [0]
ylist = [0]
for i in range(n):
  a = list(map(int,input().split()))
  tlist.append(a[0])
  xlist.append(a[1])
  ylist.append(a[2])

count = 0
for i in range(n):
  dt = tlist[i+1] - tlist[i]
  dis = abs(xlist[i+1]-xlist[i]) + abs(ylist[i+1]-ylist[i])
  if dis > dt:
    print("No")
    exit()
  else:
    if dt%2 == 0 and dis%2==0:
      count +=1
    elif dt%2 == 1 and dis%2==1:
      count +=1
    else:
      print("No")
      exit()
      
      
if count == n:
  print("Yes")

Measured memory_bytes: 11848
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cassert>
#include <functional>
#include <string>
#include <sstream>
#include <cctype>
using namespace std;

int main(){
  int H, W; cin >> H >> W;
  vector<string> C(H);
  for(int i = 0; i < H; i++) cin >> C[i];
  for(int i = 0; i < 2 * H; i++) cout << C[i/2] << endl;
  
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
	int result1;
	int N;
	scanf("%d", &N);
	char S[N];
	scanf("%s", S);
	int ctr = 0;
	if(N%2 != 0){
		printf("No\n");
	}else{
		result1 = N/2 ;
		for(int i = 0 ; i < result1 ; i++){
			if(S[i] == S[result1 + i])
			ctr++;
		}
		if(result1 == ctr){
			printf("Yes\n");
		}else{
			printf("No\n");
		}
	}
	return 0;
}

Measured memory_bytes: 1632
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>

using namespace std;

int main(){
    int card[210],card2[210],n,m,k;
    
    scanf("%d%d",&n,&m);
    
    for(int i=1;i<=2*n;i++)
        card[i]=i;
    
    for(int i=0;i<m;i++){
        scanf("%d",&k);
        
        if(k==0){
            for(int j=1;j<=n;j++){
                card2[j*2-1]=card[j];
                card2[j*2]=card[n+j];
            }
        }else{
            for(int j=k+1;j<=2*n;j++){
                card2[j-k]=card[j];
            }
            for(int j=1;j<=k;j++){
                card2[2*n-k+j]=card[j];
            }
        }
        
        for(int j=1;j<=2*n;j++){
            card[j]=card2[j];
        }
    }
    
    for(int i=1;i<=2*n;i++){
        printf("%d\n",card[i]);
    }
    
    return 0;
}

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

/*
提出前に確認!
- setとmultisetを間違えない
*/

/*
nは偶数
自分以外のxorがわかっているので自分を求めなさい
xorは二回やると0になる
つまりn-1回やったときに残るのは最後の値だけ -> これで最後の値が特定できる
最後の値が特定できれば全体のxorがわかるのであとは、全体とxorしていくだけ
*/

int	main(void)
{
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) cin >> a[i];
	int tmp = 0;
	for (int i = 0; i < n - 1; i++) tmp ^= a[i];
	int all = tmp ^ a[n - 1];
	for (int i = 0; i < n; i++) 
	{
		cout << (all ^ a[i]);
		if (i == n - 1) cout << endl;
		else cout << " ";
	}
	return (0);
}


Measured memory_bytes: 3972
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
template<class T> inline bool chmax(T& a, T b) {if (a<b) {a=b; return true;} return false;}
template<class T> inline bool chmin(T& a, T b) {if (a>b) {a=b; return true;} return false;}

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

int main() {
  ll n; cin >> n;
  vll a(n); REP(i, n) cin >> a[i];
  ll ans=0;
  while (true) {
    ll tmp = n-1, maxi=-1;
    REP(i, n) {
      if (a[i] > tmp) {
        tmp = a[i]; maxi = i;
      }
    }
    if (tmp == n-1) break;
    ll c = a[maxi] / n;
    REP(i, n) {
      if (i == maxi) a[i] -= c*n;
      else a[i] += c;
    }
    ans += c;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
N, K = map(int, input().split())
A = list(map(int, input().split()))
sm = 1
for i in range(K):
    sm += A[i]
before = sm
for i in range(K, N):
    sm -= A[i-K]
    sm += A[i]
    if sm > before:
        print('Yes')
    else:
        print('No')
    before = sm

Measured memory_bytes: 31564
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REP1(i,n) for(int i = 1; i < n+1 ;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()
#define SZ(x) ((int)(x).size())
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
using namespace std;
typedef long long ll;
using p = pair<int, int>;
using P = pair<ll, ll>;
using V = vector<int>;
using VV = vector<vector<int>>;
using VVV = vector<vector<vector<int>>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VVVL = vector<vector<vector<ll>>>;
using Graph = VV;


int main(){
    ios::sync_with_stdio(false); cin.tie(0);
    int a,b,c;
    cin >> a >> b >> c;
    cout << c<<" " << a<< " "<< b << endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

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

        final int n = sc.nextInt();
        long k = sc.nextLong();

        final int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }


        int[] ord = new int[n+1];
        for (int i = 0; i < n+1; i++) {
            ord[i] = -1;
        }

        int v = 1;
        List<Integer> s = new ArrayList<>();
        while (ord[v] == -1) {
            ord[v] = s.size();
            s.add(v);
            v = a[v-1];
        }
        int c = s.size() - ord[v]; // loop size
        int l = ord[v]; // loopが始まる場所

        if (k < l) {
            System.out.println(s.get((int)k));
        } else {
            k -= l;
            k %= c;
            System.out.println(s.get((int)k+l));
        }
    }
}

Measured memory_bytes: 62100
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long ;
int main(){
    ll n,m,k;
    ll ans = -1;
    cin >> n >> m >> k;
    vector<ll> a(n);
    vector<ll> b(m);
    rep(i,n) cin >> a[i];
    rep(i,m) cin >> b[i];
    
    vector<ll> r_a(n+1);
    vector<ll> r_b(m+1);
    r_a[0] == 0;
    r_b[0] == 0;
    
    for(int i=1; i<n+1; i++){
        r_a[i] = r_a[i-1] + a[i-1];
    }
    for(int i=1; i<m+1; i++){
        r_b[i] = r_b[i-1] + b[i-1];
    }

    rep(i,n+1){
        ll time = r_a[i];
        if(time > k) break;
        ll hon = upper_bound(r_b.begin(),r_b.end(),k-time) - r_b.begin()-1;
        ans = max(ans,hon+i);
    }
    cout << ans << endl;

}

Measured memory_bytes: 9568
#define _USE_MATH_DEFINES
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <math.h>
#include <cmath>
#include <set>   

using namespace std;

int main() {
	int w, h, n;
	cin >> w >> h >> n;

	int minX = 0;
	int maxX = w;
	int minY = 0;
	int maxY = h;

	for (int i = 0; i < n; i++)
	{
		int x, y, a;
		cin >> x >> y >> a;

		if (a == 1) {
			minX = max(minX, x);
		}

		if (a == 2) {
			maxX = min(maxX, x);

		}

		if (a == 3) {
			minY = max(minY, y);
		}

		if (a == 4) {
			maxY = min(maxY, y);

		}

	}
	
	
	cout << max(maxX - minX, 0) * max(maxY - minY, 0) << endl;
	
	
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <map>
#include <sstream>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <iterator>
#include <stack>
#include <list>
using namespace std;
#define INF 100000000
typedef long long int lli;
typedef pair<int,int> P;
bool dp[1000001];
bool pn[1000001];

void eratos(bool f[]){
	for(int i=0; i<1000001; ++i){
		f[i]=true;
	}
	pn[0]=false;
	pn[1]=false;
	for(int i=2; i*i<1000001; ++i){
		if(f[i]){
			for(int j=2; i*j<1000001; ++j){
				f[i*j]=false;
			}
		}
	}
}
int main(){
	int n,x;
	eratos(pn);
	while(cin >> n >> x){
		if(n==0&&x==0) break;
		vector<int> cost(n);
		for(int i=0; i<=x; ++i){
			dp[i]=false;
		}
		for(int i=0; i<n; ++i){
			cin >> cost[i];
			dp[cost[i]]=true;
		}
		for(int i=0; i<n; ++i){
			for(int j=0; j<=x; ++j){
				if(dp[j]&&j+cost[i]<=x){
					dp[j+cost[i]]=true;
				}
			}
		}
		bool flag=false;
		int ans;
		for(int i=x; i>=0; --i){
			if(dp[i]&&pn[i]){
				flag=true;
				ans=i;
				break;
			}
		}
		if(flag) {
			cout << ans << "\n";
		} else {
			cout << "NA\n";
		}
	}
	return 0;
}

Measured memory_bytes: 3144
#include "bits/stdc++.h"
using namespace std;

int main()
{
  int a,b,c,count,k;
  count=0;
  cin>>a>>b>>c>>k;
  while(a>=b)
  {
    b*=2;
    count++;
  }
  while(b>=c)
  {
    c*=2;
    count++;
  }
  if(k>=count)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
}

Measured memory_bytes: 3588
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
int n;
cin>>n;
ll a[n];
for(int zz=0;zz<n;zz++)
        cin>>a[zz];
sort(a,a+n);
ll l=a[n-1];
ll r=l;            
ll i=0,j=n-2;
ll sum=0;
while(i<j){
        ll li=abs(l-a[i]),ri=abs(r-a[i]);
        ll lj=abs(l-a[j]),rj=abs(r-a[j]);
        if(li>ri||lj>rj){ //left side
                if(li>lj){
                        sum+=li;
                        l=a[i++];
                }else{
                        sum+=lj;
                        l=a[j--];
                }
        }else{
                if(ri>rj){
                        sum+=ri;
                        r=a[i++];
                }else{
                        sum+=rj;
                        r=a[j--];
                }
        }
}
sum+=max(abs(l-a[i]),abs(r-a[i]));
cout<<sum<<endl;
return 0;
}


Measured memory_bytes: 1024
package main

import (
	"bufio"
	"fmt"
	"os"
	"reflect"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func main() {
	sc.Split(bufio.ScanWords)
	defer out.Flush() // !!!!coution!!!! you must use Fprint(out, ) not Print()
	/* --- code ---*/
	s := []rune(next())
	ans := 0
	idx := 0
	for i := 0; i < len(s); i++ {
		tmp := 0
		for idx < len(s) {
			if string(s[idx]) == "A" || string(s[idx]) == "G" || string(s[idx]) == "C" || string(s[idx]) == "T" {
				tmp += 1
				idx += 1
			} else {
				break
			}
		}
		ans = max(ans, tmp)
		idx = i
	}
	fmt.Fprintln(out, ans)
}

func max(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func nextFloat64() float64 {
	a, _ := strconv.ParseFloat(next(), 64)
	return a
}

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}
func nextFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := 0; i < n; i++ {
		ret[i] = nextFloat64()
	}
	return ret
}
func nextStrings(n int) []string {
	ret := make([]string, n)
	for i := 0; i < n; i++ {
		ret[i] = next()
	}
	return ret
}

func PrintOut(src interface{}, joinner string) {
	switch reflect.TypeOf(src).Kind() {
	case reflect.Slice:
		s := reflect.ValueOf(src)
		for idx := 0; idx < s.Len(); idx++ {
			fmt.Fprintf(out, "%v", s.Index(idx))
			if idx < s.Len()-1 {
				fmt.Fprintf(out, "%s", joinner)
			} else {
				fmt.Fprintln(out)
			}
		}
	default:
		fmt.Fprintln(out, "fuck")
	}
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define repi(i, a, b) for (int i = (a); i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ull << (b))

using namespace std;
using i32 = long long;
using u32 = unsigned long long;
using i64 = long long;
using u64 = unsigned long long;
using f64 = double;
using vi32 = vector<i32>;
using vu32 = vector<u32>;
using vi64 = vector<i64>;
using vu64 = vector<u64>;
using vf64 = vector<f64>;
using vstr = vector<string>;
using vvi32 = vector<vi32>;
using vvu32 = vector<vu32>;
using vvi64 = vector<vi64>;
using vvu64 = vector<vu64>;
using vvf64 = vector<vf64>;

template<typename T, typename S> void amax(T &x, S y) { if (x < y) x = y; }
template<typename T, typename S> void amin(T &x, S y) { if (y < x) x = y; }

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(16);
  int a, b;
  cin >> a >> b;
  if (a < 0 && b < 0) {
    int cnt = abs(a - b) + 1;
    if (cnt % 2 == 0) {
      cout << "Positive" << endl;
    } else {
      cout << "Negative" << endl;
    }
  } else if (a > 0 && b > 0) {
    cout << "Positive" << endl;
  } else {
    cout << "Zero" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include "stdio.h"

int main(void)
{
    int a;
    int choose;
    int i;
    scanf("%d",&a);
    int syurui[a];
    scanf("%d",&choose);

    for(i=0;i<a;i++)
    {
        scanf("%d",&syurui[i]);
    }
    
    int max=0;
    int k=-1;
    int count=0;
    int j;
    int max1;
    int b[a];
    for(i=0;i<a;i++)
    {
        b[i] = syurui[i];
    }
    for(j=0;j<choose;j++){
    for(i=0;i<a;i++)
    {
        if(max<syurui[i])
        {
        max = syurui[i];
        k = i;
        }
    }
    max1 =max;
    syurui[k] = -1;
    max = 0;
    count++;
    }
    float tokuhyou=0;
    for(i=0;i<a;i++)
    {
        tokuhyou = tokuhyou + b[i];
    }
    tokuhyou = tokuhyou/(4*choose);
    if(max1 >= tokuhyou)
    {
        printf("Yes");
    }
    else
    {
        printf("No");
    }
    
}

Measured memory_bytes: 1728
#include<bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main() {
int N;
  int K;
  cin >>N>>K;
  vector<int> vec(N);
  rep(i,N) {
cin >>vec.at(i);
  }
  sort(all(vec));
  int sum=0;
  rep(i,K) {
    sum+=vec.at(N-1-i);
  }
  cout << sum << endl;
}
    
  
  
 

Measured memory_bytes: 256
n = gets.to_i
p = gets.split.map(&:to_i)
psort = p.sort
count = 0

p.zip(0..p.length-1).each do |i,j|
  if i != psort[j]
	count += 1
  end
end

if count <= 2
  puts "YES"
else
  puts "NO"
end

Measured memory_bytes: 1788
n=int(input())
if n < 105:
  print(0)
elif n == 105:
  print(1)
else:
  k = range(106, n+1)
  l = [i for i in k if i%2 != 0]
  ans = [105]
  for m in l:
    l = [i for i in range(1,m//2+1) if m%i == 0]
    if len(l) == 7:
      ans.append(m)

  print(len(ans))

Measured memory_bytes: 38512
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>

int main()
{
    int n;
    std::cin >> n;
    std::vector<int> a(n);
    std::vector<int> ac;
    std::set<int> as;
    for (int i = 0; i < n; i++)
    {
        std::cin >> a[i];
        as.insert(a[i]);
    }

    std::sort(a.begin(), a.end());

    int evennum = 0;
    for (auto itr = as.begin(); itr != as.end(); itr++)
    {
        int num = std::upper_bound(a.begin(), a.end(), *itr) - std::lower_bound(a.begin(), a.end(), *itr);

        if (num % 2 == 0)
        {
            evennum++;
        }
    }

    int ans = evennum % 2 ? as.size() - 1 : as.size();

    std::cout << ans << std::endl;
}


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

int main() {
    string s ;
    cin >> s ;
    bool is = false ;
    rep(i, 3){
        if(s[i] == s[i + 1]){
            is = true ;
            break ;
        }
    }
    if(is){
        cout << "Bad" << endl ;
    }
    else {
        cout << "Good" << endl ;
    }
}

Measured memory_bytes: 3576
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1001010;
int p[MAXN], a[MAXN], n;
int dp[MAXN];
int main(){
    scanf("%d", &n);
    for(int i = 1; i <= n; i ++){
        scanf("%d", &a[i]);
        dp[i] = 1; p[a[i]] = i;
    }
    for(int i = 2; i <= n; i ++){
        if(p[i] > p[i-1])
            dp[i] = dp[i-1] + 1;
    }
    
    int ans = MAXN;
    for(int i = 1; i <= n; i ++){
        ans = min(ans, n - dp[i]);
    }
    printf("%d", ans);
}

Measured memory_bytes: 9216
n = int(input())
s = input()
s += s[0]
pat = ["WW","WS","SW","SS"]

for j in pat:
    now = j
    flag = True
    for i in range(1,n+1):
        if (now[i] == "S" and s[i] == "o") or (now[i] == "W" and s[i] == "x"):
            now += now[i-1]
        else:
            if now[i-1] == "S":
                now += "W"
            else:
                now += "S"
    if now[0] == now[-2] and now[1] == now[-1]:
        print(now[:-2])
        exit()

print(-1)

Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define vll vector<ll>
#define vvll vector<vll>
#define mll map<ll,ll>
#define f(i,m,n) for(i=m;i<n;i++)
#define ee endl
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define take(v,n) for(i=0;i<n;i++) cin>>v[i];
#define NO() cout<<"NO"<<endl
#define YES() cout<<"YES"<<endl
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define sot(v) sort(v.begin(),v.end());
bool isPrime(int n) 
{ 
    // Corner cases 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
  
    // This is checked so that we can skip  
    // middle five numbers in below loop 
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (int i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
}

ll powe(ll x, ll y){
    ll res = 1;
    while (y > 0){
        if (y & 1) res = res*x;
        y = y>>1;
        x = x*x;
    }
    return res;
}
vvll dp(100001,vll(3,-1));
ll sol(vvll &v,ll &n,ll i,ll j)
{
    if(i==n-1)
    {
        return v[i][j];
    }
    ll a1=-1,a2,a3;
    if(dp[i][j]!=-1) return dp[i][j];
    for(ll k=0;k<=2;k++)
    {
        if(k==j) continue;
        a1=max(a1,sol(v,n,i+1,k));
    }
    dp[i][j]=a1+v[i][j];
    return dp[i][j];
}

void solve()
{
    ll i,j,k=0,n,l;
    cin>>n;
    vvll v(n,vll(3));
    for(i=0;i<n;i++)
    {
        for(j=0;j<=2;j++)
        {
            cin>>v[i][j];
        }
    }
    k=sol(v,n,0,0);
    //cout<<k<<ee;
    k=max(k,sol(v,n,0,1));
    //cout<<k<<ee;
    k=max(k,sol(v,n,0,2));
    cout<<k<<ee;


}

int main() {
    fast;
    ll i,j,l,k,t,n;
    t=1;
    while(t--)
    solve();
}


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

int main() {
  int N;
  cin >> N;
  
  int l, r;
  int A = 0;
  for (int i = 0; i < N; i++) {
    cin >> l >> r;
    A += r - l + 1;
    if(i + 1 == N)
      cout << A << endl;
  }

}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Scanner;

public class Main {
	private Scanner sc;

	int nico;
	
	int[][] map;
	
	int[][][] pat = {
			{{0, -1, 0, 1, 0},
			{0, 1, 1, 1, 2}},
			{{0, 1, 2, 0, 1, 2, 0, 1, 2},
			{0, 0, 0, 1, 1, 1, 2, 2, 2}},
			{{0, -1, 0, 1, -2, -1, 0, 1, 2, -1, 0, 1, 0},
			{0, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 4}}
	};
	
	
	LinkedList<String> ans;
	
	public static void main(String[] args) {
		new Main();
	}
	
	public Main() {
		sc = new Scanner(System.in);

		nico = Integer.parseInt(sc.nextLine());
		
		map = new int[10][10];
		for (int i = 0; i < map.length; i++) {
			String[] data = sc.nextLine().split(" ");
			
			for (int j = 0; j < map.length; j++) {
				map[j][i] = Integer.parseInt(data[j]);
			}
		}
		
		ans = new LinkedList<String>();
		for (int i = 0; i < pat.length; i++) {
			check(0, 0, i);
		}
		
		while (ans.isEmpty() == false) {
			System.out.println(ans.pop());
		}
	}
	
	private boolean check(int x, int y, int p) {
		while (map[x][y] == 0) {
			x++;
			if (x == map.length) {
				x = 0;
				y++;
			}
			if (y == map.length) {
				boolean flag = true;
				for (int i = 0; i < map.length; i++) {
					for (int j = 0; j < map.length; j++) {
						if (map[i][j] != 0) {
							flag = false;
							break;
						}
					}
					if (flag == false) break;
				}
				if (ans.size() != nico) flag = false;
				
				return flag;
			}
		}
		
		for (int i = 0; i < pat[p][0].length; i++) {
			int nx = x + pat[p][0][i];
			int ny = y + pat[p][1][i];
			
			if ((nx < 0) || (nx >= map.length) || (ny < 0) || (ny >= map.length)) return false;
			if (map[nx][ny] == 0) return false;
		}
		
		String r = "";
		switch (p) {
		case 0:
			r = r + x + " " + (y + 1) + " " + 1;
			break;
		case 1:
			r = r + (x + 1) + " " + (y + 1) + " " + 2;
			break;
		case 2:
			r = r + x + " " + (y + 2) + " " + 3;
			break;
		}
		ans.push(r);
		
		for (int i = 0; i < pat[p][0].length; i++) {
			map[x + pat[p][0][i]][y + pat[p][1][i]]--;
		}
		
		boolean end = false;
		for (int i = 0; i < pat.length; i++) {
			end = end | check(x, y, i);
		}
		
		if (end == false) {
			for (int i = 0; i < pat[p][0].length; i++) {
				map[x + pat[p][0][i]][y + pat[p][1][i]]++;
			}
			ans.pop();
		}
		
		return end;
	}
}

Measured memory_bytes: 32236
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bits/stdc++.h>
#include<cmath>
#include<bitset>
#include<queue>
#define ll long long
#define itn int
#define co(ans) cout<<ans<<endl;
#define COYE cout<<"YES"<<endl;
#define COYe cout<<"Yes"<<endl;
#define COye cout<<"yes"<<endl;
#define CONO cout<<"NO"<<endl;
#define CONo cout<<"No"<<endl;
#define COno cout<<"no"<<endl;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define INF ((1LL<<62)-(1LL<<31))
#define MOD 1000000007
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; }
using namespace std;


int main(){
  ll N,ans=1,mx=0,mn=INF;
  cin>>N;
  
  vector<pair<ll,ll>> L;
  vector<pair<ll,ll>> P;
  
  REP(i,N){
    ll a,b;
    cin>>a>>b;
    L.push_back(make_pair(a,b));
    P.push_back(make_pair(b,a));
    ans=max(b-a+1,ans);
    mx=max(b-a+1,mx);
    mn=min(b-a+1,mn);
  }
  
  SORT(L);
  
  
  ll A[N+10],B[N+10],C[N+10],D[N+10];
  A[0]=0,B[0]=INF,C[N]=0,D[N]=INF;
  
  for(ll i=1; i<N; ++i){
    A[i]=max(A[i-1],L[i-1].first);
    B[i]=min(B[i-1],L[i-1].second);
  }
  
  for(ll i=N-1; i>0; --i){
    C[i]=max(C[i+1],L[i].first);
    D[i]=min(D[i+1],L[i].second);
  }
  
  
  for(ll i=1; i<N; ++i){
    ans=max(ans,max(B[i]-A[i]+1,0ll)+max(D[i]-C[i]+1,0ll));
  }
  
  
  
  
  
  
  
  
  
  
  
  SORT(P);
  
  
  ll AA[N+10],BB[N+10],CC[N+10],DD[N+10];
  AA[0]=0,BB[0]=INF,CC[N]=0,DD[N]=INF;
  
  for(ll i=1; i<N; ++i){
    AA[i]=max(AA[i-1],P[i-1].second);
    BB[i]=min(BB[i-1],P[i-1].first);
  }
  
  for(ll i=N-1; i>0; --i){
    CC[i]=max(CC[i+1],P[i].second);
    DD[i]=min(DD[i+1],P[i].first);
  }
  
  
  for(ll i=1; i<N; ++i){
    ans=max(ans,max(BB[i]-AA[i]+1,0ll)+max(DD[i]-CC[i]+1,0ll));
  }
  
  
  
  
  for(int i=2; i<=N-1; ++i){
    ll T=L[i-1].second-L[i-1].first+1;
    
    T+=max(min(B[i-1],D[i])-max(A[i-1],C[i])+1,0ll);
    
    ans=max(ans,T);
  }
  
  
  
  
  
  
  
  
  
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 9828
// バブルソート
#include<iostream>
#include<algorithm>
using namespace std;

static const int MAX_N = 100;

void bubbleSort(int A[], int n);

int main(void)
{
    int N;
    int ary_sequence[MAX_N];

    cin >> N;

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

    bubbleSort(&ary_sequence[0], N);

    return 0;
}

// バブルソートを実施する関数
void bubbleSort(int A[], int n)
{
    int count = 0, tmp;
    int flag = 1;

    while( flag )
    {
        flag = 0;

        for(int i = n - 1; i > 0; i--)
        {
            if( A[i - 1] > A[i] )
            {
                // 値の入れ替え
                tmp = A[i];
                A[i] = A[i - 1];
                A[i - 1] = tmp;

                flag = 1;

                // 交換回数の保存
                count++;
            }
        }
    }

    // 結果表示用
    for(int i = 0; i < n - 1; i++)
    {
        cout << A[i] << ' ';
    }

    cout << A[n - 1] << endl;
    cout << count << endl;

    return;
}



Measured memory_bytes: 3096
#include <iostream>
#include <map>

using namespace std;

void AssignWherePossible(int &a, int &b, int value)
{
    if (a == 0) {
        a = value;
    } else if (b == 0) {
        b = value;
    }
}

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

    map<int, int> count;
    for (auto i = 0; i < n; i += 1) {
        int length;
        cin >> length;
        count[length] += 1;
    }

    auto side1 = 0;
    auto side2 = 0;

    for (auto it = count.rbegin(); it != count.rend(); it++) {
        if (it->second > 1) {
            AssignWherePossible(side1, side2, it->first);
        }
        if (it->second > 3) {
            AssignWherePossible(side1, side2, it->first);
        }
        if (side2 != 0) {
            break;
        }
    }

    cout << 1LL * side1 * side2 << "\n";
    return 0;
}


Measured memory_bytes: 4992
#include <stdio.h>
int main(void){
    int H,W,h,w;
    while(1){
  
        scanf("%d %d", &H, &W);
        if(H==0&&W==0){
            break;
        }
        for(h = 0; h < H; h++){
            for(w = 0; w < W; w++){
                printf("#");
        }printf("\n");
    }printf("\n");
    
    }
    return 0;
}


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

int main(){
    ll n;
    cin >> n;
    if(n%1000==0){
        cout << 0 << endl;
    }else{
        cout << 1000-n%1000 << endl;
    }
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#include <map>
#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()
typedef long long ll;


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


int main() {
    ll n, a, b;
    cin >> n >> a >> b;
    ll x = n /(a + b);
    ll ans = 0;
    ans = x * a + min(n - (a + b) * x, a);
    cout << ans << endl;
}


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

using namespace std;

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> l(N);
  for (int i = 0; i < N; i++) {
    cin >> l[i];
  }
  sort(l.begin(), l.end(), greater<int>());

  int ans = 0;
  for (int i = 0; i < K; i++) {
    ans += l[i];
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
//Sani buyuk Osman Pasa Plevneden cikmam diyor.
//FatihSultanMehmedHan
//Bismillahirrahmanirrahim
#include <bits/stdc++.h>

using namespace std;

typedef long long int lo;
typedef pair< int,int > PII;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=1;i<=n;i++)
#define mid (bas+son)/2

const lo MAX = -1000000000000000000; 
const lo MIN = 1000000000000000000; 
const lo inf = 1000000000; 
const lo KOK = 100000; 
const lo LOG = 30; 
const lo li = 100005; 
const lo mod = 1000000007; 

int n,m,cev,b,a[li],k;
string s;
vector<int> v;

int main(){
	char c;
	cin>>c;
	if(c=='C'){cout<<"G";return 0;}
	if(c=='G'){cout<<"C";return 0;}
	if(c=='A'){cout<<"T";return 0;}
	if(c=='T'){cout<<"A";return 0;}
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int LL;
//Compiler version g++ 6.3.0

int main()
{
  string a, b;
  cin>>a>>b; 
  LL ans=0;
  for(LL i=0;i<a.size();i++){
    if(a[i]!=b[i]){
      ans++;
    }
  }
  cout<<ans<<endl; 
  return 0;
 }
       


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

#define ll                                 long long
#define mp                                 make_pair
#define pb                                 push_back
#define pii                              pair<long long,long long>
#define vi                                 vector<long long>
#define setbits(x)                          __builtin_popcountll(x)
#define zrobits(x)                          __builtin_ctzll(x)
#define mod                              1000000007
#define inf                               1e18
#define make_array(array_name,array_size,type)   type array_name[array_size];
#define print_array(array_name,array_size)        for(int i=0;i<n;i++){cout<<array_name[i]<<" ";}cout<<endl;
#define input_array(array_name,array_size)       for(int i=0;i<n;i++){cin>>array_name[i];}

long long binexpo(long long a, long long b)
{
   long long res = 1;
   while (b > 0)
   {
      if (b & 1)
         res = res * a;
      a = a * a;
      b >>= 1;
   }
   return res;
}

void initialize()
{
   ios_base::sync_with_stdio(false);
   cin.tie(nullptr);
   cout.tie(nullptr);
#ifndef ONLINE_JUDGE
   freopen("input.txt", "r", stdin);
   freopen("output.txt", "w", stdout);
#endif
}
int main()
{
   initialize();

   ll x;
   cin >> x;
   for (int i = 1; i <= 50000; i++)
   {
      if ((int)(i * 1.08) == x)
      {
         cout << i << endl;
         return 0;
      }
   }
   cout << ":(" << endl;
   return 0;
}

Measured memory_bytes: 3652
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<queue>
#define N 2010
using namespace std;
int nxt[N<<5],to[N<<5],head[N],cnt;
void add(int u,int v)
{
	nxt[++cnt]=head[u];
	to[cnt]=v;
	head[u]=cnt;
}
int in[N];
bool vis[N];
int num[N],n;
void dfs(int u)
{
	vis[u]=true;
	for(int i=1;i<=n;i++)
	if(!vis[i] && __gcd(num[u],num[i])!=1)
	{
		add(u,i);
		in[i]++;
		dfs(i);
	}
}
priority_queue<int>q;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&num[i]);
	sort(num+1,num+n+1);
	for(int i=1;i<=n;i++)
	if(!vis[i])dfs(i);
	for(int i=1;i<=n;i++)
	if(!in[i]) q.push(i);
	while(!q.empty())
	{
		int u=q.top();
		printf("%d ",num[u]);
		q.pop();
		for(int i=head[u];i;i=nxt[i])
		q.push(to[i]);
	}
	
	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){

	int w,q;
	while(cin >> w >> q && !(w == 0 && q == 0)){
		char kind;
		int id,wide;

		int place[100];
		fill(place,place+100,-1);
		for(int i = 0; i < q; i++){
			cin >> kind;
			if(kind == 's'){
				cin >> id >> wide;
				bool isSpleepable=false;
				for(int j = 0; j+wide-1 < w; j++){
					bool f=false;
					for(int k = 0; k < wide; k++){
						if(place[j+k]!=-1){
							f=true;
							break;
						}
					}
					if(f){
						continue;
					}
					else{
						isSpleepable=true;
						// ツ配ツ療アツづーツ青カツづ淞づゥ
						for(int k = 0; k < wide; k++){
							place[j+k]=id;
						}
						cout << j << endl;
						break;
					}
				}
				if(!isSpleepable){
					cout << "impossible" << endl;
				}
			}
			else{
				cin >> id;
				for(int j = 0; ;j++){
					if(place[j]==id){
						while(place[j]==id){
							place[j]=-1;
							j++;
						}
						break;
					}
				}
			}
		}
		cout << "END" << endl;
	}
	

	return 0;
}

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

using namespace std;

int main() {
    int N;
    int a[120];
    cin >> N;
    for(int i = 0; i < N; ++i) cin >> a[i];

    sort(a, a+N, greater<int>()); //a[0:N] を大きい順にソート
    int Alice = 0;
    int Bob = 0;

    for(int i = 0; i < N; ++i) {
        if(i % 2 == 0) { //Aliceのターン
            Alice += a[i];
        } else { //Bobのターン
            Bob += a[i];
        }
    }

    cout << Alice - Bob << endl;

    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <iomanip>
using namespace std;
#define MOD int(1e9 + 7)

int main()
{
    long long N, C;
    vector<vector<long long>> D;
    vector<vector<long long>> A;

    cin >> N >> C;
    for (long long i = 0; i < C; i++)
    {
        vector<long long> t1;
        for (long long j = 0; j < C; j++)
        {
            long long t2;
            cin >> t2;
            t1.push_back(t2);
        }
        D.push_back(t1);
    }
    for (long long i = 0; i < N; i++)
    {
        vector<long long> t1;
        for (long long j = 0; j < N; j++)
        {
            long long t2;
            cin >> t2;
            t1.push_back(t2 - 1);
        }
        A.push_back(t1);
    }

    vector<vector<long long>> t(3, vector<long long>(C, 0));
    for (long long i = 0; i < C; i++)
        for (long long j = 0; j < N; j++)
            for (long long k = 0; k < N; k++)
                t[(j + k + 2) % 3][i] += D[A[j][k]][i];

    long long mv = MOD;
    for (long long i = 0; i < C; i++)
        for (long long j = 0; j < C; j++)
            for (long long k = 0; k < C; k++)
                if (i != j && j != k && i != k)
                    mv = min(mv, t[0][i] + t[1][j] + t[2][k]);

    cout << mv << endl;
}

Measured memory_bytes: 2304
<?php

// your code goes here

        $setnum = trim(fgets(STDIN));
        for($i=0;$i<$setnum;$i++){
                $blknum = trim(fgets(STDIN));	
        	    $blks = explode(" ",trim(fgets(STDIN)));
        	    $max = 0; $min = 0;
        	    for($j=1;$j<$blknum;$j++){
        	       $df = $blks[$j] - $blks[$j-1];
                   if ($max < $df) $max = $df;
                   if ($df < $min) $min = $df;
        	
                }
                echo($max . " " . -$min . "\n");
        }

Measured memory_bytes: 15424
#include <bits/stdc++.h>
using namespace std;
int main() {
    string s;
    cin >> s;
    int count = 0;
    for(int i = 0;i < s.size()/2;i++) {
        if(s.at(i) != s.at(s.size()-i-1)) count++;
    }
    cout << count << endl;
}

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

string to_bit(char n) {
    string s;
    for(int i = 0; i < 7; i++) {
        s.push_back((n & (1 << i)) ? '1' : '0');
    }
    return s;
}

int main() {
    for(int N; cin >> N, N != -1; ) {
        char state = 0;
        char numbers[] = {
            0b01111110,
            0b00110000,
            0b01101101,
            0b01111001,
            0b00110011,
            0b01011011,
            0b01011111,
            0b01110010,
            0b01111111,
            0b01111011
        };
        while(N--) {
            int T; cin >> T;
            string ans = "NA";
            for(char i = 0; i < (1 << 7); i++) {
                if((state ^ i) == numbers[T]) {
                    ans = to_bit(i);
                    state ^= i;
                    break;
                }
            }
            cout << ans << endl;
        }

    }
}

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

using namespace std;
int bfs(vector<vector<int>> graph, int start, int end) {
    int sizeE = graph.size();
    queue<int> q;

    q.push(start);
    vector<int> dist(sizeE, -1);
    dist[start] = 0;
    while (!q.empty()) {
        int u = q.front(); q.pop();
        for (int v : graph[u]) {
            if (dist[v] == -1) {
                dist[v] = dist[u] + 1;
                q.push(v);
            }
        }
    }
    return dist[end];
}
int main() {
    int n, m;

    cin >> n >> m;

    vector<vector<int>> g(n * 3);

    for (int i = 0; i < m; i++) {
        int u, v;
        cin >> u >> v;

        for (int j = 0; j < 3; j++) {
            g[(u-1)*3+j].push_back((v-1)*3+(j+1)%3);
        }
    }
    
    int  s, t; cin >> s >> t;
    
    int ans = bfs(g, (s-1)*3, (t-1)*3);
    if (ans == -1) {
        cout << -1 << "\n";
    } else {
        cout << ans / 3 << "\n";    
    }

}

Measured memory_bytes: 34176
H, W = map(int, input().split())
 
if H == 1 or W == 1:
    print(1)
else:
    if H % 2 == 0:
        e_h = H // 2
        o_h = H // 2
    else:
        e_h = H // 2 + 1
        o_h = H // 2
    if W % 2 == 0:
        print(e_h * (W // 2) + o_h * (W // 2))
    else:
        print(e_h * (W // 2 + 1) + o_h * (W // 2))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main(void) {
    int n,a;
    std::deque<int>deq ;
    cin >> n;
    for (int i=0;i<n;i++) {
        cin >> a;
        deq.emplace_back(a);
    }
    if (prev_permutation(deq.begin(),deq.end())!=false) {
        for (int j=0;j<deq.size();j++) {
            if (j==deq.size()-1) {
                cout << deq[j] << endl;
            } else {
                cout << deq[j] << " ";
            }
        }
        if (next_permutation(deq.begin(),deq.end())!=false) {
            for (int k=0;k<deq.size();k++) {
                if (k==deq.size()-1) {
                    cout << deq[k] << endl;
                } else {
                    cout << deq[k] << " ";
                }
            }
        }
        if (next_permutation(deq.begin(),deq.end())!=false) {
             for (int l=0;l<deq.size();l++) {
                if (l==deq.size()-1) {
                    cout << deq[l] << endl;
                } else {
                    cout << deq[l] << " ";
                }
             }
        }
    } else {
        next_permutation(deq.begin(),deq.end());
        for (int m=0;m<deq.size();m++) {
            if (m==deq.size()-1) {
                cout << deq[m] << endl;
            } else {
                cout << deq[m] << " ";
            }
        }
        if (next_permutation(deq.begin(),deq.end())!=false) {
             for (int n=0;n<deq.size();n++) {
                if (n==deq.size()-1) {
                    cout << deq[n] << endl;
                } else {
                    cout << deq[n] << " ";
                }
             }
        }
    }
}



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

int main(){
int A,B,C,X; cin >> A >> B >> C >>X;
int count = 0;
for(int a = 0; a <= A; a++){
  for(int b = 0; b <= B; b++){
    for(int c = 0; c <= C; c++){
      if(500*a + 100*b + 50*c == X){
        count++;
      } 
    }

  }
}
cout << count << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<vector>
#include<algorithm>
#include<cstring>

using namespace std;

using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
using vll=vector<ll>;
using vvll=vector<vll>;


void max_u(int&m, int v)
{
	if(m<v) m=v;
}

void dump(vi&a)
{
	for(int ma:a) printf("%d ", ma);
	printf("\n");
}

int main(void)
{
	char as[500000+4];
	char *s=as+1;

	as[0]='\0';
	while(scanf("%500000[<>]\n", s)==1)
	{
		int l=strlen(s);
		vi a(l+2, -1);
		vi p;

		s[l]='<';
		s[l+1]='\0';
		for(int i=0;i<=l;i++)
		{
			if(s[i]=='<' && s[i]!=s[i-1])
			{
				a[i]=0;
				p.push_back(i);
			}
		}

		for(int mp:p)
		{
			for(int i=mp-1;s[i]=='>';i--)
			{
				max_u(a[i], a[i+1]+1);
			}
//			dump(a);
			for(int i=mp+1;s[i-1]=='<';i++)
			{
				max_u(a[i], a[i-1]+1);
			}
//			dump(a);
		}
		a[l+1]=0;

		ll ans=0;
		for(int ma:a)
		{
			ans+=ma;
		}
		printf("%lld\n", ans);
	}
	return 0;
}


Measured memory_bytes: 3324
using System;
using System.Collections.Generic;
using System.Text;

public class ABC0124_A3v2 {
    private static void Main(string[] args) {
        string input = Console.ReadLine().Trim();
        ConvertInput(input);
    }

    private static void ConvertInput(string input) {
        var satisfyLists = GetSatisfyLists(input.Length);

        Solve(input, satisfyLists);
    }

    private static void Solve(string input, List<string> satisfyLists) {
        var countA = CountDifferentPairs(input, satisfyLists[0]);
        var countB = CountDifferentPairs(input, satisfyLists[1]);
        OutputAnswer(Math.Min(countA, countB).ToString());
    }

    private static void OutputAnswer(string text) => Console.WriteLine(text);

    private static List<string> GetSatisfyLists(int size) {
        var sb1 = new StringBuilder();
        var sb2 = new StringBuilder();

        for (int index = 0; index < size; index++) {
            if (index % 2 == 0) {
                sb1.Append("1");
                sb2.Append("0");

            } else {
                sb1.Append("0");
                sb2.Append("1");
            }
        }

        var satisfyLists = new List<string>() {
            sb1.ToString(),
            sb2.ToString(),
        };

        return satisfyLists;
    }

    private static int CountDifferentPairs(string a, string b) {
        var count = 0;

        for (var index = 0; index < a.Length; index++) {
            if (a[index] == b[index])
                count++;
        }

        return count;
    }
}

Measured memory_bytes: 14176
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>
#include <bitset>
#include <cmath>
#include <stack>
#include <iomanip>
#include <map>
#include <math.h>
typedef long long ll;
using namespace std;
const int MOD = 1000000007;

ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }



int main()
{
    int N,K;
    cin >> N >> K;
    int A[N];
    for(int i = 0; i < N; i++) cin >> A[i];
    int res = 1;
    int sum = K;
    while(sum < N)
    {
        res++;
        sum += (K -1);
    }
    cout << res << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
ifstream f("1.in");
ofstream g("1.out");
typedef long long ll;
typedef pair<int,int> pi;
int t,T;

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

    string S,T;
    cin>>S>>T;
    int n=S.size()-1,m=T.size()-1,ans=1e9;
    for(int i=m;i<=n;i++)
    {
        int cnt=0;
        for(int j=i;j>=i-m;j--)
        if(S[j]!=T[m-(i-j)]) cnt++;
        ans=min(ans,cnt);
    }
    cout<<ans;

    return 0;
}


Measured memory_bytes: 3660