akhauriyash/Code-Regression huggingface dataset:
#https://ikatakos.com/pot/programming_algorithm/contest_history/atcoder/2018/0908_abc109
#コピペコード
H,W = map(int, input().split())
relation = []
for i in range(H):              #一筆書きをリストに詰める
    if i % 2 == 0:
        relation.extend((i, j) for j in range(W))
    else:
        relation.extend((i, j) for j in range(W - 1, -1, -1))
field = [list(map(int, input().split())) for _ in range(H)]
 
buf = []
for (i1, j1), (i2, j2) in zip(relation, relation[1:]):
    if field[i1][j1] % 2 == 1:
        field[i1][j1] -= 1
        field[i2][j2] += 1
        buf.append((i1 + 1, j1 + 1, i2 + 1, j2 + 1))
 
print(len(buf))
print('\n'.join(' '.join(map(str, line)) for line in buf))

Measured memory_bytes: 56800
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.FilterInputStream;
import java.io.BufferedInputStream;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        ScanReader in = new ScanReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        AFrog1 solver = new AFrog1();
        solver.solve(1, in, out);
        out.close();
    }

    static class AFrog1 {
        int[] arr;
        long[] dp;

        public void solve(int testNumber, ScanReader in, PrintWriter out) {
            int n = in.scanInt();
            arr = new int[n];
            for (int i = 0; i < n; i++) arr[i] = in.scanInt();
            dp = new long[n];
            Arrays.fill(dp, -1);
            out.println(findIt(n - 1));

        }

        long findIt(int n) {
            if (n < 0) return Integer.MAX_VALUE;
            if (n == 0) return dp[0] = 0;
            if (dp[n] != -1) return dp[n];
            long ans = Long.MAX_VALUE / 2;
            for (int i = 1; i <= 2; i++)
                if (n - i >= 0) ans = Math.min(ans, findIt(n - i) + Math.abs(arr[n] - arr[n - i]));
            return dp[n] = ans;
        }

    }

    static class ScanReader {
        private byte[] buf = new byte[4 * 1024];
        private int INDEX;
        private BufferedInputStream in;
        private int TOTAL;

        public ScanReader(InputStream inputStream) {
            in = new BufferedInputStream(inputStream);
        }

        private int scan() {
            if (INDEX >= TOTAL) {
                INDEX = 0;
                try {
                    TOTAL = in.read(buf);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                if (TOTAL <= 0) return -1;
            }
            return buf[INDEX++];
        }

        public int scanInt() {
            int I = 0;
            int n = scan();
            while (isWhiteSpace(n)) n = scan();
            int neg = 1;
            if (n == '-') {
                neg = -1;
                n = scan();
            }
            while (!isWhiteSpace(n)) {
                if (n >= '0' && n <= '9') {
                    I *= 10;
                    I += n - '0';
                    n = scan();
                }
            }
            return neg * I;
        }

        private boolean isWhiteSpace(int n) {
            if (n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1) return true;
            else return false;
        }

    }
}



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

using ll = long long;
using ull = unsigned long long;

#define MOD 1000000007

int main(void) {
    ll N, Y;
    cin >> N >> Y;
    for(ll i = 0;i <= 2000;i++) {
        for(ll j = 0;j <= 2000;j++) {
            ll sum = 10000 * i + 5000 * j;
            ll k = max(0LL, (Y - sum) / 1000);
            if(i + j + k == N && i * 10000 + j * 5000 + 1000 * k == Y) {
                cout << i << ' ' << j << ' ' << k << endl;
                return 0;
            }
        }
    }
    cout << -1 << ' ' << -1 << ' ' << -1 << endl;
    return 0;
}


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

int main() {
   int N,K;
   cin >> N >> K;
   string S;
   cin >> S;

   if(S[K - 1] == 'A') {
       S[K - 1] = 'a';
   }else if(S[K - 1] == 'B') {
       S[K - 1] = 'b';
   }else if(S[K - 1] == 'C') {
       S[K - 1] = 'c';
   }

   cout << S;
   
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;

template<class T> inline T sqr(T x) {return x*x;}

void solve() {
    VI n(4);
    REP(i,0,4) cin >> n[i];
    sort(all(n));
    if (n[0] == 1 && n[1] == 4 && n[2] == 7 && n[3] == 9) cout << "YES" << endl;
    else cout << "NO" << endl;
}

int main() {
    solve();
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
  	string s,m;
  	getline(cin,s);
  	getline(cin,m);
  	int c=0;
  	for(int i=0;i<s.length();i++){
    	if(s[i]!=m[i])
          c++;
    }
  	cout << c;
	return 0;
}

Measured memory_bytes: 3876
import sys
sys.setrecursionlimit(10 ** 7)
read = sys.stdin.buffer.read 
input = sys.stdin.buffer.readline
def inputS(): return input().rstrip().decode()
readlines = sys.stdin.buffer.readlines  

A, B, K = map(int, input().split())

eat = min(A, K)
A -= eat
K -= eat

eat = min(B, K)
B -= eat

print(A, B)  
  

Measured memory_bytes: 3060
#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 H;
  int W;
  cin >>H>>W;
  char data[H][W];
  rep(i,H) {
    rep(j,W) {
cin >>data[i][j];
    }
  }
  
  char dat[2*H][W];
  
  rep(i,H) {
rep(j,W) {
  dat[2*i][j]=data[i][j];
  dat[2*i+1][j]=data[i][j];
}
  }

  rep(i,2*H)  {
    rep(j,W) {
      
      cout<<dat[i][j];
    }
    cout<<endl;
  }
  
  
  
  
  
}

  

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
   cin >> N ;
  int j;
  int M;
  cin >> M ;
  
  vector<int> ans(N);
  long answer;
  answer = 0;
  int i;
  long jousuu;
  vector<int> s(M);
  vector<int> c(M);
  for (i=0;i<M;i++){
  cin >>s.at(i);
   // cout << s.at(i);
  cin >>c.at(i);
   // cout << c.at(i);
  }
   ans.at(0)=1;  
  int temp;
  for (i=0; i<M; i++) {
    for (j=i+1; j<M; j++) {
      if (c.at(i) < c.at(j)) {
        temp =  c.at(i);
        c.at(i) = c.at(j);
        c.at(j) = temp;
         temp =  s.at(i);
        s.at(i) = s.at(j);
        s.at(j) = temp;
        
      }
    }
  }

  
  
  
   for (i=0;i<M;i++){
  ans.at(s.at(i)-1)=c.at(i);
     //cout << ans.at(s.at(i)-1) << c.at(i) << endl;
  }
  jousuu = 1;
   for(i=N-1;i>0;i--){
  jousuu=jousuu*10;
   }
 for(i=0;i<N;i++){
    answer = answer +ans.at(i)*jousuu;
   jousuu=jousuu/10;
  }
  
  //かぶりがあったらマイナス１
  for(i=0;i<M;i++){
   for(j=0;j<M;j++){
   if(i==j){continue;}
    if(s.at(i)==s.at(j)){
      if(c.at(i)!=c.at(j)){
        answer = (-1);
      }
    }
     
   }
  }
   
  for(i=0;i<M;i++){
   if(s.at(i)==1&&c.at(i)==0){answer = (-1);}
   }
   if(M!=0){
   if(N==1&&s.at(0)==1&&c.at(0)==0){answer = 0;}
   }else{
   if(N==1){answer = 0;}
   }
  
  
  /*
  for(i=0;i<M-1;i++){
    if(s.at(i)==s.at(i+1)){
      if(c.at(i)!=c.at(i+1)){
   cout <<  answer<< endl;
        cout << s.at(i) << endl;
    cout << s.at(i+1) << endl;
    cout << c.at(i) << endl;
    cout << c.at(i+1) << endl;
     answer = (-1);
    }
    }
  }
  */
  cout << answer << endl; 
}

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

