akhauriyash/Code-Regression huggingface dataset:
from operator import mul
from functools import reduce
import numpy as np
def ConZ(i):
    z_num = i+int(i*(i-1)/2)
    return z_num
#def ConN(i):
    #n_num = int(i*(i-1)/2)
    #return n_num
def cmb(n):
    over = reduce(mul, range(n, n - 2, -1))
    under = reduce(mul, range(1,2 + 1))
    return over // under


S = input()[::-1]
keta = 1
A_num = 0
x = 0
mod = np.array([0]*2019)
for i in range(len(S)):
    A_num += int(S[i:i+1])*keta
    if A_num >= 2019:
        A_num = A_num%2019
    mod[A_num] +=1
    #keta*=10
    keta = keta * 10 % 2019
#print(mod)
x += ConZ(mod[0])
#del mod[0]

for j in range(1,len(mod)):
    x+=cmb(mod[j])
print(x)
#print(int(np.sum(mod* (mod - 1) /2)))


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

#define int long long

int N;
bool S[201][201];
vector<int> col;
bool flag = true;

void dfs(int v, int c) {
  // cout << v << " " << c << endl;
  if ( col[v] && col[v] != c ) {
    flag = false;
    return;
  }
  if ( col[v] ) return;
  col[v] = c;
  for ( int i = 0; i < N; i++ ) {
    if ( S[v][i] ) dfs(i, 3-c);    
  }

  return;  
}

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);
  const int INF = 1e9;  

  cin >> N;
  col.resize(N, 0);
  int d[N][N];
  fill_n(*d, N*N, INF);
  for ( int i = 0; i < N; i++ ) d[i][i] = 0; 
  for ( int i = 0; i < N; i++ ) {
    string s;
    cin >> s;
    for ( int j = 0; j < N; j++ ) {
      if ( s[j] == '0' ) S[i][j] = false;
      else {
	S[i][j] = true;
	d[i][j] = 1;	
      }
    }
  }

  for ( int i = 0; i < N; i++ ) {
    if ( col[i] == 0 ) dfs(i, 1);
    // cout << col[i];
  }  

  if ( !flag ) {
    cout << -1 << endl;
    return 0;
  }

  for (int k = 0; k < N; k++){       // 経由する頂点
    for (int i = 0; i < N; i++) {    // 始点
      for (int j = 0; j < N; j++) {  // 終点	
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }

  int ans = 0;
  for ( int i = 0; i < N; i++ ) {
    for ( int j = 0; j < N; j++ ) {
      if ( i == j ) continue;
      if ( d[i][j] < INF ) ans = max(ans, d[i][j]);      
    }
  }

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


Measured memory_bytes: 640
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


class Magatro
{
    
    static void Main()
    {
        long a, b, x;
        string[] s = Console.ReadLine().Split(' ');
        a = long.Parse(s[0]);
        b = long.Parse(s[1]);
        x = long.Parse(s[2]);
        if (a == 0)
        {
            Console.WriteLine(b / x + 1);
        }
        else
        {
            Console.WriteLine((b / x + 1) - ((a - 1) / x + 1));
        }
    }
}



Measured memory_bytes: 2648
#include <iostream>
#include <queue>

using namespace std;
typedef long long ll;

int main(){
    ll n, m;
    cin >> n >> m;
    priority_queue<ll> a;
    for(int i = 0; i < n; ++i){
        ll ai;
        cin >> ai;
        a.push(ai);
    }
    for(int i = 0; i < m; ++i){
        ll x = a.top();
        a.pop();
        x /= 2;
        a.push(x);
    }
    ll ans = 0;
    while(!a.empty()){
        ans += a.top();
        a.pop();
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1400
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a, b, c;
int main()
{
	cin >> a >> b >> c;
	if (c - a - b <= 0)
	{
		cout << "No" << endl;
	}
	else
	{
		cout << ((4 * a * b < (c - a - b) * (c - a - b)) ? "Yes" : "No") << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
   int a ,b, c,i;

for(int i=1;i<=3000 ;i++){
    cin >> a >> b;
if (a>b)
{
   c=a;
   a=b;
   b=c;
}
   if (a==0 && b==0)
   break ;
   else
  
   cout << a << " " << b<< endl;
}
}


Measured memory_bytes: 3004
/*************************************************************************
	> File Name: 1.cpp
	> Author: Knowledge_llz
	> Mail: 925538513@qq.com 
	> Blog: https://blog.csdn.net/Pig_cfbsl 
	> Created Time: 2020/7/5 19:59:25
 ************************************************************************/

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#define For(i,a,b) for(register int i=(a);i<=(b);++i)
#define LL long long
using namespace std;
int read(){
	char x=getchar(); int u=0,fg=0;
	while(!isdigit(x)){ if(x=='-') fg=1; x=getchar(); }
	while(isdigit(x)){ u=(u<<3)+(u<<1)+(x^48); x=getchar(); }
	return fg?-u:u;
}
char s[100000];
int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.in", "r", stdin);
	freopen("output.out", "w", stdout);
#endif
	int n,ac=0,wa=0,tle=0,re=0;
	cin>>n;
	For(i,1,n){
		cin>>s;
		if(s[0]=='A') ++ac;
		else if(s[0]=='W') ++wa;
		else if(s[0]=='T') ++tle;
		else ++re;
	}
	printf("AC x %d\n",ac);
	printf("WA x %d\n",wa);
	printf("TLE x %d\n",tle);
	printf("RE x %d\n",re);

	return 0;
}


Measured memory_bytes: 3764
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int[] num = new int[100];
        for(int i = 0 ; i < 100 ; i++)
            num[i] = 0;
        int max = 0;
        while(sc.hasNext()){
            int a = sc.nextInt();
            num[a-1]++;
            max = Math.max(max,num[a-1]);
        }
        for(int i = 0 ; i < 100 ; i++){
            if(num[i] == max)
                System.out.println(i+1);
        }
    }
}


Measured memory_bytes: 26360
/**
        	C++14 (GCC 5.4.1)
**/
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <algorithm>    // std::copy
#include <iterator>     // std::back_inserter
#include <set>
using namespace std;
 
int main(){
    int H,W;
    cin >> H >> W;
    vector<vector<char>> A(H, vector<char>(W,0));
    vector<vector<char>> An(H, vector<char>(W,0));
    vector< pair<int, int> > black;
    int count = 0;
    for(int i = 0 ; i < H  ; i++){
        for (int j = 0; j < W ; j++){
            cin >> A[i][j];
            An[i][j] = A[i][j];
            if(A[i][j] == '#') {
                black.push_back(make_pair(i,j));
                count++;
            }
        }
    }
    // for(int i = 0 ; i < H  ; i++){
    //     for (int j = 0; j < W ; j++){
    //         cout << A[i][j];
    //     }
    //     cout << endl;
    // }
    
    int ans = 0;
    int start = 0;
    while(1){
        // cout << endl;
        // int count = 0;
        // for(int i = 0 ; i < H  ; i++){
        //     for (int j = 0; j < W  ; j++){
        //         // cout << A[i][j] << " ";
        //         if(A[i][j] == '#')  count++;
        //     }
        //     // cout << endl;
        // }
        if(count == H * W){break;}
 
        int m = black.size();
        for(int i = start ; i < m; i++){
            // black.erase(black.begin());
 
            // if(A[black[i].first][black[i].second] == '#'){
                if(black[i].first != 0 && A[black[i].first-1][black[i].second] != '#'){
                    A[black[i].first-1][black[i].second] = '#';
                    count++;
                    black.push_back(make_pair(black[i].first-1,black[i].second));
                }
                if(black[i].second != 0 && A[black[i].first][black[i].second-1] != '#'){ 
                    A[black[i].first][black[i].second-1] = '#';
                    count++;
                    black.push_back(make_pair(black[i].first,black[i].second-1));
                }
                if(black[i].first != H - 1 && A[black[i].first+1][black[i].second] != '#'){ 
                    A[black[i].first+1][black[i].second] = '#';
                    count++;
                    black.push_back(make_pair(black[i].first+1,black[i].second));
                }
                if(black[i].second !=  W - 1 && A[black[i].first][black[i].second+1] != '#'){
                    A[black[i].first][black[i].second+1] = '#';
                    count++;
                    black.push_back(make_pair(black[i].first,black[i].second+1));
                }
 
            // }
        }
        start = m;
        // copy(An.begin(), An.end(), A.begin() );
        ans++;
    }
    cout << ans << endl;
    
 
    return 0;
}

Measured memory_bytes: 11760
N = int(input())
L = list(map(int,input().split()))
L.sort()
from bisect import bisect_left
ans = 0
for i in range(N):
  for j in range(i+1, N):
    sum = L[i]+L[j]
    count = bisect_left(L, sum)
    ans += max(0, count-j-1)
print(ans)

Measured memory_bytes: 3188
#include <iostream>
#include <vector>

using namespace std;


int main(int argc, const char * argv[]) {
    int N = 0;
    cin >> N;
    
    vector<int> Nums(N, 0);
    for(int i = 0; i < N; i++) {
        cin >> Nums[i];
    }
    
    int opNum = 0;
    while(true) {
        bool isAllEven = true;
        for(int i = 0; i < N; i++) {
            if(Nums[i]%2 == 1) {
                isAllEven = false;
                break;
            }

            Nums[i] /= 2;
        }
        if(!isAllEven) {
            break;
        }
        opNum++;
    }
    cout << opNum << endl;
    return 0;
}


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

using namespace std;
#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 rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()
#define int long long
#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
#define mod 1000000007
#define INF 10e10
template <typename T>

void print(T x)
{
	std::cout << x << " ";
}
template <typename T>

void println(T x)
{
	std::cout << x << "\n";
}

bool is_prime[100001];
int like_num[100002];//2～nで条件に当てはまるものの個数
int eratosthenes(int n)
{
	int ret = 0;
	FOR(i, 2, n+1) {
		if (is_prime[i]) {
			ret++;
			for (int j = 2 * i; j <= n; j += i) {
				is_prime[j] = false;
			}
		}
	}
	return ret;
}

signed main(void) {
	rep(i, 100000) {
		is_prime[i] = true;
	}
	is_prime[0] = false;
	is_prime[1] = false;
	eratosthenes(100000);
	like_num[0] = 0;
	like_num[1] = 0;
	like_num[2] = 0;
	for (int i = 3; i <= 100000;i+=2) {
		if (is_prime[i] && is_prime[(i + 1) / 2]) {
			like_num[i] = like_num[i - 2] + 1;
		}
		else {
			like_num[i] = like_num[i - 2];
		}
	}
	int q;
	cin >> q;
	vector<int>l(q);
	vector<int>r(q);
	rep(i, q) {
		cin >> l[i] >> r[i];
	}
	rep(i, q) {
		println(like_num[r[i]] - like_num[l[i] - 2]);
	}
}

Measured memory_bytes: 5596
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
#include<set>
#include<climits>
#include<cstdlib>
#include<cmath>
#include<string>

using namespace std;

#define INF 1 << 29
#define LL long long int

LL const MOD = 1000000007;

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

    vector<LL> a(3);
    cin >> a[0] >> a[1] >> a[2];

    LL ans = INF;

    for(int i = 0; i < 3; i++){
        LL tmp = a[i];
        LL tmpcost = 0;
        for(int j = 0; j < 3; j++){
            if(i != j){
                tmpcost = abs(tmp-a[j]);
                LL tmp2 = a[j];
                for(int k = 0; k < 3; k++){
                    if(i != k && j != k){
                        if(ans > tmpcost + abs(a[k] - tmp2)){
                            ans = tmpcost + abs(a[k] - tmp2);
                        }
                    }
                }
            }
        }
    }

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

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

using namespace std;

int main()
{
  int n, m, x, y;

  cin >> n >> m >> x >> y;

  int ax[n];

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

  int ay[m];
  for (int i = 0; i < m; i++)
  {
    int _y;
    cin >> _y;
    ay[i] = _y;
  }

  sort(ax, ax + n);
  sort(ay, ay + m);

  int xmax = ax[n - 1];
  int ymin = ay[0];

  string ans = "War";
  for (int i = x + 1; i <= y; i++)
  {
    if (xmax < i && ymin >= i)
    {
      ans = "No War";
    }
  }

  cout << ans << endl;
}


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

using namespace std;
using ll=long long ;
ll cut(ll n, ll i, ll m) {
    ll x = i*m;
    ll res = 1ll<<60;
    if (n-i > 1){
        ll y = (n-i)/2;
        ll z = n-i - y;
        y*=m; z*=m;
        ll d = max({x,y,z}) - min({x,y,z});
        res = min(res, d);
    }
    if (m > 1) {
        ll y = m/2;
        ll z = m - y;
        y*=n-i; z*=n-i;
        ll d = max({x,y,z}) - min({x,y,z});
        res = min(res, d);
    }
    return res;
}

void solve() {
    int n,m;
    cin >> n >> m;
    if (n%3==0 || m%3==0) {
        cout << 0; return;
    }
    ll res = 1ll<<60;
    if (n/3 > 0) res = min(res, cut(n,n/3,m));
    res = min(res, cut(n,n/3+1,m));
    swap(n,m);
    if (n/3 > 0) res = min(res, cut(n,n/3,m));
    res = min(res, cut(n,n/3+1,m));
    cout << res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <map>
#include <cstdio>
#include <math.h>
#include <utility>
#include <list>
#include <functional>
using namespace std;

#define ll long long
#define vecint vector<int>
#define Pii pair<int, int>

#define REP(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define print(a) cout << a << endl

#define MOD 1000000007
#define NIL -1

int main(){
  string O;
  string E;
  cin>>O;
  cin>>E;
  while(1){
    if(O.size()==0) break;
    cout<<O[0];
    O.erase(O.begin());
    if(E.size()==0) break;
    cout<<E[0];
    E.erase(E.begin());
  }
  print("");
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
typedef unsigned int uint;
using namespace std;

int main(){
  int H,W;
  cin >> H >> W;
  int a[H][W];
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cin >> a[i][j];
    }
  }


  vector<pair<int,int> > ope1;
  vector<pair<int,int> > ope2;
  int cnt=0;
  for(int i=0;i<H;i++){
    for(int j=0;j<=W-2;j++){
      if(a[i][j]%2 == 1){
        a[i][j]--;
        a[i][j+1]++;
        cnt++;
        ope1.push_back(make_pair(i+1,j+1));
        ope2.push_back(make_pair(i+1,j+2));
      }
    }
  }

  for(int i=0;i<=H-2;i++){
    if(a[i][W-1]%2 == 1){
      a[i][W-1]--;
      a[i+1][W-1]++;
      cnt++;
      ope1.push_back(make_pair(i+1,W));
      ope2.push_back(make_pair(i+2,W));
    }
  }

  /*for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cout << a[i][j] << " ";
    }
    cout << endl;
  }*/

  cout << cnt << endl;
  for(int i=0;i<ope1.size();i++){
    cout << ope1[i].first << " ";
    cout << ope1[i].second << " ";
    cout << ope2[i].first << " ";
    cout << ope2[i].second << endl;
  }
  return 0;
}



Measured memory_bytes: 5228
/* template.cpp(shinobu_menkoi) {{{ */
#include <bits/stdc++.h>
using namespace std;

// clang-format off
#define GET_MACRO(_1, _2, _3, _4, NAME, ...) NAME
#define rep(...) GET_MACRO(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rep1(n) rep2(_, n)
#define rep2(i, n) rep3(i, 0, n)
#define rep3(i, a, n) rep4(i, a, n, 1)
#define rep4(i, a, n, s) for (lint i = (a); i < (lint)(n); i += (s))
#define rrep(...) GET_MACRO(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define rrep1(a) rrep2(_, a)
#define rrep2(i, a) rrep3(i, a, 0)
#define rrep3(i, a, n) rrep4(i, a, n, 1)
#define rrep4(i, a, n, s) for (lint i = (a); i >= (lint)(n); i -= (s))
#define each(i, ctn) for (auto &&i : (ctn))

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define all(v) begin(v), end(v)
#define debug(x) cerr << (x) << " (L:" << __LINE__ << ")" << '\n'
#define TEMP_T template <class T>
#define TEMP_TU template <class T, class U>

TEMP_T using vec = vector<T>;
TEMP_T using heap = priority_queue<T>;
TEMP_T using minheap = priority_queue<T, vec<T>, greater<T>>;
using lint = long long;
using ulint = unsigned long long;
using ld = long double;
using vi = vec<int>;
using vvi = vec<vi>;
using vvvi = vec<vvi>;
using pii = pair<int, int>;
using vs = vec<string>;

TEMP_TU ostream &operator<<(ostream &os, const pair<T, U> &p) { return os << p.fi << " " << p.se; }
TEMP_TU istream &operator>>(istream &is, pair<T, U> &p) { return is >> p.fi >> p.se; }

const int INF{1001001001};
const lint LINF{1001001001001001001ll};
const int MOD{(int)1e9 + 7};
const double EPS{1e-9};
const double PI{acos(-1)};
const int dx[]{0, 1, 0, -1, 1, -1, 1, -1}, dy[]{1, 0, -1, 0, 1, -1, -1, 1};

inline bool inside(int y, int x, int h, int w) { return y >= 0 && x >= 0 && y < h && x < w; }
TEMP_T inline bool chmin(T &a, const T &b) { if (a > b) a = b; return a > b; }
TEMP_T inline bool chmax(T &a, const T &b) { if (a < b) a = b; return a < b; }
TEMP_T inline void print(const T &x) { cout << x << '\n'; }
TEMP_T inline void print(const vec<T> &v, string d = "\n") { rep(i, v.size()) cout << v[i] << (i == (lint)v.size() - 1 ? "\n" : d); }
template <class T = int> inline T in() { T x; cin >> x; return x; }
template <class T = string> vec<T> split(const string &s, char d = ',') {
  vec<T> v; stringstream ss(s); for (string b; getline(ss, b, d); ) {
    stringstream conv(b); T t; conv >> t; v.eb(t); } return v;
}
struct pre_ { pre_() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(12); } } pre__;
// clang-format on
/* }}} */

signed main() {
  int a[3];
  rep(i, 3) cin >> a[i];
  sort(all(a));
  print(a[0] + a[1]);
}


Measured memory_bytes: 256
object Main{
	def main(args:Array[String]){
		val s = new java.util.Scanner(System.in)
		val a,b,c,n = s.nextInt
		var r = 0
		for(i <- 0 to 3000) {
			for(j <- 0 to 3000) {
				val t = n - i * a - j * b
				if(t >= 0 && t % c == 0) {
					r += 1
				}
			}
		}
		println(r)
	}
}

Measured memory_bytes: 25528
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>
#include<math.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rep1(i,n) for(int i = 1; i < (n); i++)

int main(){
    long long n, a, b;
    cin >> n >> a >> b;
    long long c = a+b;
    long long ans;
    ans = a * (n / c);
    ans += min(n%c, a);
    cout << ans << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define RFOR(i,n1,n2) for(ll i=((ll)(n1)-1);i>=(ll)(n2);i--)
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
#define IOS cin.tie(0),ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
template<typename T1, typename T2> inline bool chmin(T1& a, T2 b) { if (a > b) { a = b; return 1; }return 0; }
template<typename T1, typename T2> inline bool chmax(T1& a, T2 b) { if (a < b) { a = b; return 1; }return 0; }
template<class Type>struct is_vector : std::false_type {};
template<class ValueType, class Alloc>struct is_vector<std::vector<ValueType, Alloc>> : std::true_type {};
template <typename T> inline ostream& operator << (ostream& out, const vector<T>& v) {
    if (v.empty())return out;
    constexpr bool is_vector_v = is_vector<T>::value;
    if (is_vector_v)for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? "\n" : "");
    else for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? " " : "");
    return out;
}
inline void put() {}
template<class T> inline void put(const T& first) { std::cout << first << "\n"; }
template<class T, class... N> inline void put(const T& first, const N& ... rest) { std::cout << first << " "; put(rest...); }
inline void putn() {}
template<class T, class... N> inline void putn(const T& first, const N& ... rest) { std::cout << first << "\n"; putn(rest...); }

