akhauriyash/Code-Regression huggingface dataset:
import math

if __name__ == '__main__':
    s = input().split(' ')
    X, K, D = abs(int(s[0])), int(s[1]), int(s[2])

    a = X // D

    if a >= K:
        print(X - K*D)

    else:
        if (K -a)  % 2 == 0:
            print(X % D)
        else:
            print(D - X % D)


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

typedef double du ;
typedef string st ;
typedef long long ll ;
typedef long double ld ;
typedef long long int lli ;

#define vi vector <lli>
#define loop(num) for (lli i = 0 ; i < num ; i ++ )
#define loopcin(num , ar ) for (lli i = 0 ; i < num ; i ++ ) {cin >> ar [i] ;}
#define loopcout(num , ar) for (lli i = 0 ; i < num ; i ++ ) {cout << ar [i] << ' '; }

#define forr(num1 , num2) for (lli i = num1 ; i < num2 ; i ++ )
#define forrcin(num1 , num2 , ar ) for (lli i = num1 ; i < num2 ; i ++ ) {cin >> ar [i] ;}
#define forrcout(num1 , num2 , ar) for (lli i = num1 ; i < num2 ; i ++ ) {cout << ar [i] << ' '; }

#define D2forrcin(num1_1 , num1_2 , num2_1 , num2_2 , A ) for (lli i = num1_1 ; i < num1_2 ; i ++){ for (lli j = num2_1 ; j < num2_2 ; j++){cin >> A[i][j] ;}}
#define D2forrcout(num1_1 , num1_2 , num2_1 , num2_2 , A ) for (lli i = num1_1 ; i < num1_2 ; i ++){ for (lli j = num2_1 ; j < num2_2 ; j++){cout << A[i][j] << ' ' ;}cout << endl ;}

#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl

#define F first
#define S second

#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

int main ()
{
    fastio
    set <lli> a ;
    loop(3)
    {
        lli x ;
        cin >> x ;
        a . insert (x) ;
    }
    (a. size() == 2 ? Yes : No ) ;


    return 0 ;
}

/*___________________________________________________________________functions___________________________________________________________________________*/



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

char a[51][51]={0}, b[51][51]={0};

int main(){
    int n,m;
    scanf("%d %d",&n,&m);
    getchar();
    for(int i=0;i<n;++i)
        for(int j=0;j<n;++j)
            scanf("%c ",&a[i][j]);
    for(int i=0;i<m;++i)
        for(int j=0;j<m;++j)
            scanf("%c ",&b[i][j]);

    bool flag;
    for(int i=0;i<=n-m;++i){
        for(int j=0;j<=n-m;++j){
            flag = false;
            for(int k=i;k<i+m;++k){
                for(int l=j;l<j+m;++l){
                    if(a[k][l] != b[k-i][l-j]){
                        flag = true;
                        break;
                    }
                }
                if(flag)break;
            }
            if(!flag)break;
        }
        if(!flag)break;
    }
    if(flag == false)printf("Yes\n");
    else printf("No\n");

    return 0;
}


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

int getDigital(int sum) {
	int a=1;
	while ( sum / 10 ) {
		a++;
		sum /= 10;
	}
	return a;
}

int main() {
	int a,b,c;
	while(cin >> a >> b) {
		c = getDigital(a + b);
		cout << c << endl;
	} 
} 

Measured memory_bytes: 2972
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <tuple>
#include <cmath>
using namespace std;