int main() {

	string a;
	string b;

	int count = 0;

	cin >> a;
	cin >> b;

	a = a + a;//リングの形だから最初と最後をつなげる

	//a.substr(開始位置,終了位置)文字列の取得

	for (int i = 0; i < a.size(); i++) {
		if (a.substr(i, b.size()) == b && count ==0) {
			cout << "Yes" << endl;
			count = 1;
		}
	}

	if (count == 0) {
		cout << "No" << endl;
	}


	return 0;
}


Measured memory_bytes: 3212
#include<bits/stdc++.h>
#define ll long long
#define pi acos(-1)
#define pa pair<ll,ll>
#define mp make_pair
#define xx first
#define yy second
using namespace std;
const int N=105,mod=1e9+7;
const ll inf=1e18;
inline ll rd(){
	ll x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-') f=0;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
	return f?x:-x;
}ll fib[N];vector<pa>a[N];
vector<pa>::iterator it;
ll x,y,n,num,m;int tot,tes,ans;
int main(){
	tes=rd();fib[0]=fib[1]=1;tot=1;
	while(1){
		fib[tot+1]=fib[tot]+fib[tot-1];
		if(fib[tot+1]>inf) break;
		tot++;
	}
	a[1].push_back(mp(1,2));a[1].push_back(mp(1,3));
	a[1].push_back(mp(1,4));
	for(int i=1;i<=tot-3;i++){
		it=a[i].begin();
		while(it!=a[i].end()){
			x=(*it).xx,y=(*it).yy;
			x+=y;
			while(x<=fib[i+3]+fib[i]){
				a[i+1].push_back(mp(y,x));
				x+=y;
			}
			it++;
		}
	}
	while(tes--){
		n=rd(),m=rd();
		if(n>m) swap(n,m);ans=1;
		while(fib[ans+1]<=n&&fib[ans+2]<=m) ans++;
		printf("%d ",ans);
		if(ans==1){
			printf("%lld\n",n*m%mod);
			continue;
		}
		else{
			num=0;it=a[ans-1].begin();
			while(it!=a[ans-1].end()){
				x=(*it).xx;y=(*it).yy;
				if(y<=n){
					num=(num+(m-x)/y)%mod;
				}
				if(y<=m){
					num=(num+(n-x)/y)%mod;
				}
				it++;
			}
			printf("%d\n",num);
		}
	}
	return 0;
}

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

int main() {
  int W,H,N;
  cin >> W >> H >> N;
  vector<vector<int>> L(N, vector<int>(3));
  rep(i,N) cin >> L[i][0] >> L[i][1] >> L[i][2];
  int left=0,right=W,bottom=0,top=H;
  rep(i,N) {
    if(L[i][2]==1) left = max(left,L[i][0]);
    if(L[i][2]==2) right = min(right,L[i][0]);
    if(L[i][2]==3) bottom = max(bottom,L[i][1]);
    if(L[i][2]==4) top = min(top,L[i][1]);
  }
  if(left >= right || top <= bottom) cout << 0 << endl;
  else cout << (right-left)*(top-bottom) << endl;
}

Measured memory_bytes: 3584
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <stack>
#include <cmath>
#define ll long long
#define out(a) printf("%d",a)
using namespace std;
int n;
int t[100050],x[100050],y[100050];
int dis,times;
bool flag;
int read()
{
	int s=0,t=1; char c;
	while (c<'0'||c>'9') {if (c=='-') t=-1; c=getchar();}
	while (c>='0'&&c<='9') {s=s*10+c-'0'; c=getchar();}
    return s*t;
}
int main()
{
	n=read(); flag=true;
	for (int i=1;i<=n;i++) {
	  t[i]=read(),x[i]=read(),y[i]=read();
      dis=x[i]-x[i-1]+y[i]-y[i-1]; times=t[i]-t[i-1];
      if (times<dis) flag=false;
      else {
	  times-=dis; 
	  if (times%2!=0) flag=false;
      }
      if (not flag) break;
  }
  if (flag) puts("Yes");
  else puts("No");
  return 0;
}