int main() {
    IOS;
    string s;
    ll k;
    cin >> s >> k;
    ll n = s.size();
    ll pre=1,post=1;
    ll res = 0;
    bool flag = true;
    REP(i,n-1){
        if(flag&&s[i]==s[i+1]){
            pre++;
        }else{
            flag=false;
        }
    }
    flag=true;
    RFOR(i,n,1){
        if(flag&&s[i]==s[i-1]){
            post++;
        }else{
            flag=false;
        }
    }
    if(pre==n){
        put(n*k/2);
        return 0;
    }
    
    res+=pre/2+post/2;
    if(s[0]!=s[n-1]){
        res+=pre/2*(k-1)+post/2*(k-1);
    }else{
        res+=(pre+post)/2*(k-1);
    }
    ll con = 1;
    FOR(i,pre,n-post){
        if(s[i]==s[i+1]){
            con++;
        }else{
            res+=con/2*k;
            con=1;
        }
    }
    put(res);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define PB push_back
using namespace std;
typedef pair<int, int> P1;
typedef pair<int, pair<int, int> > P2;
static const int INF = 1ll<<60;
static const int dx[] = { 1, -1, 0, 0, };
static const int dy[] = { 0, 0, 1, -1 };
static const int mod = 1000000007;

int Q;
int V[100005];
bool sosuu[100005];
bool flag[100005];

void Sosuu(){
    for(int i=2;i<100005;++i){
        if(flag[i])continue;
        for(int j = 1;;++j){
            if(i*j > 100000)break;
            flag[i*j] = true;
        }
        sosuu[i] = true;
    }
}


signed main(){
    cin>>Q;
    Sosuu();
    for(int i=1;i<100005;++i){
        V[i] = V[i-1];
        if(sosuu[i] && sosuu[(i+1)/2])V[i]++;
    }
    for(int i=0;i<Q;++i){
        int l,r;
        cin>>l>>r;
        cout<<V[r]-V[l-1]<<endl;
    }
}



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

using namespace std;

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

#define N 100010
#define M 200010
#define endl "\n"
#define mod 1000000007 

int main(){
	
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(NULL);
	
	ll n, arr[110];
	ll ans = 0;
	map<vector<int>, int> mp;
	
	cin >> n;
	for(int i = 0; i < n; i++) cin >> arr[i];
	
	for(int i = 0; i < n; i++){
		for(int j = i + 1; j < n; j++){
			for(int k = j + 1; k < n; k++){
				if(arr[i] + arr[j] > arr[k] && arr[i] + arr[k] > arr[j] && arr[j] + arr[k] > arr[i] && arr[i] != arr[j] && arr[j] != arr[k] && arr[k] != arr[i]) ans++;
			}
		}
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 3656
#include<bits/stdc++.h>
#define ll long long
#define loop(a,b) for(ll i=a;i<b;i++)
#define iloop(a,b) for(int i=a;i<b;i++)
#define it(c) for(auto it=c.begin();it!=c.end();it++)
#define MOD 1000000007

using namespace std;

void Thai_Jase() {
    int d,t,s;
    cin>>d>>t>>s;
    if(t*s>=d) cout<<"Yes";
    else cout<<"No";
}

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

    int ts=1;
    while(ts--) {
      Thai_Jase();
    }
    return 0;
}


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

int main() {
	// your code goes here
	int n,m,i,j,con[607]={0},don[607];
	int s[400005],t[400005];
	double px[607],qx[607],pg[607]={0},qg[607]={0},pm,pmk,pmm,memo,mpt;
	vector<int> g[607],h[607];
	cin >> n >> m;
	for(i=0;i<m;i++){
		cin >> s[i] >> t[i];
		g[s[i]].push_back(t[i]);
		h[t[i]].push_back(s[i]);
	}
	con[n]=1;
	px[n]=0;
	pg[1]=1;
	for(i=n-1;i>=1;i--){
		for(j=0;j<g[i].size();j++){
			con[i]+=con[g[i][j]];
			px[i]+=px[g[i][j]];
		}
		px[i] /= (double)g[i].size();
		px[i] += 1;
	}
	for(i=1;i<n;i++){
		for(j=0;j<g[i].size();j++){
			pg[g[i][j]] += (double)pg[i] / (double)g[i].size();
		}
	}
	don[1]=1;
	qx[1]=0;
	qg[n]=1;
	for(i=2;i<=n;i++){
		for(j=0;j<h[i].size();j++){
			don[i]+=don[h[i][j]];
			qx[i]+=qx[h[i][j]];
		}
		qx[i] /= (double)h[i].size();
		qx[i] += 1.0;
	}
	for(i=n;i>1;i--){
		for(j=0;j<h[i].size();j++){
			qg[h[i][j]] += (double)qg[i] / (double)h[i].size();
		}
	}
	pm = px[1];
	pmk = px[1];
	pmm = px[1] * (double)con[1];
	for(i=0;i<m;i++){
		double pmr;
		pmr=pmk;
		if(g[s[i]].size()==1&&h[s[i]].size()>=1) continue;
		mpt = pg[s[i]]/(double)g[s[i]].size();
		pmr -= mpt;
		pmr -= mpt * px[t[i]];
		memo = (px[s[i]] - (1.0 + px[t[i]]) / (double)g[s[i]].size())/(1.0-1.0/(double)g[s[i]].size());
		pmr += mpt * memo;
		pm=min(pm,pmr);
		
	}
	//printf("%.13lf\n",pmk);
	printf("%.13lf\n",pm);
	return 0;
}

Measured memory_bytes: 5248
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static int H;

        static void Main(string[] args)
        {
            StringBuilder sb = new StringBuilder();
            int[] A = new int[2000001];

            while (true)
            {
                string[] input = Console.ReadLine().Split(' ');

                if (input[0] == "end") break;

                if (input[0][0] == 'i') Insert(A, int.Parse(input[1]));
                else sb.AppendLine(Extract(A).ToString());
            }
            Console.Write(sb);
        }

        static int Extract(int[] A)
        {
            int ret;

            if (H < 1) return int.MinValue;

            ret = A[1];
            A[1] = A[H--];

            MaxHeapify(A, 1);

            return ret;
        }

        static void Insert(int[] A, int key)
        {
            H++;
            A[H] = int.MinValue;

            IncreaseKey(A, H, key);
        }

        static void IncreaseKey(int[] A, int i, int key)
        {
            if (key < A[i]) return;
            A[i] = key;

            while (i > 1 && A[i / 2] < A[i])
            {
                int temp = A[i];
                A[i] = A[i / 2];
                A[i / 2] = temp;

                i /= 2;
            }
        }

        static void MaxHeapify(int[] A, int i)
        {
            int l = i * 2;
            int r = i * 2 + 1;

            int largest = (l <= H && A[l] > A[i]) ? l : i;

            if (r <= H && A[r] > A[largest]) largest = r;

            if (largest != i)
            {
                int temp = A[i];
                A[i] = A[largest];
                A[largest] = temp;

                MaxHeapify(A, largest);
            }
        }
    }
}

