akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(long long i=0;i<x;i++)
#define repn(i,x) for(long long i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
vector<pair<string,P> >vec;
// vector<vector<int>> data(3, vector<int>(4));
ll d[2010][2010];
long long K;

ll nor(ll n) {
	return max(min(n, 2*K+2), 0LL);
}

void dplus(ll x, ll y) {
	ll le = nor(x), ri = nor(x+K), dw = nor(y), up = nor(y+K);
	d[le][dw]++;
	d[ri][dw]--;
	d[le][up]--;
	d[ri][up]++;
}

int main(){	
	long long N;
	scanf("%lld",&N);
	vector<char> c(N-1+1);
	vector<long long> y(N-1+1);
	vector<long long> x(N-1+1);
	scanf("%lld",&K);
	for(int i = 0 ; i <= N-1 ; i++){
		scanf("%lld",&x[i]);
		scanf("%lld",&y[i]);
		cin >> c[i];
	}
	rep(i, N) {
		if (c[i] == 'B') {
			x[i] = x[i]%(2*K);
			y[i] = y[i]%(2*K);
		} else {
			x[i] = x[i]%(2*K);
			y[i] = (y[i]+K)%(2*K);
		}
	}

	rep(i, N) {
		dplus(x[i]+1-2*K, y[i]+1);
		dplus(x[i]+1-2*K, y[i]+1-2*K);
		dplus(x[i]+1-K, y[i]+1-K);
		dplus(x[i]+1+K, y[i]+1-K);
		dplus(x[i]+1, y[i]+1);
		dplus(x[i]+1, y[i]+1-2*K);
		dplus(x[i]+1-K, y[i]+1+K);
		dplus(x[i]+1+K, y[i]+1+K);
	}
	
	rep(i, 2*K) {
		rep(j, 2*K) {
			d[i+1][j] += d[i][j];
		}
	}

	rep(j, 2*K) {
		rep(i, 2*K) {
			d[i][j+1] += d[i][j];
		}
	}

	ll res = 0;

	ll xx = 0, yy = 0;
	rep(i, 2*K) {
		rep(j, 2*K) {
			if (res < d[i][j]) {
				xx = i; yy = j;
			}
			res = max(res, d[i][j]);
		}
	}

	cout << res << endl;
	// cout << xx << " " << yy << endl;

	return 0;
}



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

