akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

int main(int argc, char const* argv[])
{
  int i, n, a, b, a_score, b_score;

  while (true) {
    a_score = 0;
    b_score = 0;

    std::cin >> n;
    if (n == 0) { break; }

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

      if (a > b) {
        a_score += (a + b);
      } else if (b > a) {
        b_score += (a + b);
      } else {
        a_score += a;
        b_score += b;
      }
    }
    std::cout << a_score << " " << b_score << std::endl;
  }

  return 0;
}

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

int main(){
    ll n, m; cin >> n >> m;
    map<ll,ll> data;
    ll sum = 0; data[0]++;
    for(int i=0; i<n; i++){
        ll a; cin >> a;
        sum += a;
        sum %= m;
        data[sum]++;
    }
    ll ans = 0;
    for(auto x : data) ans += x.second*(x.second-1)/2;
    cout << ans << endl;
}

Measured memory_bytes: 7460
import java.util.Scanner;

import javax.sql.rowset.serial.SerialArray;

public class Main {

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

			
			int A = sc.nextInt();
			int B = sc.nextInt();

			int ans = 0;
			int ans_max = 0;
			
			ans_max = A + B;
			
			ans = A - B;
			if(ans > ans_max){
			    ans_max = ans;
			}
			
			ans = A * B;
			if(ans > ans_max){
			    ans_max = ans;
			}

		    System.out.println(ans_max);
		    return ;
		}
}


Measured memory_bytes: 22740
import java.util.*;

class Main{
    static Scanner sc=new Scanner(System.in);
    public static void main(String args[]){
        int n=sc.nextInt(),m=sc.nextInt();
        List<String> s=new ArrayList<String>();
        String tmp;
        for(int i=0;i<n;i++){
            tmp=sc.next();
            s.add(tmp);
        }
        Collections.sort(s);

        for(int i=0;i<n;i++){
            System.out.print(s.get(i));
        }
        System.out.println();
    }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); ++i)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using Graph = vector<vi>;  // vi <=> vl
using vb = vector<bool>;
using boolGraph = vector<vb>;
using P = pair<int, int>;  // int <=> ll
const int MOD = 1e9+7;
const double EPS = 1e-9;

int main() {
  int n; cin >> n;
  vi arr(n+1);
  rep(i,n) cin >> arr[i];
  arr[n] = -1;

  sort(all(arr));

  int i = arr.back();

  auto iter = lower_bound(all(arr), i/2);
  int r1 = *iter;
  --iter;
  int r2 = *iter;

  int j;
  if (abs(i - 2*r1) < abs(i - 2*r2)) j = r1;
  else j = r2;

  cout << i << ' ' << j << endl;
  return 0;
}


Measured memory_bytes: 640
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long[] a = new long[n];
		for(int i = 0; i<n; i++){
			a[i]=sc.nextLong();
		}
		long res=0;
		int r = 0;
		long sum=0;
		for(int l = 0; l<n; l++){
			while(r<n && (sum^a[r])==(sum+a[r])){
				sum+=a[r++];
			}
			res+=r-l;
			sum-=a[l];
			
		}
		System.out.println(res);
	}
}

Measured memory_bytes: 85276
/*#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>*/
#include <bits/stdc++.h>

using namespace std;
//using namespace __gnu_pbds;
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

#define FOR(i, a, b) for (int i=a; i<b; i++)
#define F0R(i, a) for (int i=0; i<a; i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
 
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound

const int MOD = 1000000007;
double PI = 4*atan(1);

int H,W,N, grid[100][100];
vector<pii> ok;

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin >> H >> W >> N;
	F0R(i,H) {
	    if (i % 2 == 0) F0R(j,W) ok.pb({i,j});
	    else F0Rd(j,W) ok.pb({i,j});
	}
	int lst = 0;
	FOR(i,1,N+1) {
	    int x; cin >> x;
	    FOR(j,lst,lst+x) grid[ok[j].f][ok[j].s] = i;
	    lst += x;
	}
	F0R(i,H) {
	    F0R(j,W) cout << grid[i][j] << " ";
	    cout << "\n";
	}
}

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

#define endl '\n'
#define int ll
using namespace std;
typedef long long ll;

ll n, k;

void init();
void process();

int32_t main()
{
    ios::sync_with_stdio(false); cin.tie(0);
    init();
    process();
    cout.flush();
    return 0;
}

void init()
{
    cin >> n >> k;
}

void process()
{
    if(k == 0)
    {
        for(ll i = 0; i < (1<<n); i++) cout << i << " " << i << " ";
        cout << endl;
    }
//    else if(k == 1 && n == 1)
//    {
//        cout << 1 << " " << 0 << " " << 1 << " " << 0 << endl;
//    }
    else if(k < (1<<n))
    {
        ll xorsum = 0;
        for(ll i = 0; i < (1<<n); i++) xorsum ^= i;
        if(xorsum == 0)
        {
            for(ll i = 0; i < (1<<n); i++) if(i != k) cout << i << " ";
            cout << k << " ";
            for(ll i = (1<<n)-1; i >= 0; i--) if(i != k) cout << i << " ";
            cout << k << endl;
        }
        else cout << -1 << endl;
    }
    else cout << -1 << endl;
}



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

typedef pair<int, int> P;

vector<P> v;
int N, M;
int ans = 0;

int main() {
  cin >> N >> M;
  bool ok[M];
  v.resize(M);
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    v[i] = P(b-1, a-1);
  }
  sort(v.begin(), v.end());
  int min = 0;
  for (int i = 0; i < M; i++) {
    if (v[i].second >= min) {
      min = v[i].first;
      ans++;
    }
  }
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
int main(){
    int h,w;
    int i,j;
    scanf("%d %d",&h,&w);
    while(h||w){
        for(i=0;i<h;i++){
            for(j=0;j<w;j++){
                printf((i+j)%2? "." : "#");
            }
            printf("\n");
        }
        printf("\n");
        scanf("%d %d",&h,&w);
    }
}

Measured memory_bytes: 1016
A, B = list(map(int, input().rstrip().split()))
if A == 1:
    A = 14

if B == 1:
    B = 14

result = ''
if A == B:
    result = 'Draw'