Measured memory_bytes: 38800
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n;
    scanf("%lld",&n);
    ll *a = new ll[n];
    ll *b = new ll[n];
    ll *c = new ll[n];
    for(ll i=0;i<n;i++)
    {
        scanf("%lld%lld%lld",&a[i],&b[i],&c[i]);
    }
    ll dp[n][3];
    dp[0][0] = a[0];
    dp[0][1] = b[0];
    dp[0][2] = c[0];
    for(ll i=1;i<n;i++)
    {
        dp[i][0] = max(dp[i-1][1]+a[i],dp[i-1][2]+a[i]);
        dp[i][1] = max(dp[i-1][2]+b[i],dp[i-1][0]+b[i]);
        dp[i][2] = max(dp[i-1][1]+c[i],dp[i-1][0]+c[i]);
    }
    ll res = max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
    printf("%lld\n",res);
}


Measured memory_bytes: 4992
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <numeric>
# include <tuple>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr int INF = 2000000000;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
#define ALL(x)    (x).begin(),(x).end()
#define UNIQ(c)   (c).erase(unique(ALL((c))), end((c)))
#define mp        make_pair
#define eb        emplace_back
typedef pair<LL, LL> P;
typedef pair<P, P> PP;

const int MAX_V = 300;
LL d[MAX_V][MAX_V];//d[i][j]はe={u,v}のコスト
int V;