int main(){
  string s;
  int k;
  cin >>s >>k;
  int n = s.size();
  int cnt = 1;
  rep(i,n-1){
    if(s[i]==s[i+1]) cnt++;
    else break;
  }
  if(cnt==n){
    cout << (ll)n*k/2 << endl;
    return 0;
  }
  ll ans = 0;
  rep(i,n-1){
    if(s[i]==s[i+1]){
      ans++;
      s[i+1]='*';
    }
  }
  ans *= k;
  if(s[0]==s[n-1]&&cnt%2==1) ans+=k-1;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3612
#include <stdio.h>

int main(){

  int i,n,F[45];
  scanf("%d",&n);

  F[0]=1;
  F[1]=1;
  for(i=2;i<=n;i++){
    F[i]=F[i-2]+F[i-1];
  }
  printf("%d\n",F[n]);
  return 0;
}

Measured memory_bytes: 596
package main

import "fmt"

func solve(a, b, c int) bool {
	for i := 0; i < b; i++ {
		if a*i%b == c {
			return true
		}
	}
	return false
}

func main() {
	var a, b, c int
	fmt.Scan(&a, &b, &c)
	if solve(a, b, c) {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}


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

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

	vector<int> a(n + 1);
	vector<int> b(n);
	a[0] = 0;
	for (int i = 1; i <= n; i++)
	{
		cin >> a[i];
		b[i - 1] = a[i] - a[i - 1];
	}

	b[0] = k - a[n] + a[1];

	int max = 0;

	for (int i = 0; i < n; i++)
	{
		if (b[i] > max)
		{
			max = b[i];
		}
	}

	int ans = 0 - max;

	for (int i = 0; i < n; i++)
	{
		ans += b[i];
	}

	cout << ans << endl;

	return 0;
}

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

//{ START
using namespace std;
#define int int64_t
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define reps(i, a, n) for (int i = (a); i > (n); --i)
#define arep(i, x) for (auto &&i : (x))
#define irep(i, x) for (auto i = (x).begin(); i != (x).end(); ++i)
#define rirep(i, x) for (auto i = (x).rbegin(); i != (x).rend(); ++i)
//降順はgreater<T>()
#define all(x) (x).begin(), (x).end()
#define rv(s) reverse((s).begin(), (s).end())
// gcd lcmはそのままok
#define gcd(a, b) __gcd(a, b)
#define bits(n) (1LL << (n))
#define pcnt(x) __builtin_popcountll(x)
//配列内等要素削除
#define unique(x) (x).erase(unique((x).begin(), (x).end()), (x).end())
#define Fixed(n) fixed << setprecision(n)
//総和
#define sowa(n) (((n) * ((n) + 1)) / 2)
#define pb(x, a) (x).push_back(a)
#define fb(x, a) (x).push_front(a)
#define eb(x, a) (x).emplace_back(a)
#define cauto const auto &
using P = pair<int, int>;
using Graph = vector<vector<P>>;
template <class T>  //昇順
using min_heap = priority_queue<T, vector<T>, greater<T>>;
template <class T>  //降順
using max_heap = priority_queue<T>;
template <class A, class B>
using umap = unordered_map<A, B>;
template <class A>
using uset = unordered_set<A>;
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {  //多次元初期化
  std::fill((T *)array, (T *)(array + N), val);
}
template <class A, class B>
bool chmax(A &a, const B &b) {  //最大値更新 返り値はbool
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class A, class B>
bool chmin(A &a, const B &b) {  //最小値更新 返り値はbool
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
constexpr int INF = 0x3f3f3f3f;
constexpr int LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9 + 7;
constexpr int mod2 = 998244353;
//} END

signed main(void) {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);

  int n;
  cin >> n;
  string s;
  cin >> s;
  int ans = 0;

  int j = 0, k = n - 1;
  rep(i, 0, n) {
    if (j >= k) break;
    if (s[j] != 'W') ++j;
    if (s[k] != 'R') --k;
    if (s[j] == 'W' && s[k] == 'R') {
      swap(s[j], s[k]);
      ++j;
      --k;
      ++ans;
    }
  }

  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 3764
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
int h[n];
for(int i=0;i<n;i++)
cin>>h[i];
vector<int> ans(n,INT_MAX);
ans[0]=0;
for(int i=0;i<n;i++){
 if(i+1<n){
    ans[i+1]=min(ans[i+1],ans[i]+abs(h[i+1]-h[i])); 
 }
 if(i+2<n){
  ans[i+2]=min(ans[i+2],ans[i]+abs(h[i+2]-h[i])); 
 }
}
cout<<ans[n-1]<<"\n";
}


Measured memory_bytes: 1024
n = int(input())
d,x = map(int,input().split())
A = []
for i in range(n):
    a = int(input())
    A.append(a)
count = 0
for i in range(len(A)):
    if d%A[i]==0:
        count+=d//A[i]
    else:
        count += d//A[i]+1
print(count+x)
    

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = (1e9)+7;
void fastIO(){
  ios_base::sync_with_stdio(0); cin.tie(0);
}


int main(){
  fastIO();
  int n;
  cin>>n;
  vector<int>score(n);
  int sum = 0;
  for(int i=0;i<n;i++){
  	cin>>score[i];
  	sum+=score[i];
  }
  sort(score.begin(),score.end());
  int pos = 0;
  while(sum%10==0){
  	if(pos==n){
  		break;
  	}
  	if((sum-score[pos])%10!=0){
  		sum-=score[pos];
  		break;
  	}
  	pos++;
  }
  if(sum%10==0){
  	cout<<0<<endl;
  }else{
  	cout<<sum<<endl;
  }
}  




Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<unordered_map>
#define ll long long int
#define pb emplace_back
#define mp make_pair
#define mod 1000000007
#define For(i,n) for(ll i=0;i<n;i++)
using namespace std;
unordered_map<int, bool>lo;
 
int main()
{
    int h,k;
    cin>>h>>k;
    int a[h][k]={0};
    int n;
    cin>>n;
    int b[n];
    for(int i=0;i<n;i++)
    {
        cin>>b[i];
    }
    int y=0;
    for(int i=0;i<h;i++)
    {
         if(i%2==0)
         {
             for(int j=0;j<k;j++)
             {
                 a[i][j]=y+1;
                 b[y]--;
                 if(b[y]==0)
             {
                 y++;
             }
             }
             
         }
        else
        {
            for(int j=k-1;j>=0;j--)
             {
                 a[i][j]=y+1;
                 b[y]--;
                if(b[y]==0)
             {
                 y++;
             }
             }
             
        }
    }
    for(int i=0;i<h;i++)
    {
        for(int j=0;j<k;j++)
        {
            cout<<a[i][j]<<" ";
        }
        cout<<endl;
    }
	return 0;
}      

Measured memory_bytes: 384
/***
**   AUTHOR::ASHUTOSH MOUDGIL
***/


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

#define pb push_back
#define mp make_pair
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL);
#define F first
#define S second
#define int long long
//#define ll long long
#define all(x) x.begin(),x.end()
#define rsort(x) sort(all(x)); reverse(all(x));
#define endl '\n'
#define vi vector<int>
#define vlli vector<long long>
#define pii pair<int,int>
#define mod 1000000007
#define LMAX 1e18
#define deb(x) cout<<#x<<" : "<<x<<endl;

#define M 1000000
void mymain(){
    int n;
    cin >> n;
    map<string,int> m;
    for(int i=0;i<n;i++){
        string s;
        cin >> s;
        vi cnt(26,0);
        for(int i=0;i<s.size();i++){
            cnt[s[i]-'a']++;
        }
        string ss;
        for(int i=0;i<26;i++){
            for(int j=0;j<cnt[i];j++){
                ss += 'a'+i;
            }
        }
        m[ss]++;
    }
    int ans=0;
    for(auto it:m){
        int a=it.S;
        ans += (a*(a-1))/2;
    }
    cout << ans <<endl;
}

signed main(){
IOS;
///freopen("input.txt", "r", stdin);
///freopen("output.txt", "w", stdout);
int t;
t=1;
///cin>>t;
for(int tt=0;tt<t;tt++){
   ///cout << "Case #" << tt+1 <<": ";
   mymain();
   }
return 0;
}


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

int main(){
    int n;
    cin>>n;
    int i;
    for(i=1;i<=n;i++){
        if(i % 3 == 0){
            cout << " " << i;
        }
        else{
            int x = i;
            while(x>1){
                if(x % 10 == 3){
                    cout << " "<< i;
                    break;
                    }
                else{
                    x /= 10;
                }
            }
        }
    }
    cout << endl;
}


Measured memory_bytes: 3116
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main() {
	long long n;
	long long pipe[65000] = {};
	vector<long long> joint;
	while (cin >> n,n) {
		long long sum = 0;
		for (long long i = 0; i < n; i++) {
			cin >> pipe[i];
			sum += pipe[i];
		}
		for (long long i = 0; i < n - 1; i++) {
			int a;
			cin >> a;
			joint.push_back(a);
		}
		long long ct = n;
		sort(joint.begin(),joint.end());
		long long max = sum * n;
		for (long long i = joint.size() - 1; i >= 0; i--){ 
			max = std::max(max, (i + 1) * (sum + joint[i]));
			sum += joint[i];
		}
		cout << max << endl;
		joint.clear();
		for (long long i = 0; i < n; i++)pipe[i] = 0;
	}
	return 0;
}

Measured memory_bytes: 2244
#include <algorithm>
#include <iostream> //入出力
#include <stdio.h>
#include <map>
#include <set>
#include <string>
#include <math.h> //算術演算子
#include <vector>
#include <cstdlib>
#include <queue>
#include <stack>
#include <list>
#include <iomanip> //小数点以下を表示させる(setprecision())
//#include <bits/stdc++.h>
using namespace std;
typedef long long ll; //64bit型

#define debug(x) cerr << x << " " \
                      << "(L:" << __LINE__ << ")" << '\n'
#define PRINT(V)                                   \
        {                                          \
                for (int i = 0; i < V.size(); i++) \
                {                                  \
                        cout << V[i] << " ";       \
                }                                  \
                cout << endl;                      \
        }

int gcd(int a, int b)
{
        return b ? gcd(b, a % b) : a;
}

int main()
{
        //input->compute->output//

        int S, T;
        cin >> S >> T;

        cout << 2 * T - S << endl;

        return 0;
}


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

int main(void){
  const int inf = 100000000;


  int n,m;
  cin >> n >> m;

  int a[1000],b[1000],c[1000],dist[100][100];

  for(int i = 0; i < m; ++i){
    cin >> a[i] >> b[i] >> c[i];
    a[i]--,b[i]--;
  }

  for(int i = 0; i < n; ++i){
    for(int j = 0; j < n; ++j){
      if(i==j)
        dist[i][j]=0;
      else
        dist[i][j]=inf;
    }
  }

  for(int i = 0; i < m; ++i){
    dist[a[i]][b[i]]=min(dist[a[i]][b[i]],c[i]);
    dist[b[i]][a[i]]=min(dist[b[i]][a[i]],c[i]);
  }

  for(int k = 0; k < n; ++k){
    for(int i = 0; i < n; ++i){
      for(int j = 0; j < n; ++j){
        dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);
      }
    }
  }

  int ans=m;
  for(int i = 0; i < m; ++i){
    bool shortest=false;
    for(int j = 0; j < n; ++j) if(dist[j][a[i]]+c[i]==dist[j][b[i]]) shortest=true;
    if(shortest==true){
      ans=ans-1;
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
constexpr int MOD = 1e9 + 7;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int s;
    cin >> s;
    vector<int> dp(2020);
    dp[0] = 1;
    for (int i = 0; i <= s; i++) {
        for (int j = 3; i + j <= s; j++) {
            (dp[i + j] += dp[i]) %= MOD;
        }
    }
    cout << dp[s] << "\n";
    return 0;
}


Measured memory_bytes: 3612
import math
N = int(input())

ans_array = [2]

num = 7

while len(ans_array) != N:
    for i in range(2,int(math.sqrt(num))+1):
        if num % i == 0:
            break
    else:
        ans_array.append(num)
    num += 5

ans_str = " ".join(map(str,ans_array))
print(ans_str)

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

int main() {
    
    int n; cin >> n;
    const int q = 10;
    vector<vector<int>> f(n, vector<int>(q));
    vector<vector<int>> p(n, vector<int>(q+1));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < q; j++) {
            cin >> f[i][j];
        }
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < q + 1; j++) {
            cin >> p[i][j];
        }
    }
    int ans = -1000000000;
    for (int bit = 1; bit < (1 << q); ++bit) {
        vector<int> timeCnt(n, 0);
        int profit = 0;
        for (int j = 0; j < q; ++j) {
            if (bit & (1 << j)) {
                for (int i = 0; i < n; i++) {
                    if (f[i][j] == 1) timeCnt[i]++;
                }
            }
        }
        for (int i = 0; i < n; i++) {
            profit += p[i][timeCnt[i]];
        }
        ans = max(ans, profit);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3576
/**
 *  author: sourav rakshit
 *  created: 22.08.2020 17:30:44
**/

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

#define ar array
#define all(x) begin(x), end(x)
#define len(x) (int)(x).size()
#define fast ios::sync_with_stdio(false), cin.tie(nullptr)
#ifdef LOCAL
#define log(x) cerr<<"[ " << #x << " : " << (x) << " ]\n";
#else
#define log(x) (void)0x30
#endif

using ll = long long;

int32_t main() {
    fast; 
    int tt = 1;
    while(tt--){
        int n,x,t;
        cin >> n >> x >> t;
        if(n%x == 0) {
            cout << n / x * t << '\n';
        }
        else cout << n / x * t + t << '\n';
    }
#ifdef LOCAL
    cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << "s.\n";
#endif
}



Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
#define ll           long long int
#define ld           long double
#define vi           vector<ll>
#define vvi          vector<vi>
#define vs           vector<string>
#define pb           push_back
#define pf           push_front
#define mp           make_pair
#define fs           first
#define se           second
#define all(x)       (x).begin(), (x).end()
#define rall(x)      (x).rbegin(), (x).rend()
#define fall(x)      (x).begin(),(x).end(),x.begin()
#define fastio       ios_base::sync_with_stdio(false); cin.tie(NULL);
int main()
{
    fastio
    ll a,b,c,k,ma=0; cin>>a>>b>>c>>k;
    ll q=max(a,k) ;
    if(q==a)
    {
        ma+=(k*1);
        k=0;
    }
    else if(q==k)
    {
        ma+=(a*1);
        k-=a;
    }
    // cout<<ma<<endl;
    // cout<<k<<endl;
    ll w=max(b,k);
    if(w==b)
    {
        ma+=(k*0);
        k=0;
    }
    else if(w==k)
    {
        ma+=(b*0);
        k-=b;
    }
    // cout<<ma<<endl;
    // cout<<k<<endl;
    if(k>0)
    {
        ma-=k;
    }
    cout<<ma<<endl;
}

Measured memory_bytes: 3652
import sys
sys.setrecursionlimit(10**6)
def solve():
    readline = sys.stdin.readline
    write = sys.stdout.write
    N, M = map(int, readline().split())
    *W, = map(int, readline().split())
    G = [[] for i in range(N)]
    for i in range(M):
        u, v = map(int, readline().split())
        G[u-1].append(v-1)
        G[v-1].append(u-1)
    U = [0]*N
    L = [0]*N
    D = [0]*N
    R = [0]*N

    U[0] = 1
    stk = [0]
    it = [0]*N
    while stk:
        v = stk[-1]
        p = stk[-2] if len(stk) > 1 else -1
        if it[v] == 0:
            U[v] = 1
        else:
            w = G[v][it[v]-1]
            D[v] = max(D[v], D[w])
            if L[w]:
                L[v] = 1

        while it[v] < len(G[v]):
            w = G[v][it[v]]; it[v] += 1
            if U[w]:
                if w != p:
                    L[v] = 1
                continue
            U[w] = 1
            stk.append(w)
            break
        else:
            D[v] = D[v] + W[v]
            stk.pop()

    ans = su = 0
    for i in range(N):
        if L[i]:
            ans += W[i]
        else:
            su = max(su, D[i])
    write("%d\n" % (ans + su))
solve()


Measured memory_bytes: 33516
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#include <iostream>
#include <ctype.h>
#include <string>
typedef long long ll;
using namespace std;

int main(){
  ll n,k,sum=0;
  cin>>n>>k;
  ll vec[n+1];
  ll ans[n+1];
  ans[0]=1;
  for(int i=1; i<n+1; i++)
    cin>>vec[i];
  int a=1,flag=0;
  for(int i=1; i<n+1; i++){
    a=vec[a];
    ans[i]=a;
    if(i==k){
      flag++;
      cout<<a<<endl;
      break;
    }
    
  }
  
  
   /*rep(i,n+1){
      cout<<ans[i]<<" ";
    }
    cout<<endl;
  cout<<a<<endl;*/
  
  ll start;
  if(flag==0){
    for(int i=1; i<n; i++){
      if(ans[i]==a){
        start=i;
        //cout<<"start " <<start<<endl;
        break;
      }
    }
    ll amari=(k-start+1)%(n-start);
    cout<<ans[start+amari-1];
    //cout<<" "<<amari<<" "<<start; 
  }
    
    

    
    
  
}

Measured memory_bytes: 6800
#include <bits/stdc++.h>
using namespace std;
 
const int MAXBIT = 60;
const long long MOD = 1E9+7;
 
long long f[MAXBIT+2][2][2];
 
long long n;
 
long long dp(int i, int mod, bool ok){
	long long& ret = f[i][mod][ok];
	if(ret != -1) return ret;
	if(i == MAXBIT) return ret = (mod == 0 && ok == 0);
	int bitn = (n>>i)&1;
	ret = 0;
	for(int a = 0; a < 2; ++a)
		for(int b = 0; b <=a ; ++b){
			int curbit = (a+b+mod)%2;
			int nmod = (a+b+mod)/2;
			bool nok = ok;
			if(curbit > bitn) nok = 1;
			if(curbit < bitn) nok = 0;
			ret += dp(i+1, nmod, nok);
			ret %= MOD;
 		}
 	return ret;
}
 
int main() {
	cin >> n;
	memset(f, -1, sizeof f);
	cout << dp(0,0, 0);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define endl "\n"
#define sz(u) (int)(u.size())
typedef long long ll;
using namespace std;
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    cout<<n*n;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main()
{
	long long a,b,c,d,e,f,g,h,i,j,k,l;
	scanf("%lli%lli%lli",&a,&b,&c);
	if(a%b==0)d=(a/b)*c;
	else d=((a/b)+1)*c;
	printf("%lli\n",d);
	return 0;
}

Measured memory_bytes: 1736
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <queue>
using namespace std;
#define loop(i,N) for(ll (i)=0; (i)<(N);++(i))
struct TEMP_OMAZINAI_ { TEMP_OMAZINAI_() { std::ios::sync_with_stdio(false); std::cin.tie(0); } } TEMP__omazinai_instance__;
#define INF ((1LL<<61) + (1<<29))
#define YesNo(x) {std::cout << ((x)?"Yes":"No") << std::endl;}
#define YESNO(x) {std::cout << ((x)?"YES":"NO") << std::endl;}
#define OddEven(x) {std::cout << ((x)%2?"Odd":"Even") << std::endl;}
#define ODDEVEN(x) {std::cout << ((x)%2?"ODD":"EVEN") << std::endl;}
typedef long long int ll;
ll my_gcd(ll a, ll b) { return b ? my_gcd(b, a%b) : a; };
void TEMP_INPUT_IMPL_() {};
template <class T, class... Args> void TEMP_INPUT_IMPL_(T& dest, Args&... args) { cin >> dest; TEMP_INPUT_IMPL_(args...); }
void TEMP_OUTPUT_IMPL_() {};
template <class T, class... Args> void TEMP_OUTPUT_IMPL_(T dest, Args... args) { cout << dest << (sizeof...(Args) ? " " : ""); TEMP_OUTPUT_IMPL_(args...); }
#define in(type, ...) type __VA_ARGS__; TEMP_INPUT_IMPL_(__VA_ARGS__)
#define in_v(type, name, cnt) vector<type> name(cnt); loop(i, cnt) cin >> name[i];
#define sort_v(v) std::sort(v.begin(), v.end())
#define unique_v(v) v.erase(std::unique(v.begin(), v.end()), v.end()) //必ずソート後に実行
#define out(...) (TEMP_OUTPUT_IMPL_(__VA_ARGS__), std::cout<<std::endl)
#define set_fix(x) ((std::cerr<<std::fixed<<std::setprecision(x)),(std::cout<<std::fixed<<std::setprecision(x)))
//小さい方に寄る
#define space_op(x, y, a, b, c) ([](auto x_, auto y_, auto a_, auto b_, auto c_){if(x_<y_)return a_;if(x_>y_)return c_;return b_;}(x,y,a,b,c))
#define space_out(x, y, a, b, c) out(space_op(x, y, a, b, c))

// ^^^ Template ^^^ //


int main() {
	in(string, s);
	if (s.size() == 2) out(s);
	else out(string(s.rbegin(), s.rend()));
	return 0;
}


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

int main(){
    int n, m;cin>>n>>m;
    priority_queue<long long> products;
    long long temp;
    for(int i=0;i<n;i++){
        cin>> temp;
        products.push(temp);
    }

    for (int i=0;i<m;i++){
        auto max_product_with_discount = products.top() / 2;
        products.pop();
        products.push(max_product_with_discount);
    }
    long long acc = 0;
    while(!products.empty()){
        acc += products.top();
        products.pop();
    }
    cout << acc << endl;
    return 0;
}


Measured memory_bytes: 1400
#include<iostream>
using namespace std;
#include<algorithm>
#include<vector>
void dfs(int src,bool visited[],vector<int> adj[])
{
	if(visited[src])
	   return ;
	else
	{
		visited[src]=true;
		for(int x:adj[src])
		   dfs(x,visited,adj);
	}
}
int32_t main()
{
     int n,m;
     cin>>n>>m;
     vector<int> adj[n+1];
     vector<int> lang[m+1];
     int j;
     for(j=1;j<=n;j++)
     {
		 int k;
		 cin>>k;
		 int i;
		 for(i=0;i<k;i++)
		 {
			 int x;
			 cin>>x;
			 lang[x].push_back(j);
		 }
	 }
	 for(j=1;j<=m;j++)
	 {
		 int s=lang[j].size();
		 int i;
		 for(i=0;i<s-1;i++)
		 {
			 adj[lang[j][i]].push_back(lang[j][i+1]);
			 adj[lang[j][i+1]].push_back(lang[j][i]);
		 }
	 }
     bool visited[n+1]={false};
     dfs(1,visited,adj);
     bool result=true;
     for(j=1;j<=n;j++)
     {
		 if(!visited[j])
		 {
			 result=false;
			 break;
		 }
	 }
	 if(result)
	     cout<<"YES"<<endl;
	 else
	    cout<<"NO"<<endl;
}


Measured memory_bytes: 13176
#include<iostream>
#include<algorithm>
#include<math.h>
using namespace std;

int main()
{
	int N[3];
	cin >> N[0] >> N[1] >> N[2];
	sort(N, N + 3);
	cout << N[2] * 10 + N[1] + N[0] << endl;
	return 0;
}

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

using ll = int64_t;
#define int ll

#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(i, 0, b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(), x.end()
auto &errStream = cerr;
#ifdef LOCAL
#define cerr (cerr << "-- line " << __LINE__ << " -- ")
#else
class CerrDummy {
} cerrDummy;
template <class T> CerrDummy &operator<<(CerrDummy &cd, const T &) {
  return cd;
}
using charTDummy = char;
using traitsDummy = char_traits<charTDummy>;
CerrDummy &operator<<(CerrDummy &cd,
    basic_ostream<charTDummy, traitsDummy> &(
      basic_ostream<charTDummy, traitsDummy> &)) {
  return cd;
}
#define cerr cerrDummy
#endif
#define REACH cerr << "reached" << endl
#define DMP(x) cerr << #x << ":" << x << endl
#define ZERO(x) memset(x, 0, sizeof(x))
#define ONE(x) memset(x, -1, sizeof(x))

using pi = pair<int, int>;
using vi = vector<int>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  REP(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

ll read() {
  ll i;
  scanf("%" SCNd64, &i);
  return i;
}

void printSpace() { printf(" "); }

void printEoln() { printf("\n"); }

void print(ll x, int suc = 1) {
  printf("%" PRId64, x);
  if (suc == 1)
    printEoln();
  if (suc == 2)
    printSpace();
}

string readString() {
  static char buf[3341000];
  scanf("%s", buf);
  return string(buf);
}

char *readCharArray() {
  static char buf[3341000];
  static int bufUsed = 0;
  char *ret = buf + bufUsed;
  scanf("%s", ret);
  bufUsed += strlen(ret) + 1;
  return ret;
}

template <class T, class U> void chmax(T &a, U b) {
  if (a < b)
    a = b;
}

template <class T, class U> void chmin(T &a, U b) {
  if (b < a)
    a = b;
}

template <class T> T Sq(const T &t) { return t * t; }

#define CAPITAL
void Yes(bool ex = true) {
#ifdef CAPITAL
  cout << "YES" << endl;
#else
  cout << "Yes" << endl;
#endif
  if (ex)
    exit(0);
}
void No(bool ex = true) {
#ifdef CAPITAL
  cout << "NO" << endl;
#else
  cout << "No" << endl;
#endif
  if (ex)
    exit(0);
}

const ll infLL = LLONG_MAX / 3;

#ifdef int
const int inf = infLL;
#else
const int inf = INT_MAX / 2 - 100;
#endif

signed main() {
  string str;
  cin >> str;
  int year = atoi(str.substr(0, 4).c_str());
  int month = atoi(str.substr(5, 2).c_str());
  int date = atoi(str.substr(8, 2).c_str());
  int input = (year * 10000) + (month * 100) + date;

  if (input <= 20190430)
    cout << "Heisei" << endl;
  else
    cout << "TBD" << endl;

  return 0;
}


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

A = list(map(int, input().split()))
check_list = [0]*n

pos = 0
loop_left = []
loop = []

while check_list[pos]<2:
  
  if check_list[pos]==0:
    loop_left.append(pos+1) 
    
  if check_list[pos]==1:
    loop.append(pos+1)
  
  check_list[pos] += 1
  pos = A[pos]-1

if k<=len(loop_left)-1:
  print(loop_left[k])
else:
  k -= (len(loop_left)-len(loop))
  ind = k%len(loop)
  print(loop[ind])

Measured memory_bytes: 32808
#include<stdio.h>

int main(void){

int h,n;

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

int a[n];

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

int sum=a[0];

for(int i=1;i<n;i++){
  sum=sum+a[i];
}

if(sum<h){printf("No");}
if(sum>=h){printf("Yes");}

return 0;
}

Measured memory_bytes: 2060
N, Y = map(int, input().split())
for i in range(N + 1):
    for j in range(N + 1 - i):
        if N - i - j < 0:
            break
        if 9000 * i + 4000 * j == Y - 1000 * N:
            print(i, j, N - i - j)
            exit()
print(-1, -1, -1)


Measured memory_bytes: 3064
#include <algorithm>
#include <iostream>
using namespace std;
 
int main() {
  int N, M;
  cin >> N >> M;
  
  if(M==1){cout << 0 << endl; return 0;}
  
  int points[M];
  
  for(int i=0; i<M; i++){cin >> points[i];}
  
  sort(points,points+M);
  
  int dist[M-1];
  int sorted_dist[M-1];
  
  for(int i=0; i<M-1; i++){
    dist[i] = points[i+1]-points[i];
    sorted_dist[i] = points[i+1]-points[i];
  }
  
  sort(sorted_dist,sorted_dist+M-1);
  
  int sum = 0;
  
  for(int i=0;i<M-N;i++){sum = sum + sorted_dist[i];}
  
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <cmath>

int main(){
    int n;
    int a[200000];
    long long int sum = 0;

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

    long long int zenhan = 0;
    long long int kohan = 0;
    int r = 1;
    int l = 0;
    for(int i=0; i<n; i++){
        if(zenhan <= kohan){
            zenhan += a[l];
            l++;
        }else{
            kohan += a[n-r];
            r++;
        }
    }

    printf("%lld",std::abs(kohan-zenhan));

    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define pb push_back
const int maxn=1e6+10;
const int mod=1e9+7;
const double pi=3.1415926535;
int w[3005],v[3005];
int dp[3005][3005][2];




int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,t;
    cin>>n>>t;
    for(int i=1;i<=n;i++)
    {
        cin>>w[i]>>v[i];
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=0;j<=t-1;j++)
        {
            for(int x=0;x<=1;x++)
            {
                if(x==0)
                {
                    if(j>=w[i])
                    {
                        dp[i][j][x]=max(dp[i-1][j][x],dp[i-1][j-w[i]][x]+v[i]);
                    }
                    else
                    {
                        dp[i][j][x]=dp[i-1][j][x];
                    }
                }
                else
                {
                    dp[i][j][x]=max(dp[i-1][j][x],dp[i-1][j][0]+v[i]);
                    if(j>=w[i])
                    {
                        dp[i][j][x]=max(dp[i][j][x],dp[i-1][j-w[i]][x]+v[i]);
                    }
                }
            }
        }
    }
    cout<<dp[n][t-1][1]<<'\n';






}


Measured memory_bytes: 74012
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,n) for ( int i = (a); i < (n); ++i)
#define REP(i,n) for( int i = 0; i < (n); ++i )
#define ALL(obj) (obj).begin(), (obj).end()

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

    int seikai = 0;
    int count = 0;

    vector<bool> fstep;
    vector<int> wacnt;

    fstep.resize(N+1);
    wacnt.resize(N+1);

    REP(i,N+1){fstep[i]=false;}

    REP(i,M) {
        int no;
        string stat;

        cin >> no >> stat;

        if( fstep[no] ) { continue; }
        if( stat == "AC" ) {
            fstep[no] = true;
            count += wacnt[no];
            seikai++;
        } else if( stat == "WA") {
            wacnt[no]++;
        }
    }
    cout << seikai << " " << count << std::endl;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
typedef pair<int,int>P;
 
int main() {
  ll r,g,b,n,count;
  cin>>r>>g>>b>>n;
  count=0;
  for(ll i=0;i<=n/r;i++){
    for(ll j=0;j<=(n-r*i)/g;j++){
      if(i*r+j*g>n){
        break;
      }
      else if((n-r*i-j*g)%b==0){
        count++;
      }
    }
  }
  cout<<count<<endl;
}
        

Measured memory_bytes: 256
#include <iostream>

using namespace std;

#define MAX_N 100

int K[MAX_N];
int P[MAX_N];

int solve(int i){

    if(K[i] % P[i] == 0){
        return P[i];
    }else{
        return K[i] % P[i];
    }
}

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

    if(N>0){
        for(int i=0;i<N;++i){
            cin >> K[i] >> P[i];
        }
        for(int i=0;i<N;++i){
            cout << solve(i) << endl;
        }
    }
}

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

using namespace std;

typedef long long LL;
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

int main(){
	int H,W; cin >> H >> W;
	queue<pair<int,int>> Q;
	vector<vector<int>> b(H+2,vector<int>(W+2,-1));
	repp(i,0,H+2) b[i][0] = b[i][W+1] = 0;
	repp(j,0,W+2) b[0][j] = b[H+1][j] = 0;
	repp(i,0,H){
		string S; cin >> S;
		repp(j,0,W) if(S[j] == '#'){
			b[i+1][j+1] = 0;
			Q.push(make_pair(i+1,j+1));
		}
	}
	int ans = 0;
	while(!Q.empty()){
		auto p = Q.front(); Q.pop();
		if(b[p.first-1][p.second] == -1){
			ans = b[p.first][p.second]+1;
			b[p.first-1][p.second] = ans;
			Q.push(make_pair(p.first-1,p.second));
		}
		if(b[p.first+1][p.second] == -1){
			ans = b[p.first][p.second]+1;
			b[p.first+1][p.second] = ans;
			Q.push(make_pair(p.first+1,p.second));
		}
		if(b[p.first][p.second-1] == -1){
			ans = b[p.first][p.second]+1;
			b[p.first][p.second-1] = ans;
			Q.push(make_pair(p.first,p.second-1));
		}
		if(b[p.first][p.second+1] == -1){
			ans = b[p.first][p.second]+1;
			b[p.first][p.second+1] = ans;
			Q.push(make_pair(p.first,p.second+1));
		}
	}
	cout << ans << endl;
	return 0;
}


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

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define MIN(a, b) ((a) > (b) ? (b) : (a))
#define MAX(a, b) ((a) < (b) ? (b) : (a))

const long long INF = 1LL << 60;
typedef long long ll;
const long long MOD = 1000000000 + 7;

int main()
{
    ll n;
    cin >> n;
    set<ll> a;
    ll tmp;
    rep(i, n)
    {
        cin >> tmp;
        a.insert(tmp);
    }
    set<ll> b;
    while (a.size() > 1)
    {
        b.clear();
        auto itr = a.begin();
        b.insert(*itr);
        ll a_min = *itr;
        rep(i, a.size() - 1)
        {
            itr++;
            if (*itr % a_min != 0)
                b.insert(*itr % a_min);
        }
        a = b;
    }
    auto res = a.begin();
    cout << *res << endl;
    return 0;
}

Measured memory_bytes: 8608
sx,sy,tx,ty=map(int,input().split())
dx=tx-sx
dy=ty-sy
root1='U'*dy+'R'*dx
root2='D'*dy+'L'*dx
root3='L'+'U'*(dy+1)+'R'*(dx+1)+'D'
root4='R'+'D'*(dy+1)+'L'*(dx+1)+'U'
print(root1+root2+root3+root4)

Measured memory_bytes: 3060
import java.util.*;
public class Main{
	
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int x = sc.nextInt();
		int t = sc.nextInt();
		int div = n/x + (n%x == 0 ? 0 : 1);
		System.out.println(div * t);


	}	
}