Measured memory_bytes: 1408
n,x = map(int,input().split())
a = sorted(list(map(int,input().split())))

ans = 0
for i in range(len(a)):
    if not i == len(a)-1:
        if x > a[i]:
            ans += 1
            x = x-a[i]
        elif x == a[i]:
            ans += 1
            break
        else: #x < a[i]
            break
    else:
        if x == a[i]:
            ans += 1
        else:
            pass

print (ans)


Measured memory_bytes: 3060
#include <iostream>
#include <sstream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    int N, K;
    cin >> N >> K;
    const lint MOD = 1000000007;
    lint ret = 1;
    FOR(i, K, N + 1) {
        ret += (N - i + 1) * 1LL * i + 1;
        ret %= MOD;
    }
    cout << ret << endl;
    return 0;
};


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll inf=1e18;
const int N=6000;
ll d[N],e[N];
int a[N],b[N],c[N];
int n,m,p;
int main() {
//	freopen("p.in","r",stdin);
//	freopen("p.out","w",stdout);
	cin>>n>>m>>p;
	for(int i=1; i<=m; i++) {
		cin>>a[i]>>b[i]>>c[i];
		c[i]=p-c[i];
	}
	for(int i=2; i<=n; i++)d[i]=e[i]=inf;
	for(int j=1; j<=n-1; j++)
		for(int i=1; i<=m; i++)
			if(d[b[i]]>d[a[i]]+c[i]&&d[a[i]]!=inf)d[b[i]]=d[a[i]]+c[i];
	e[1]=inf;
	e[n]=0;
	for(int j=1; j<=n-1; j++)
		for(int i=1; i<=m; i++)
			if(e[a[i]]>e[b[i]]+c[i]&&e[b[i]]!=inf)e[a[i]]=e[b[i]]+c[i];

	for(int i=1; i<=m; i++)if(d[a[i]]<inf&&e[a[i]]<inf&&d[b[i]]<inf&&e[b[i]]<inf&&d[b[i]]>d[a[i]]+c[i]) {
			printf("-1");
			return 0;
		}
	ll ans=-1*d[n];
	if(ans<0)ans=0;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 384
import java.util.*;
import java.io.*;

class Main{
  static PrintWriter out = new PrintWriter(System.out);
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int a = sc.nextInt();
    int b = sc.nextInt();
    String s = sc.next();
    int nai = 0;
    int gai = 0;
    for(int i=0;i<n;i++){
      if(s.charAt(i)=='a'){
        if(nai+gai<a+b){
          out.println("Yes");
          nai++;
        }else{
          out.println("No");
        }
      }else if(s.charAt(i)=='b'){
        if(nai+gai<a+b&&gai<b){
          out.println("Yes");
          gai++;
        }else{
          out.println("No");
        }
      }else{
        out.println("No");
      }
    }
    out.flush();
  }
}

Measured memory_bytes: 26624
char p[15] = "aaaaaaaaaaaaaa\0";
int n, tok = 0;

void dfs(int lst) {
  if (tok == n) {
    for (int i = 0; i < n; ++i) {
      printf("%c", p[i]);
    }
    puts("");
    return;
  }
  for (int i = 0; i <= lst+1; ++i) {
    p[tok++] = (char)('a'+i);
    dfs(i>lst?i:lst);
    --tok;
  }
}

main() {
  scanf("%d", &n);
  dfs(-1);
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
int main(){
	ios_base :: sync_with_stdio(false);
	cin.tie(NULL);             
	bool a = false, b = false;
	char ch;
	while(cin >> ch){
		if(ch == 'A')	a = true;
		else if (ch == 'B') b = true;
	}	
	if(a && b)
		cout << "Yes\n";
	else
		cout << "No\n";
	return 0;    	
}

Measured memory_bytes: 256
N = int(input())
lstB = list(map(int,input().split()))

lstA = []

for i in range(N):
    if i == 0:
        lstA.append( lstB[i] )
    elif i == N-1:
        lstA.append( lstB[i-1] )
    else:
        lstA.append( min(lstB[i],lstB[i-1]))
        
print(sum(lstA))



Measured memory_bytes: 3060
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
using namespace std;
typedef long long ll;
ll mod = 1000000007;


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

Measured memory_bytes: 256
#include <array>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
#include <tuple>
using namespace std;


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

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}

template <class T>
T clampMax(const T& a, const T& b) { return min(a, b); }

template <class T>
T clampMin(const T& a, const T& b) { return max(a, b); }

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

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

#define REP(i,n) for(int i=0;i<int(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define RALL(v) (v).rbegin(),(v).rend()
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define PB push


#define MOD 1000000007LL
#define EPS 1e-10

int N;
vector<LL> a;
bool visited[3010][3010];
LL dp[3010][3010];

LL Solve(int l, int r)
{
    if (l > r) return 0;
    if (visited[l][r]) return dp[l][r];

    visited[l][r] = true;

    int diff = N - (r - l + 1);

    LL res = 0;

    if (diff % 2 == 0)
    {
        res = -100000000000000;
        updateMax(res, Solve(l + 1, r) + a[l]);
        updateMax(res, Solve(l, r - 1) + a[r]);
    }
    else
    {
        res = 100000000000000;
        updateMin(res, Solve(l + 1, r) - a[l]);
        updateMin(res, Solve(l, r - 1) - a[r]);
    }

    return dp[l][r] = res;
}