void warshall_floyd() {
	for (int k = 0; k < V; k++) {
		for (int i = 0; i < V; i++) {
			for (int j = 0; j < V; j++) {
				d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
			}
		}
	}
}

int main() {
	V = 10;
	int h, w;
	cin >> h >> w;
	for (int i = 0; i < 10; i++) {
		for (int j = 0; j < 10; j++) {
			cin >> d[i][j];
		}
	}
	warshall_floyd();
	/*cout << endl;
	for (int i = 0; i < 10; i++) {
		for (int j = 0; j < 10; j++) {
			cout << d[i][j] << " ";
		}
		cout << endl;
	}*/
	int ans = 0;
	int a;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cin >> a;
			if (a == -1)continue;
			if (a == 1)continue;
			ans += d[a][1];
		}
	}
	cout << ans << endl;
	//system("pause");
}



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


void solve(long long N, long long D, std::vector<std::vector<long long>> X){
    long long res = 0;
    for(int i=0;i<N;++i){
        for(int j=i+1;j<N;++j){
            long long tmp = 0;
            for(int k=0;k<D;++k){
                tmp += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
            }
            long long tmp2 = sqrt(tmp);
            if(tmp == tmp2 * tmp2) res++;
        }
    }
    cout<<res<<endl;
}

// Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    long long D;
    scanf("%lld",&D);
    std::vector<std::vector<long long>> X(N, std::vector<long long>(D));
    for(int i = 0 ; i < N ; i++){
        for(int j = 0 ; j < D ; j++){
            scanf("%lld",&X[i][j]);
        }
    }
    solve(N, D, std::move(X));
    return 0;
}


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