elif A > B:
    result = 'Alice'
else:
    # A < B
    result = 'Bob'

print(result)


Measured memory_bytes: 2940
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_10_C

最長共通部分列
"""


c = []
def prep_array(X, Y):
    global c
    """ 値が0の2次元配列を用意する。サイズは入力データの最大値を想定して縦横(1000+1)以上必要。 """
    # from array import array
    # c = [array('I', [0] * (len(X)+1)) for _ in range(len(Y)+1)]  #  arrayで用意
    c = [[0]*(len(Y)+2) for _ in range(len(X)+2)] #  リストで用意
    return c


def check_max(array):
    """ 2次元配列の中の最大の値を返す """
    max_lcs = 0
    for row in array:
        temp_max = max(row)
        if temp_max > max_lcs:
            max_lcs = temp_max
    return max_lcs


def calc_lcs4(X, Y, c):
    """
    Y[j]のアクセス方法を変更
    リストの値を一旦変数に保存するように変更
    最長共通部分長を関数内で計算するように変更
    4/5 のテストデータを使用してプロファイリングすると実効時間は 5.6秒
    """
    X = ' ' + X
    Y = ' ' + Y
    m = len(X)
    n = len(Y)
    max_lcs = 0

    pre_row = c[0]
    for i in range(1, m):
        row = c[i]
        XX = X[i]
        for j, YY in enumerate(Y):
            if XX == YY:
                pr_j1 = pre_row[j - 1]
                row[j] = pr_j1 + 1
                if pr_j1+1 > max_lcs:
                   max_lcs = pr_j1 + 1
            else:
                pr_j = pre_row[j]
                r_j1 = row[j-1]
                if pr_j >= r_j1:
                    row[j] = pr_j
                else:
                    row[j] = r_j1
        pre_row = row
    return max_lcs


if __name__ == '__main__':
    # データの入力
    num = int(input())
    #f = open('input.txt')
    #num = int(f.readline())

    for _ in range(num):
        X = input().strip()
        Y = input().strip()

        # 処理の実行
        result = calc_lcs4(X, Y, prep_array(X, Y))

        # 結果の表示
        print(result)



Measured memory_bytes: 31056
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
int INF = 1000000009;
int main()
{
  ll n,m;
  cin >> n >> m;
  ll ans = 0;
  if(n <= m/2){
    ans += n;
    m -= n * 2;
    ans += m / 4;
    cout << ans << endl;
  }else{
    ans += m/2;
    cout << ans << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<unordered_map>
#include<queue>
#include<iomanip>
#include<math.h>
#include<bitset>
#include<cassert>
#include<random>
#include<time.h>
using namespace std;
using ll=long long;
using ld=long double;
using P=pair<int,int>;
#define MOD 1000000007LL
#define INF 1000000000LL
#define EPS 1e-10
#define FOR(i,n,m) for(ll i=n;i<(ll)m;i++)
#define REP(i,n) FOR(i,0,n)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v)  sort(ALL(v));v.erase(unique(ALL(v)),v.end());
#define pb push_back

/* --------------------------------------- */

ll v, e, k;
ll dp[30][150][150];

void solve(ll r) {
	vector<ll> tmp(v, 0);
	vector<vector<ll>> back(r,vector<ll>(v, -1));
	REP(i,r) {
		vector<ll> ntmp(v,-1);
		REP(j,v) REP(k,v) {
			if(tmp[j] == -1 || dp[0][j][k] == -1) continue;
			if(ntmp[k] < tmp[j] + dp[0][j][k]) {
				ntmp[k] = tmp[j] + dp[0][j][k];
				back[i][k] = j;
			}
		}
		tmp = ntmp;
	}
	vector<ll> ans;
	ll maxi = 0;
	REP(i,v) maxi = max(maxi,tmp[i]);
	REP(i,v) {
		if(tmp[i] == maxi) {
			ll pos = i;
			REP(j,r) {
				ans.pb(pos);
				pos = back[r - 1 - j][pos];
			}
			ans.pb(pos);
			reverse(ALL(ans));
			break;
		}
	}
	DUMP(ans);
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> v >> e >> k;
	REP(i,30) REP(j,v) REP(k,v) dp[i][j][k] = -1;
	REP(i,e) {
		ll a, b, c;
		cin >> a >> b >> c;
		dp[0][a][b] = max(dp[0][a][b], c);
	}
	if(k == 0) {
		cout << 0 << endl;
		return 0;
	}
	FOR(i,1,30) REP(j,v) REP(k,v) {
		dp[i][j][k] = dp[i - 1][j][k];
		REP(l,v) {
			if(dp[i - 1][j][l] == -1 || dp[i - 1][l][k] == -1) continue;
			dp[i][j][k] = max(dp[i][j][k], dp[i - 1][j][l] + dp[i - 1][l][k]);
		}
	}
	ll l = 0, r = INF;
	while(r - l > 1) {
		ll m = (l + r) / 2;
		bitset<30> bit(m);
		vector<ll> dp2(v, 0);
		REP(i,30) {
			if(!bit[i]) continue;
			vector<ll> tmp(v, 0);
			REP(j,v) REP(k,v) {
				if(dp[i][j][k] == -1) continue;
				tmp[k] = max(tmp[k], dp2[j] + dp[i][j][k]);
			}
			dp2 = tmp;
		}
		ll maxi = 0;
		REP(i,v) maxi = max(maxi, dp2[i]);
		if(maxi >= k) r = m;
		else l = m;
	}
	if(r == INF) {
		cout << -1 << endl;
	}
	cout << r << endl;
	if(r <= 100) solve(r);
	return 0;
}

/* --------------------------------------- */



Measured memory_bytes: 8492
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<math.h>
#include<map>
#include<iomanip>
#include<functional>

using namespace std;
using  ull = unsigned long long int;

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


int main() {

	int a, b;
	cin >> a >> b;
	if (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0)cout << "Possible" << endl;
	else cout << "Impossible" << endl;




	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<math.h>
#include<string>
#include <iomanip>
#include<deque>

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e8;

using namespace std;


//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(int i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用


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

	int n;
	cin >> n;

	if (n >= 1000)
	{
		cout << "ABD"<< endl;
	}
	else
	{
		cout << "ABC"<< endl;
	}

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define ff first
#define ss second
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define boost ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define check(x) cout << #x << " : " << (x) << endl
#define all(v) v.begin(),v.end() 
#define endl '\n'  
#define show(a) for(auto i:a) cout<<i<<" ";cout<<endl
typedef long long ll; 
typedef unsigned long long ull; 
typedef long double ld;
typedef pair< int , int > mypair;
typedef priority_queue <int> max_heap;
typedef priority_queue <int, vector<int>, greater<int> > min_heap;
const ll mod=1e9+7;
const ll inf=1e9;
const ll N=1e3+10;
bool visited[N];
int dist[N];
int parent[N];
bool g[N][N];
std::vector<int> v[N];
vector<int> ans;
int n;
int sz;
void bfs(int node)
{
	visited[node]=1;
	parent[node]=-1;
	dist[node]=0;
	queue<int> q;
	q.push(node);
	while(q.empty()==0)
	{
		node=q.front();
		q.pop();
		for(auto i:v[node]) if(visited[i]==0) q.push(i),parent[i]=node,dist[i]=dist[node]+1,visited[i]=1;		
	}
}

int main()
{
	boost;
	int m;
	cin>>n>>m;
	while(m--)
	{
		int x,y;
		cin>>x>>y;
		v[x].pb(y);
		g[x][y]=1;
	}
	sz=inf;
	for(int i=1;i<=n;i++)
	{
		memset(visited,0,sizeof(visited));
		memset(dist,0,sizeof(dist));
		memset(parent,0,sizeof(parent));
		bfs(i);
		int dis=inf,ver=-1;
		for(int j=1;j<=n;j++)
		{
			if(visited[j])
			{
				if(dist[j]<dis and  g[j][i])
				{
					dis=dist[j];
					ver=j;
				}
			}

		}
		if(ver!=-1 and sz>dis)
		{
			std::vector<int> temp;
			while(ver!=-1) temp.pb(ver),ver=parent[ver];
			ans=temp;
			sz=ans.size();
		}

	}
	if(sz!=inf) 
	{
		cout<<ans.size()<<endl;
		for(auto i:ans) cout<<i<<endl;
	}
	else cout<<"-1";


   	return 0;
}

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

int main(void){
    string s;
    cin >> s;
    
    long long b = 1;
    long long i;
    for(i = 1; i < s.length(); i++){
        b *= 2;
    }
    
    long long ans = 0;
    long long a = b;
    for(i = s.length() - 1; i >= 0; i--){
        ans += (long long)(s[i] - '0') * a;
        b /= 2;
        a += b * 9;
        b *= 10;
    }
    
    cout << ans << endl;
    
    return 0;
}


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

using namespace std;
typedef long long ll;

int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll n, x, m, s = 0; cin >> n >> x >> m;
    deque<ll> w(m), a;
    for (int i = 0; i < n; i++) {
        if (x == 0) {
            break;
        }
        if (w[x]) {
            ll r = s; n -= i;
            while (a.front() != x) {
                a.pop_front();
            }
            s = accumulate(a.begin(), a.end(), 0ll);
            i = a.size(); r += n / i * s;
            for (int j = 0; j < n % i; j++) {
                r += a[j];
            }
            return cout << r << endl, 0;
        }
        s += x;
        w[x] = 1;
        a.push_back(x);
        x = x * x % m;
    }
    cout << s << endl;
    return 0;
}


Measured memory_bytes: 4608
def b_search(target, sorted)
    l = 0
    r = sorted.size - 1
    while l < r
        center = (l + r) >> 1
        if target < sorted[center] then
            r = center - 1
        else
            l = center + 1
        end
    end
    if target <= sorted[l] then
        return l
    else
        return l + 1
    end
end

input = STDIN.readlines.map{|line|line.strip.split()}
line = input.shift

INF = 10**20
a = line[0].to_i
b = line[1].to_i
q = line[2].to_i

s_list = [-INF]
a.times do |t|
    s_list.push(input.shift[0].to_i)
end
s_list.push(INF)
t_list = [-INF]
b.times do |t|
    t_list.push(input.shift[0].to_i)
end
t_list.push(INF)
q.times do |t|
    x = input.shift[0].to_i
    si = b_search(x, s_list)
    ti = b_search(x, t_list)
    puts([
        (x - s_list[si - 1]).abs + (t_list[ti - 1] - s_list[si - 1]).abs,
        (x - s_list[si - 1]).abs + (t_list[ti] - s_list[si - 1]).abs,
        (x - s_list[si]).abs + (t_list[ti - 1] - s_list[si]).abs,
        (x - s_list[si]).abs + (t_list[ti] - s_list[si]).abs,
        (x - t_list[ti - 1]).abs + (s_list[si - 1] - t_list[ti - 1]).abs,
        (x - t_list[ti - 1]).abs + (s_list[si] - t_list[ti - 1]).abs,
        (x - t_list[ti]).abs + (s_list[si - 1] - t_list[ti]).abs,
        (x - t_list[ti]).abs + (s_list[si] - t_list[ti]).abs,
    ].min)
end


Measured memory_bytes: 55096
//C
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

//Others

//LOVE NyantakoGG

using namespace std;


int main() {
	int N;
	cin >> N;
	vector<int>data(N);
	for (int i = 0; i < N; i++) {
		cin >> data[i];
	}
	vector<int>dp(N);
	dp[0] = 0;
	dp[1] = abs(data[1] - data[0]);
	for (int i = 2; i < N; i++) {
		dp[i] = min(dp[i - 2] + abs(data[i - 2] - data[i]), dp[i - 1] + abs(data[i - 1] - data[i]));
	}
	cout << dp[N - 1] << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define DB(x) cerr << __LINE__ << ": " << #x << " = " << (x) << endl
#define ll long long
using namespace std;

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

	int n;
	cin >> n;
	vector<int> a(n+5, 0);
	int ans = 0;
	for(int i = 1; i <= n; ++i) cin >> a[i];
	for(int i = 1; i <= 100; ++i) {
		int cnt = 0, start = 0;
		for(int j = 1; j <= n+1; ++j) {
			if(start == 0 && a[j] != 0) {
				++cnt;
				start = 1;
			}
			else if(start == 1 && a[j] == 0) {
				start = 0;
			}
			if(a[j] != 0) --a[j];
		}
		ans += cnt;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES //M_PI, M_E
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define ar array
#define pb push_back
ll power(ll a,ll b){ll r=1;for(;b;b>>=1){if(b&1)r=r*a%mod;a=a*a%mod;}return r;}
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	string s,t;
	cin>>s>>t;
	sort(s.begin(),s.end());
	sort(t.begin(),t.end());
	reverse(t.begin(),t.end());
	if(s<t)
		cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
typedef long long ll;
int main(){
  ll x,n;
  ll tmp;
  cin>> n >> x;
  if(x==1||x==2*n-1){
    cout << "No\n";
    return 0;
  }
  cout << "Yes\n";
  for(int i=0;i<2*n-1;i++){
    if(i<n-1){
      tmp = x-(n-1-i);
      if(tmp<=0) tmp += 2*n-1;
    }else{
      tmp = x+(-n+1+i);
      if(tmp>2*n-1) tmp-=2*n-1;
    }
    cout << tmp<<endl;
  }
}


Measured memory_bytes: 1536
from math import log10
from math import factorial

n = int(input())
m_keta = int(log10(n)) + 1
res = 0
for i in range(3, m_keta):
    for n3 in range(i-3+1):
        for n5 in range(i-3-n3+1):
            n7 = i-3-n3-n5
            res += factorial(i)//(factorial(n3+1) * factorial(n5+1)* factorial(n7+1))
shichigo = (3,5,7)
cnt = 0
def tes(k, x):
    cnt = 0
    for s in shichigo:
        y = x + s * (10 ** (k-1))
        if y <= n:
            if k==1:
                if '3' in str(y) and '5' in str(y) and '7' in str(y):
                    cnt += 1 
                else:
                    continue
            else:
                cnt += tes(k-1, y)
        else:
            continue
    return cnt
cnt += tes(m_keta, 0)
res += cnt
print(res)

Measured memory_bytes: 3064
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repe(i,n) for (int i = 0; i <= (n); ++i)
#define repe1(i,n) for (int i = 0; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
#define pb(x) push_back(x)
#define eb(k,v) emplace_back(k,v)
#define ct(res) cout << res << "\n";
#define vi vector<int>
#define vl vector<ll>
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1e9;
const ll MOD = 1000000007;
using Graph = vector<vector<int>>;
ll gcd(ll a, ll b) {return (a%b) ? gcd(b, a%b) : b;}
ll modPow(ll x, ll n) {
    if(n==0) return 1;
    ll res = modPow(x*x%MOD, n/2);
    if(n&1) res=res*x%MOD;
    return res;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int a,b;cin>> a>>b;
    int d = a/b;
    int r = a%b;
    long double f2;
    f2 = 1.0*a/b;
    cout << d << " " << r << " " << fixed << setprecision(30) << f2 << "\n";
}



Measured memory_bytes: 3256
#include <bits/stdc++.h>
#define PREP(i, s, x) for(ll i = (s); i < (x); i++)
#define MREP(i, s, x) for(ll i = (s); i >= (x); i--)
#define REP(i, x) PREP(i, 0, x)
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
template<typename T> inline bool chmax(T &a, T b) { return ((a < b) ? (a = b, true) : (false)); }
template<typename T> inline bool chmin(T &a, T b) { return ((a > b) ? (a = b, true) : (false)); }

// variable -------------------------------------------

constexpr ll INF = (1ll << 59);
constexpr ll MOD = 1000000007ll;

// structure ------------------------------------------

// function -------------------------------------------

// main -----------------------------------------------

int main() {
	ll n;
	cin >> n;
	vector<ll> l(n);
	REP(i, n){
		cin >> l[i];
	}

	ll cnt = 0;
	REP(i, n){
		PREP(j, i+1, n){
			PREP(k, j+1, n){
				if(l[i] != l[j] && l[j] != l[k] && l[k] != l[i]){
					ll mx = max(max(l[i], l[j]), l[k]);
					if(mx < (l[i] + l[j] + l[k]) - mx){
						cnt ++;
					}
				}
			}
		}
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
int n,m,u,v;
vector<int> g[100010];
int dp[100010];

int dfs(int u,int par){
	if(~dp[u])return dp[u];
	int a=-1;
	for(auto x:g[u]){
		if(x==par)continue;;
		a=max(a,dfs(x,u));
	}
	return dp[u]=a+1;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	memset(dp,-1,sizeof dp);
	int ma=0;
	cin>>n>>m;
	for(int i=0;i<m;i++){
		cin>>u>>v;
		g[u].push_back(v);
	}
	for(int i=1;i<=n;i++){
		ma=max(ma,dfs(i,-1));
	}
	cout<<ma<<endl;
	return 0;
}

Measured memory_bytes: 8832
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
typedef long long ll;
int a[N],n;
bool cmp(const int &a,const int &b){return a>b;}
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i];
	sort(a+1,a+n+1,cmp);
	int X;
	int th;
	for(int i=0;i<n;i++){
		int H=i,W=a[i+1]-1;
		if(H<=W)X=H,th=(a[i+1]-1-H)%2;
	}
	int tu=0;
	for(int i=X+1;i<n;i++){
		if(a[i+1]-1==X)tu^=1;
	}
	if(tu||th)cout<<"First"<<endl;
	else cout<<"Second"<<endl;
}

Measured memory_bytes: 640
n = int(input())
if n%10 == 2 or n%10 == 4 or n%10 == 5 or n%10 == 7 or n%10 == 9:
	print('hon')
if n%10 == 3:
	print('bon')
if n%10 == 0 or n%10 == 1 or n%10 == 6 or n%10 == 8:
	print('pon')

Measured memory_bytes: 9176
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include <cmath>
#include <limits>
#include<set>
#include <iomanip>
#include <queue>
#include <string>
#pragma GCC optimize("Ofast")
using namespace std;
const long long INF=200000000;
//setprecision(2) <<

const int MOD = 1000000007;

long long max(long long a,long long b){
	if(a<b)return b;
	else return a;	
}
long long min(long long a,long long b){
	if(a>b)return b;
	else return a;	
}

class Edge{
public:
	long long from;
	long long to;
	long long w;
};


int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	long long N;
	cin>>N;
	long long ans=INF;
	int a[N];
	for(int i=0;i<N;i++){
		cin>>a[i];
	}
	for(int i=-200;i<200;i++){
		long long num=i;
		long long data=0;
		for(int j=0;j<N;j++){
			data+=(num-a[j])*(num-a[j]);
		}
		ans=min(ans,data);
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
#ABC142 A

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
print(math.ceil(n/2)/n)

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

int main(){
  ll x;
  cin >> x;
  vector<ll> a = {5,4,3,2,1};
  ll n = x/100;
  ll rest = x%100;
  ll cnt = 0;
  ll num = 0;
  ll c = 0;
  while( true ){
    if( rest - num >= a.at(c) ){
      num += a.at(c);
      cnt++;
    }else{
      c++;
    }
    if( num > rest || cnt > n ){
      cout << 0 << endl;
      return 0;
    }
    if( rest == num ){
      cout << 1 << endl;
      return 0;
    }
    
  }
  return 0;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	var ans int64
	g := func(x int) int64 {
		y := int64(n / x)
		return int64(x) * y * (y + 1) / 2
	}
	for i := 1; i <= n; i++ {
		ans += g(i)
	}
	fmt.Println(ans)
}


Measured memory_bytes: 1792
function main(input) {
    var n = input[0]-0;
    var sum = 0;
    var s = input[0].split("").forEach(v=>{
        sum += v-0;
    });
    console.log(n%sum==0?"Yes":"No");
}
main(require('fs').readFileSync('/dev/stdin', 'utf8').trim().split("\n"))


Measured memory_bytes: 7496
use std::io;

fn main() {
    println!("{}", yes_no(read_string().starts_with("YAKI")))
}

fn read_string() -> String {
    let mut input = String::new();
    io::stdin().read_line(&mut input).unwrap();
    input.trim().to_owned()
}

fn yes_no(flag: bool) -> String {
    match flag {
        true => "Yes".to_owned(),
        false => "No".to_owned(),
    }
}


Measured memory_bytes: 4352
<?php
fscanf(STDIN, "%d %d", $N, $K);

$answer = 0;
if ($K % 2 === 0) {
	$base = $K / 2;
	$answer += pow(floor(($N - $base) / $K) + 1, 3);
}
$answer += pow(floor($N / $K), 3);
printf("%d", $answer);


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

int main()
{
    char a;
    cin >> a;
    if(a == 'a' || a == 'i' || a == 'u' || a == 'e' || a == 'o') cout << "vowel" << endl;
    else cout << "consonant" << endl;
}


Measured memory_bytes: 256
import java.util.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main {

	int INF = 1 << 28;
	int[][] map;
	int w,h,n;
	P s;
	
	void run() {
		Scanner sc = new Scanner(System.in);
		h = sc.nextInt();
		w = sc.nextInt();
		n = sc.nextInt();
		map = new int[h+2][w+2];
		
		for(int i=0;i<h+2;i++) fill(map[i], -1);
		for(int i=1;i<=h;i++) {
			String str = sc.next();
			for(int j=1;j<=w;j++) {
				switch (str.charAt(j-1)) {
				case('.'): map[i][j] = 0; break;
				case('X'): map[i][j] = -1; break;
				case('S'): map[i][j] = 0; s = new P(j, i, 0); break;
				default: map[i][j] = str.charAt(j-1)-'0';
				}
			}
		}
		System.out.println(bfs());
	}
	int dx[] = {-1,0,1,0};
	int dy[] = {0,-1,0,1};
	int bfs() {
		
		P p = s;
		int ans = 0;
		
		for(int i=1;i<=n;i++) {
			boolean[][] visited = new boolean[h+2][w+2];
			LinkedList<P> que = new LinkedList<P>();
			que.add(p);
			for(;!que.isEmpty();) {
				p = que.removeFirst();
				if(map[p.y][p.x] == i) break;
				for(int j=0;j<4;j++) {
					if( !visited[p.y+dy[j]][p.x+dx[j]] && map[p.y+dy[j]][p.x+dx[j]] >= 0 ) {
						que.addLast(new P(p.x+dx[j], p.y+dy[j], p.c+1));
						visited[p.y+dy[j]][p.x+dx[j]] = true;
					}
				}
			}
			ans += p.c;
			p.c = 0;
		}
		return ans;
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
	
	class P {
		int x, y, c;
		P(int x, int y, int c) {
			this.x = x;
			this.y = y;
			this.c = c;
		}
	}
}

Measured memory_bytes: 21000
#include <bits/stdc++.h>
using namespace std;
 
 int Arr[101];
int main() {
	// your code goes here
	int K,T;
	scanf("%d%d",&K,&T);
	for(int i=0;i<T;i++){
		scanf("%d",&Arr[i]);
	}
	sort(Arr,Arr+T,greater<int>());
	for(int i=0;i<T-1;i++){
		int A = max(Arr[i],Arr[i+1]);
		int B = min(Arr[i],Arr[i+1]);
		Arr[i] = 0;
		Arr[i+1] = A-B;
	}
	if(Arr[T-1]==0)printf("0");
	else printf("%d",Arr[T-1]-1);
	return 0;
}

Measured memory_bytes: 384
#include "bits/stdc++.h"

using namespace std;

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

const double PI = 3.1415926535897932384626433832795;

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

int gcd(int x, int y) { return y ? gcd(y, x % y) : abs(x); }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : abs(x); }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

// 解法はすぐ分かったが、何故が実装がバグったので、解説をﾁｮｯﾄ見た(は?)

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

	int n, k;
	cin >> n >> k;

	vector<int> v(n);
	for (auto &a : v) {
		cin >> a;
	}

	int ans = 0;
	for (int left = 0; left <= k; left++) {
		for (int right = 0; right <= k - left; right++) {
			if (left + right > n) {
				continue;
			}

			int now = 0;
			vector<int> s;

			for (int i = 0; i < left; i++) {
				now += v[i];
				s.push_back(v[i]);
			}

			for (int i = n - right; i < n; i++) {
				now += v[i];
				s.push_back(v[i]);
			}

			sort(begin(s), end(s));

			int d = k - left - right;
			for (int i = 0; i < d; i++) {
				if (i >= s.size() || s[i] >= 0) {
					break;
				}
				now -= s[i];
			}

			ans = max(ans, now);
		}
	}

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
	int w, h, n;
	cin >> w >> h >> n;

	int A[3 * n];
	for (int i = 0; i < 3 * n; i++) {
		cin >> A[i];
	}
	int C[w][h];
	for (int i = 0; i < w; i++) {
		for (int j = 0; j < h; j++) {
			C[i][j] = 0;
		}
	}
	for (int k = 0; k < n; k++) {
		if (A[3 * k + 2] == 1) {
			for (int j = 0; j < h; j++) {
				for (int i = A[3 * k]-1; i >= 0; i--) {
					C[i][j] = 1;
				}
			}
		}
		else if (A[3 * k + 2] == 2) {
			for (int j = 0; j <h; j++) {
				for (int i = A[3 * k] ; i<w; i++) {
					C[i][j] = 1;
				}
			}

		}
		else if (A[3 * k + 2] == 3) {
			for (int i = 0; i < w; i++) {
				for (int j = A[3 * k+1]-1; j >=0; j--) {
					C[i][j] = 1;
				}
			}
		}
		else if (A[3 * k + 2] == 4) {
			for (int i = 0; i < w; i++) {
				for (int j = A[3 * k+1]; j < h ; j++) {
					C[i][j] = 1;
				}
			}
		}
	}
	int cnt = 0;

	for (int i = 0; i < w; i++) {
		for (int j = 0; j < h; j++) {
			if (C[i][j] == 1) {
				cnt++;
			}
		}
	}

	cout << w * h - cnt << endl;
	return 0;

}

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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vd = vector<double>;
using vs = vector<string>;

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

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

    ll N, M;
    cin >> N >> M;
    string S, T;
    cin >> S >> T;

    ll L = (N*M)/gcd(N, M);

    ll s = L/M;
    ll r = L/N;
    for(ll i=0; i*s<N; i++) {
        if(S[i*s] != T[i*r]) {
            cout << -1 << endl;
            return 0;
        }
    }

    cout << L << endl;

    return 0;
}


Measured memory_bytes: 640
#include <iostream> // cin, cout, cerr
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota
#include <cstdio> // printf, scanf
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <iomanip> // cout<<setprecision(n)
#include <functional> // function<void(int)>
#include <cmath>

#ifdef DEBUG
#include "debug.hpp"
#else
#define debug(...)
#endif

#define int long long // at least int64 > 9*10^18
#define ENDL '\n'
#define rep(i,n) for(int i = 0; i < (n); i++)
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
/* libraries */

// ceil of a/b
inline int ceil(int a, int b) { return (a%b?a/b+1:a/b); }


signed main() {
	int h,a;
	std::cin >> h >> a;
	print(ceil(h,a));
	return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;

namespace AizuOnlineJudge
{
    class Program
    {
        static void Main(string[] args)
        {
            while(true)
            {
                var arr = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
                if (arr[0] == 0 && arr[1] == 0) break;

                var en = Enumerable.Range(0, arr[1]);

                var a = string.Join("", en.Select(e => e % 2 == 0 ? "#" : "."));
                var b = string.Join("", en.Select(e => e % 2 == 0 ? "." : "#"));

                Enumerable.Range(0, arr[0]).ToList().ForEach(e => Console.WriteLine(e % 2 == 0 ? a : b));

                Console.WriteLine();
            }
        }
    }
}



Measured memory_bytes: 18372
#include <bits/stdc++.h>
typedef long long ll;
#define pb push_back
#define mii map <int, int>
#define mll map <ll, ll>
#define pii pair <int, int>
#define pll pair <ll, ll>
#define vi vector <int>
#define vd vector <double>
#define vll vector <ll>
#define fi first
#define se second
#define si set <int>
#define sll set <ll>
#define spii set <pii>
#define vs vector <string>
#define vpii vector <pair <int,int> >
#define vpll vector <pair <long long,long long> >
#define vvi vector <vector <int> >
#define vvpii vector <vector <pii > >
#define forn(i, n) for (int i = 0; i < (n); i++)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define for1(i, n) for (int i = 1; i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(),(x).rend()


using namespace std;
const ll INFLL = 1e18;
const int MAXN = 1e6+100;
const ll INF = 1e9;
const ll mod1=1e9+7;
const ll mod2=2e9+11;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#ifdef LOCAL
    freopen("a.in","r",stdin);
#endif
    int n;
    cin>>n;
    string s;
    cin>>s;
    int q;
    cin>>q;
    set <int> ss[26];
    for (int i=0;i<s.size();i++)
        ss[s[i]-'a'].insert(i);
    while (q--)
    {
        int x;
        cin>>x;
        if (x==1)
        {
            int l;
            char c;
            cin>>l>>c;
            l--;
            ss[s[l]-'a'].erase(l);
            ss[c-'a'].insert(l);
            s[l]=c;

        }
        else
        {
            int sum=0;
            int l,r;
            cin>>l>>r;
            l--,r--;
            for (int i=0;i<26;i++)
            {
                auto to=ss[i].lower_bound(l);
                if (to!=ss[i].end())
                {
                    if (*to<=r)
                        sum++;
                }
            }
            cout<<sum<<'\n';
        }
    }




}

Measured memory_bytes: 26268
N = int(input())
A = [int(c) for c in input().split()]
A.sort()
while True:
    pivot = A.pop(0)
    A = [a % pivot for a in A if a % pivot != 0]
    if len(A) == 0:
        print(pivot)
        break
    A.append(pivot)
    A.sort()


Measured memory_bytes: 14224
N = int(input())
H = [int(x) for x in input().split()]
C = 0
for i in range(N-1):
  if H[i] > H[i+1]:
    H[i+1]=H[i+1]+1
  if H[i] <= H[i+1]:
    C += 1
if C == N-1:
  print("Yes")
else:
  print("No")


Measured memory_bytes: 14252
import java.util.Scanner;

public class Main {
	static int[][] a = new int[3][3];
	static int[][] opened = new int[3][3];
			
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		for (int i = 0; i < 3; i++) {
			for (int j = 0; j < 3; j++) {
				a[i][j] = sc.nextInt();
			}
		}
		
		int n = sc.nextInt();
		
		for (int i = 0; i < n; i++) {
			int b = sc.nextInt();
			open(b);
		}
		
//		for (int i = 0; i < 3; i++) {
//			for (int j = 0; j < 3; j++) {
//				System.out.print(opened[i][j] + " ");
//			}
//			System.out.println();
//		}
		
		String ans = isBingo() ? "Yes" : "No";
		System.out.println(ans);
		sc.close();
	}
	
	static void open(int b) {
		for (int i = 0; i < 3; i++) {
			for (int j = 0; j < 3; j++) {
				if (a[i][j] == b) {
					opened[i][j] = 1;
				}
			}
		}
	}
	
	static boolean isBingo() {
		for (int i = 0; i < 3; i++) {
			int cnt = 0;
			for (int j = 0; j < 3; j++) {
				cnt += opened[i][j];
			}
			if (cnt == 3) {
				return true;
			}
		}
		
		for (int j = 0; j < 3; j++) {
			int cnt = 0;
			for (int i = 0; i < 3; i++) {
				cnt += opened[i][j];
			}
			if (cnt == 3) {
				return true;
			}
		}
		
		if (opened[0][0] + opened[1][1] + opened[2][2] == 3 
				|| opened[2][0] + opened[1][1] + opened[0][2] == 3) {
			return true;
		}
			
		return false;
	}

}


Measured memory_bytes: 22612
S = input().split()
W = int(S[0])
H = int(S[1])
x = int(S[2])
y = int(S[3])
r = int(S[4])
-100 <= x,y <= 100
0 < W,H,r <= 100
if (x - r < 0 or W < x + r or y - r < 0 or H < y + r) :
    print("No")
else :
    print("Yes")


Measured memory_bytes: 5600
/*
 * atcoder/abc130/a.cpp
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>

using namespace std;

#define ll long long

#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template <class T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }

int N, K;
string S;

void input() {
  cin >> N >> K >> S;
  K--;
}

void solve() {
  for (int n=0; n<N; n++) {
    if (n==K) cout << (char)tolower(S[n]);
    else cout << S[n];
  }
  cout << endl;
}

int main() {
  // cout.precision(15);
  input();
  solve();
  return 0;
}


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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

std::string S;

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

  std::cin >> S;

  if(S[2] == S[3] && S[4] == S[5]){
      std::cout << "Yes" << std::endl;
  }else{
      std::cout << "No" << std::endl;
  }
}


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

int main() {
    string S;
    cin >> S;

    int N = S.size();
    vector<int> a(2020);
    a[0]++;
    ll cnt = 0, now = 0, sum = 1;

    for (int i = N - 1; i >= 0; --i) {
        now += (S[i] - '0') * sum;
        now %= 2019;
        cnt += a[now];
        ++a[now];
        sum *= 10;
        sum %= 2019;
    }

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 3752
N, M = map(int, input().split())
route = [list(map(int, input().split())) for i in range(M)]

first = [a[1] for a in route if a[0] == 1]
second = [a[0] for a in route if a[1] == N]

ans = 'POSSIBLE' if set(first) & set(second) else 'IMPOSSIBLE'
print(ans)

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

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("avx,avx2")

using namespace std;

#define int long long
#define sz(a) (int) (a).size()
#define all(a) (a).begin(), (a).end()
#define x first
#define y second

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

int can(int x, int y) {
    while (x % y == 0) x /= y;
    return ((x - 1) % y == 0);
}

int solve2(int n) {
    int ans = 0;
    int nn = n - 1;
    int d = 1;
    while (d * d <= nn) {
        if (nn % d == 0) {
            if (d != 1) {
                ans++;
            }
            if (nn / d != 1 && d != nn / d) {
                ans++;
            }
        }
        d++;
    }
    d = 1;
    while (d * d <= n) {
        if (n % d == 0) {
            if (d != 1) {
                if (can(n, d)) {
                    ans++;
                }
            }
            if (n / d != 1 && d != n / d) {
                if (can(n, n / d)) {
                    ans++;
                }
            }
        }
        d++;
    }
    return ans;
}

int model(int n, int k) {
    while (n >= k) {
        if (n % k == 0) n /= k;
        else n -= k;
    }
    return n == 1;
}

int solve1(int n) {
    int ans = 0;
    for (int i = 2; i <= n; i++) {
        if (model(n, i)) {
            ans++;
        }
    }
    return ans;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    int n;
    cin >> n;
    cout << solve2(n) << "\n";


    return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main (String[] args) {
		Scanner in = new Scanner(System.in);
		int h = in.nextInt();
		int w = in.nextInt();
		String[] a = new String[h];
		for (int i = 0; i < h; i++) {
			a[i] = in.next();
		}

		boolean[] row = new boolean[h];
		Arrays.fill(row, false);
		boolean[] col = new boolean[w];
		Arrays.fill(col, false);
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				if (a[i].charAt(j) == '#') {
					row[i] = true;
					col[j] = true;
				}
			}
		}

		for (int i = 0; i < h; i++) {
			if (row[i]) {
				for (int j = 0; j < w; j++) {
					if (col[j]) {
						System.out.print(a[i].charAt(j));
					}
				}
				System.out.println();
			}
		}
	}
}


Measured memory_bytes: 24512
#include "bits/stdc++.h"

using namespace std;

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

int main() {
    int a;
    cin >> a;
    int sum = 0;
    for (int i = 1; i <= a; ++i) {
        for (int j = 1; j <= a; ++j) {
            for (int k = 1; k <= a; ++k) {
                 int b = gcd (j, k);
                 int c = gcd(i, b);
                 sum += c;
            }
        }
    }

    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 3640
#include<stdio.h>
#include<stdlib.h>

#define MAX 100005

typedef struct{
  char name[10];
  int time;
}Q;

Q data[MAX+1];
int head=0, tail=0, n;

void enqueue(Q);
Q dequeue(void);

int main()
{
  int q, sum_t=0, i;
  Q p;
  
  scanf("%d%d",&n,&q);
  for( i=0 ; i<n ; i++ ){
    scanf("%s%d",data[i].name, &data[i].time);
    enqueue(data[i]);
  }
  i=0;

  while(i!=n){
    p = dequeue();
    if(p.time>q) {
      p.time = p.time-q;
      enqueue(p);
      sum_t += q;
    }
    else{
      sum_t += p.time;
      p.time = sum_t;
      data[i]=p;
      printf("%s %d\n",data[i].name,data[i].time);
      i++;
    }
  }


  return 0;
}

void enqueue(Q x)
{
  data[tail] = x;
  if(tail+1==MAX) tail=0;
  else tail++;
}

Q dequeue(void)
{
  Q x;
  x = data[head];
  if(head+1==MAX) head = 0;
  else head++;
  return x;
}

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

#ifndef __TOPCYBERFLOWER
#define debug(...) 0
#else
#define debug(...) cout << " [-] ", _dbg(#__VA_ARGS__, __VA_ARGS__)
template<class TH> void _dbg(const char *sdbg, TH h){ cout << sdbg << '=' << h << endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
    while(*sdbg != ',') cout << *sdbg++;
    cout << '=' << (h) << ','; 
    _dbg(sdbg+1, a...);
}
#endif

#define TYPEMAX(type)   numeric_limits<type>::max()
#define TYPEMIN(type)   numeric_limits<type>::min()
typedef long long ll;
typedef pair<int,int> pii;
const ll MD=1e9+7;
ll pow(ll x, ll y){
    ll res=1;
    while(y>0ll){
        if(y%2==1ll) res=(res*x)%MD;
        x=(x*x)%MD;
        y/=2;
    }
    return res;
}
ll combi(ll n, ll x){
    ll res=1;
    ll xx=1;
    for(ll i=1;i<=x;i++) xx=(xx*i)%MD;
    for(ll i=n-x+1;i<=n;i++) res=(res*i)%MD;
    return (res*pow(xx,MD-2))%MD;
}
int main(void){
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    ll n,x,y; cin>>n>>x>>y;
    cout<<(pow(2ll,n)+MD-1ll+MD-combi(n,x)+MD-combi(n,y))%MD;
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <queue>
#include <climits>
#include <set>
#include <map>
#include <stack>
#include <iomanip>
#include <tuple>
#include <limits>
#define ll long long
using namespace std;
struct all_init
{
    all_init()
    {
        cout << fixed << setprecision(12);
    }
} All_init;

int main()
{
    string s;
    cin>>s;
    ll ans=0;
    for(ll i=0;i<s.size()-1;i++){
        if(s[i]!=s[i+1]){
            ans++;
        }

    }
    cout<<ans<<endl;
    

    

}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define LOOP(i,o) for(i=0;i<o;i++)
int main() {
  int n;
  string s;
  cin>>n;
  cin>>s;
  int i;
  int ans=1;
  LOOP(i,n-1){
    if(s[i]!=s[i+1]){
      ans++;
    }
  }
  cout<<ans<<endl;
}


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

using namespace std;

using ll = long long;

const int maxn = 2e5 + 5;
int n;
int a[maxn], b[maxn];

int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) scanf("%d %d", a + i, b + i);
	sort(a, a + n); sort(b, b + n);
	if (n % 2 == 1) {
		printf("%lld\n", (ll)b[n / 2] - a[n / 2] + 1);
	}
	else {
		printf("%lld\n", (ll)b[n / 2 - 1] + b[n / 2] - a[n / 2 - 1] - a[n / 2] + 1);
	}

	return 0;
}

Measured memory_bytes: 5388
import sys
import copy
import math
import bisect
import pprint
import bisect
from functools import reduce
from copy import deepcopy
from collections import deque

def lcm(x, y):
    return (x * y) // math.gcd(x, y)

if __name__ == '__main__':
    a = [int(i) for i in input().split()]

    if a[0] %2 ==1:
        print((a[0]//2)*(a[0]//2+1))
    else:
        print((a[0]//2)*(a[0]//2))


Measured memory_bytes: 3828
#include<bits/stdc++.h>
using namespace std;
//#define int long long
const int inf = INT_MAX;

signed main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int n;
	cin>>n;
	int a[n], c[n];

	for(int i=0; i<n; ++i)
	{
		cin>>a[i];
		c[i]=inf;
	}
	if(n==2){
		cout<<(int)abs(a[0]-a[1]);
		return 0;
	}
	c[0]=0;
	for(int curpos=0; curpos<=n-2; ++curpos)
	{
		for(int i : {1, 2})
			if(curpos+i<=n-1)
				c[curpos+i] = min(c[curpos+i], c[curpos]+ (int)abs(a[curpos]-a[curpos+i]));
	}
	cout<<c[n-1];
	return 0;	
}

Measured memory_bytes: 4296
#include <bits/stdc++.h>
typedef long long ll;
#define REP(i,n) for(int i=0;i<n;i++)
#define ALL(x) (x).begin(),(x).end()
using namespace std;

//素因数分解
vector<pair<ll,int>> factorize(ll n){
    vector<pair<ll,int>>res;
    for(ll i=2;i*i<=n;i++){
        if(n%i)continue;
        res.emplace_back(i,0);
        while (n%i == 0)
        {
        n /= i;
        res.back().second++;
        }
        
    }
    if(n != 1) res.emplace_back(n,1);
    return res;
}

int main(){
    string A,B,C,ans;
    cin >> A >> B >> C;
    ans =  A[0];
    ans += B[1];
    ans += C[2];
    cout << ans << endl;
}

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

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

    vector<int> c(26);
    rep(i, 26) cin >> c.at(i);

    vector<vector <int>> s(d, vector<int>(26));

    rep(i, d) {

        rep(j, 26) {
            cin >> s.at(i).at(j);
        }

        int MaxValue = 0;
        int num = 0;
        rep(k, 26) {
            if (s.at(i).at(k) > MaxValue) {
                MaxValue = s.at(i).at(k);
                num = k + 1;
            }
        }
        cout << num << endl;
    }
    return 0;
}

Measured memory_bytes: 3680