Measured memory_bytes: 35668
#include <iostream>
#include<cstdlib>
#include<queue>
#include<set>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include<stack>
#include<map>
#include<deque>
#include<cstdio>
#include<cstdio>
#include<time.h>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define pd(a,n) for(int i=0;i<n;i++)cout<<a[i]<<((i==n-1)?"\n":" ")
#define pdd(a,n,m)for(int i=0;i<m;i++)pd(a,m)
#define mp make_pair
#define pb push_back
#define ll __int64
#define __int64 long long
#define P pair<int,int>
#define PP pair<P,int>

int n,x;

int main(){
  while(cin>>n>>x,n||x){
    int ans=0;
    for(int i=1;i<=n;i++){
      for(int j=i+1;j<=n;j++){
        for(int k=j+1;k<=n;k++)
          if(i+j+k==x)ans++;
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}



Measured memory_bytes: 3092
#include<stdio.h>
int push(int, int);

int main()
{
    int a,b;
    scanf("%d %d", &a, &b);

    printf("%d", push(a,b));
}

int push(int a,int b)
{
	if (a == b)
		return 2*a;
	else if(a > b)
		return 2*a - 1;
	else
		return 2*b - 1;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define endl '\n'
#define Endl '\n'
#define fi first
#define ii pair<int,int>
#define iii pair<ii, int>
#define se second
#define ld long double
#define mod 1000000007
#define popcount __builtin_popcountll
#define PI acos(-1.0)
using namespace std;

int main(){
    string str;
    cin>>str;
    int n = str.length(), amid = 0;
    for(int i=0, j=n-1;i<j;i++, j--){
        amid+=(str[i]!=str[j]);
    }
    cout<<amid<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<set>
#include <string>
#include<set>
using namespace std;
int main()
{
    int N,M;
   set<int>a;
   cin>>N;
   
   for(int i=0;i<N;i++)
   {
       int b;
       cin>>b;
       a.insert(b);
   }
   if(a.size()==N)
   printf("YES\n");
   else
   printf("NO\n");
    return 0;
}


Measured memory_bytes: 9600
while True:
  h,w=map(int,input().split())
  if h==0 and w==0:
      break
  for i in range(1,1+h):
    if i%2==1:
        if w%2==1:
            print('#.'*(w//2)+'#')
        else:
            print('#.'*(w//2))
    else:
        if w%2==1:
            print('.#'*(w//2)+'.')
        else:
            print('.#'*(w//2))
  print(end='\n')


Measured memory_bytes: 5612
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
int main(void) {
  long long N, M;
  cin >> N >> M;
  long long ans = 0;
  for(long long p = 1; p <= sqrt(M); p++) {
    if(0 == M % p) {
      if(N * p <= M) {
        ans = max(ans, p);
      }
      if(N * (M / p) <= M) {
        ans = max(ans, M / p);
      }
    }
  }
  cout << ans << endl;
  return 0;
}

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

int main()
{
    int a,b,h,m;
    
    cin >> a;
    cin >> b;
    cin >> h;
    cin >> m;
    // a = 889;
    // b = 464;
    // h = 0;
    // m = 0;

    long double rtn = 0;

    long double  hd = h * 30 + m * 0.5;
    long double  md = m * 6;

    long double  dd = 0.0;
    if (hd > md)
    {
        dd = hd - md;
    }
    else
    {
        dd = md - hd;
    }

    long double radian = dd * 3.14159265358979323846264338327950L / 180.0;

    rtn = (long double)(a * a + b * b) - (long double)(2 * a * b) * cosl(radian);


    printf("%20.20Lf\n", sqrtl(rtn));

    return 0;
}

Measured memory_bytes: 4108
# ABC 104

D, G = map(int, input().split())
p, c= [], []
for i in range(D):
    tmp_0, tmp_1 = map(int, input().split())
    p.append(tmp_0)
    c.append(tmp_1)

min_ans = 9999999999
ans = 0
sum_point = 0
dont_solved = [i for i in range(D)]

for bit in range(1<<D):
    dont_solved = [i for i in range(D)]
    ans = 0
    sum_point = 0
    for i in range(D):
        if bit & (1<<i):
            ans += p[i]
            sum_point += (100 * (i+1)) * (p[i]) + c[i]
            dont_solved.remove(i)
    if sum_point < G:
        for i in dont_solved[::-1]:
            for j in range(p[i]):
                sum_point += 100 * (i+1)
                ans += 1
                if sum_point >= G:
                    break
            else:
                continue
            break
    if ans <= min_ans:
        min_ans = ans
print(min_ans)

Measured memory_bytes: 3064
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        int c = Integer.parseInt(sc.next());
        int d = Integer.parseInt(sc.next());

        // 主処理
        int minTrain = Math.min(a, b);
        int minBus = Math.min(c, d);
        int result = minTrain + minBus;

        // 出力
        System.out.println(result);
        sc.close();
    }
}


Measured memory_bytes: 23252
n, s = int(input()), input()
a = ["R", "G", "B"]
cnt = [0, 0, 0]
for i in s:
    cnt[a.index(i)] += 1
c = cnt[0] * cnt[1] * cnt[2]
for i in range(1, n-1):
    for j in range(i+1, n):
        k = 2 * j - i
        if j-1 < k-1 < n:
            if s[i-1] != s[j-1] and s[j-1] != s[k-1] and s[k-1] != s[i-1]:
                c -= 1

print(c)

Measured memory_bytes: 68544
import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """5
1 1 2 2"""
        output = """2
2
0
0
0"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """10
1 1 1 1 1 1 1 1 1"""
        output = """9
0
0
0
0
0
0
0
0
0"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """7
1 2 3 4 5 6"""
        output = """1
1
1
1
1
1
0"""
        self.assertIO(input, output)


def resolve():
    a = read()
    result = think(a)
    write(result)


def read():
    n = read_int(1)[0]
    return read_int(n - 1)


def read_int(n):
    return read_type(int, n, sep=' ')


def read_float(n):
    return read_type(float, n, sep=' ')


def read_type(t, n, sep):
    return list(map(lambda x: t(x), read_line().split(sep)))[:n]


def read_line(n=0):
    if n == 0:
        return input().rstrip()
    else:
        return input().rstrip()[:n]


def think(a):
    n = len(a) + 1
    boss = [0] * (n + 1)
    for b in a:
        boss[b] += 1
    return boss[1:]


def write(result):
    for r in result:
        print(r)


if __name__ == '__main__':
    # unittest.main()
    resolve()

Measured memory_bytes: 96904
class Solution:

    def solve(self, N: int, M: int, cakes) -> int:

        sign = []
        for i in [1, -1]:
            for j in [1, -1]:
                for k in [1, -1]:
                    sign.append((i, j, k))

        def sumprod(c, s):
            ret = 0
            for i in range(len(c)):
                ret += c[i] * s[i]
            return ret

        candidates = []
        for s in sign:
            cakes = sorted(cakes, key=lambda c: sumprod(c, s))

            xyz = [0, 0, 0]
            for i in range(M):
                for j in range(3):
                    xyz[j] += cakes[i][j]

            candidates.append(
                sum([abs(xyz_) for xyz_ in xyz])
            )

        return max(candidates)


if __name__ == '__main__':

    # standard input
    N, M = map(int, input().split())
    cakes = []
    for i in range(N):
        cakes.append(tuple(map(int, input().split())))

    # solve
    solution = Solution()
    print(solution.solve(N, M, cakes))


Measured memory_bytes: 3276
#include<bits/stdc++.h>
//cervello|Phoenix
using namespace std;
#define ll long long int
#define eb emplace_back
#define mk make_pair
#define pr pair<int,int>
#define all(x) x.begin(),x.end()
#define mod 1000000007

int main(){
  ios_base::sync_with_stdio(false);
    // #ifndef ONLINE_JUDGE
    //   freopen("input.txt", "r", stdin);
    //   freopen("output.txt", "w", stdout);
    // #endif
  int a,b,c;
  cin>>a>>b>>c;
  cout<<c<<" "<<a<<" "<<b<<"\n";
  return 0;
}

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

const int MAXN = 21;
const int MAXL = (1 << 21 ) + 2;
const int MOD = 1e9 + 7;

int dp[MAXN][MAXL],mascara[MAXN],N;

int solve(int pos,int bitmask){

	if(pos == N) return (__builtin_popcount(bitmask) == N);
	if(dp[pos][bitmask] != -1) return dp[pos][bitmask];

	int tot = 0;
	for(int i = 0;i<N;i++){
		if(!(bitmask & (1 << i)) && ((1 << i) & mascara[pos])){
			tot = (tot + solve(pos+1, bitmask | (1 << i) )) % MOD;
		}
	}

	return dp[pos][bitmask] = tot;

}

int main(){

	memset(dp,-1,sizeof(dp));
	cin >> N;
	for(int i = 0;i<N;i++){
		for(int j = 0;j<N;j++){
			int x;
			cin >> x;
			if(x) mascara[i] |= (1 << j);
		}
	}
	cout << solve(0,0) << endl;

	return 0;

}

Measured memory_bytes: 172416
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<functional>
#include<math.h>
#include<vector>

using namespace std;

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

	long int a = sqrt(n);

	long long int ret;
	for (long int i = a; i > 0; i--) {
		if (n%i == 0) {
			ret = n / i;
			break;
		}
	}
	
	if (ret - 1000000000 >= 0)cout << 10 << endl;
	else if (ret - 100000000>= 0)cout << 9 << endl;
	else if (ret - 10000000 >= 0)cout << 8 << endl;
	else if (ret - 1000000 >= 0)cout << 7 << endl;
	else if (ret - 100000 >= 0)cout << 6<<endl;
	else if (ret - 10000 >= 0)cout << 5 << endl;
	else if (ret - 1000 >= 0)cout << 4 << endl;
	else if (ret - 100 >= 0)cout << 3 << endl;
	else if (ret - 10 >= 0)cout << 2 << endl;
	else cout << 1 << endl;
	return 0;

}

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

int main(){
  int n;
  cin >> n;
  vector<ll> L(n+1);
  L[0]=2; L[1]=1;

  REP(i,2,n+1){
    L[i]=L[i-2]+L[i-1];
  }
  cout << L[n] << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

//Scene in a Picture
public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true){
			int n = sc.nextInt();
			int m = sc.nextInt();
			if(n==0&&m==0)break;
			int[][] map = new int[n][n];
			for(int i=0;i<n;i++)for(int j=0;j<n;j++)map[i][j]=sc.nextInt();
			int[][][] p = new int[m][m][4];
			for(int i=0;i<m;i++)for(int j=0;j<m;j++)p[i][j][0]=sc.nextInt();
			for(int k=1;k<4;k++){
				for(int i=0;i<m;i++)for(int j=0;j<m;j++)p[i][j][k]=p[j][m-1-i][k-1];
			}
			boolean f = false;
			for(int i=0;i<n-m+1;i++){
				if(f)break;
				for(int j=0;j<n-m+1;j++){
					if(f)break;
					for(int k=0;k<4;k++){
						boolean match = true;
						int ti = -1;
						int tj = -1;
						for(int di=0;di<m;di++){
							for(int dj=0;dj<m;dj++){
								if(p[di][dj][k]==-1)continue;
								else if(ti==-1){
									ti = di;
									tj = dj;
								}
								if(p[di][dj][k]!=map[i+di][j+dj]){
									match = false;
									break;
								}
							}
						}
						if(match){
							f = true;
							System.out.println((j+tj+1) + " " + (i+ti+1));
							break;
						}
					}
				}
			}
			if(!f)System.out.println("NA");
		}
	}
}

Measured memory_bytes: 13000
#include<stdio.h>
#include<string.h>

int main(){
    int length,C;
    int i,flag = 0;
    char S[11];
    if (fgets(S, 10, stdin) == NULL || S[0] == '\n') {
        return 1;
    }
    length = strlen(S);

    if(S[0] != 65){
        printf("WA\n");
        return 0;
    }

    for(i = 2; i < length - 2; i++){
        if(S[i] == 67){
            flag++;
            C = i;
        }
    }
    if(flag == 0 || flag > 1){
        printf("WA\n");
        return 0;
    }

    for(i=1; i < length; i++){
        if(i != C && S[i] >= 65 && S[i] <= 90 ){
            printf("WA\n");
            return 0;
        }
    }
    printf("AC\n");
    return 0;
        
    
}

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

using ll = long long;
// #define int long long

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, r, n) for (int i = (r); i < (n); ++i)
#define REPR(i, n) for(int i = (n); i >= 0; --i) // from n to 0
#define REPRS(i, r, n) for(int i = (n); i >= (r); --i) // from n to r
#define COUTB(x) cout << (x) << "\n"
#define COUTS(x) cout << (x) << " "
#define PB push_back
#define SORT(obj) sort((obj).begin(), (obj).end())
#define SORTR(obj) sort((obj).begin(), (obj).end(), greater<>())
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define PI (acos(-1))

int Lcm(int, int);
bool IsPrime(int);
int Factorial(int);
int NPR (int, int);
int NCR (int, int);

/***** MAIN *****/
signed main() {
  ll x;
  cin >> x;
  if(IsPrime(x)) {
    cout << x << endl;
    return 0;
  }
  if(x % 2 == 0) {
    if(IsPrime(x+1)) {
      cout << x+1 << endl;
      return 0;
    }
    ++x;
  }
  ll i = 0;
  while(true) {
    if(IsPrime(x+(2*i))) {
      cout << x+(2*i) << endl;
      return 0;
    }
    ++i;
  }
  return 0;
}
/***** MAIN *****/

int Lcm(int a, int b) {
  int bigger = max(a,b);
  int smaller = min(a,b);
  int ans = bigger;
  while(ans%smaller!=0) ans+=bigger;
  return ans;
}

bool IsPrime(int a) {
  if(a <= 1) return false;
  if(a == 2) return true;
  if(a%2 == 0) return false;
  for(int i = 3; i*i <= a; i+=2) {
    if(a%i==0) return false;
  }
  return true;
}

int Factorial(int n){
  int ans = 1;
  while(n > 1){
    ans *= n;
    --n;
  }
  return ans;
}

int NPR(int n, int r) {
  return Factorial(n)/Factorial(n-r);
}

int NCR (int n, int r){
  return NPR(n,r)/Factorial(r);
}

Measured memory_bytes: 256
'''
ABC 131 D:Megalomania
Accepted    　:Yes
difficult   　: 
ペナルティ　  　:5分
実際の回答時間  :9分
WAの回数　     :0回
合計時間　　  　:9分
'''
import sys
input = sys.stdin.readline

def myAnswer(N:int,A:list,B:list) -> str:
   dic = {}
   # 締め切り時間をkey、作業時間をvalueにした辞書を作成
   for a,b in  zip(A,B):
      if(b in dic.keys()):
         dic[b].append(a)
      else:
         dic[b] = [a]
   now = 0
   dic = sorted(dic.items())
   for deadline,time in dic:
      time.sort()
      # print(deadline,time)
      for t in time:
         if(deadline < now + t):
            return "No"
         now += t
   return "Yes"

def modelAnswer(N:int,dic:dict) -> str:
   now = 0
   dic = sorted(dic.items())
   for deadline,time in dic:
      time.sort()
      for t in time:
         if(deadline < now + t):
            return "No"
         now += t
   return "Yes"

def main():
   N = int(input())
   dic = {}
   # A = []
   # B = []
   for _ in range(N):
      a,b = map(int,input().split())
      if(b in dic.keys()):
         dic[b].append(a)
      else:
         dic[b] = [a]
      # A.append(a)
      # B.append(b)
   print(modelAnswer(N,dic))
if __name__ == '__main__':
   main()

Measured memory_bytes: 60524