using namespace std;

void sshuffle(string &s, size_t h) {
    // shuffle string; swap s[:h) and s[h:)
    string t=s.substr(0, h), u=s.substr(h);
    s = u + t;
}

int main() {
    while (true) {
        char buf[1<<8];
        scanf("%s", buf);
        string s(buf);
        if (s == "-") return 0;

        size_t m;
        scanf("%zu", &m);
        for (size_t i=0; i<m; ++i) {
            size_t h;
            scanf("%zu", &h);
            sshuffle(s, h);
        }

        printf("%s\n", s.c_str());
    }
}

Measured memory_bytes: 2780
/*
  Vivek Rathi
  CSE 2nd Year
  MNNIT
*/
#include<bits/stdc++.h>
using namespace std;
#define M 1000000007
#define ll long long int
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define debug1(x) cout<<#x<<" "<<x<<endl;
#define debug2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<endl;
#define present(c,x) ((c).find(x) != (c).end())
#define null NULL
#define mp make_pair
#define fi first
#define se second
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);
#define inf 1e17
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
int main()
{
	boost
	ll n;
	cin>>n;
	ll h[n];
	for(ll i=0;i<n;i++) cin>>h[i];
	if(n<3)
	{
		if(n==1)
		{
			cout<<0<<endl;
		}
		else if(n==2)
		{
			cout<<abs(h[0]-h[1])<<endl;
		}
		return 0;
	}
	ll dp[n];
	dp[n-2]=abs(h[n-1]-h[n-2]);
	dp[n-3]=min(abs(h[n-1]-h[n-3]),abs(h[n-2]-h[n-3])+dp[n-2]);
	for(ll i=n-4;i>=0;i--)
	{
		dp[i]=min(abs(h[i]-h[i+1])+dp[i+1],abs(h[i+2]-h[i])+dp[i+2]);
	}
	cout<<dp[0]<<endl;
	return 0;
}

Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {

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

        int n = sc.nextInt();
        int k = sc.nextInt();

        String s = sc.next();
        String t  = s.substring(k - 1, k ).toLowerCase();
        System.out.println(s.substring(0, k - 1) + t + s.substring(k , n));

    }

}