int main()
{
    cin >> N;
    a.resize(N);
    REP(i, N)
    {
        cin >> a[i];
    }
    REP(l, 3010) REP(r, 3010) dp[l][r] = -1;
    cout << Solve(0, N - 1) << endl;
    return 0;
}

Measured memory_bytes: 80128
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <iomanip>
#define ll long long
using namespace std;
int main(){
    ll n,k;
    cin>>n>>k;
    double nc=1.0/(double)n;
    double ans=0;
    for(ll i=1;i<n+1;i++){
        ll point=i;        
        ll d=0;
        for(ll j=1;j<19;j++){
            if(point>=k) {
                ans+=nc*pow(0.5,d);
                break;
            }
            point*=2;
            d++;
        }        
    }
    cout<<fixed<<setprecision(15)<<ans<<endl;
    return 0;
}


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

int main() {
  int k;
  string s;
  cin >> k >> s;
  
  if (s.size() <= k) cout << s << endl;
  else {
    for (int i = 0; i < k; i++) {
      cout << s.at(i);
    }
    cout << "..." << endl;
  }
}

Measured memory_bytes: 3576
import java.util.*;
class Main {

	public static Boolean process(String s) {
		int i = 0, j = s.length() - 1;
		while(i < j) {
			if(s.charAt(i) != s.charAt(j)) {
				return false;
			}
			i++;
			j--;
		}
		return true;
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int n = s.length();
		String s1 = s.substring(0, ((n-1)/2));
		String s2 = s.substring((n+3)/2 - 1, n);

		if(process(s) && process(s1) && process(s2)) {
			System.out.println("Yes");	
		}
		else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 24916
package main

import "fmt"

func main() {

	var (
		n int
		q int
		s string
		l int
		r int
	)

	fmt.Scan(&n, &q)
	acCnt := make([]int, n)

	fmt.Scan(&s)

	for i := 1; i < n; i++ {
		acCnt[i] = acCnt[i-1]
		if s[i-1] == 'A' && s[i] == 'C' {
			acCnt[i]++
		}
	}

	for i := 0; i < q; i++ {
		fmt.Scan(&l, &r)
		fmt.Println(acCnt[r-1] - acCnt[l-1])
	}
}


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

/* #pragma */
/*
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
*/

/*alias*/
#define F first
#define S second

#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define itn int

/*template*/
template<class T>inline bool amax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>inline bool amin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }

/* func */
int GCD(int a,int b){return b?GCD(b,a%b):a;}
long long GCD(long long a, long long b){return b ? GCD(b, a%b) : a;}
int LCM(int a, int b){return a * b / GCD(a, b);}
long long LCM(long long a, long long b){return a * b / GCD(a, b);}

/*struct*/
struct aaa {
	aaa() {
		cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20);
	};
}aaaaaaa;

/* const */
const int INF = 1001001001;
const long long LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7; //10^9
const double EPS = 1e-9;
const int dx[] = { 1, 1, 0, -1, -1, -1, 0, 1 }, dy[] = { 0, 1, 1, 1, 0, -1, -1, -1 };
//const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
//Counterclockwise from the 6o'clock direction
//Take the x-axis downward and the y-axis right

#define int long long

//g++ -std=c++14 -Wall --pedantic-errors -o template template.cpp
//chcp 65001

signed main()
{
	int r, d, x; cin >> r >> d >> x;
	int x1,x2,x3,x4,x5,x6,x7,x8,x9,x10;
	for(int i = 0; i < 10; ++i){
		if(i == 0)x1 = r*x-d;
		if(i == 1)x2 = r*x1-d;
		if(i == 2)x3 = r*x2-d;
		if(i == 3)x4 = r*x3-d;
		if(i == 4)x5 = r*x4-d;
		if(i == 5)x6 = r*x5-d;
		if(i == 6)x7 = r*x6-d;
		if(i == 7)x8 = r*x7-d;
		if(i == 8)x9 = r*x8-d;
		if(i == 9)x10 = r*x9-d;
	}
	cout << x1 << endl;
	cout << x2 << endl;
	cout << x3 << endl;
	cout << x4 << endl;
	cout << x5 << endl;
	cout << x6 << endl;
	cout << x7 << endl;
	cout << x8 << endl;
	cout << x9 << endl;
	cout << x10 << endl;
	return 0;
}


Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<numeric>
#include<cstdio>
#include<cmath>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<ctype.h>
#include <fstream>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
using namespace std;
typedef long long ll;//int64
typedef unsigned long long ull;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a*b/gcd(a,b);}
int dy[4]={0,1,0,-1};
//----------program from here----------

int main(){
  int N=0,A=0,B=0;
  cin >> N >> A >> B;
  cout << (A*N<B?A*N:B) << endl;

  return 0;
}

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

typedef pair<int, int> P;
typedef priority_queue<int, vector<int>, greater<int>> PQ;
const int MOD = 1000000007;

const int maxv = 100005;




