akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <utility>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <unordered_map>
#include <limits.h>
#include <bitset>
#include <math.h>
#define int long long
using namespace std;
using P = pair<int, int>;
using ll = long long;
using prique = priority_queue<int>;
const int MOD = 1000000007;
const int INF = LLONG_MAX/3;
const int MAX = 510000;

/*-----Library-----*/

struct UnionFind {
    vector<int> par; // 親ノード
    vector<int> rank; // ランク
    vector<int> sizeuf; //要素数
    UnionFind(int n = 1) {
        init(n);
    }

    void init(int n = 1) {
        par.resize(n); rank.resize(n); sizeuf.resize(n);
        for (int i = 0; i < n; ++i) {
            par[i] = i;
            rank[i] = 0;
            sizeuf[i]=1;
        }
    }

    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            return par[x] = r;
        }
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        sizeuf[x]+=sizeuf[y];
        return true;
    }

    int size(int x){
        return sizeuf[root(x)];
    }
};

long long gcd(long long a,long long b){
    if(b==0)return a;
    return gcd(b,a%b);
}

long long lcm(long long i,long long j){
    return i*(j/gcd(i,j));
}

long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

/*-----Library-----*/
signed main(){
    int n;
    string s;
    cin>>n>>s;
    int t=0;
    int a=0;
    for(int i=0;i<n;i++){
        if(s[i]=='(')t++;
        else if(s[i]==')'&&t==0){
            a++;
        }else{
            t--;
        }
    }
    for(int i=0;i<a;i++)cout<<'(';
    cout<<s;
    for(int i=0;i<t;i++)cout<<')';
    cout<<endl;
}


Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h,w;
    cin >> h >> w;
    vvint c(10,vint(10,INF));
    REP(i,10){
        REP(j,10){
            cin >> c[i][j];
        }
    }
    for(int k=0;k<10;k++){
        for(int i=0;i<10;i++){
            for(int j=0;j<10;j++){
                c[i][j] = min(c[i][j], c[i][k]+c[k][j]);
            }
        }
    }
    int ans=0;
    REP(i,h){
        REP(j,w){
            int a;
            cin >> a;
            if(a>=0){
                ans+=c[a][1];
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
def main():
    n, m = map(int, input().split())
    h = list(map(int, input().split()))
    route = [[] for _ in range(n)]
    for _ in range(m):
        a, b = map(lambda x: int(x) - 1, input().split())
        route[a].append(b)
        route[b].append(a)
    answer = 0
    for i in range(n):
        if all(h[i] > h[j] for j in route[i]):
            answer += 1
    print(answer)


if __name__ == '__main__':
    main()



Measured memory_bytes: 29372
#include "bits/stdc++.h"
#define MAXN 100009
#define INF 1000000007
#define mp(x,y) make_pair(x,y)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
#define wr cout<<"----------------"<<endl;
#define ppb() pop_back()
#define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++)
#define ff first
#define ss second
#define my_little_dodge 46
#define debug(x)  cerr<< #x <<" = "<< x<<endl;
using namespace std;

typedef long long ll;
typedef pair<int,int> PII;
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
ll arr[88];
int main(){
    //~ freopen("file.in", "r", stdin);
	arr[0]=2;
	arr[1]=1;
	for(int i=2;i<=86;i++)
		arr[i]=arr[i-1]+arr[i-2];
	int n;
	scanf("%d",&n);
	printf("%lld\n",arr[n]);	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
static const int INF (1<<30);

int main() {
  int N; cin >> N;
  vector<ll> A(N+1);
  vector<ll> B(N);

  rep(i, N+1) cin >> A[i];
  rep(i, N) cin >> B[i];

  ll ans = 0LL;
  ll rem = 0LL;

  rep(i, N) {
    if (A[i] <= rem) {
      ans += A[i];
      rem = B[i];
    } else {
      ans += min(A[i], B[i]+rem);
      rem = max(0LL, -A[i]+(B[i]+rem));
    }
  }

  ans += min(A[N], rem);

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1792
<?php
//Request Question
function getq($get_word=null){
	if($get_word===null){
		return str_replace("\n","",fgets(STDIN));
	}else if($get_word===1){
		return explode(" ",str_replace("\n","",fgets(STDIN)));
	}
}

/*		START		*/
$temp = getq();
$ans=700;
if($temp[0]=="o")$ans+=100;
if($temp[1]=="o")$ans+=100;
if($temp[2]=="o")$ans+=100;
echo "$ans\n"
?>

Measured memory_bytes: 4856
#include <iostream>
#include <algorithm>
#include <cmath>
#define INF 100000000
using namespace std;
typedef long long ll;
ll n, m, a[1000], b[1000], c[1000], dst[101][101];

void warshall_floid(){
	for(ll k = 1; k <= n; k++)
		for(ll i = 1; i <= n; i++)
			for(ll j = 1; j <= n; j++)
				dst[i][j] = min(dst[i][k]+dst[k][j], dst[i][j]);
}

int main() {
	cin >> n >> m;
	for(ll i = 1; i <= n; i++){for(ll j = 1; j <= n; j++){dst[i][j] = INF;} dst[i][i] = 0;}
	for(ll i = 0; i < m; i++){
		cin >> a[i] >> b[i] >> c[i];
		dst[a[i]][b[i]] = c[i];
		dst[b[i]][a[i]] = c[i];
	}
	
	warshall_floid();
	
	ll ans = m;
	for(ll e = 0; e < m; e++){
		for(ll i = 1; i <= n; i++){
			if(dst[i][b[e]] == dst[i][a[e]] + c[e]){
				ans--;
				break;
			}
		}
	}
	
	cout << ans;
	return 0;
}

Measured memory_bytes: 384
a, b, c, x, y = map(int, input().split())
s_ab = a + b
s_c = 2 * c


if s_c < s_ab:
    if x < y:
        price1 = s_c * x + b * (y-x)
        price2 = s_c * y
        print(min(price1, price2))
    elif x > y:
        price1 = s_c * x
        price2 = s_c * y + a * (x-y)
        print(min(price1, price2))
    else:
        print(s_c * x)
elif s_c >= s_ab:
    print(a * x + b * y)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define  INF 1ll<<60
signed main(){
  string a,b;
  cin>>a>>b;
  int soma=0;
  for(int i=0;i<3;i++){
  	if(a[i]==b[i])
  		soma++;
  }
  cout<<soma<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<29;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-11;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};


int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	while(1){
		int n,m;
		cin>>n;
		map<string,int> mp;
		vvi a(100005);
		int id=0;
		for(int i=0;i<n;i++){
			string s;
			int x;
			cin>>s>>x;
			if(mp.find(s)==mp.end()){
				mp[s]=id;
				id++;
			}
			a[mp[s]].push_back(x);
		}
		for(int i=0;i<100005;i++) sort(a[i].rbegin(),a[i].rend());
		cin>>m;
		bool B=1;
		int now=0;
		for(int i=0;i<m;i++){
			string s;
			cin>>s;
			if(mp.find(s)==mp.end()) B=0;
			else{
			id=mp[s];
			while(!a[id].empty()&&a[id].back()<=now) a[id].pop_back();
			if(a[id].empty()) B=0;
			else{
				int x=a[id].back();
				a[id].pop_back();
				if(now>=x) B=0;
				now=x;
			}
			}
		}
		cout<<(B?"Yes":"No")<<endl;
		break;
	}
}


Measured memory_bytes: 20836
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
   string s,t;
   cin>>s;
   cin>>t;
   int cnt=0,i;
   for(i=0;i<s.size();i++)
   {
       if(s[i]==t[i])cnt++;
   }
   cout<<cnt<<endl;

}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        sc.close();
        int rank;
        if (x < 600) {
            rank = 8;
        } else if (x < 800) {
            rank = 7;
        } else if (x < 1000) {
            rank = 6;
        } else if (x < 1200) {
            rank = 5;
        } else if (x < 1400) {
            rank = 4;
        } else if (x < 1600) {
            rank = 3;
        } else if (x < 1800) {
            rank = 2;
        } else {
            rank = 1;
        }
        System.out.println(rank);
    }
}


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

using ll=long long;
const int inf=100000000;

int in(){
  int a;
  cin >> a;
  return a;
}//int型関数の受け取り

void forin(int* x,int y){
  for (int i=0;i<y;i++){
    cin >> x[i];
  }
}//(x,y) int型配列x[y]の受け取り

int intpow(int x,int y){
  double a=x,b=y;
  return pow(a,b);
}//(x,y) xをy乗

int intfabs(int x){
  double a=x;
  return fabs(a);
}//(x) xの絶対値

int fact(int x){
  if (x == 1) return 1;
  return x*fact(x-1);
}//(x) x!

int fib(int x){
  if (x <= 2) return x;
  int a[x];
  a[0]=1;
  a[1]=2;
  for (int i=2;i<x;i++){
    a[i]=a[i-1]+a[i-2];
  }
  return a[x-1];
}//(x) フィボナッチ数列のx番目

int div1(ll x){
  return x%1000000007;
}

main(){
    int n=in(),x=in(),l[n],m=0,i;
    forin(l,n);
    for (i=0;i<n;i++){
        m+=l[i];
        if (m>x) break;
    }
    cout << i+1 << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include <cstdio>
#include <cmath> 
#define INF 0x3f3f3f3f
#define LL long long
using namespace std;
 
int main() {
    LL n,s;
    scanf("%lld%lld",&n,&s);
    if(n==s)
        printf("%lld\n",s+1);
    else if(n<s)
        printf("-1\n");
    else {
        LL mid=sqrt(n)+1;
        bool flag=false;
        LL res;
        for(LL i=2; i<=mid; i++) {
            res=0;
            LL temp=n;
            while(temp) {
                res+=temp%i;
                temp/=i;
            }
            if(res==s) {
                printf("%lld\n",i);
                flag=true;
                break;
            }
        }
        if(!flag) {
            LL factor=n-s;
            LL res;
            mid=sqrt(factor)+1;
            for(LL i=mid; i>=1; i--) {
                if(factor%i==0) {
                    res=factor/i+1;
                    LL j=s-i;
                    if(i<res&&res>=2&&j<res&&j>=0) { 
                        printf("%lld\n",res);
                        flag=true;
                        break;
                    }
                }
            }
    }
        if(!flag)
            printf("-1\n");
    }
 
    return 0;
}

Measured memory_bytes: 256
s = input()
K = int(input())

alphabet = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]

count = 0

for alp in alphabet:
    ss = []
    # print(alp)
    if alp in s:
        pos = [i for i, x in enumerate(s) if x == alp]
        # print(pos)
        for i in pos:
            for j in range(1,6):
                if i+j == len(s) + 1:
                    break
                else:
                    ss.append(s[i:i+j])
        ss = list(set(ss))
        ss.sort()
        # print(ss)
        if K - count <= len(ss):
            print(ss[K - count -1])
            break
        else:
            count += len(ss)

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int main() {
    //cout.precision(10);
    string KEY = "keyence";
    string s;
    cin >> s;
    for(int i = 0; i <= s.size(); i++) {
        for(int j = 0; i + j <= s.size(); j++) {
            if(s.substr(0, i) + s.substr(s.size() - j, j) == KEY) {
                cout << "YES" << endl;
                return 0;
            }
        }
    }
    cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#define ll long long
using namespace std;
const ll mod=1e9 +7;
const int mid=2002;
int f[4020][4020];
int n;
ll ans,jc[8500],jc_n[8500]; 
ll power(ll x,ll k)
{
	ll sss=1;
	while (k)
	{
		if (k%2) sss=sss*x%mod;
		x=x*x%mod;
		k/=2;
	}
	return sss;
}
ll ny(ll x)
{
	return power(x,mod-2);
}
ll C(int x,int y)
{
//	printf("%d %d\n",x,y);
	if (y>x||y<=0) return 0;
	ll sss=jc[x];
	sss=sss*jc_n[x-y]%mod*jc_n[y]%mod;
//	printf("%lld\n",sss);
	return sss;
}
void sol()
{
	for (int i=1;i<=4010;++i)
		for (int j=1;j<=4010;++j)
		{
			int ch=0;
			if (f[i][j]<0) 
				ch-=f[i][j],f[i][j]=0;
			f[i][j]=( (f[i-1][j]+f[i][j-1])%mod +f[i][j])%mod;
//			if (ch) 
//				for (int kkk=1;kkk<=ch;++kkk)
//					printf("+%lld\n",(ll)f[i][j]);
			ans=(ans+(ll)f[i][j]*ch%mod)%mod;
		}
}
int main()
{
//	freopen("E.in","r",stdin);
//	freopen("E.out","w",stdout);
	jc[0]=1;
	for (int i=1;i<=8400;++i)
	{
		jc[i]=jc[i-1]*i%mod;
		jc_n[i]=ny(jc[i]);
	}

	scanf("%d",&n);
	int x,y;
	for (int i=1;i<=n;++i)
	{
		scanf("%d%d",&x,&y);
		ans=((ans-C(2*x+2*y,x+x))%mod +mod)%mod;
		++f[mid-x][mid-y];
		--f[mid+x][mid+y];
	}
//	printf("%lld\n",ans);
	sol();
//	printf("check:%d\n",f[mid+1][mid+1]);
//	printf("%lld\n",ans);
	ans=ans*ny(2)%mod;
	printf("%lld\n",ans);
	return 0;
}


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

int main(){
	deque<int> b;

	int n;	cin>>n;
	for(int i=1;i<=n;i++){
		int a;	cin>>a;
		if(i%2) b.push_back(a);
		else b.push_front(a);
	}

	vector<int> ans(n);
	int pos=0;
	for(auto it=b.begin(); it!=b.end(); it++){
		ans[pos]=*it;
		pos++;
	}

	if(n%2==0){
		for(int i=0;i<n;i++){
			if(i)cout<<" ";
			cout<<ans[i];
		}cout<<endl;
	}else{
		for(int i=n-1;i>=0;i--){
			if(i!=n-1)cout<<" ";
			cout<<ans[i];
		}cout<<endl;
	}

	return 0;
}


Measured memory_bytes: 3840
import std.stdio: writeln, writefln, readln;
import std.array: array, split;
import std.algorithm: map;
import std.string: chomp;
import std.conv: to;

void main() {
	int[3][3] bingo;
	foreach(byte i; 0..3) {
		int[] input = readln.split.map!(to!int).array;
		foreach(int j; 0..3)
			bingo[i][j] = input[j];
	}
	int n = readln.chomp.to!int;
	bool[int] won;
	foreach(_; 0..n) {
		int x = readln.chomp.to!int;
		won[x] = true;
	}
	// Check rows
	foreach(int[3] i; bingo) {
		if (won.get(i[0], false) && won.get(i[1], false) && won.get(i[2], false)) {
			writeln("Yes");
			return;
		}
	}
	// Check columns
	foreach(byte i; 0..3) {
		if (won.get(bingo[0][i], false) && won.get(bingo[1][i], false) && won.get(bingo[2][i], false)) {
			writeln("Yes");
			return;
		}
	}
	bool diagonal_a = true;
	// Check a diagonal
	foreach(byte i; 0..3)
		diagonal_a = diagonal_a && won.get(bingo[i][i], false);

	// The other diagonal
	bool diagonal_b = true;
	foreach(byte i; 0..3)
		diagonal_b = diagonal_b && won.get(bingo[i][2-i], false);

	if (diagonal_a || diagonal_b)
		writeln("Yes");
	else
		writeln("No");
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
    int a,b,c;
    scanf("%d %d",&a,&b);
    c = a * b;
    if (c % 2 == 0)
    {
        printf("Even");/* code */
    } else {
        printf("Odd");
    }
    return 0;
    
}

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

int main()
{
	string s;
	cin>>s;
	if(s=="MON") cout<<"6"<<endl;
	else if(s=="TUE") cout<<"5";
	else if(s=="WED") cout<<"4";
	else if(s=="THU") cout<<"3";
	else if(s=="FRI") cout<<"2";
	else if(s=="SAT") cout<<"1";
	else if(s=="SUN") cout<<"7";
	return 0;
 } 

Measured memory_bytes: 256
import java.util.*;
import java.util.regex.Pattern;

public class Main {
	 
	public static void main(String[] args) {
		Scanner cin=new Scanner(System.in);
		
		String str=cin.nextLine();
		str=str+str;
		String jstr=cin.nextLine();
		
		if(str.indexOf(jstr)!=-1)System.out.println("Yes");
		else System.out.println("No");
	}
	
}


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

#define FLASH ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define int long long int
#define MAX 1e9
#define MIN -1e9
#define mod 1000000007
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define output(x) cout << ( x ? "YES" : "NO" ) << '\n' ;
#define mxn 100005
using namespace std;

void solve(){
    int x,k,d;
    cin >> x >> k >> d;
    if(x > 0)x = -x;
    if(x < 0){
        if((abs(x) + d - 1) / d <= k){
            int lower = (abs(x) / d);
            int upper = (abs(x) + d - 1) / d;
            int step = (abs(x) + d - 1) / d;
            if(lower == upper){
                k = k - step;
                if(k % 2 == 1){
                    cout << d ;
                }
                else{
                    cout << "0";
                }
                return;
            }
            if((k - step) % 2 == 1){
                cout << abs(x + lower * d);
            }
            else{
                cout << abs(x + upper * d);
            }
        } 
        else{
            cout << abs(x + k * d); 
            return;
        }
    }
    else if(x == 0) {
        if(k % 2 == 1){
            cout << d ;
        }
        else{
            cout << "0";
        }
    }
}

int32_t main()
{
    FLASH
    int t = 1;
    // cin >> t;
    while(t--){
        solve();
    }
    return 0;
}



Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
////////////////////////////////////////////////*kedar1514*////////////////////////////////////////////////(Template Start)*****
#define endl "\n"
#define ll long long
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,n) for(i=1;i<=n;i++)
#define si(x)   scanf("%d",&x)
#define sl(x)   scanf("%lld",&x)
#define ss(s)   scanf("%s",s)
#define pi(x)   printf("%d\n",x)
#define pl(x)   printf("%lld\n",x)
#define ps(s)   printf("%s\n",s)
#define all(x)  (x.begin(),x.end())
#define sortAll(x) sort(all(x))   
#define clearAll(arr) memset(arr,0,sizeof(arr))
#define deb(sum) cout<<"deb = "<<sum<<endl;
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define PI 3.1415926535897932384626
typedef pair<int, int>              pii;
typedef pair<long long, long long>  pll;
typedef vector<int>                 vi;
typedef vector<long long>           vl;
typedef vector<pii>                 vpii;
typedef vector<pll>                  vpll;
#define kedar ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

ll powerMod(ll x, ll n, ll mod) {
  ll res = 1;
  x %= mod;
  while (n) {
	if (n & 1)
	  res = (res * x) % mod;
	x = (x * x) % mod;
	n >>= 1;
  }
  return res;
}

ll power(ll x, ll n) {
  ll res = 1;
  while (n) {
	if (n & 1)
	  res = (res * x);
	x = (x * x);
	n >>= 1;
  }
  return res;
}

int gcd(int A, int B) {
    if(B==0)
        return A;
    else
        return gcd(B, A % B);
}
////////////////////////////////////////////////*kedar1514*////////////////////////////////////////////////(Template ends)*****
// <<
//  <<,
//  , cout<<<<endl;
ll arr[100005];
ll dp[100105];
ll n;
ll k;
int totalCost(int ind,int k)
{
  if(dp[ind]!=-1) 
    return dp[ind];

  if(ind==(n-1))
  {
    return 0;
  }
  if(ind>=n)
  {
    return INT_MAX;
  }

  int left = abs(arr[ind]-arr[ind+1]) + totalCost(ind+1,k);
  int right = INT_MAX;
  int temp;
  for (int i = 2; i <=k; i++)
  {
    if(ind+i<n)
    {
      temp = abs(arr[ind]-arr[ind+i]) + totalCost(ind+i,k);
      right = min(right, temp);
    }  
  }
  
  dp[ind] = min(right,left);

  return dp[ind];
}

void solve()
{
  cin>>n>>k;
  for (ll i = 0; i < n; i++)
  {
    cin>>arr[i];
  }
  memset(dp,-1,sizeof(dp));
  cout<<totalCost(0,k);
  
}

int main(){
    kedar;
// <<
//  <<,
//  ,

    ll t=1;
    //cin>>t;
    while(t--)
    {       
        solve();
    }
    return 0;
}// <<
//  <<,
//  ,


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

int main() {
  int N,K,sum=0;
  cin >>N >>K ;
  for(int i=0;i<N;i++){
   int x;
    cin>>x;
    if(2*x >= K){sum+=2*(K-x);}
    else{sum+=2*x;}
  }
  cout<<sum <<endl;
}


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

using namespace std;

typedef long long llint;
typedef tuple<llint, llint, llint> TP;

char c[3] = {'R', 'G', 'B'};

int main() {
  int n;
  string s;
  cin >> n >> s;
  vector<TP> v(n);
  llint r = 0, g = 0, b = 0;
  for (int i = n - 1; 0 <= i; i--) {
    v[i] = TP(r, g, b);
    if (s[i] == 'R') r++;
    if (s[i] == 'G') g++;
    if (s[i] == 'B') b++;
  }

  llint ans = 0;
  for (int i = 0; i < n - 2; i++) {
    for (int j = i + 1; j < n - 1; j++) {
      if (s[i] == s[j]) continue;
      int k = j - i;
      k += j;
      tie(r, g, b) = v[j];
      if (k < n) {
        if (s[k] == 'R') r--;
        if (s[k] == 'G') g--;
        if (s[k] == 'B') b--;
      }
      for (int p = 0; p < 3; p++) {
        for (int q = 0; q < 3; q++) {
          if (s[i] == c[p] && s[j] == c[q]) {
            int z = 3 - p - q;
            if (z == 0) ans += r;
            if (z == 1) ans += g;
            if (z == 2) ans += b;
          }
        }
      }
    }
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)

int N;
vector<int> p;

int main(){
  cin >> N;
  p.resize(N);
  rep(i,0,N - 1) cin >> p[i];
  int ans= 0;
  for(int i = 0;i < N - 1;i++){
    if(p[i] == i + 1){
      swap(p[i],p[i + 1]);
      ans++;
    }
  }
  if(p[N - 1] == N) ans++;
    cout << ans << endl;
}


Measured memory_bytes: 640
//yewala
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)  for(int i = 0; i < n; i++)
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.rbegin(), cont.rend()
#define unique(a)        (a).erase(unique((a).begin(), (a).end()),(a).end())
#define fastio          ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define PB push_back
#define endl "\n"
#define mod 1000000007 
typedef long long LL;
typedef long double LD;
typedef vector<int> VI;

inline LL moduloMultiplication(LL x, LL y) { return (x%mod * 1LL * y%mod) % mod; }
inline LL power(LL a, LL b) {
	LL x = 1 % mod;
	while (b) {
		if (b & 1) x = moduloMultiplication(x, a);
		a = moduloMultiplication(a, a);
		b >>= 1;
	}
	return x % mod;
}

inline LL add(LL x, LL y) { x += y; if (x >= mod) x -= mod; return x; }
inline LL inv(LL a) { return power(a, mod - 2) % mod; }

bool isPrime(int n)
{

	if (n <= 1)  return false;
	if (n <= 3)  return true;

	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;
}


int main()
{

	int n;
	cin >> n;
	while (1)
	{
		if (isPrime(n)) {
			cout << n << endl;
			break;
		}
		n++;
	}

}


Measured memory_bytes: 256
import java.util.*;

public class Main {

  public static void main (String[] args) {

    Scanner sc = new Scanner(System.in);
    
    int sx = sc.nextInt();
    int sy = sc.nextInt();
    int tx = sc.nextInt();
    int ty = sc.nextInt();

    sc.close();

    // パターン1：ty -> txへ移動する
    for (int i = 0; i < ty - sy; i++){
      System.out.print("U");
    }

    for (int i = 0; i < tx - sx; i++) {
      System.out.print("R");
    }

    // パターン2：sy -> sxへ移動する
    for (int i = 0; i < ty - sy; i++){
      System.out.print("D");
    }

    for (int i = 0; i < tx - sx; i++) {
      System.out.print("L");
    }

    // パターン3：sx-1 -> ty+1 -> tx -> tyへ移動する
    System.out.print("L");

    for (int i = 0; i < ty - sy + 1; i++){
      System.out.print("U");
    }

    for (int i = 0; i < tx - sx + 1; i++) {
      System.out.print("R");
    }

    System.out.print("D");

    // パターン4：tx+1 -> sy-1 -> sx -> syへ移動する
    System.out.print("R");

    for (int i = 0; i < ty - sy + 1; i++){
      System.out.print("D");
    }

    for (int i = 0; i < tx - sx + 1; i++) {
      System.out.print("L");
    }

    System.out.print("U");

    System.out.println("");
    

  }

}

Measured memory_bytes: 23508
#include<stdio.h>
int main()
{
    int card[4][13] = {0};
    int num;
    int n, i, j;
    char mark;
    scanf("%d", &n);

    for(i = 0; i < n; i++)
    {
        scanf(" %c %d", &mark, &num);

        if(mark == 'S')
        {
            card[0][num - 1] = 1;
        }
        else if(mark == 'H')
        {
            card[1][num - 1] = 1;
        }
        else if(mark == 'C')
        {
            card[2][num - 1] = 1;
        }
        else if(mark == 'D')
        {
            card[3][num - 1] = 1;
        }
    }
    for(i = 0; i < 4; i++)
    {
        for(j = 0; j < 13; j++)
        {
            if(card[i][j] != 1)
            {
                if(i == 0)
                {
                    printf("S %d\n", j + 1);
                }
                else if(i == 1)
                {
                    printf("H %d\n", j + 1);
                }
                else if(i == 2)
                {
                    printf("C %d\n", j + 1);
                }
                else if(i == 3)
                {
                    printf("D %d\n", j + 1);
                }
            }
        }
    }

    return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
using namespace std;
int main(){
  char a,b;
  cin >> a >> b;
  if(a<b){
    cout << "<" << endl;
  }else if(a>b){
    cout << ">" << endl;
  }else{
    cout << "=" << endl;
  }
  return 0;
}

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

using namespace std;

int main()
{
    int N;
    cin >> N;
    set<string> words;
    string word;
    cin >> word;
    words.insert(word);
    char last = word.back();
    for (int i = 1; i < N; ++i)
    {
        cin >> word;
        if (word.front() != last)
        {
            cout << "No" << endl;

            return 0;
        }
        if (words.find(word) != words.end())
        {
            cout << "No" << endl;
            return 0;
        }
        words.insert(word);
        last = word.back();
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
    string s;
    cin>>s;
    vector<int> a(4,0);
    rep(i,s.size()){
        a[i]=s[i]-'0';
    }
    rep(i,1<<3){
        int ans = 0;
        int now = a[0];
        string ss="";
        ss.push_back(a[0]+'0');
        rep(j,3){
            if((i>>j)&1){
                now+=a[j+1];
                ss.push_back('+');
            }
            else{
                now -=a[j+1];
                ss.push_back('-');
            }
            ss.push_back(a[j+1]+'0');
        }
        if(now==7){
            cout<<ss<<"=7"<<endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <string>

using namespace std;

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

  int h1,h2;
  cin >> h1;
  int cnt = 0;
  int ans = 0;
  for (int i=1; i<n; i++) {
    cin >> h2;
    if (h1>=h2) {
      cnt++;
      if(cnt>ans) ans = cnt;
    } else cnt=0;
    h1 = h2;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

template<class T>
constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

template<class T>
class Dinic {
    struct edge {
        int to{}, rev{};
        T cap;
        edge() = default;
        edge(int to, T cap, int rev):to(to), cap(cap), rev(rev) {}
    };
    int n{};
    vector<vector<edge>> G;
    vector<int> level, iter;
public:
    Dinic() = default;
    explicit Dinic(int sz): n(sz), G(n), level(n), iter(n){}
    void add_edge(int from, int to, T cap){
        G[from].emplace_back(to, cap, G[to].size());
        G[to].emplace_back(from, 0, G[from].size()-1);
    }

    void bfs(int s){
        fill(level.begin(), level.end(), -1);
        queue<int> Q;
        level[s] = 0;
        Q.emplace(s);
        while(!Q.empty()){
            int v = Q.front(); Q.pop();
            for (auto &&e : G[v]) {
                if(e.cap > 0 && level[e.to] < 0){
                    level[e.to] = level[v]+1;
                    Q.emplace(e.to);
                }
            }
        }
    }

    T dfs(int v, int t, T f){
        if(v == t) return f;
        for (int &i = iter[v]; i < G[v].size(); ++i) {
            edge &e = G[v][i];
            if(e.cap > 0 && level[v] < level[e.to]){
                T d = dfs(e.to, t, min(f, e.cap));
                if(d > 0){
                    e.cap -= d;
                    G[e.to][e.rev].cap += d;
                    return d;
                }
            }
        }
        return 0;
    }

    T flow(int s, int t, T lim = INF<T>){
        T fl = 0;
        while(true){
            bfs(s);
            if(level[t] < 0 || lim == 0) return fl;
            fill(iter.begin(), iter.end(), 0);
            T f;
            while((f=dfs(s,t, lim))>0){
                fl += f;
                lim -= f;
            }
        }
    }

    bool back_edge(int s, int t, int from, int to){
        for (auto &&e : G[from]) {
            if(e.to == to) {
                if(e.cap == 0 && flow(from, to, 1) == 0){
                    flow(from, s, 1);
                    flow(t, to, 1);
                    return true;
                }
            }
        }
        return false;
    }

};

int main() {
    int n;
    cin >> n;
    vector<ll> v(n);
    for (auto &&i : v) scanf("%lld", &i);
    Dinic<ll> fl(n+2);
    ll ans = 0;
    for (int i = 0; i < n; ++i) {
        if(v[i] >= 0){
            fl.add_edge(0, i+1, 0);
            fl.add_edge(i+1, n+1, v[i]);
            ans += v[i];
        }else {
            fl.add_edge(0, i+1, -v[i]);
            fl.add_edge(i+1, n+1, 0);
        }
    }
    for (int i = 0; i < n; ++i) {
        if(v[i] == 0) continue;
        for (int j = 0; j < n; ++j) {
            if(i == j) continue;
            if((j+1)%(i+1) == 0) {
                fl.add_edge(i+1, j+1, 1000LL*MOD);
            }
        }
    }
    cout << ans-fl.flow(0, n+1) << "\n";
    return 0;
}


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

#define int long long int
#define MOD 1000000007
#define N 100001
#define pii pair<int,int>
#define MAX 1e18
#define _mp make_pair
#define pb push_back
#define _sort(v) sort(v.begin(),v.end())
#define _rsort(v) sort(v.rbegin(),v.rend())
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;

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

int32_t main(){
SPEED
char c;
cin>>c;
if(c<'a')
cout<<'A';
else cout<<'a';
    
    // end_timer = std::chrono::high_resolution_clock::now();
    // ll elapsed_time = std::chrono::duration_cast<std::chrono::milliseconds>(end_timer - start_timer).count();

return 0;
}

Measured memory_bytes: 3648
//サンプル
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
using namespace std;

class UnionFind {
public:
	//親の番号を格納する。親だった場合は-(その集合のサイズ)
	vector<int> Parent;

	//作るときはParentの値を全て-1にする
	//こうすると全てバラバラになる
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}

	//Aがどのグループに属しているか調べる
	int root(int A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}

	//自分のいるグループの頂点数を調べる
	int size(int A) {
		return -Parent[root(A)];//親をとってきたい]
	}

	//AとBをくっ付ける
	bool connect(int A, int B) {
		//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
		A = root(A);
		B = root(B);
		if (A == B) {
			//すでにくっついてるからくっ付けない
			return false;
		}

		//大きい方(A)に小さいほう(B)をくっ付けたい
		//大小が逆だったらひっくり返しちゃう。
		if (size(A) < size(B)) swap(A, B);

		//Aのサイズを更新する
		Parent[A] += Parent[B];
		//Bの親をAに変更する
		Parent[B] = A;

		return true;
	}
};

int main() {
	int N, M;
	cin >> N >> M;
	vector<int> A(M), B(M);
	for (int i = 0; i < M; i++)
	{
		cin >> A[i] >> B[i];
		A[i]--;
		B[i]--;
	}

	vector<long long> ans(M);
	ans[M - 1] = (long long)N * (N - 1) / 2;

	UnionFind Uni(N);

	for (int i = M - 1; i >= 1; i--)
	{
		ans[i - 1] = ans[i];

		//繋がってなかったのが繋がった時
		if (Uni.root(A[i]) != Uni.root(B[i])) {
			ans[i - 1] -= (long long)Uni.size(A[i]) * Uni.size(B[i]);
			Uni.connect(A[i], B[i]);
		}
	}

	for (int i = 0; i < M; i++)
	{
		cout << ans[i]<< endl;
	}
}



Measured memory_bytes: 3328
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <limits.h>
int main(){
    int i,j,k,l,x,y,z,n,count=0,f[10010]={};
    scanf("%d",&n);
    for(l=1; l<=n; l++){
        for(i=1; i<sqrt(1.0*l); i++){
            for(j=i; j<sqrt(1.0*l); j++){
                for(k=j; k<sqrt(1.0*l); k++){
                    if(i*i+j*j+k*k+i*j+j*k+k*i==l){
                        if(i!=j && j!=k && k!=i)f[l]+=6;
                        else if(i==j && j==k)f[l]++;
                        else{f[l]+=3;}
                    }
                }
            }
        }
    }
    for(i=1; i<=n; i++){
        printf("%d\n",f[i]);
    }
    return 0;
}

Measured memory_bytes: 2172
#include<stdio.h>
#include<algorithm>
#define INF 50000000000LL
using namespace std;
int s[2000];
long long r[100001];
long long dp[2][2000];//直前に使わなかった方がiでその一つ前がjのときの最小値
long long min(long long a,long long b){return a<b?a:b;}
int main(){
	int n,m,k;
	int i,j;
	scanf("%d %d %d",&n,&m,&k);
	for(i=0;i<n;i++)scanf("%d",&s[i]);
	sort(s,s+n);
	r[0]=0;
	for(i=1;i<=m;i++){
		scanf("%d",&r[i]);
		r[i]+=r[i-1];
	}
	for(j=0;j<n;j++)dp[1][j]=INF;
	dp[1][0]=0;
	for(i=1;i<n-1;i++){
		for(j=0;j<n;j++)dp[(i+1)%2][j]=INF;
		for(j=0;j<i;j++){
			dp[(i+1)%2][j]=min(dp[(i+1)%2][j],dp[i%2][j]+(r[s[i]]-r[s[i-1]-1])/k);
			dp[(i+1)%2][i-1]=min(dp[(i+1)%2][i-1],dp[i%2][j]+(r[s[i]]-r[s[j]-1])/k);
		}
	}
	long long ans=INF;
	for(i=0;i<n;i++){
		long long res=dp[(n-1)%2][i]+(r[s[n-1]]-r[s[i]-1])/k+(r[s[n-1]]-r[s[n-2]-1])/k;
		ans=min(ans,res);
	}
	printf("%lld\n",ans);
	return 0;
}

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

int main() {
    int h,w;
    cin>>h>>w;
    string s[h];
    for (int i=0;i<h;i++)
        cin>>s[i];
    set<int> r,c;
    for (int i=0;i<h;i++)
        for (int j=0;j<w;j++)
            if (s[i][j]=='#') {
                r.insert(i);
                c.insert(j);
            }
    for (int i=0;i<h;i++) {
        if (r.count(i)==0)
            continue;
        for (int j=0;j<w;j++) {
            if (c.count(j)==0)
                continue;
            cout<<s[i][j];
        }
        cout<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.math.BigInteger;
import java.util.ArrayList;

public class Main {
    private static StringBuilder builder = new StringBuilder();
    public static void main(String[] args) {
        int x = readInt();
        int n = readInt();
        ArrayList<Integer> list = new ArrayList<>(n);
        for (int i = 0; i < n; i++) {
            list.add(readInt());
        }

        int i = 0;
        while (true) {
            if (!list.contains(x - i)) {
                System.out.print(x - i);
                break;
            }

            if (!list.contains(x + i)) {
                System.out.print(x + i);
                break;
            }

            list.remove(Integer.valueOf(x - i));
            list.remove(Integer.valueOf(x + i));
            if (x + i == Integer.MAX_VALUE || x - i == Integer.MIN_VALUE) {
                break;
            }

            i++;
        }
    }

    private static void read() {
        builder.setLength(0);
        while (true) {
            try {
                int b = System.in.read();
                if (b == ' ' || b == '\n' || b == -1) {
                    break;
                } else {
                    builder.appendCodePoint(b);
                }
            } catch (IOException e) {
                break;
            }
        }
    }

    private static int readInt() {
        read();
        return Integer.parseInt(builder.toString());
    }

    private static int readInt(int radix) {
        read();
        return Integer.parseInt(builder.toString(), radix);
    }

    private static long readLong() {
        read();
        return Long.parseLong(builder.toString());
    }

    private static long readLong(int radix) {
        read();
        return Long.parseLong(builder.toString(), radix);
    }

    private static BigInteger readBigInteger() {
        read();
        return new BigInteger(builder.toString());
    }

    private static BigInteger readBigInteger(int radix) {
        read();
        return new BigInteger(builder.toString(), radix);
    }

    private static void skipLine() {
        while (true) {
            try {
                int b = System.in.read();
                if (b == '\n' || b == -1) {
                    break;
                }
            } catch (IOException e) {
                break;
            }
        }
    }

    private static void skip() {
        while (true) {
            try {
                int b = System.in.read();
                if (b == ' ' || b == '\n' || b == -1) break;
            } catch (IOException e) {
                break;
            }
        }
    }

}


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

#define ll long long
#define N 2010
const ll p = 1e9 + 7; 
int n, m;
int a[N], b[N];
ll f[N][N];  
void add(ll &x, ll y) {
	x += y;
	if (x >= p) {
		x -= p;
	}
}

int main() {
	while (scanf("%d%d", &n, &m) != EOF) {
		for (int i = 1; i <= n; ++i) {
			scanf("%d", a + i);
		}
		for (int i = 1; i <= m; ++i) {
			scanf("%d", b + i);
		}
		memset(f, 0, sizeof f);
	//	for (int i = 1; i <= max(n, m); ++i) {
	//		f[i][0] = 1;
	//		f[0][i] = 1;
	//	}
		for (int i = 1; i <= n; ++i) {
			for (int j = 1; j <= m; ++j) {
				add(f[i][j], f[i - 1][j]);
				add(f[i][j], f[i][j - 1]);
			   	add(f[i][j], p - f[i - 1][j - 1]); 	
				if (a[i] == b[j]) {
					add(f[i][j], f[i - 1][j - 1] + 1);  
				} 
			}	
		}
		printf("%lld\n", f[n][m] + 1); 
	}
	return 0;
}


Measured memory_bytes: 31872
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> b(n-1);
  int i;
  for(i=0;i<n-1;i++){
    cin >> b.at(i);
  }
  vector<int> a(n);
  a.at(0)=b.at(0);
  int sum=a.at(0);
  for(i=1;i<n-1;i++){
    a.at(i)=min(b.at(i-1),b.at(i));
    sum+=a.at(i);
  }
  a.at(n-1)=b.at(n-2);
  sum+=a.at(n-1);
  cout << sum;
}

Measured memory_bytes: 256
# https://atcoder.jp/contests/abc075/tasks/abc075_c?lang=ja

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):                                          # 根を見つける関数を定義（同時にxを直接根にくっつける操作も行う）
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])        # 右辺で再帰的に根を探索。根に到達すると一つ目のif判定に引っかかるので、
                                                                # 最終的にself.parents[根]が返ってくる。
                                                                # これを左辺に代入することで、根が親になるように変更する。（根までの距離が長いとO(N)になってしまうので）
            return self.parents[x]

    def union(self, x, y):                                      # 二つの木をくっつける（子を多く持つ方を根とした親子関係）。これは破壊的操作を行う。
        x = self.find(x)                                        # xをxの根に置き換える
        y = self.find(y)                                        # yをyの根に置き換える

        if x == y:                                              # 根が同じなら置き換える必要なし
            return

        if self.parents[x] > self.parents[y]:                   # 子がたくさんある方を x とする（出来るだけ浅い木にするため）
            x, y = y, x

        self.parents[x] += self.parents[y]                      # xの子の数を更新
        self.parents[y] = x                                     # yの親を更新

    def same(self, x, y):                                       # xとyが同じ根の子かを判定
        return self.find(x) == self.find(y)

    def size(self, x):                                          # xの根のparent（= 要素数）を返す
        return -self.parents[self.find(x)]

    def members(self, x):                                       # xが属するグループの要素をリストとして返す
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):                                            # 全ての根の要素をリストとして返す
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):                                      # グループの数を返す
        return len(self.roots())

    def all_group_members(self):                                # {根:[根の子のリスト],...}を辞書で返す
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):                                          # print(self) での返し方を定義
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


N, M = map(int, input().split())

data = [tuple(map(int, input().split())) for _ in range(M)]
res = 0

for k in range(M):
    tree = UnionFind(N)
    for a, b in data[:k] + data[k+1:]:
        a -= 1
        b -= 1
        tree.union(a,b)
    if tree.group_count() > 1:
       res += 1
print(res)

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

int main(){
  int l,a,b,c,d,cou=0;
  cin >> l >> a >> b >> c >> d;
  while(a>0 || b>0){
    a -= c;
    b -= d;
    cou++;
  }
  cout << l-cou << endl;
}

Measured memory_bytes: 1160
#include<stdio.h>

int judge(char s[], char p[]) {
  int sn = 0, pn = 0, flag = 0, i, j, k, temp, pi, hantei = 0, breakflag = 0;
  while (flag == 0)
  {
    if (s[sn] >= 97 && s[sn] <= 122)
    {
      sn++;
    }
    else
    {
      flag = 1;
    }
  }
  
  flag = 0;
  
  while (flag == 0)
  {
    if (p[pn] >= 97 && p[pn] <= 122)
    {
      pn++;
    }
    else
    {
      flag = 1;
    }
  }
  
  for (i = 0; i < sn; i++)
  {
    pi = 0;
    for (k = 0; k < pn; k++)
    {
      if (s[k] == p[k])
      {
        pi++;
      }
      
      if (pi == pn)
      {
        return hantei = 1;
      }
    }
    
    temp = s[sn - 1];
    for (j = sn - 2; j >= 0; j--)
    {
      s[j + 1] = s[j];
    }
    s[0] = temp;
  }
  
  if (hantei == 1)
  {
    return 1;
  }
  else
  {
    return 0;
  }
}

int main(void) {
  char s[100], p[100], i;
  scanf("%s", s);
  scanf("%s", p);
  
  if (judge(s, p) == 1)
  {
    printf("Yes\n");
  }
  else
  {
    printf("No\n");
  }
  
  return 0;
}

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

// #define NDEBUG
#include<assert.h>
const int INF = 1001001001;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n ;
  string s;
  cin >> n >> s;
  int left = 0, right = n - 1;
  int res = 0;
  while(left < right) {
      while(left < right && s[left] == 'R') left++;
      while(left < right && s[right] == 'W') right--;
      if(left != right) res++;
      left++;
      right--;
  }
  cout << res << endl;
  return 0;
}

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

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

  string str;
  cin >> str;

  if(N%2!=0)
    {
      cout << "No" << endl;
      return 0;
    }

  string str1 = str.substr(0, N/2);
  string str2 = str.substr(N/2, N-1);


  if(str1==str2)
    cout <<"Yes"<<endl;
  else
    cout <<"No"<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstring>