Measured memory_bytes: 21844
from math import ceil

S = input().strip()
L = len(S)
ans = [0] * L
for i in range(L):
    if S[i] == 'R' and S[i + 1] == 'L':
        ans[i] = 1
        ans[i+1] = 1
# Rだけ考える
cnt = 0
for i in range(L-1):
    if S[i] == 'R' and S[i+1] == 'L':
        if cnt % 2:
            ans[i] += cnt//2
            ans[i+1] += ceil(cnt/2)
        else:
            ans[i] += cnt//2
            ans[i+1] += cnt//2
        cnt = 0
    else:
        if S[i] == 'R':
            cnt += 1
# Rだけ考える
cnt = 0
for i in range(L-1):
    if S[-i-1] == 'L' and S[-i-2] == 'R':
        if cnt % 2:
            ans[-i-1] += cnt//2
            ans[-i-2] += ceil(cnt/2)
        else:
            ans[-i-1] += cnt//2
            ans[-i-2] += cnt//2
        cnt = 0
    else:
        if S[-i-1] == 'L':
            cnt += 1

print(' '.join([str(a) for a in ans]))


Measured memory_bytes: 10496
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right
# from math import gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint

INF = float("inf")

def myinput():
    return map(int,input().split())

def mylistinput(n):
    return [ list(myinput()) for _ in range(n) ]

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse_flag):
    data.sort(key=lambda x:x[col],reverse=reverse_flag)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    # lsはソート済みであること
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

n = int(input())
a = list(myinput())

ans = 0
for i in range(n):
    if a[a[i]-1]==(i+1):
        ans += 1