int main(){
    string s, t;
    map<char, vector<int>> counter;
    cin >> s >> t;

    rep(i,s.size()){
        int index = i+1;
        // 各文字毎の出現位置を格納
        counter[s[i]].push_back(index);
    }

    ll ans = 0;
    int prev_index;
    // tの文字数分繰り返す
    rep(i, t.size()){
        char ch = t[i];
        // Sに登場しなかった場合は終了
        if (counter[ch].empty()){
            cout << -1 << endl;
            return 0;
        }
        if (i == 0) {
            prev_index = counter[ch][0];
            ans = prev_index;
            continue;
        }
        else{
            int size = counter[ch].size();
            vector<int> c = counter[ch];
            int next_index;
            if (prev_index >= c[size-1]){
                next_index = c[0];
            }
            else{
                int c_index = upper_bound(c.begin(), c.end(), prev_index) - c.begin();
                next_index = c[c_index];
            }

           if (prev_index < next_index){
                ans += next_index - prev_index;
            }else{
                ans += next_index + (s.size() - prev_index);
            }
            prev_index = next_index;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 4404
#include <cstdio>
int A, K, M, N;

int bitcount(unsigned int n) { return n ? __builtin_popcount(n) : 0; }

int main() {
  scanf(" %d%d", &N, &M);
  int every = (1<<M) - 1;
  for (int i = 0; i < N; ++i) {
    int mask = 0;
    scanf("%d", &K);
    for (int j = 0; j < K; ++j) {
      scanf("%d", &A);
      mask |= (1<<(A-1));
    }
    every &= mask;
  }
  printf("%d\n", bitcount(every));
  return 0;
}

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

int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n, a, b; cin >> n;
    int mx = 0, cnt = 0;

    for(int i=0; i<n; ++i)
    {
        cin >> a >> b;

        if(a == b) cnt++;
        else cnt = 0;

        mx = max(cnt,mx);
    }
    cout << ((mx>=3)? "Yes" : "No") << endl;


    return 0;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a) for(int i=0; i<(int)(a); i++)
typedef long long ll;
const ll INF = 1LL<<60;

int main()
{
  string s; cin>>s;
  string t = "";
  ll n = s.size();
  rep(i, n) {
    if (i < n-1) {
      if (s[i] == 'B' && s[i+1] == 'C') {
        t.push_back('D');
        i++;
        continue;
      }
    }
    t.push_back(s[i]);
  }

  ll a = 0;
  ll ans = 0;
  for (auto c:t) {
    if (c == 'A') a++;
    else if (c == 'D') ans += a;
    else a = 0;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 776
#include<bits/stdc++.h>
#define fr first
#define sc second
#define pb push_back
#define ll long long
#define maxheap priority_queue<int>
#define minheap priority_queue<int,vector<int>,greater<int>>
const double pi = acos(-1.0);
const double eps = 1e-9;
using namespace std;

void solve(){
    int n;
    cin >> n;
    vector <ll> a(n), b(n);
    
    
    for (int i = 0; i < n; i++)
        cin >> a[i] >> b[i];
    ll res = 0, ans = 0;
    for (int i = n - 1; i >= 0; i--){
        a[i] += res;
        ll oc = a[i] % b[i];
        ll need = (b[i] - oc) % b[i];
        ans += need;
        res += need;
     }
     cout << ans << endl;
}       
int main(){
    ios::sync_with_stdio(NULL), cin.tie(0), cout.tie(0);
    cout.setf(ios::fixed), cout.precision(20);
    //freopen("input.txt", "r", stdin);//freopen("output1.txt", "w", stdout);
    //freopen("icecream.in","r",stdin);// freopen("exam.out", "w", stdout);
    int step;
    step = 1;
    //cin >> step;
    for (int i = 1; i <= step; i++){
         solve();
    }
}

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

#ifdef DEBUG
#define PRINT(x)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#x<<" = "<<(x)<<endl;
#define PRINTA(a,first,last)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#a<<"["<<(first)<<", "<<(last)<<")"<<endl;\
    for (int i=(first);i<(last);++i){cout<<#a<<"["<<i<<"] = "<<(a)[i]<<endl;}
#else
#define PRINT(x)
#define PRINTA(a,first,last)
#endif

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

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

ll powint(ll n, int k)
{
    ll ret = 1;
    while (k > 0) {
        ret *= n;
        k--;
    }
    return ret;
}

int f(ll n)
{
    if (n <= 9) {
        return n;
    }
    ll m = n;
    int k = 0;
    while (m >= 10) {
        m /= 10;
        k++;
    }
    return max(m - 1 + 9 * k, m + f(n - m * powint(10, k)));
}

int main(void)
{
    ll N;
    cin >> N;
    cout << f(N) << endl;
    return 0;
}


Measured memory_bytes: 256
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    H,W=INTM()
    h,w=INTM()
    print(H*W-H*w-h*W+h*w)
if __name__ == '__main__':
    do()

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

template <class T>
T gcd(T a, T b) {

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

int main() {

    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n){
        cin >> a[i];
    }
    vector<int> l(n), r(n);
    l[0] = a[0];
    r[n-1] = a[n-1];
    REP(i, 1, n){
        l[i] = gcd(l[i-1], a[i]);
    }
    for(int i=n-2; i>=0; --i){
        r[i] = gcd(r[i+1], a[i]);
    }

    int ans = 0;
    REP(i, 1, n-1){
        int res = gcd(l[i-1], r[i+1]);
        ans = max(ans, res);
    }
    ans = max(ans, l[n-2]);
    ans = max(ans, r[1]);

    cout << ans << endl;

    return 0;
}

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

int main(){
  int p,i;
  string c;
  
  c = "No";
  
  cin >> p;
  
  for(i=1;i<10;i++){
    if(p/i<10 && p%i==0){
      c = "Yes";
    }
  }
  
  cout << c << '\n';
  
  return 0;
  
}

Measured memory_bytes: 256
N=int(input())
S=[]
for n in range(N):
    S.append( input() )
AC, WA, TLE, RE = 0, 0, 0, 0
for n in range(N):
    if S[n]=='AC':
        AC += 1
    elif S[n]=='WA':
        WA += 1
    elif S[n]=='TLE':
        TLE += 1
    elif S[n]=='RE':
        RE += 1
print('AC x %d' % AC)
print('WA x %d' % WA)
print('TLE x %d' % TLE)
print('RE x %d' % RE)


Measured memory_bytes: 16268
import math
def main():
    a, b, x = map(float, input().split())
    thX = a * a * b / 2.0
    if x == (a*a*b):
        print(0)
    elif x <= thX:
        h = 2.0 * x / (a * b)
        deg = math.degrees(math.atan(h / b))
        print(90.0 - deg)
    else:
        c = 2.0 * x / (a*a) - b
        deg = math.degrees(math.atan(a / (b-c)))
        print(90.0 - deg)

main()

Measured memory_bytes: 3060
/*input
6 0



*/

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

#define rep(i,j,n) for(i=j;i<n;i++)
#define repi(i,j,n) for(i=j;i>n;i--)
#define inf 100001
#define M 1000000007
#define ll long long
#define vll vector<long long>
#define vi vector<int>
#define pll pair<long long,long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define vpll vector<pair<long long,long long> >
#define pb push_back
#define pf pop_front
#define mp make_pair
#define F first
#define S second


ll power(ll a,ll m,ll mod){
	ll ans=1;
	while(m){
		if(m%2){
			ans*=a;
			ans%=(mod);
		}
		a=(a*a)%(mod);
		m>>=1;
	}
	return ans;
}


void init(long long* a,long long n,long long val){
	for(long long i=0;i<n;i++)
		a[i]=val;
}



int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);	
	ll t=1,i,j;
	ll n,m;
	cin>>n>>m;
	ll x,y;
	ll a=0,b=0;
	vll v[n];
	string s;
	rep(i,0,m){
		cin>>x>>s;
		if(s=="WA")
			y=0;
		else
			y=1;
		v[x-1].pb(y);
	}
	rep(i,0,n){
		rep(j,0,v[i].size()){
			if(v[i][j]){
				a++;
				b+=j;
				break;
			}
		}
	}
	cout<<a<<" "<<b<<endl;

	return 0;
}




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

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

using ll = long long int;
const ll MOD = 1e9 + 7;

int main() {
  int N, X, Y;
  std::cin >> N >> X >> Y;
  --X;
  --Y;
  if(X > Y) {
    std::swap(X, Y);
  }

  std::map<int, int> cnt;
  rep(i, N) {
    for(int j = i + 1; j < N; ++j) {
      int d = std::min(j - i, std::abs(i - X) + 1 + std::abs(j - Y));
      ++cnt[d];
    }
  }

  for(int k = 1; k < N; ++k) {
    std::cout << cnt[k] << '\n';
  }
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define endl '\n'
#define ld long double
typedef pair<ll,ll> pii;
const int maxn=100005;
const int mod=1e9+7;
int a[maxn];
int calc(int x,int n)
{
    int ret=0;
    for(int i=1;i<=n;i++) ret+=(a[i]-x)*(a[i]-x);
    return ret;
}
int main()
{
    #ifdef local
    freopen("in.txt","r",stdin);
    #endif // local
    IOS;
    int n;
    cin>>n;
    for(int i=1;i<=n;i++) cin>>a[i];
    int mn=1e9;
    for(int i=-100;i<=100;i++) mn=min(mn,calc(i,n));
    cout<<mn<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    ll sum = 0;
    for(int i = 1; i <= n; i++){
        if(i%3 != 0 && i%5 != 0){
            sum += i;
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 3656
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <bitset>
#include <cstring>
#include <map>
#include <math.h>
#include <queue>
#include <set>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i,n) for (int i = 0; i < n; i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fi first
#define se second
#define pb push_back
#define mp make_pair
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 1<<30;
const ll LINF = 1LL<<58;
const int mod = 1000000007;

string s;
int n;
ll ans = 0;

void DFS(string str){
    if(str.size()==n){
        ll tmp = 0;
        rep(i,n){
            if(str[i] == '+'){
                ans += tmp;
                tmp = s[i]-'0';
            }
            else{
                tmp = tmp*10 + s[i]-'0';
            }
        }
        ans += tmp;
        return;
    }
    DFS(str+"+");
    DFS(str+"_");
}

int main(){
    cin >> s;
    n = s.size();
    DFS("_");
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#include "string.h"
 
using namespace std;
 
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define NFOR(i,a,b) for(ll i=a;i>b;i--)
#define sz(a) int((a).size())
#define all(c) c.begin(),c.end()
#define loop(c,i) for(typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define pb push_back
#define mp make_pair
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mod 1000000007
#define MAX 200005
#define f first
#define s second
 
typedef unsigned long long ull;
typedef long long ll;
 
//4 and 8 directions
int dx4[]={1,0,-1,0};
int dy4[]={0,1,0,-1};
int dx8[]={1,1,0,-1,-1,-1,0,1};
int dy8[]={0,1,1,1,0,-1,-1,-1};
 
inline void swap(ll *a,ll *b){ ll temp=*a; *a=*b; *b=temp;}
inline ll add(ll a, ll b,ll m) { return a + b >= m ? a + b - m : a + b; }
inline ll sub(ll a, ll b,ll m) { return a - b < 0 ? a - b + m :a - b; }
inline ll mul(ll a, ll b) { return a * 1ll * b % mod; }
inline ll setbits(ll a){ return __builtin_popcount(a);}
inline ll bit32(ll a){ return 31-__builtin_clz(a);}
inline ll bit64(ll a){ return 63-__builtin_clzll(a);}
inline ll parent(ll a){ return (a-1)>>1;}

ll arr[200005];

vector<ll>line;
vector<ll>cycle;
ll vis[200005];

int main(){
  boost
  ll n,k;
  cin>>n>>k;
  FOR(i,1,n+1) cin>>arr[i];
  ll town = 1;
  while(!vis[town]){
    vis[town] = 1;
    line.push_back(town);
    town = arr[town];
  }
  
  bool flag = false;
  ll cnt = 0;
  for(auto it:line){
    if(it == town){
      flag = true;
    }
    if(flag){
      cycle.push_back(it);
    } else{
      cnt+=1;
    }
  }
  cycle.push_back(town);
  
  if(k<line.size()){
    
    cout<<line[k];
  }else{
    k = k-cnt;

    ll sz = cycle.size()-1;
    k=k%sz;
    cout<<cycle[k];
  }

  return 0;
}


/*
6 4
6 5 2 5 3 2*/



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

int main() {
  string S;
  cin >> S;
  int C0 = 0, C1 = 0;
  int N = S.size();
  for (int i=0; i<N; i++) {
    if (S.at(i) == '0') {
      C0++;
    }
    else {
      C1++;
    }
  }
  int answer = 2*min(C0, C1);
  cout << answer << endl;
}

Measured memory_bytes: 512
import sys
s = input()

l = s.replace("x", "")
ll = len(l) // 2
lr = len(l) - ll
if l[:ll] != l[lr:][::-1]:
    print(-1)
    sys.exit()

xcnt = [0] * lr
c = 0
cnt = 0
i = 0
while c != lr:
    if s[i] != "x":
        xcnt[c] = cnt
        c += 1
        cnt = 0
    else:
        cnt += 1
    i += 1
    
c = 0
cnt = 0
i = len(s) - 1
while c != lr:
    if s[i] != "x":
        xcnt[c] -= cnt
        xcnt[c] = abs(xcnt[c])
        c += 1
        cnt = 0
    else:
        cnt += 1
    i -= 1

print(sum(xcnt))

Measured memory_bytes: 3680
#include "iostream"
#include "vector"
#include "string"
#include "algorithm"
#include "math.h"
#include "cstring"
#include "stack"
#include "queue"
#include "cmath"
#include "set"
#include "map"

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<vector<ll> > mat;

const ll mod = 1e9 + 7;
const int MAX_N = 100100;
const int MAX_Q = 100100;
struct UnionFind
{
  int par[MAX_N];	//親
  int height[MAX_N];	//木の深さ
  int size[MAX_N];	//子の数

	//n要素で初期化
  void init (int n)
  {
    for (int i = 0; i < n; i++)
    {
      par[i] = i;
      height[i] = 0;
      size[i] = 1;
    }
  }

	//木の根を求める
  int find (int x)
  {
    if (par[x] == x)
    {
      return x;
    }
    else
    {
      return par[x] = find(par[x]);
    }
  }

	//xとyの属する集合を併合
  void unite (int x, int y)
  {
    x = find(x);
    y = find(y);
    if (x == y)
    {
      return;
    }

    if (height[x] < height[y])
    {
      par[x] = y;
      size[y] = size[x] + size[y];
    }
    else
    {
      par[y] = x;
      size[x] = size[x] + size[y];
      if (height[x] == height[y])
      {
        height[x]++;
      }
    }
  }

	//xとyが同じ集合に属するか否か
  bool same (int x, int y)
  {
    return find(x) == find(y);
  }

  int siz (int x)
  {
    return size[x];
  }
};

int main()
{
  int n, m, k;
  cin >> n >> m >> k;
  UnionFind uf;
  uf.init(n);
  int a[MAX_N], b[MAX_N], c[MAX_N], d[MAX_N];
  for (int i = 0; i < m; i++)
  {
    cin >> a[i] >> b[i];
    a[i]--;
    b[i]--;
    uf.unite(a[i], b[i]);
  }

  int ans[MAX_N];
  for (int i = 0; i < n; i++)
  {
    ans[i] = uf.siz(uf.find(i)) - 1;
  }

  for (int i = 0; i < m; i++)
  {
    if (uf.same(a[i], b[i]))
    {
      ans[a[i]]--;
      ans[b[i]]--;
    }
  }
  for (int i = 0; i < k; i++)
  {
    cin >> c[i] >> d[i];
    c[i]--;
    d[i]--;
    if (uf.same(c[i], d[i]))
    {
      ans[c[i]]--;
      ans[d[i]]--;
    }
  }
  for (int i = 0; i < n; i++)
  {
    cout << ans[i] << " ";
  }
  cout << "\n";
}

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

int main()
{
  int n;
  cin >> n;
  vector<string> s(n);
  for (int i = 0; i < n; i++) {
    cin >> s.at(i);
    sort(s.at(i).begin(), s.at(i).end());
  }
  sort(s.begin(), s.end());
  long total = 0, serial = 0;
  for (int i = 1; i < n; i++) {
    if (s.at(i) == s.at(i - 1)) {
      serial++;
    } else {
      serial = 0;
    }
    total += serial;
  }
  cout << total << endl;
}


Measured memory_bytes: 7296
a = input()
b = input()
c = input()
li = [a,b,c]


d = a[0]
a = a[1:]
while True:
    if d == "a":
        if a == "":
            print("A")
            break
        d = a[0]
        if a != "":
            a = a[1:]
    elif d == "b":
        if b == "":
            print("B")
            break
        d = b[0]
        if b != "":
            b = b[1:]
    else:
        if c == "":
            print("C")
            break
        d = c[0]
        if c != "":
            c = c[1:]

Measured memory_bytes: 3064
h, w = map(int, input().split())

total = []
tmp = ''
for i in range(w+2):
    tmp += '.'
total.append(tmp)

for i in range(h):
    tmp = '.'
    row = input()
    tmp += row
    tmp += '.'
    total.append(tmp)

tmp = ''
for i in range(w+2):
    tmp += '.'
total.append(tmp)

flag = 0
for i in range(1, h+1):
    for j in range(1, w+1):
        if total[i][j] == '#' and total[i-1][j] == '.' and total[i+1][j] == '.' and total[i][j-1] == '.' and total[i][j+1] == '.':
            flag = 1

if flag:
    print('No')
else:
    print('Yes')

Measured memory_bytes: 3064
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iomanip>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define esb(x,e,b) (int e=fst[x],b=vb[e];e;e=nxt[e],b=vb[e])
#define SZ 666666
int n,m,d[2][SZ]; Edg
char s[SZ];
queue<int> q;
int vis[SZ];
int main()
{
	scanf("%d%d%s",&n,&m,s+1);
	for(int i=1,a,b;i<=m;++i)
		scanf("%d%d",&a,&b),
		++d[s[a]-'A'][b],
		++d[s[b]-'A'][a],
		adde(a,b);
	for(int i=1;i<=n;++i)
		if(d[0][i]&&d[1][i]);
		else q.push(i),vis[i]=1;
	while(!q.empty())
	{
		int x=q.front(); q.pop();
		for esb(x,e,b) if(!vis[b])
		{
			if(!(--d[s[x]-'A'][b]))
				q.push(b),vis[b]=1;
		}
	}
	for(int i=1;i<=n;++i)
		if(!vis[i])
		{
			puts("Yes");
			return 0;
		}
	puts("No");
}


Measured memory_bytes: 13824
N = gets.to_i
ws = N.times.map{gets.chomp}

if ws.uniq.length != ws.length
    puts 'No'
    exit
end

(N-1).times do |i|
    if ws[i][-1] != ws[i+1][0]
        puts 'No'
        exit
    end
end

puts 'Yes'

Measured memory_bytes: 1788
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		int l = in.nextInt();
		int r = in.nextInt();
		System.out.println(solve(l, r));
		in.close();
	}

	private static int solve(int l, int r) {
		int s = 2019;
		if (l % 2019 == 0)
			return 0;
		if ((l / 2019 + 1) * 2019 <= r)
			return 0;
		for (int i = l % 2019; i < r % 2019; i++)
			for (int j = i + 1; j <= r % 2019; j++)
				if (s > (i * j) % 2019)
					s = (i * j) % 2019;
		return s;
	}
}


Measured memory_bytes: 21332
use std::io;

fn main(){
	let mut buf = String::new();
	io::stdin().read_line(&mut buf).expect("can't read line");
	let s = buf.trim();
	if s[0..1]==s[1..2] && s[1..2] == s[2..3] && s[0..1] == s[2..3] {
		println!("No");
	}else{
		println!("Yes");
	}
}

Measured memory_bytes: 4352
#include <iostream>
#include <queue>
using namespace std;
int main(){
  string s;
  cin>>s;
  int n,q,w,i;
  cin>>n;
  while(n--){
    string a,b;
    cin>>a;
    if(a[2]=='p'){
      int c=0;
      cin>>q>>w>>b;
      for(i=q;i<=w;i++)s[i]=b[c++];
    }
    else if(a[2]=='v'){
      int c=0;
      cin>>q>>w;
      for(i=q;i<=w;i++)b[c++]=s[i];
      for(c=0,i=w;i>=q;i--)s[i]=b[c++];
    }
    else{
      cin>>q>>w;
      for(i=q;i<=w;i++)cout<<s[i];
      cout<<endl;
    }
  }
}



Measured memory_bytes: 3220
//
// Created by yamunaku on 2020/06/13.
//

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repl(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perl(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD9 998244353
#define MOD1 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)
#define CST(x) cout<<fixed<<setprecision(x)

using ll = long long;
using ld = long double;
using vi = vector<int>;
using mti = vector<vector<int>>;
using vl = vector<ll>;
using mtl = vector<vector<ll>>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
template<typename T>
using heap = priority_queue<T, vector<T>, function<bool(const T, const T)>>;

int main(){
    //CFS;
    int n;
    cin >> n;
    vi v(n), w(n);
    rep(i, n){
        cin >> v[i] >> w[i];
    }
    int ppp = (1 << 9) - 2;
    vector<vector<pair<int, int>>> dp1(ppp + 1);
    dp1[0].push_back({0, 0});
    dp1[0].push_back({w[0], v[0]});
    repl(i, 1, ppp + 1){
        int p = (i - 1) / 2;
        for(auto &c : dp1[p]){
            dp1[i].push_back({c.first, c.second});
            dp1[i].push_back({c.first + w[i], c.second + v[i]});
        }
        sort(all(dp1[i]));
    }
    int q;
    cin >> q;
    rep(t, q){
        int s, l;
        cin >> s >> l;
        s--;
        if(s <= ppp){
            vector<pair<int, int>> dp2;
            dp2.push_back({0, 0});
            while(1){
                per(k, dp2.size()){
                    if(dp2[k].first + w[s] <= l)
                        dp2.push_back({dp2[k].first + w[s], dp2[k].second + v[s]});
                }
                if(s == 0) break;
                s = (s - 1) / 2;
            }
            int ans = 0;
            for(auto &c : dp2){
                if(c.second > ans) ans = c.second;
            }
            cout << ans << endl;
            continue;
        }
        vector<pair<int, int>> dp2;
        dp2.push_back({0, 0});
        while(s > ppp){
            per(k, dp2.size()){
                if(dp2[k].first + w[s] <= l)
                    dp2.push_back({dp2[k].first + w[s], dp2[k].second + v[s]});
            }
            s = (s - 1) / 2;
        }
        int ans = 0;
        sort(all(dp2));
        int idx = 0;
        int ma = 0;
        int sz = dp1[s].size();
        per(i, dp2.size()){
            while(idx < sz - 1){
                if(dp1[s][idx + 1].first + dp2[i].first > l) break;
                ma = max(ma, dp1[s][idx + 1].second);
                idx++;
            }
//            cout << s SP i SP ma SP l - dp2[i].first SP dp2[i].first SP dp2[i].second << endl;
            ans = max(ans, ma + dp2[i].second);
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 6692
package main

import "fmt"

func main() {
	var n, L int
	fmt.Scan(&n, &L)
	sum := 0
	for i := 0; i < n; i++ {
		sum += L + i
	}
	ans := 0
	dif := 9999999
	for i := 0; i < n; i++ {
		if abs(L+i) < dif {
			dif = abs(L + i)
			ans = L + i
		}
	}
	fmt.Println(sum - ans)
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}


Measured memory_bytes: 512