#include <chrono>
#include <complex>
#define fill(a,val) memset(a,val,sizeof(a))
#define REP(i,a,b) for (auto i = a; i != b; i++)
#define ll long long int
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001;
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define f first
#define pb push_back
#define SQ(a) (a)*(a)
 
const int N = 10005;
using namespace std;
 
int main()
{
    std::ios::sync_with_stdio(false);
    //ll p = 1000000007; 
    
    int T = 1;
    //cin>>T;
    // cin.ignore(); must be there when using getline(cin, s)
    while(T--)
    {
          int a,b,c;
          cin>>a>>b>>c;
          cout<<c<<" "<<a<<" "<<b;
          
    }
    return 0;
}

 

Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    for(int i=0;i<s.size();i++){
        s[i] = (s[i] + n > 'Z'?s[i] + n - 'Z' + 'A' - 1:s[i] + n);
    }
    cout << s << endl;
}

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

using namespace std;
typedef long long ll;

int n;
ll in[100000];

int main() {
	cin >> n;
	ll ans1 = 0,ans2 = 0;
	ll sum = 0;
	bool f;
	for (int i = 0; i < n; i++)cin >> in[i];
	if (in[0] > 0) {
		ans1 += (in[0] + 1);
		sum = -1;
		f = false;
	}
	else {
		ans1 += (1 - in[0]);
		sum = 1;
		f = true;
	}

	for (int i = 1; i < n; i++) {
		sum += in[i];
		if (!f && sum <= 0) {
			ans1 += (1 - sum);
			sum = 1;
		}
		else if (f && sum >= 0) {
			ans1 += (sum + 1);
			sum = -1;
		}
		f = !f;
	}

	if (in[0] > 0)f = true;
	else f = false;
	sum = in[0];
	
	if (in[0] == 0)ans2 += 1, sum = -1, f = false;
	for (int i = 1; i < n; i++) {
		sum += in[i];
		if (!f && sum <= 0) {
			ans2 += (1 - sum);
			sum = 1;
		}
		else if (f && sum >= 0) {
			ans2 += (sum + 1);
			sum = -1;
		}
		f = !f;
	}
	cout << min(ans1, ans2) << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int main(void){
  int a,b,c;
  int temp;
  cin>>a>>b>>c;

  temp=b;
  b=a;
  a=temp;

  temp=c;
  c=a;
  a=temp;

  cout<<a<<" "<<b<<" "<<c<<endl;

  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<limits.h>

void Sort(int A[], int N);

int main()
{
	char S[101] = { NULL };
	long K = 0;

	scanf("%s", S);
	scanf("%d", &K);

	char ans = NULL;
	
	//SがKまで１なら１
	//それ以外なら一番最初に出てくる１以外の数
	for (long i = 0; i < K; i++) {
		if (S[i] != '1') {
			ans = S[i];
			goto ELSE;
		}
	}

	printf("1");
	return 0;

ELSE:
	printf("%c", ans);
	return 0;
}

void Sort(int A[], int N) {
	for (int j = 0; j < N ; j++) {
		for (int i = 0; i < N - j; i++) {
			if (A[i] < A[i + 1]) {
				int tmp = A[i];
				A[i] = A[i + 1];
				A[i + 1] = tmp;
			}
		}
	}
}

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

string s[302];
int n, ans;

int main()
{
	cin >> n;
	for (int i = 0; i < n; ++i)
    {
        cin >> s[i];
    }

	for (int b = 0; b < n; ++b)
	{
		for (int row = 0; row < n; ++row)
        {
            rotate(s[row].begin(), s[row].begin()+1, s[row].end());
        }

		bool flag = true;
		for (int i = 0; i < n; ++i)
        {
            for (int j = i + 1; j < n; ++j)
            {
                flag &= (s[i][j] == s[j][i]);
            }
        }

		ans += flag;
	}

	cout << ans * n <<endl;

	return 0;
}


Measured memory_bytes: 384