print(ans//2)

Measured memory_bytes: 56432
//~ while (clock()<=69*CLOCKS_PER_SEC)
//~ #pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("-Ofast","-funroll-all-loops","-ffast-math")
//~ #pragma GCC target ("avx2")
//~ #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <random>
#include <cmath>
#include <chrono>
#include <cstring>
#include <string>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <bitset>
#include <cassert>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
using LL = long long;
#define eps 1e-8
#define fi first
#define se second
#define endl '\12'
#define eb emplace_back
#define SZ(a) int32_t(a.size())
#define ALL(x) (x).begin(),(x).end()
#define trav(a,x) for (auto& a: x)
#define LOG(FMT...) fprintf(stderr, FMT)
#define close std::ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
#define FOR(i, x, y) for (LL i = (x), _##i = (y); i < _##i; ++i)
#define FORD(i, x, y) for (LL i = (x), _##i = (y); i > _##i; --i)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define CASET int ___T; cin>>___T; for(int __CS=1;__CS<=___T;__CS++)
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pii;
constexpr int mod = 1e9+7;
constexpr int Erica = 998244353;
mt19937 dlsrand(random_device{}());
mt19937 mrand(std::chrono::system_clock::now().time_since_epoch().count()); 
int rnd(int x) { return mrand() % x;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll ex_gcd(ll a, ll b, ll& x, ll& y){if(!b){x=1;y=0;return a;}ll ret=ex_gcd(b,a%b,y,x);y-=a/b*x;return ret;}
LL bin(LL x, LL n, LL MOD) {LL ret = MOD != 1;for (x %= MOD; n; n >>= 1, x = x * x % MOD)if (n & 1) ret = ret * x % MOD;return ret;}
int norm(int x) { return x >= mod ? (x - mod) : x; }
inline LL get_inv(LL x, LL p) { return bin(x, p - 2, p); }
inline ll get_inv(ll a) { ll x, y; ex_gcd(a, mod, x, y); return norm(x + mod);}
template<class T>inline void umin(T &x, T y) {x = x > y ? y : x;}
template<class T>inline void umax(T &x, T y) {x = x < y ? y : x;}
template<class T>inline void dec(T &x, T y) {x -= y; if(x < 0) x += mod;}
template<class T>inline void add(T &x, T y) {x += y; if(x >= mod) x -= mod;}
const double PI = acos(-1.0);
constexpr int INF = 0x3f3f3f3f;
constexpr ll linf = 0x3f3f3f3f3f3f3f3f;
constexpr ull base=2333, P_1=19260817, P_2=999998639;
constexpr int maxn = 1e6+10; // remember to calculate. if tle, check maxn first.

int main()
{
    ll a, b , c;
    cin >> a >> b >> c;
    cout << min(c , a * b) << endl;
    return 0;
}

Measured memory_bytes: 3636
#include<iostream>
#include<cstdio>
#include<string>
#include<ctime>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<stack>
#include<climits>
#include<queue>
#include<map>
#include<set>
#include<sstream>
using namespace std;
typedef long long ll;   
typedef unsigned long long ull;
const int c=1e9 +7;
const int N=900010;
inline long long read()//inline 加速读入
{
	long long x=0;char c=getchar();//x代表返回值，c代表读取的字符
	while (c<'0'||c>'9') c=getchar();//读取所有非数部分
	while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();//如果读取的字符为数，加入返回值
	return x;
}
 inline void write(ll x)
 {
     char F[200];
      int tmp=x>0?x:-x ;
    if(x<0)putchar('-') ;
    int cnt=0 ;
       while(tmp>0)
       {
            F[cnt++]=tmp%10+'0';
            tmp/=10;
       }
       while(cnt>0)putchar(F[--cnt]) ;
 }
int gcd(int x, int y)
 {
     int MAX = max(x, y);
     int MIN = min(x, y);
     return MAX % MIN == 0? MIN : gcd(MIN, MAX % MIN);
 }
 // 快速幂求逆元
long long power_mod(long long a, long long b) {
    long long ans = 1;
    a %= c;
    while (b) {
        if (b & 1) {
            ans = ans * a % c;
        }
        b >>= 1;
        a = a * a % c;
    }
    return ans;
}

int n,m,k;
ll fac[N],ifac[N],p[N]; 
ll inv(ll x) {
    return power_mod(x,c-2);
}

ll C( ll x , ll y ) {
    return (fac[x]*ifac[y]%c*ifac[x-y]%c)%c;
}

int main() {
    cin>>n>>m>>k;
    fac[0]=1ll;
    p[0]=1ll;
    for(int i=1;i<N;i++){
        fac[i]=fac[i-1]*i%c;
        p[i]=p[i-1]*3ll%c;
    }
    for(int i=0;i<N;i++){
        ifac[i]=inv(fac[i]) ;
    }
    ll ans=0,x=1ll;
    n--;
    if(m<k)swap(m,k) ;
    for(int i=0;i<=m+k;i++){
        ans=(ans+C(n+i,n)*p[m+k-i]%c*x)%c;
        if(i<k)x=(x*2ll)%c;
        else if(i<m)x=(x*2ll-C(i,k))%c;
        else  x=(x*2ll-C(i,k)-C(i,m))%c;
    }
    printf("%lld\n",(ans+c)%c) ;
    return 0 ;
}

Measured memory_bytes: 21504
#include <algorithm>
#include <iostream>
using namespace std;
#define MAX_N 110

int main() {
  int N;
  cin >> N;
  int A[2][N];
  for (int i = 0; i < N; i++) cin >> A[0][i];
  for (int i = 0; i < N; i++) cin >> A[1][i];
  int ans = 0, sum1 = 0, sum2 = 0;
  for (int i = 0; i < N; i++) {
    sum1 += A[0][i];
    sum2 = 0;
    for (int j = i; j < N; j++) sum2 += A[1][j];
    ans = max(ans, sum1 + sum2);
  }

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

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

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

	S[K - 1] = S[K - 1] + 0x20;

	cout << S << endl;

	return 0;
}

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

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

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

  int sum = 0;
  for (int a = 1; a <= K; a++) {
    for (int b = 1; b <= K; b++) {
      int d = gcd(a, b);
      for (int c = 1; c <= K; c++) {
	sum += gcd(c, d);
      }
    }
  }

  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 3636
#include <iostream>

using namespace std;

int main(){
    int N, D1, D2; cin >> N >> D1 >> D2;
    int v1 = 1, v2 = 1;
    while(D1%4 == 0){ D1 /= 4; v1 *= 2; }
    while(D2%4 == 0){ D2 /= 4; v2 *= 2; }
    int cnt = 0;
    for(int i=0;i<2*N;i++){
        for(int j=0;j<2*N;j++){
            if(D1%2 == 1){
                if((i/v1 + j/v1)%2 == 1) continue;
            } else {
                if(i/v1%2 == 1) continue;
            }
            if(D2%2 == 1){
                if((i/v2 + j/v2)%2 == 1) continue;
            } else {
                if(i/v2%2 == 1) continue;
            }
            if(cnt < N*N) cout << i << " " << j << endl;
            ++cnt;
        }
    }
}

Measured memory_bytes: 896
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CSharp_AtCoder
{
    
    class Program
    {

        static void Main(string[] args)
        {
            int[] input = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            int sum = input.Sum();

            if (sum >= 22) Console.WriteLine("bust");
            else Console.WriteLine("win");

        }
    }
}


Measured memory_bytes: 13396
#include <stdio.h>
int main(void){
    int n, a[1000], i, f, c=0;
    
    scanf("%d",&n);
    for(i=0;i<n;i++) scanf("%d",&a[i]);
    
    while(1){
        f=0;
        for(i=0;i<n;i++){
            if(a[i]%2!=0) f=1;
        }
        if(f==1) break;
        for(i=0;i<n;i++){
            a[i]=a[i]/2;
        }
        c++;
    }
    printf("%d\n",c);
    return 0;
}

Measured memory_bytes: 1692
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define N 100
ll a,b,c;

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define ces(d) cout<<" "<<endl;

int main() {

ll H,W;
cin>>H>>W;
ll mini=min(H,W);

if(H%3==0||W%3==0){
ce("0");
}else{

fyg(H,1){
	ll max1=W*y;
	ll max2=(H-y)*(W/2);
         ll max3;
if(W%2==0){
max3=max2;
}else{
max3=(H-y)*(W/2+1);
}
        ll mini2=min({max1,max2,max3});
        ll maxi=max({max1,max2,max3});
	mini=min(mini,maxi-mini2);
}

fyg(W,1){
	ll max1=H*y;
	ll max2=(W-y)*(H/2);
         ll max3;
if(H%2==0){
max3=max2;
}else{
max3=(W-y)*(H/2+1);
}
        ll mini2=min({max1,max2,max3});
        ll maxi=max({max1,max2,max3});
	mini=min(mini,maxi-mini2);
}


ce(mini);

}

}

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

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    vector<int> B(N);
    vector<int> C(N);
    for(int i = 0; i < N; i++){
        cin >> A[i];
    }
    for(int i = 0; i < N; i++) cin >>  B[i];
    for(int i = 0; i < N; i++) cin >> C[i];
    int ans = 0;
    int pa = -1;
    for(int a : A){
        //cout << a << "," << B[a-1] << endl;
        ans += B[a-1];
        if(a - pa == 1){
            ans += C[pa-1];
            //cout << C[pa-1] << endl;
        }
        pa = a;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
n, m, x = map(int, input().split())

c = [tuple(map(int, input().split())) for i in range(n)]

ans = []

for i in range(1, 2 ** n):
    com = [0] * n
    for j in range(n):
        if i >> j & 1 == 1:# iのj番目の桁が1かどうか
            com[j] += 1
    ind = [i for i, x in enumerate(com) if x == 1]
    score = [0]*m
    money = 0
    for j in ind:
        money += c[j][0]
        for l in range(m):
            score[l] += c[j][l+1]
    if all([l >= x for l in score]):
        ans.append(money)

if not ans:
    print("-1")
else:
    print(min(ans))

Measured memory_bytes: 69168
#include <iostream>

using namespace std;
int a[60];
int main()
{


    int n,m;
    cin>>n>>m;
    int c,b;
    for(int i=0;i<m;i++)
    {
        cin>>c>>b;
        a[c]++,a[b]++;
    }
    for(int i=1;i<=n;i++)
    {
        cout<<a[i]<<endl;
    }
    return 0;
}


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

typedef long long ll;
#define pii pair<ll , ll>
#define _FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MAXX 105

double dist(ll a , ll b , ll c , ll d){
    return sqrt((a - c) * (a - c) + (b - d) * (b - d));
}

ll n;
ll x[MAXX];
ll y[MAXX];
ll a[MAXX];

int main()
{
    cout.precision(10);
    cin >> n;
    for(ll i = 0; i < n; i++){
        cin >> x[i] >> y[i];
    }
    for(ll i = 1; i <= n; i++){
        a[i] = i;
    }
    double ans = 0;
    ll k = 0;
    do{
            k++;
        for(ll i = 0; i < n - 1; i++){
            ans += dist(x[a[i]] , y[a[i]] , x[a[i + 1]] , y[a[i + 1]]);
        }
    }while(next_permutation(a , a + n));
    ans /= k;
    cout << fixed << ans << endl;
    return 0;
}


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

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);

signed main() {
	int n, k;
	while (cin >> n >> k, n || k) {
		vector<int>s(k, 0);
		vector<vector<int>>b(k, vector<int>(n));
		rep(i, 0, k)cin >> s[i];
		rep(i, 0, n) rep(j, 0, k)cin >> b[j][i];
		rep(j, 0, k) {
			if (accumulate(all(b[j]), 0) > s[j]) {
				cout << "No" << endl;
				goto here;
			}
		}
		cout << "Yes" << endl;
	here:;
	}
	return 0;
}

Measured memory_bytes: 3120
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long n=sc.nextLong();
		long a=2,b=1,c=0;
		for(long i=1; i<n; i++) {
			c = a+b;
			a = b;
			b = c;
		}
		if(n==0)System.out.println(2);
		else if(n==1)System.out.println(1);
		else System.out.println(c);
	}
}


Measured memory_bytes: 22612
<?php
fscanf(STDIN, '%d', $N);
$A = array_map('intval', explode(' ', trim(fgets(STDIN))));
$abs = PHP_INT_MAX;
$neg = 0;
$ans = 0;
for ($i = 0; $i < $N; $i++) {
    $ans += abs($A[$i]);
    $abs = min($abs, abs($A[$i]));
    if ($A[$i] < 0) {
        $neg++;
    }
}
if ($abs === 0 || $neg % 2 === 0) {

} else {
    $ans -= $abs * 2;    
}
printf('%d', $ans);


Measured memory_bytes: 16884
#include <iostream>
#include <string>

using namespace std;

int main()
{
	int k;
	string s;
	cin >> k >> s;

	if (s.length() > k) {
		for (int i = 0; i < k; i++) {
			cout << s[i];
		}
		cout << "..." << endl;
	} else {
		cout << s << endl;
	}

	return 0;
}

Measured memory_bytes: 3620