int main(int argc, const char * argv[]) {
  int n,x;
  cin >> n >> x;
  vector<int> m(n);
  int sum = 0;
  for(int i = 0; i < n ; i++){
    cin >> m.at(i);
    sum += m.at(i);
  }
  sort(m.begin(), m.end());
  int ans = n + (x - sum)/m.at(0);

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


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

int main()
{

    int a1,a2,a3;
    cin>>a1>>a2>>a3;
    int x1=abs(a1-a2)+abs(a2-a3);
    int x2=abs(a2-a1)+abs(a2-a3);
    int x3=abs(a1-a3)+abs(a3-a2);
    int x4=abs(a3-a1)+abs(a1-a2);
    int x5=abs(a2-a3)+abs(a3-a1);
    int x6=abs(a3-a2)+abs(a2-a1);
    vector<int>v;
    v.pb(x1);
    v.pb(x2);
    v.pb(x3);
    v.pb(x4);
    v.pb(x5);
    v.pb(x6);
    sort(v.begin(),v.end());
    cout<<v[0]<<endl;
}


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

int	main(void)
{
	long long x;
	cin >> x;
	int ans = 0;
	long long value = 100;
	while (1)
	{
		if (value >= x)
		{
			cout << ans << endl;
			return (0);
		}
		value += (value / 100);
		ans++;
	}
	return (0);
}


Measured memory_bytes: 3636
#include <stdio.h>

int main(void){
    
    int x,sq,po,i,max;
    max=0;
    scanf("%d",&x);
    
    for(i=1; i*i<=x; i++){
        sq=i*i;
        po=0;
        if(sq*i<=x){
            po=sq;
            while(po*i<=x && i!=1){
                po*=i;
            }
        }
        if(max<sq)
            max=sq;
        if(max<po)
            max=po;
    }
    printf("%d",max);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
#define fix10 cout << fixed << setprecision(10);
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define MOD 1000000007

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  if((a+b+c)%2==1) cout << "No" << endl;
  else{
    int n = (a+b+c)/2;
    if(a == n || b == n || c == n) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
}


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

static const int MAX = 100;
static const long long INFTY = (1LL<<32);

int n;
long long d[MAX][MAX];

void floyd(){
    for(int k = 0; k < n; k++){
        for(int i = 0; i < n; i++){
            if(d[i][k] == INFTY) continue;
            for(int j = 0; j < n; j++){
                if(d[k][j] == INFTY) continue;
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }
}

int main(){
    int e, u, v, c;
    cin >> n >> e;
    
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            d[i][j] = ((i == j) ? 0: INFTY);
        }
    }
    
    for(int i = 0; i < e; i++){
        cin >> u >> v >> c;
        d[u][v] = c;
    }
    
    floyd();
    
    bool negative = false;
    for(int i = 0; i < n; i++) if(d[i][i] < 0) negative = true;
    
    if(negative){
        cout << "NEGATIVE CYCLE" << endl;
    }
    else{
        for(int i = 0; i < n; i++){
            for(int j = 0; j < n; j++){
                if(j) cout << " ";
                if(d[i][j] == INFTY) cout << "INF";
                else cout << d[i][j];
            }
            cout << endl;
        }
    }
    
    return 0;
}


Measured memory_bytes: 3172
n = int(input())
As = [int(i) for i in input().split()]
Bs = [int(i) for i in input().split()]
ABs = sorted([a - b for a, b in zip(As, Bs)])
# print(As, Bs, ABs)
if sum(As) < sum(Bs):
    print(-1)
    exit()
if min(ABs) > 0:
    print(-1)
    exit()
mABs = [ab for ab in ABs if ab < 0]
msum, ans = sum(mABs), len(mABs)
# print(mABs, msum, ans)
now = -1
while msum < 0:
    msum += ABs[now]
    ans += 1
    now -= 1
print(ans)

Measured memory_bytes: 19060
abc = list(map(int, input().split()))

c = max(abc)
abc.remove(c)
a = abc[0]
b = abc[1]

#%%
d_ca = c - a
d_cb = c - b
if d_ca%2 == 0 and d_cb%2 == 0:
    ans = d_ca // 2 + d_cb // 2
elif d_ca%2 == 1 and d_cb%2 == 1:
    ans = d_ca // 2 + d_cb // 2 + 1
else:
    ans = d_ca // 2 + 1 + d_cb // 2 + 1

print(ans)

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

int main() {
    int a, b, c;
    cin >> a >> b >> c; 
    for (int i=1; i<=b; i++)
        if (a * i % b == c) {
            puts("YES");
            return 0;
        }
    puts("NO");
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <locale>
#include <iostream>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()

using namespace std;

using ll = long long;
using ld = long double;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> int len(const T &x) { return x.size(); }

template<typename T>
vector<T> table(int n, T v) { return vector<T>(n, v); }

template <class... Args>
auto table(int n, Args... args) {
  auto val = table(args...);
  return vector<decltype(val)>(n, move(val));
}

struct yes_no : numpunct<char> {
  string_type do_truename()  const { return "Yes"; }
  string_type do_falsename() const { return "No"; }
};

int dp[5010][5010];

void solve(ll N, vector<ll> H, vector<ll> P) {
  vector<tuple<int,int,int>> vec;
  REP(i,N) vec.emplace_back(P[i] + H[i], H[i], P[i]);
  sort(ALL(vec));
  REP(i,5010) REP(j,5010) dp[i][j] = 2e9 + 100;
  dp[0][0] = 0;
  REP(i,N) {
    int H, P;
    tie(ignore, H, P) = vec[i];
    REP(j,N+1) {
      chmin(dp[i+1][j], dp[i][j]);
      if (dp[i][j] <= H) {
        chmin(dp[i+1][j+1], dp[i][j] + P);
      }
    }
  }
  int res = 0;
  REP(j,N+1) if (dp[N][j] <= int(2e9 + 10)) res = j;
  cout << res << endl;
}

int main() {
  locale loc(locale(), new yes_no);
  cout << boolalpha << setprecision(12) << fixed;
  cout.imbue(loc);
	ll N;
	scanf("%lld", &N);
	vector<ll> P(N-1+1);
	vector<ll> H(N-1+1);
	for (int i = 0 ; i <= N-1 ; i++) {
	  scanf("%lld", &H[i]);
	  scanf("%lld", &P[i]);
	}
	solve(N, H, P);
	return 0;
}


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

int main() {
  ll N, M;
  cin >> N >> M;
  vector<ll> A(N);
  vector<pair<ll,ll>> B(M);
  ll sum = 0;
  for (ll &e : A) {
    cin >> e;
    sum += e;
  }
  
  for (auto &p : B) cin >> p.second >> p.first;
  
  sort(A.begin(), A.end());
  sort(B.begin(), B.end(), greater<pair<int,int>>());
  
  ll p = 0;
  for (ll i = 0; i < N; i++) {
    if (A[i] >= B[p].first) break;
    sum += (B[p].first-A[i]);
    B[p].second--;
    if (B[p].second == 0) p++;
  }
  
  cout << sum << endl;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N, T, ans = 2000;
  cin >> N >> T;
  for(int i = 0; i < N; i += 1){
    int c, t;
    cin >> c >> t;
    if(t <= T) ans = min(ans, c);
  }
  if(ans == 2000) cout << "TLE";
  else cout << ans;
}

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

int w,h;
string g[100];
const int dy[] = {-1,0,1,0}, dx[] = {0,1,0,-1};

int dfs(int y, int x){
  g[y][x] = '#';

  int res = 1;
  for(int i=0;i<4;i++){
    int ny = y+dy[i], nx = x+dx[i];
    if(ny<0 || nx<0 || ny>=h || nx>=w)continue;
    if(g[ny][nx] == '.')res += dfs(ny,nx);
  }
  return res;
}

int main(){
  while(cin >> w >> h, w){
    for(int i=0;i<h;i++)cin >> g[i];

    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	if(g[i][j] == '@')cout << dfs(i,j) << endl;
      }
    }
  }
}

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

int numdif(string s, string t) {
	int ans = 0;
	for (int i = 0; i < s.size(); i++)
		if (s[i] != t[i])
			ans++;
	cout << ans;
}

int main() {
	string s;
	cin >> s;
	numdif(s, "CODEFESTIVAL2016");
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fastio     ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define debug(x)   cerr<<#x<<": "<<x<<endl;
#define all(x)     (x).begin() , (x).end()
#define rep(i,a,b) for(int i=a;i<b;i++)
#define endl       '\n'
#define MAX        1000000
typedef long long int ll;
using namespace std;


const ll mod = 1e9+7;
const double eps = 1e-9;




void solve(){
    int n;
    cin>>n;
    set<string>s;
    while(n--){
        string tt;
        cin>>tt;
        s.insert(tt);
    }
    cout<<s.size();
}





int main(){
    fastio
    int test=1;
    while(test--)
        solve();
    return 0;
}


Measured memory_bytes: 19240
# import fractions
# import sys
from sys import stdin

w, h, n = map(int, stdin.readline().rstrip().split())

data = [list(map(int, stdin.readline().rstrip().split())) for i in range(n)]

l, r = 0, w
d, u = 0, h
for di in data:
    if di[2] == 1:
        if l < di[0]:
            l = di[0]
    elif di[2] == 2:
        if r > di[0]:
            r = di[0]
    elif di[2] == 3:
        if d < di[1]:
            d = di[1]
    else:
        if u > di[1]:
            u = di[1]


if (r - l) <= 0 or (u - d) <= 0:
    print(0)
else:
    print((r - l)*(u - d))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define F first
#define S second
#define MAXN   1000005
#define Tsetso ios_base::sync_with_stdio(0) ; cin.tie(0) ;
using namespace std;
const ll N = 1e4+10, inf = 1e3+5, mod = 1e9+7, NN = 1e6+10;
ll h,w, n, color[150][150],a[N];
int main()
{
    Tsetso ;
    cin >> h >> w >> n ;
    for ( int i = 1 ; i <= n ; i++)
        cin >> a[i];
    int idx= 1, cnt = 0 ;
    for ( int i = 1 ; i <= h ; i++)
    {
        if ( i%2)
            for ( int j = 1 ; j <= w ; j++)
            {
                color[i][j] = idx ;
                cnt++ ;
                if ( cnt == a[idx])
                    idx++, cnt = 0 ;
            }
        else
            for ( int j = w ; j >=  1 ; j--)
            {
                color[i][j] = idx ;
                cnt++ ;
                if ( cnt == a[idx])
                    idx++, cnt = 0 ;
            }
    }
    for ( int i = 1 ; i <= h ;i++)
    {
        for ( int j = 1 ; j <= w ; j++)
                cout << color[i][j] << " " ;
        cout << '\n' ;
    }
}


Measured memory_bytes: 3760
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007
using vi = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける

ll n,k,x,y;

int main(){
  ll ans=0;
  cin >> n ;

  ll m=1;
  REP(i,900){
    ans+=m;
    n/=2;
    m=m*2;
    if (n==0)break;
  }
cout<<ans<<endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>

int main()
{
  std::string s = "";
  
  std::cin >> s;
  
  int length = s.size();
  std::string temp = s;
  for (int loop=1;loop < length/2; ++loop){
    temp= temp.erase(length-2* loop, 2 * loop);
    int len = temp.size();
    std::string temp2 = temp;
    std::string temp3 = temp;
    temp2= temp2.substr(0, len/2);
    temp3= temp3.substr(len/2, len);
    if(temp2 == temp3)
    {
      std::printf("%d", len);
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 256
from collections import Counter
N = int(input())
S = input()
CC = Counter(S)
#print(CC)
if len(CC) < 3:
  print(0)
  exit(0)

ans = CC['R'] * CC['G'] * CC['B']
for i in range(N):
  for x in range(1,N):
    if i+2*x >= N:
      break
    if S[i] != S[i+x] and S[i+x] != S[i+2*x] and S[i+2*x] != S[i]:
      ans -= 1
      
print(ans)

Measured memory_bytes: 68780
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
typedef long long int ll;

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n; cin >> n;
	vector<ll> a(n);
	for(int i=0;i<n;i++){
		cin >> a[i];
	}
	ll ans=0;
	for(int i=1;i<n;i++){
		map<int,int> mp;
		ll ret=0;
		for(int j=0;j<n;j+=i){
			if(n-1<j+i)break;
			ret+=a[j];
			mp[j]++;
			if(mp[j]>1)break;
			ret+=a[n-1-j];
			mp[n-1-j]++;
			if(mp[n-1-j]>1)break;
			ans=max(ans,ret);
		}
	}
	cout << ans << endl;
}

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


int main(){
  int N;
  cin >> N;
  long long  ene =1;
  int mod = 1000000007;
  for (int i = 1; i<= N; i++){
    ene*=i;
    ene %=mod;
  }
 cout <<ene << endl;
}


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

#define pb push_back
#define ll long long int
#define mpi map<int, int>
#define vi vector<int>
#define qi queue<int>
#define si set<int>
#define pii pair<int, int>
#define vpi vector<pii>
#define vs vector<string>
#define pri priority_queue<int>
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007
#define For(i, n) for (int i = 0; i < n; i++)
#define Ford(i, a, b) for (int i = a; i >= b; i--)
#define Rep(i, x, y) for (int i = x; i <= y; i++)
#define mem(a, b) memset(a, b, sizeof(a))
#define fastio                    \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0)

double tick()
{
    static clock_t oldt, newt = clock();
    double diff = 1.0 * (newt - oldt) / CLOCKS_PER_SEC;
    oldt = newt;
    return diff;
}

ll fastExpo(ll a, ll n)
{
    ll res = 1;
    while (n)
    {
        if (n % 2)
            res = res * a;
        n /= 2;
        a = a * a;
    }
    return res;
}

int main()
{
    ll n;
    cin >> n;
    ll sq = sqrt(n), res = 0;

    Rep(i, 2, sq)
    {
        if (n % i == 0)
        {
            ll c = 0;
            while (n % i == 0)
            {
                n /= i;
                c++;
            }
            ll j = 1;
            while (c >= j)
            {
                c -= j;
                j++;
                res++;
            }
        }
    }
    if (n != 1)
        res++;
    cout << res << endl;

    cerr << "execution time is: " << tick() << "\n";
}


Measured memory_bytes: 3848
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const ll MOD = 1000000007;

int a[200002], b[200002];
int b_mod[200002];

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

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

    int T = 1;
    int ans = 0;
    for(int k=0;k<=28;k++){
        for(int i=0;i<N;i++){
            b_mod[i] = b[i] % (2 * T);
        }
        sort(b_mod, b_mod + N);
        ll cnt = 0;
        for(int i=0;i<N;i++){
            int a_mod_i = a[i] % (2 * T);
            cnt += lower_bound(b_mod, b_mod + N, 2 * T - a_mod_i) - lower_bound(b_mod, b_mod + N, T - a_mod_i);
            cnt += lower_bound(b_mod, b_mod + N, 4 * T - a_mod_i) - lower_bound(b_mod, b_mod + N, 3 * T - a_mod_i);
        }
        if(cnt % 2 == 1){
            ans += T;
        }
        T *= 2;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <cstring>
#include <vector>
using namespace std;
vector<int> o;
vector<int> z;
int main() {
  string s;
  int n,k;
  cin >> n >> k;
  cin >> s;
  int c = 0;
  int i = 0;
  for(; i < n; i++) {
    int j = 0;
    while(i + j < n && s[i+j] == '1') j++;
    o.push_back(j);
    i += j;
    int l = 0;
    while(i + l < n && s[i+l] == '0') l++;
    o.push_back(l);
    c++;
    i += l - 1;
  }
  int j = 0;
  while(i < n && s[i+j] == '1') j++;
  o.push_back(j);
  o.push_back(0);
  o.push_back(0);
  int r = min(k,c) * 2;
  int tmp = 0;
  int ans = 0;
  // for(int i = 0; i <o.size(); i++) cout << o[i] << endl;
  
  for(int l = 0; l <= r; l++) {
    tmp += o[l];
  }
  for(int l = 0; r + l < o.size(); l += 2) {
    ans = max(ans,tmp);
    int tmp1 = o[l] + o[l+1];
    int tmp2 = o[l+r+1] + o[l+r+2];
    tmp += tmp2 - tmp1;
  }

  cout << ans << endl;
  
}
  


Measured memory_bytes: 1020
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
 
long long N, M, a[100009][3], maxn = -(1LL << 60);
 
int main() {
	cin >> N >> M;
	for (int i = 1; i <= N; i++) {
		for (int j = 0; j < 3; j++) cin >> a[i][j];
	}
	for (int i = 0; i < 8; i++) {
		vector<long long>vec;
		for (int j = 1; j <= N; j++) {
			long long S = 0;
			for (int k = 0; k < 3; k++) { if ((i / (1 << k)) % 2 == 0) S += a[j][k]; else S -= a[j][k]; }
			vec.push_back(S);
		}
		sort(vec.begin(), vec.end()); reverse(vec.begin(), vec.end());
		long long ans = 0;
		for (int j = 0; j < M; j++) ans += vec[j];
		maxn = max(maxn, ans);
	}
	cout << maxn << endl;
	return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
 
using namespace std;
 
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P > PP;
 
int tx[] = {0,1,0,-1};
int ty[] = {-1,0,1,0};
 
static const double EPS = 1e-8;

bool check_sequence(const string& command){
  for(int i=0;i+1<command.size();i++){
    if(command[i] == command[i+1]) return false;
  }
  return true;
}

bool check_cross(int lpos,int rpos){
  if(lpos == -1 || rpos == -1) return true;
  if(lpos !=0 && lpos < rpos) return false;
  if(lpos == 0 && rpos == 3) return false;
  return true;
}

int compute_pos(char dir){
  int pos = 0;
  if(dir == 'U'){
    pos = 0;
  }
  else if(dir == 'R'){
    pos= 1;
  }
  else if(dir == 'D'){
    pos = 2;
  }
  else if(dir == 'L'){
    pos = 3;
  }

  return pos;
}

int main(){
  int N;
  while(~scanf("%d",&N)){
    for(int i = 0; i < N; i++){
      bool isok = true;
      string command;
      cin >> command;

      int lpos = -1;
      int rpos = -1;
      int flag = 0;

      if(!check_sequence(command)){
        isok = false;
        goto gameover;
      }

      for(int command_i = 0; command_i < command.size(); command_i++){
        if(command_i % 2 == 1) {
          lpos = compute_pos(command[command_i]);
        }
        else {
          rpos = compute_pos(command[command_i]);
        }

        if(!check_cross(lpos,rpos)){
          flag |= (1<<0);
        }
      }

      lpos = -1;
      rpos = -1;

      for(int command_i = 0; command_i < command.size(); command_i++){
        if(command_i % 2 == 0) {
          lpos = compute_pos(command[command_i]);
        }
        else {
          rpos = compute_pos(command[command_i]);
        }

        if(!check_cross(lpos,rpos)){
          flag |= (1<<1);
        }
      }

    gameover:;
      printf("%s\n",(!isok || (flag == (1<<2) - 1)) ? "No" : "Yes");
    }
  }
}

Measured memory_bytes: 1336
from itertools import product

MAX_ITEM = 4
NUM = 7
OPS = ("+", "-")

ABCD = list(input())


def main():
    for p in product(OPS, repeat=3):
        eq = ABCD[0]

        for o, abcd in zip(p, ABCD[1:]):
            eq += o
            eq += abcd

        if eval(eq) == NUM:
            print(eq + "=" + str(NUM))
            break

    return


main()


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

int main()
{
	int n;
	cin >> n;
	map<ll,ll> mp;
	vector<int> A(n);
	ll ans = 0;
	for(int i = 0;i<n;i++)
	{
		cin >> A[i];
		int now = i+1;
		ans += mp[now-A[i]];
		//cout<<now+A[i]-2<<' '<<ans<<endl;
		mp[now+A[i]]++;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 26744
package main

import (
	"fmt"
)

func main() {
	var n, k int
	fmt.Scan(&n, &k)
	d := make([]int, k)
	var e [10]bool
	var f []int
	for i := range d {
		fmt.Scan(&d[i])
		e[d[i]] = true
	}
	for i := 0; i < 10; i++ {
		if !e[i] {
			f = append(f, i)
		}
	}
	var x []int
	for n > 0 {
		x = append(x, n%10)
		n /= 10
	}
	p := len(x) - 1
	for p >= 0 {
		if e[x[p]] {
			break
		}
		p--
	}
	if p >= 0 {
		for {
			c := false
			j := x[p]
			for {
				j++
				if j == 10 {
					j = 0
					c = true
				}
				if !e[j] {
					break
				}
			}
			x[p] = j
			if !c {
				break
			}
			p++
			if p == len(x) {
				if f[0] == 0 {
					x = append(x, f[1])
				} else {
					x = append(x, f[0])
				}
				break
			}
		}
		for i := p - 1; i >= 0; i-- {
			x[i] = f[0]
		}
	}
	for i := len(x) - 1; i >= 0; i-- {
		fmt.Print(x[i])
	}
}


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

int main() {
  int n;
  cin >> n;
  int r = -1;
  for (int x = 0; x <= n; x++) {
    if (int(1.08 * x) == n) {
      r = x;
      break;
    }
  }
  if (r == -1) {
    cout << ":(" << endl;
  } else {
    cout << r << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,n) for(int i=1;i<(int)(n);i++)

typedef long long ll;
using namespace std;
int main()
{

  string s1,s2,s3;
  cin>>s1>>s2>>s3;
  cout<<"A";
  cout<<s2[0];
  cout<<"C"<<endl;
  return 0;
}


Measured memory_bytes: 3596
A, B = map(int, input().split())
hantei = 0

for i in range(2000):
    zeiA = int(i*0.08)
    zeiB = int(i*0.1)
    if zeiA == A and zeiB == B:
        print(i)
        hantei = 1
        break

if hantei == 0:
    print(-1)


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

int main(){
  int A[3],memo = 0;cin >> A[0] >> A[1] >> A[2];
  if (A[0] > A[1]){
    memo = A[0];
    A[0] = A[1];
    A[1] = memo; 
  }
  if (A[1] > A[2]){
    memo = A[1];
    A[1] = A[2];
    A[2] = memo; 
  }
  if (A[0] > A[1]){
    memo = A[0];
    A[0] = A[1];
    A[1] = memo; 
  }
  cout << (A[1] - A[0]) + (A[2] - A[1]) <<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define SC               scanf
#define PF               printf
#define ull              unsigned long long
#define ld               long double
#define D                double
#define F                first
#define S                second
#define pb               push_back
#define pf               push_front
#define MP               make_pair
#define sort_a(a)        sort(a.begin(),a.end());
#define sort_d(a)        sort(a.rbegin(),a.rend());
#define READ(f)          freopen(f, "r", stdin)
#define WRITE(f)         freopen(f, "w", stdout)
#define rev(s)           reverse(s.begin(),s.end())
#define it(it,mp)        for(auto it=mp.begin() ; it!=mp.end() ; it++)
#define IOS              ios_base :: sync_with_stdio(false); cin.tie(NULL);
const int N = 1e5 + 5;
const int inf = 1e9 + 1;
const double eps = 1e-15;
const double EPS = 1e-9;
const double PI = acos(-1.0);
typedef long long int                   ll;
typedef pair<int,int>                   PII;

int main()
{
    IOS
    // READ(0test.txt);
    //WRITE(0out.txt) ;
    string s ;
    cin >> s ;
    int ans = 0 ;
    char ok = s[0] ;
    for(int i= 1 ; i< s.size() ; i++){
        if(ok==s[i] ){
            (s[i]=='0')?ok='1':ok='0';
            ans++;
        }
        else (s[i]=='0')?ok='0':ok='1';
        //cout<<ans<<" "<<ok<<endl;

    }
    cout<<ans;


}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> PA;
typedef priority_queue<int, vector<int>, greater<int> > PQG;
#define REP(i, a, n) for(ll i = (ll) a;i < (ll) n;i++)
#define fi first
#define se second
#define pb push_back
#define INF 1000000009
#define MOD 1000000007
#define MAXN 100005
#define MAXM 100005
#define MAXV 1000000009

ll n, a[MAXN], ma, ans[MAXN];

int main()
{
    cin >> n;
    REP(i, 0, n){
        cin >> a[i];
    }
    sort(a, a + n, greater<int>() );
    REP(i, 1, n){
        if(a[i] == a[i - 1] && ma < 2){
            ans[ma] = a[i];
            //cout << a[i] << endl;
            a[i] = INF;
            ma++;
        }
    }
    if(ma >= 2)cout << ans[0] * ans[1] << endl;
    else cout << 0 << endl;

    return 0;
}
/*
*/





Measured memory_bytes: 1024
def make_divisors(n):
    """約数を計算する"""
    divisors = []
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n // i)
    divisors.sort()
    return divisors


N = int(input())

divisors = make_divisors(N)
ans = min([(a, b) for a, b in zip(divisors, reversed(divisors))], key=lambda x: x[0] + x[1] - 2)
print(ans[0] + ans[1] - 2)

# print(make_divisors(N))


Measured memory_bytes: 3676
#include<iostream>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

uintmax_t combination(unsigned int n, unsigned int r)
{
    if ( r * 2 > n ) r = n - r;
    uintmax_t dividend = 1;
    uintmax_t divisor  = 1;
    for ( unsigned int i = 1; i <= r; ++i )
    {
        dividend *= (n-i+1);
        divisor  *= i;
    }
    return dividend / divisor;
}

int main()
{
    unsigned n,m;
    cin>>n>>m;
    uintmax_t ans=0;
    if(n>=2)ans+=combination(n,2);
    if(m>=2)ans+=combination(m,2);
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

typedef pair<int,int> P;

int main(){
	char S[11];
	scanf("%s",S);

	long long ans = 0;
	for(int i=0;i<strlen(S);i++){
		for(int j=0;j<strlen(S)-i;j++){
			int len = strlen(S)-1-i-j;
			long long tmp;
			if(len==0) tmp = 1;
			else tmp = pow(2,len-1);
			long long tmp2;
			if(i==0) tmp2 = 1;
			else tmp2 = pow(2,i);
			ans += (long long)(S[i]-'0')*pow(10,j)*tmp*tmp2;
		}
	}

	printf("%lld\n",ans);


	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int M=1e6+10;
vector<int> e[M];
int vis[M],n,m;
void dfs(int x) {
    int l1 = e[x].size()-1;vis[x]=1;
    for(int i = 0; i <= l1 ; i ++){int v=e[x][i];if(vis[v]) continue;dfs(v);}
}
int main () {
    memset(vis,0,sizeof vis);
    cin >> n >> m;
    for (int i = 1;i <= m;i ++){int u,v,w;cin >> u >> v >> w;e[u].push_back(v);e[v].push_back(u);}
    int ans=0;
    for(int i = 1;i <= n;i++)
	if(!vis[i]){dfs(i);ans++;}
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 38680
def solve():
    N, P = list(map(int, input().split()))
    A = list(map(int, input().split()))
    if all([x % 2 == 0 for x in A]):
        if P == 0:
            print(2 ** N)
        else:
            print(0)
    else:
        print(2 ** (N-1))

solve()


Measured memory_bytes: 3316
/* imports all std modules {{{*/
import
  std.algorithm,
  std.array,
  std.ascii,
  std.base64,
  std.bigint,
  std.bitmanip,
  std.compiler,
  std.complex,
  std.concurrency,
  std.container,
  std.conv,
  std.csv,
  std.datetime,
  std.demangle,
  std.encoding,
  std.exception,
  std.file,
  std.format,
  std.functional,
  std.getopt,
  std.json,
  std.math,
  std.mathspecial,
  std.meta,
  std.mmfile,
  std.net.curl,
  std.net.isemail,
  std.numeric,
  std.parallelism,
  std.path,
  std.process,
  std.random,
  std.range,
  std.regex,
  std.signals,
  std.socket,
  std.stdint,
  std.stdio,
  std.string,
  std.system,
  std.traits,
  std.typecons,
  std.uni,
  std.uri,
  std.utf,
  std.uuid,
  std.variant,
  std.zip,
  std.zlib;
/*}}}*/

/+---test
4
10 30 40 20
---+/
/+---test
2
10 10
---+/
/+---test
6
30 10 60 10 60 50
---+/

void main(string[] args) {
  readln;

  const heights = readln.split.map!(to!long).array;
  const N       = heights.length;

  auto dp = new long[N];
  foreach (i; 0..N-1) {
    dp[i+1] = dp[i] + abs(heights[i] - heights[i+1]);
    if (i >= 1) {
      dp[i+1] = dp[i+1].min(dp[i-1] + abs(heights[i-1] - heights[i+1]));
    }
  }

  dp[$-1].writeln;
}


Measured memory_bytes: 4340
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define all(v) v.begin(), v.end()
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

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

    if ((n + 1) / 2 >= k) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;

}


Measured memory_bytes: 256
import math
s = input()
ls = [(ord(s[len(s) - i - 1]) - ord('0')) for i in range(len(s))]
cnt = [0 for _ in range(2019)]
cur = 0
ans = 0
power = 1
cnt[0] = 1
for i in ls:
    cur = (cur + power * i) % 2019
    ans = ans + cnt[cur]
    cnt[cur] = cnt[cur] + 1
    power = (power * 10) % 2019

print(ans)


Measured memory_bytes: 10732
#pragma GCC optimize("Ofast")
#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()
const long double PI = acos(-1.0L);
const long long MOD = 1000000007LL;
// const long long MOD = 998244353LL;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true;} return false; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true;} return false; }
///////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    while (1) {
		int N,M,P; cin >> N >> M >> P;
		if (N+M+P==0) break;
		vector<int> A(N);
		rep(i,N) cin >> A[i];
		int m = accumulate(all(A),0)*(100-P);
		if(A[--M])cout << m/A[M] << endl;
		else cout << 0 << endl;
	}
}


Measured memory_bytes: 3112
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<queue>
using namespace std;
typedef struct pp
{   char x[50];
    int t,R;
}S;
S s[105];
bool cmp(int a,int b)
{   return a>b;
}
int main()
{   int i,j,T,n,maxn=0,k,s=0,q;
    int y[26]={0};
    char x[6000];
    scanf("%d",&n);
    scanf("%s",x);
    for(i=0;i<n-1;i++)
    {
        for(j=i+1;j<n;j++)
        {   if(x[i]==x[j]&&x[i-1]!=x[j-1])
            {   //if(j==2)printf("##\n");
                q=1;
                for(k=1;k<j-i;k++)
                {   if(x[i+k]==x[j+k])q++;
                    else break;
                }
                if(q>maxn&&j-i>=q)maxn=q;
                //if(j==2)printf("##%d\n",q);
            }
        }
    }
    printf("%d\n",maxn);
    return 0;
}



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

using namespace std;

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

  for(int i = 0;i < N - 1;i++){
    double A1 = A[i];
    double A2 = A[i + 1];
    double C1 = (A1 + A2) / 2.0;
    A[i + 1] = C1;
  }
  ans = A.back();
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
const int N=1e5+3;
string s;
int32_t main()
{
	#ifndef ONLINE_JUDGE
	freopen("in","r",stdin);
	freopen("out","w",stdout);
	#endif
	int n;
	cin>>n;
	map<string,int> f;int ans=0;
	for(int i=0;i<n;i++)
	{
		cin>>s;
		sort(s.begin(),s.end());
		if(f[s])ans+=f[s];
		f[s]++;

	}
	cout<<ans;
}

Measured memory_bytes: 11448
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<map>
#include<cstdlib>
#include<cmath>
#include<numeric>
#include<iomanip>
using namespace std;
using ll =long long;
const int MOD = 1000000007;


int main() {
	ll X;
	ll A, B;
	cin >> X;
	for (ll i = 0; i <=1000; i++) {

		for (ll j = 0; j <= 1000; j++) {
			B = i*i*i*i*i;
			A = j*j*j*j*j;

			if (A-B==X) {
				cout << j <<" "<< i;
			
				return 0;
			}
			else if(B+A==X){
				cout << j <<" "<<-i;
				return 0;
			}
			
		}


	}


}

Measured memory_bytes: 3580
// {{{ by unolight
#include <bits/stdc++.h>
#include <unistd.h>
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC diagnostic ignored "-Wunused-function"
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x),end(x)
#define RALL(x) rbegin(x),rend(x)
#define REP(i,n) for ( int i=0; i<int(n); i++ )
#define REP1(i,a,b) for ( int i=(a); i<=int(b); i++ )
#define MP make_pair
#define PB push_back
using namespace std;
typedef int64_t LL;
typedef pair<int,int> PII;
typedef vector<int> VI;

namespace { namespace unolight {
// Read Input
template<class T> void _R( T &x ) { cin>>x; }
void _R( int &x ) { scanf("%d",&x); }
void _R( int64_t &x ) { scanf("%" PRId64,&x); }
void _R( double &x ) { scanf("%lf",&x); }
void _R( char &x ) { scanf(" %c",&x); }
void _R( char *x ) { scanf("%s",x); }
void R() {}
template<class T, class... U> void R( T& head, U&... tail ) { _R(head); R(tail...); }
// Write Output
template<class T> void _W( const T &x ) { cout<<x; }
void _W( const int &x ) { printf("%d",x); }
void _W( const int64_t &x ) { printf("%" PRId64,x); }
void _W( const double &x ) { printf("%.16f\n",x); }
void _W( const char &x ) { putchar(x); }
void _W( const char *x ) { printf("%s",x); }
template<class T> void _W( const vector<T> &x ) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W( const T& head, const U&... tail ) { _W(head); putchar(sizeof...(tail)?' ':'\n'); W(tail...); }

#ifdef UNOLIGHT
#include "dump.hpp"
#else
#define dump(...)
#endif

template<class T> inline bool chmax( T &a, const T &b ) { return b>a ? a=b,true : false; }
template<class T> inline bool chmin( T &a, const T &b ) { return b<a ? a=b,true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template<class T, class F=less<T>> void sort_uniq( vector<T> &v, F f=F() ) {
    sort(begin(v),end(v),f);
    v.resize(unique(begin(v),end(v))-begin(v));
}
// }}}


void main() {
    int n,x,t;
    R(n,x,t);
    W((n-1+x)/x*t);
}

}} // {{{ main
int main() { unolight::main(); return 0; }
// }}}

Measured memory_bytes: 3756
#include <stdio.h>

int main(void){
  int w=0, n=0;
  int a[30], b[30], c[30];
  int i, j, tmp;

  scanf("%d", &w);
  scanf("%d", &n);

  for (i=0; i<n; i++){
    scanf("%d,%d", &a[i], &b[i]);    
  } 

  for (i=0; i<w; i++) {
  	c[i] = i+1;
  }

 
  //printf("test----------\n");

  for (i=0; i<n; i++){
  	tmp = c[a[i]-1];
    c[a[i]-1] = c[b[i]-1];
    c[b[i]-1] = tmp;
    /*
    for (j=0; j<w; j++) {
  	  printf("%d ", c[j]);
    }
    printf("\n");*/
  } 

  for (i=0; i<w; i++) {
  	printf("%d\n", c[i]);
  }

  return 0;
}


Measured memory_bytes: 2716
T = list(input())

if len(T) == 1:
    if T[0] == '?':
        T[0] = 'D'
else:

    if T[0] == '?':
        if T[1] == 'D':
            T[0] = 'P'
        else:
            T[0] = 'D'

    for i in range(1, len(T) - 1):
        if T[i] == '?':
            if T[i - 1] == 'P':
                T[i] = 'D'
            else:
                if T[i + 1] == 'D':
                    T[i] = 'P'
                else:
                    T[i] = 'D'

    if T[-1] == '?':
        T[-1] = 'D'

print(''.join(T))



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

int f(int n) {
  if (n%2==0) return n/2;
  else return 3*n+1;
}

int main () {
  int s;
  cin >> s;
  int a[10000];
  long long i = 1;
  a[s]=s;
  while(1) {
    i++;
    s = f(s);
    
    if(a[s] == s) {
      cout << i;
      break;
    } else {
      a[s] = s;
    }
  }
}
    
    


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;main(){string r,s;cin>>s;long long N=0,a=0,b,i,m=0,n=1,x;for(auto c:s)a=a*10+c-48,n*=10,N++;s="0123456789";do{for(i=-1,b=0;++i<N;b=b*10+s[i]-48);if(m<(x=min(abs(a-b),n-abs(a-b))))m=x,r=s;}while(next_permutation(s.begin(),s.end()));cout<<r.substr(0,N)<<endl;}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define rep(i,N) for(ll i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

int n;

int main(){
  cin >> n;
  if(n <= 999)cout << "ABC" <<  endl;
  else cout << "ABD" << endl;
}

Measured memory_bytes: 256
N,X,M=map(int,input().split())
d={}
x=X
A=[]
init=0
loop=0
S=[0]
while x not in d:
    d[x]=1
    A.append(x)
    S.append(S[-1]+A[-1])
    x=x*x%M

init=A.index(x)
loop=len(A)-init

if N<=init+loop:
    print(S[N])
else:
    l=(N-init)//loop
    r=(N-init)%loop
    print((S[-1]-S[init])*l+S[init+r])



Measured memory_bytes: 79576
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define forever for (;;)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
template<typename A> using V = std::vector<A>;
template<typename A> using F = std::function<A>;
template<typename A, typename B> using P = std::pair<A, B>;
using pii = P<int, int>;
using vi = V<int>;
using vd = V<double>;
using vs = V<std::string>;
using vpii = V<pii>;
using vvi = V<vi>;
using vvpii = V<vpii>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
template<typename T> std::istream &operator>>(std::istream &is, std::vector<T> &v) { for (T &x : v) is >> x; return is; }
template<typename A, typename B> std::istream &operator>>(std::istream &is, std::pair<A, B> &p) { is >> p.first; is >> p.second; return is; }
using namespace std;
// clang-format on

main {
  int n;
  while (cin >> n, n) {
    V<P<char, pii>> v(n);
    rep(i, n) {
      cin >> v[i].first;
      rep(_, n - 1) {
        int x;
        cin >> x;
        if (x != 2) (x ? v[i].second.second : v[i].second.first)++;
      }
    }
    stable_sort(all(v), [](auto &a, auto &b) {
      if (a.second.first != b.second.first) return a.second.first > b.second.first;
      return a.second.second < b.second.second;
    });
    for (auto &x : v) cout << x.first << endl;
  }
}

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

int main(){
     string S;
     cin >> S;
  bool ans = false;
  if(S.at(0) == 'A'){
    int count = 0;
    for(int i =2;i<=S.size()-2;i++){
      if(S.at(i) == 'C'){
        count++;
      }
    }
    if(count == 1){
      sort(S.begin(),S.end());
      int B = 0;//大文字の数
      for(int i = 0; i<S.size();i++){
        if(S.at(i) >= 'A' && S.at(i)<= 'Z') B++;
      }
      if(B==2 && S.at(0) == 'A' && S.at(1) == 'C') ans =true;
    }
  }
  if(ans == false) cout << "WA" <<endl;
  else cout << "AC" << endl; 

  
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
  int n,i,j,k,m=0;
  scanf("%d",&n);
  for(i=1;i<=n;i=i+2)
  {
    for(j=1;j<=i;j++)
    {
      if(i%j==0)
      {
        k++;
      }
    }
    if(k==8)
    {
      m++;
    }
    k=0;
  }
  printf("%d\n",m);
  
  return 0;
}


Measured memory_bytes: 128
#include<cstdio>
#include<cstdlib>
#include<string>
#include<iostream>
using namespace std;

struct Node{
  int key;
  Node *right,*left,*parent;
};

Node *root,*NIL;

Node * treeMinimum(Node *x){
  while(x->left!=NIL) x=x->left;
  return x;
}

Node * find(Node *u, int k){
  while(u!=NIL&&k!=u->key){
    if(k<u->key) u=u->left;
    else u=u->right;
  }
  return u;
}

Node * treeSuccessor(Node *x){
  if(x->right!=NIL) return treeMinimum(x->right);
  Node *y=x->parent;
  while(y!=NIL&&x==y->right){
    x=y;
    y=y->parent;
  }
  return y;
}

void treeDelete(Node *z){
  Node *y,*x;

  if(z->left==NIL||z->right==NIL) y=z;
  else y=treeSuccessor(z);

  if(y->left!=NIL) x=y->left;
  else x=y->right;

  if(x!=NIL) x->parent=y->parent;

  if(y->parent==NIL) root=x;
  else{
    if(y==y->parent->left) y->parent->left=x;
    else y->parent->right=x;
  }

if(y!=z) z->key=y->key;

free(y);
}

void insert(int k){
  Node *y=NIL;
  Node *x=root;
  Node *z;

  z=(Node *)malloc(sizeof(Node));
  z->key=k;
  z->left=NIL;
  z->right=NIL;

  while(x!=NIL){
    y=x;
    if(z->key<x->key){
      x=x->left;
    }else{
      x=x->right;
    }
  }

  z->parent=y;
  if(y==NIL){
    root=z;
  }else{
    if(z->key<y->key){
      y->left=z;
    }else{
      y->right=z;
    }
  }
}

void inorder(Node *u){
  if(u==NIL) return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}

void preorder(Node *u){
  if(u==NIL) return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}

int main(){
  int n,i,x;
  string com;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    cin>>com;
    if(com[0]=='f'){
      scanf("%d",&x);
      Node *t=find(root,x);
      if(t!=NIL) printf("yes\n");
      else printf("no\n");
    }
    else if(com=="insert"){
      scanf("%d",&x);
      insert(x);
    }else if(com=="print"){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }else if(com=="delete"){
      scanf("%d",&x);
      treeDelete(find(root,x));
    }
  }
  return 0;
}



Measured memory_bytes: 22100
n = int(input())
s = input()
lv = [0] * n

lvi = 0
for i,v in enumerate(s):
    if v == '(' :
        lvi += 1
    else:
        lvi -= 1
    lv[i] = lvi
l = min(0,min(lv))
r = -lv[-1] + l

print('('*(-l) + s + ')'*(-r))

Measured memory_bytes: 3064
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
/*---------------------DEBUGGING--------------------------------------------*/
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
/*-------------------------------------------------------------------------------------*/
//#define mp make_pair
#define pb push_back
#define ll long long
#define pii pair<int,int>
#define pcc pair<char,char>
#define F first
#define S second
#define int long long
#define pi 3.141592653589793238462643383279502
#define M  1000000007
#define rep(i,a,n) for(int i=a;i<n;i++)
#define INF 10000000000000
#define N 100005
#define vi vector<int>
#define all(v) v.begin(),v.end()
//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

signed main()
{
   ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
   int l,r;
   cin>>l>>r;
   int d;
   cin>>d;
   int cnt=0;
   for(int i=l;i<=r;i++)
   {
       if(i%d==0)cnt++;
   }
   cout<<cnt<<endl;
}


Measured memory_bytes: 3652
import java.util.Scanner;

//Shuffle The Cards
public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] c = new int[2*n];
		for(int i=0;i<2*n;i++)c[i]=i+1;
		int m = sc.nextInt();
		while(m--!=0){
			int k = sc.nextInt();
			if(k==0){
				int[] a = new int[n];
				int[] b = new int[n];
				for(int i=0;i<2*n;i++){
					if(i<n) a[i]=c[i];
					else b[i-n]=c[i];
				}
				for(int i=0;i<n;i++){
					c[2*i] = a[i];
					c[2*i+1] = b[i];
				}
			}
			else{
				int[] a = new int[k];
				for(int i=0;i<k;i++)a[i]=c[i];
				for(int i=k;i<2*n;i++)c[i-k]=c[i];
				for(int i=0;i<k;i++)c[i+2*n-k]=a[i];
			}
		}
		for(int a:c)System.out.println(a);
	}
}

Measured memory_bytes: 12000
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while(true) {
            int h = scanner.nextInt();
            int w = scanner.nextInt();

            if (h == 0 && w == 0) break;

            for (int i = 0; i < h; i++) {
                for (int j = 0; j < w; j++) {
                    System.out.print((i + j) % 2 == 0 ? "#" : ".");
                }
                System.out.print("\n");
            }

            System.out.print("\n");
        }
        scanner.close();
    }
}



Measured memory_bytes: 37496