akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;

const int M=3005;

int n,t;
struct Node
{
	int a,b;
	void read()
	{
		scanf("%d%d",&a,&b);
	}
}node[M];
int dpl[M][M],dpr[M][M];

int main()
{
	scanf("%d%d",&n,&t);
	for(int i=1;i<=n;i++)
		node[i].read();
	for(int i=1;i<=n;i++)
	{
		for(int j=t-1;j>=node[i].a;j--)
			dpl[i][j]=max(dpl[i-1][j],dpl[i-1][j-node[i].a]+node[i].b);
		for(int j=node[i].a-1;j>=0;j--)
			dpl[i][j]=dpl[i-1][j];
	}
	for(int i=n;i>=1;i--)
	{
		for(int j=t-1;j>=node[i].a;j--)
			dpr[i][j]=max(dpr[i+1][j],dpr[i+1][j-node[i].a]+node[i].b);
		for(int j=node[i].a-1;j>=0;j--)
			dpr[i][j]=dpr[i+1][j];
	}
	int ans=0;
	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<=t-1;j++)
			ans=max(ans,dpl[i-1][j]+dpr[i+1][t-1-j]+node[i].b);
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 70784
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll n,k,ans=2e9+7;
  cin >> n >> k;
  ll x[n];
  for(ll i=0;i<n;i++) cin >> x[i];
  for(ll i=0;i<n-k+1;i++){
    ll c,d=x[i],e=x[i+k-1];
    if(d<0&&0<e) c=e-d+min(-d,e);
    else if(0<=d) c=e;
    else c=-d;
    ans = min(ans,c);
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
INF = 10**9
mod = 10**9+7

A,B,C,D = I()
print(max(0,min(B,D)-max(A,C)))

Measured memory_bytes: 10016
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.UncheckedIOException;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class BThin {
        public void solve(int testNumber, LightScanner in, PrintWriter out) {
            int h = in.ints(), w = in.ints();
            for (int i = 0; i < h; i++) {
                String s = in.string();
                out.println(s);
                out.println(s);
            }
        }

    }

    static class LightScanner {
        private BufferedReader reader = null;
        private StringTokenizer tokenizer = null;

        public LightScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
        }

        public String string() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new UncheckedIOException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int ints() {
            return Integer.parseInt(string());
        }

    }
}



Measured memory_bytes: 22740
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
int main(){
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    cout << s.substr(0,3) << endl;
}


Measured memory_bytes: 3636
I0 = lambda :map(int,input().split())
I1 = lambda :int(input())
I2 = lambda :list(map(int,input().split()))
#####################################################
k,x = I0()
a = x-k+1
res = list()
while a <= k+x-1:
    res.append(a)
    a+=1
print(*res)



Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <climits>
#include <bits/stdc++.h>
#include <cmath>
#include <stdio.h>
#include <utility>
using namespace std;
#define ll long long

int main()
{
  int a,b,c;
  cin>>a>>b>>c;
  map<int,int>m;
  m[a]++;
  m[b]++;
  m[c]++;
  if(m[5]==2 && m[7]==1){
      cout<<"YES"<<endl;
  }else{
      cout<<"NO"<<endl;
  }
return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <stdio.h>
using namespace std;

long long MOD = 1000000007;

int main() {
    
    int H,W;
    cin >> H >> W;
    vector< vector<int> > V( H, vector<int>(W) );
    for ( int y = 0; y < H; y++ ) {
    for ( int x = 0; x < W; x++ ) {
        int a;
        cin >> a;
        V[y][x] = a%2;
    }
    }

    vector< pair< pair<int,int>, pair<int,int> > > Ans;

    pair<int,int> pre;

    bool b = false;
    for ( int x = 0; x < W; x++ ) {

        int ys = x%2 == 0 ? 0 : H-1;
        int ye = x%2 == 0 ? H : -1;
        int dy = x%2 == 0 ? 1 : -1;
        for ( int y = ys; y != ye; y += dy ) {

            if ( b ) { Ans.push_back( make_pair( pre, make_pair(x,y) ) ); }

            if ( V[y][x] == 1 ) { b = !b; }

            pre = make_pair(x,y);
        }

    }

    cout << Ans.size() << endl;
    for ( int i = 0; i < Ans.size(); i++ ) {
        cout << Ans[i].first.second+1 << " " << Ans[i].first.first+1 << " "
         << Ans[i].second.second+1 << " " << Ans[i].second.first+1 << endl;
    }
    


    return 0;
}

Measured memory_bytes: 5232
#include <iostream>
#include <cstring>
#include <cstdio>

#define Maxm 100010

using namespace std;

inline int read() {
    int x = 0, f = 1;
    char c = getchar();
    while(c < '0' || c > '9') {
        if(c == '-') f = -1;
        c = getchar();
    }
    while('0' <= c && c <= '9') {
        x = x * 10 + c - '0';
        c = getchar();
    }
    return x * f;
}

int n, m;

int main() {
    n = read(); m = read();
    int l = 0, r = n + 1;
    bool flag = 0;
    for(int i = 1; i <= m; ++i) {
        ++l, --r;
        if(!(n & 1) && i > n / 4 && !flag) --r, flag = 1;
        printf("%d %d\n", l, r);
    }
    return 0;
}

Measured memory_bytes: 3764
input_second = int(input())
if input_second < 0 and input > 86400:
    print("not correct")
hour = input_second // (60 * 60)
minute = (input_second - (hour * 60 * 60)) // 60
second = (input_second % (60 * 60)) % 60
print(str(hour) + ":" + str(minute) + ":" + str(second))


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

using namespace std;

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

  string s;
  cin >> s;


  int left = s.size() / 2 - 1;
  int right = (s.size() + 1) / 2;
  int cnt = 0;

  for (; left >= 0 && right < s.size(); --left, ++right) {
    if (s[left] != s[right]) {
      ++cnt;
    }
  }

  cout << cnt << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<math.h>
#include<algorithm>
#include<vector>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
int main(){
    int dp[1001][1001];
    string x,y;
    cin>>x>>y;
    rep(j,x.size()+1) rep(k,y.size()+1) dp[j][k]=max(j,k);
    rep(j,x.size()) rep(k,y.size()){
        if(x[j]==y[k]) dp[j+1][k+1]=min(dp[j][k],min(dp[j+1][k]+1,min(dp[j][k+1]+1,dp[j][k]+1)));
        else dp[j+1][k+1]=min(dp[j+1][k]+1,min(dp[j][k+1]+1,dp[j][k]+1));
    }
    cout<<dp[x.size()][y.size()]<<endl;
}


Measured memory_bytes: 7132
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
int main(){
  ll n,i=1;
  cin>>n;
  while (i*i<=n) {
    if ((i+1)*(i+1)<=n) {
      i+=1;
    }
    else{
      cout<<i*i<<endl;
      break;
    }
  }
}



Measured memory_bytes: 256
# encoding: utf-8
A, B, C, D = map(int, input())

for i in range(8):
    opB = 2 * int(i & 1 > 0) - 1
    opC = 2 * int(i & 2 > 0) - 1
    opD = 2 * int(i & 4 > 0) - 1
    if A + opB * B + opC * C + opD * D == 7: break

ans = str(A)
for opX, X in [(opB, str(B)), (opC, str(C)), (opD, str(D))]:
    ans += "+" if opX > 0 else "-"
    ans += X
ans += "=7"

print(ans)

Measured memory_bytes: 3064
N = int(input())
A = list(map(int, input().split()))

res = 0
tmp = 0
for i, a in enumerate(A):
    if a == i + 1:
        tmp += 1
    else:
        res += (tmp - 1) // 2 + 1
        tmp = 0
res += (tmp - 1) // 2 + 1
print(res)

Measured memory_bytes: 14008
#include <algorithm>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <utility>
#include <vector>

int main() {
  using i64 = long long;
  constexpr i64 MInf = std::numeric_limits<i64>::lowest() / 2;

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

  std::map<std::pair<int, int>, i64> memo;
  std::function<i64(int, int)> solve, calc;

  solve = [&](int i, int k) -> i64 {
    auto itr = memo.find({i, k});
    if (itr == memo.end()) {
      itr = memo.insert({{i, k}, calc(i, k)}).first;
    }
    return itr->second;
  };

  calc = [&](int i, int k) -> i64 {
    if (k < 0 || (i + 1) / 2 < k)
      return MInf;
    if (i <= 0)
      return 0;
    return std::max(solve(i - 1, k), solve(i - 2, k - 1) + a[i - 1]);
  };

  std::cout << solve(n, n / 2) << "\n";
}


Measured memory_bytes: 47084
#include<stdio.h>

int main(void)
{
  int S,S100,S1;
  scanf("%d",&S);
  S100 = S/100;
  S1 = S - (S100*100);
  if(S100 >= 13 || S100 == 0){
    if(S1 >= 13){
      printf("NA");
    }
    else if(S1 == 0){
      printf("NA");
    }
    else{
      printf("YYMM");
    }
  }
  else{
    if(S1 >= 1 && S1 <=12){
      printf("AMBIGUOUS");
    }
    else if(S1 >= 13 && S1 <= 99){
      printf("MMYY");
    }
    else if(S1 == 0){
      printf("MMYY");
    }
    else{
      printf("NA");
    }
  }
  return 0;
  
}

Measured memory_bytes: 128
/*
* Problem URL:
*/

#include <bits/stdc++.h>
#include <cmath>
#include <sstream>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define FORD(i, a, b) for(int i = (a-1); i >= (b); i--)
using namespace std;

#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define sz(w) (int) w.size()

#define FASTER ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)

typedef vector<int> vi;
typedef long long int lli;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;

int dp[100001];
vi arr(100001);
int n;

int getAns(int pos){
	if(pos == n-1) return 0;
	if(pos >= n) return INT_MAX;
	if(dp[pos] != -1) return dp[pos];
	int x = abs(arr[pos] - arr[pos+1]) + getAns(pos+1);
	int y = INT_MAX;
	if(pos+2 < n)
	y = abs(arr[pos] - arr[pos+2]) + getAns(pos+2);
	
	return dp[pos] = min(x, y);
}
int main() {
	cin>>n;
	FOR(i, 0, n) cin>>arr[i];
	memset(dp, -1, sizeof(dp));
	cout<<getAns(0)<<endl;
	return 0;
}


Measured memory_bytes: 8740
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <iterator>
#include <utility>
#include <iomanip>
#include <stack>
#include<bitset>
#include <cmath>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
priority_queue<pair<ll,ll>,vector<pair<ll,ll> >,greater<pair<ll,ll> > >pq;
vector<ll>adj[1000005];
ld expo(ld b,ll n,ll m)
{
 ll r;
 ld p;
	p=1;
	while(n>0)
	{ 
		r=n%2;
		if(r==1)
		   p=((p)*(b));
		b=((b)*(b)); 
		n=n/2;		
	}
 return p;
}
ll divide1(ll a,ll b,ll m)
	{ ll r,p,n;
			p=a%m;
				n=m-2;
				while(n>0){
						 r=n%2;
						if(r==1)
							p=((p%m)*(b%m))%m;
						b=((b%m)*(b%m))%m; 
						n=n/2;	
					}
	return (p%m); }
int main(int argc, char const *argv[])
{	ios_base::sync_with_stdio(false);
	cin.tie(NULL),cout.tie(NULL);
	ll a,b,n;
	cin>>a>>b>>n;
	ll x=min(b-1,n);
	cout<<floor((a*x )/b)<<endl;
	return 0;
}


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

int main()
{
 	int n;
	char cs[4][3][10];
	memset(cs,'0',sizeof(cs));
	scanf("%d",&n);
	while(n--){
 		int b,f,r,v;
		scanf("%d %d %d %d",&b,&f,&r,&v);
		cs[b-1][f-1][r-1]+=v;
	}
	for(int i=0;i<4;i++){
		for(int j=0;j<3;j++){
			for(int k=0;k<10;k++){
				printf(" %c",cs[i][j][k]);
			}
			printf("\n");
		}
		if(i<3)printf("####################\n");
	}
}


Measured memory_bytes: 2052
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;
using P = pair<int,int>;
using ll = long long;
const ll INF = 1LL<<60;
const double PI = 3.1415926535897932;
const int MOD = 1e9 + 7;

//cin.tie(0);ios::sync_with_stdio(false);
int main() {
  ll a, b, n;
  cin >> a >> b >> n;

  ll x;
  if (n < b) x = n;
  else x = b - 1;
  cout << (a * (x % b) / b) - ((a * x % b) / b) << endl;
  return 0;
}


Measured memory_bytes: 3644
#include "bits/stdc++.h"
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define FOR(i,init,a) for(int i=init; i<a; i++)
#define rep(i,a) FOR(i,0,a)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()
#define chmin(a,b) a=min(a,b);
#define chmax(a,b) a=max(a,b);

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

int N;
int X[1009],Y[1009];
int dx[] = { -1, 0, 1, 0};
int dy[] = { 0, 1, 0, -1};
string nm = "LURD";

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>N;
    rep(i,N) cin>>X[i]>>Y[i];
    
    int pr=abs(X[0]+Y[0])%2;
    rep(i,N){
        int tmp=abs(X[i]+Y[i])%2;
        if(tmp!=pr){
            cout1(-1)
            return 0 ;
        }
    }
    
    vector<int> arms;
    if(pr==0) arms.push_back(1);
    rep(i,31) arms.push_back(1<<i);
    reverse(all(arms));
    
    cout1(arms.size())
    for(auto d:arms) cout<<d<<" ";
    cout<<endl;
    
    rep(i,N){
        ll nowx=0, nowy=0;
        string ans;
        for(auto d:arms){
            ll mn=LLINF;
            int best;
            rep(j,4){
                ll tmpx=nowx+d*dx[j];
                ll tmpy=nowy+d*dy[j];
                ll dist=abs(tmpx-X[i])+abs(tmpy-Y[i]);
                if(mn>dist){
                    mn=dist;
                    best=j;
                }
            }
            nowx+=d*dx[best];
            nowy+=d*dy[best];
            ans+=nm[best];
        }
        cout1(ans)
    }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#define LEN 100005
 
typedef struct pp {
    char name[100];
    int t;
} P;
 
P Q[LEN];
int head, tail, n;
 
void enqueue(P x) {
    Q[tail] = x;
    tail = (tail + 1) % LEN;
}
 
P dequeue() {
    P x = Q[head];
    head = (head + 1) % LEN;
    return x;
}
 
int min(int a,int b) {
    return a < b ? a : b; 
}
 
int main() {
    int elaps = 0, c;
    int i, q;
    P u;
    //char str[64];
    
    scanf("%d %d",&n ,&q);
    for(i = 1; i <= n; i++) {
        scanf("%s", Q[i].name);
        scanf("%d", &Q[i].t);
    }
    head = 1;
    tail = n + 1;
    
    while(head != tail) {
        u = dequeue();
        c = min(q, u.t);
        u.t -= c;
        elaps += c;
        if(u.t > 0) enqueue(u);
        else {
            printf("%s %d\n",u.name,elaps);
        }
    }
    return 0;
}


Measured memory_bytes: 11884
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) { a = b; return 1; }
  return 0; }
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) { a = b; return 1; }
  return 0; }

int main(void){
  int a[5]; rep(i,5) cin >> a[i];
  int mn = 10,check;
  for(int i = 0; i < 5; i++){
    if(a[i]%10 != 0 && a[i]%10 < mn){
      mn = a[i]%10;
      check = i;
    }
  }
  int sum = 0;
  rep(i,5){
    if(i == check) continue;
    else if(a[i]%10 != 0){
      sum += floor(a[i]/10)*10+10;
    }
    else sum += a[i];
  }
  sum += a[check];
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define f(i,a,b) for(int i(a);i<b;i++)
#define rep(i,n) for(int i(0);i<n;i++)
#define fast  ios_base::sync_with_stdio(0); cin.tie(0);
#define pres(x) cout<<fixed; cout<<setprecision(x);
#define open freopen("input.txt","r",stdin) ; freopen("output.txt","w",stdout);
#define watch(x) cout<<(#x)<<" is "<<x<<"\n";
#define out(x) cout<<x<<"\n";
#define pb push_back
#define all(v) v.begin() v.end()

int32_t main(){
	
	fast;
	//open;

	int n;
	cin>>n;
	int ans = n*(n-1);
	ans/=2;
	out(ans);


	return 0;
}

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

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

  vector<vector<int>> a(2, vector<int>(n));
  for (int i = 0; i < 2; i++) {
    for (int j = 0; j < n; j++) {
      cin >> a[i][j];
    }
  }
  int ans = 0;
  //下方向に行く位置を全部なめる
  for (int u = 0; u < n; u++) {
    int sum = 0;
    for (int l = 0; l <= u; l++) {
      sum += a[0][l];
    }
    for (int r = u; r < n; r++) {
      sum += a[1][r];
    }
    ans = max(ans, sum);
  }
  cout << ans << endl;
}

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

int main()
{
	int ans = 0;
	int a, b, c, x;

	cin >> a >> b >> c >> x;

	for( int i = 0; i <= a; i++ ) {
		for( int j = 0; j <= b; j++ ) {
			for( int k = 0; k <= c; k++ ) {
				if( i * 500 + j * 100 + k * 50 == x ) {
					ans++;
				}
			}
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
x = int(input())

res = [False for i in range(x + 1)]
res[0] = True
for i in range(100, 106):
    if x < i:
        break
    res[i] = True

for i in range(106, x + 1):
    res[i] = res[i-100] or res[i-101] or res[i-102] or res[i-103] or res[i-104] or res[i-105]

if res[x]:
    print(1)
else:
    print(0)


Measured memory_bytes: 3864
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define INF 1000000000
#define MOD 1000000007
#define EPS 0.00000001



int main(){
    int N, K; cin >> N >> K;
    if(K>(N+1)/2) cout << "NO" << endl;
    else cout << "YES" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
int n;
cin >> n;
long long a[n];
long long sum=0;
for(int i=0;i<n;i++){
cin >> a[i];
sum =sum+a[i];
}
if(n==2){
long long k ;
int s=a[0]-a[1];
if(s<0){
k=-s;
}
else{
k=s;
}
cout << k;
}
else{
long long sum2=0;
long long ans1;
long long x=sum-a[n-1];
long long ans2=x-a[n-1];
if(ans2<0){
ans2=-ans2;
}
for(int i=0;i<n-1;i++){
sum2=sum2+a[i];
long long sub=sum-sum2;
if(sub>sum2){
ans1=sub-sum2;
}
else{
ans1=sum2-sub;
}
if(ans1<0){
ans1=-ans1;
}
if(ans1<ans2){
ans2=ans1;
}
}
cout <<ans2;
}

return 0;
}

Measured memory_bytes: 1792
// ABC064A - 

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

typedef unsigned long long int ull;
typedef long long int ll;

int main() {
	int r, g, b;
	cin>> r >> g >> b;

	if ((g * 10 + b)% 4 == 0) {
		cout << "YES" << endl;
	} else {
		cout << "NO" << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
 
#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define all(v) begin(v), end(v)
#define debug(x) cerr<< #x <<": "<<x<<endl
#define debug2(x,y) cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<endl
 
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;
typedef deque<bool> db;
template<class T> using vv=vector<vector< T > >;

void yes() {
  printf("Yes\n");
  exit(0);
}

void no() {
  printf("No\n");
  exit(0);
}

int main() {
  int n;
  scanf("%d", &n);
  vi a(n);
  rep (i, n) {
    scanf("%d", &a[i]);
  }
  sort(all(a));
  if (a[n-1] - a[0] > 1) {
    no();
  }
  if (a[n-1] - a[0] == 1) {
    int ub = upper_bound(all(a), a[0]) - begin(a);
    if (n - ub == 1) {
      no();
    }
    if (ub + 1 <= a[n-1] && a[n-1] <= ub + (n - ub) / 2) {
      yes();
    } else {
      no();
    }
  }
  if (1 <= a[0] && a[0] <= n / 2) {
    yes();
  } else if (a[0] == n-1) {
    yes();
  } else {
    no();
  }

  return 0;
}


Measured memory_bytes: 888
def cmb(n, r, p):
  if (r < 0) or (n < r):
    return 0
  r = min(r, n - r)
  return fac[n]*finv[r]*finv[n-r]%p

n,m,K = map(int,input().split())
MOD = pow(10,9)+7
N = pow(10,6)
fac = [-1]*(N+1); fac[0] = 1; fac[1] = 1 #階乗
finv = [-1]*(N+1); finv[0] = 1; finv[1] = 1 #階乗の逆元
inv = [-1]*(N+1); inv[0] = 0; inv[1] = 1 #逆元
for i in range(2,N+1):
  fac[i] = fac[i-1]*i%MOD
  inv[i] = MOD - inv[MOD%i]*(MOD//i)%MOD
  finv[i] = finv[i-1]*inv[i]%MOD

factor = cmb(n*m-2,K-2,MOD)
X = factor*(m-1)*m*(m+1)//6*n*n%MOD
Y = factor*(n-1)*n*(n+1)//6*m*m%MOD
#print(X,Y)
ans = (X+Y)%MOD
print(ans)

Measured memory_bytes: 88120
N = int(input())
SP_list = [(str(i) + " " + input()).split() for i in range(1, N+1)]
key = lambda sp: (sp[1], int(sp[2])*(-1))
sorted_SP_list = sorted(SP_list, key=key)
for i, s, p in sorted_SP_list:
    print(i)


Measured memory_bytes: 38640
#include<iostream>
#include<cstdio>
#include<fstream>
#include<queue>
#include<vector>
#include<cstring>
#define MAX 110
#define INF 10000000

using namespace std;

int H, W;
char orc[MAX][MAX]; //存数据 
bool map[MAX][MAX];//标记是否使用过 

//深搜
int dfs(int x, int y, char a){
	int xi[4] = {-1,1,0,0};
	int yi[4] = {0,0,-1,1};
	//上下左右四个方向遍历
	for(int i=0; i<4; i++){
		int A = x+xi[i];
		int B = y+yi[i];
		//有a，标记统计过 
		if(orc[A][B]==a && !map[A][B] && A>=0 && B>=0 && A<H && B<W){
			map[A][B] = true;
			dfs(A, B, a);
		} 	
	} 
}

//测试函数 
int main(){
	
	while(cin >> H >> W){
		int res = 0; 
		for(int i=0; i<H; i++)
			for(int j=0; j<W; j++)
				map[i][j] = false;
		if(H == 0 && W == 0)break;
		for(int i=0; i<H; i++)
			for(int j=0; j<W; j++)
				cin >> orc[i][j];
		//遍历orc
		for(int i=0; i<H; i++)
			for(int j=0; j<W; j++){
				//苹果 
				if(orc[i][j] == '@' && !map[i][j]){
					dfs(i, j, '@');
					res++;
				}
				//梨 
				if(orc[i][j] == '#' && !map[i][j]){
					dfs(i, j, '#');
					res++;
				}
				//蜜柑 
				if(orc[i][j] == '*' && !map[i][j]){
					dfs(i, j, '*');
					res++;
				}
			}
		cout << res << endl;		
	}
	
	return 0;
} 


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

int main(){
  string S;
  cin >> S;
  
  if(S.at(0) == S.at(1) && S.at(1) == S.at(2) && S.at(2) == S.at(3)) {
    cout << "No" << endl;
  } else if(S.at(0) == S.at(2) && S.at(1) == S.at(3)) {
    cout << "Yes" << endl;
  } else if(S.at(0) == S.at(3) && S.at(1) == S.at(2)) {
    cout << "Yes" << endl;
  } else if(S.at(0) == S.at(1) && S.at(2) == S.at(3)){
  	cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")
 
#include <iostream>
#include <stdlib.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <assert.h>
#include <memory.h>
#include <time.h>
#include <bitset>
#include<iomanip>
#include <list>
 
#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = (l); i < (r); i++)
#define repb(i, r, l) for (int i = (r); i > (l); i--)
#define sz(a) (int)a.size()
#define fi first
#define se second
#define pii pair<int,int>
#define pli pair<ll,int>
#define pll pair<ll,ll>
#define mp(a, b) make_pair(a, b)
#define mt(a,b,c) make_tuple(a,b,c)
#define rank qwertyuio
#define next dfghjk
#define plus fsghsf
#define minus ytryr
#define pb push_back
using namespace std;
 
inline bool setmin(int &x, int y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(int &x, int y) { return (y > x) ? x = y, 1 : 0; }
inline bool setmin(ll &x, ll y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(ll &x, ll y) { return (y > x) ? x = y, 1 : 0; }
 
const int N = 100000;
const int inf = (int)1e9 + 1;
const ll big = (ll)1e18 + 1;
const int P = 239;
const int P1 = 31;
const int P2 = 57;
const int mod = (int)1e9 + 7;
const int mod1 = (int)1e9 + 9;
const int mod2 = 998244353;
const int mod3 = (int)1e6+3;
const ld eps = 1e-12;
const double pi = atan2(0, -1);
const int ABC = 26;
int gcd(int a, int b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b);  
      
} 
ll max(ll a,ll b){
    return (a<b)? b:a;
}
ll min(ll a,ll b){
    return (a>b)? b:a;
}

vector<int> q;
int main()
{
    //freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);<<" "
    //ios_base::sync_with_stdio(false); cin.tie(0);
    ll a,b,c,k;
    cin>>a>>b>>c>>k;
    if(k%2==0){
        cout<<a-b;
    }
    else{
        cout<<b-a;
    }
   
    return 0;
             
    
}

Measured memory_bytes: 256
#include <stdlib.h>
#include <stdio.h>
#include <math.h>

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

void solve(void){
    int n;
    scanf("%d\n", &n);
    int cs[n-1], ss[n-1], fs[n-1];
    rep(n-1, i) scanf("%d%d%d\n", &cs[i], &ss[i], &fs[i]);

    rep(n-1, j) {
        int t = ss[j] + cs[j];
        for (int k = j+1; k < n-1; k++){
            if (t <= ss[k]) t = ss[k] + cs[k];
            else if (t % fs[k]) t += fs[k] - (t % fs[k]) + cs[k];
            else t += cs[k];
        }
        printf("%d\n", t);
    }
    printf("%d\n", 0);
}

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


Measured memory_bytes: 128
// C - Rectangle Cutting
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define rep(i, m, n) for (lli i = m; i < (n); i++)
#define repe(i, m, n) for (lli i = m; i <= (n); i++)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((lli)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define _GLIBCXX_DEBUG
const lli INF = 2147483647;
const lli MINF = -2147483648;
const lli LINF = 9223372036854775807;
const lli MOD = 1000000007; //10^9+7
const double PI = acos(-1);
#define SORT(n) sort(n.begin(), n.end())
#define SORTR(n) sort(n.begin(), n.end(), greater<int>())
#define REV(n) reverse(n.begin(), n.end())
#define pb push_back
#define eb emplace_back
#define mp make_pair
#pragma GCC optimize("Ofast")
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vlli = vector<lli>;
using vvli = vector<vlli>;
using vs = vector<string>;
using vvs = vector<vs>;
using vb = vector<bool>;
using vvb = vector<vb>;
using ll = long long;
// vector入力
template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
  for (T &x : vec)
    is >> x;
  return is;
}
// vector出力
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec)
{
  // os << '{';
  for (int i = 0; i < vec.size(); i++)
  {
    os << vec[i] << (i + 1 == vec.size() ? "" : "");
  }
  // os << '}';
  return os;
}
// aよりもbが大きいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T &b)
{
  if (a < b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T &b)
{
  if (a > b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli a, b, c, h, n, w;
  double ans = 0, count = 0;
  string s, t;
  vector<pair<string, pair<lli, lli>>> pr;
  double W, H, x, y;
  cin >> W >> H >> x >> y;
  ans = W * H / 2;
  if (x == W / 2 && y == H / 2)
  {
    count = 1;
  }
  a = count;
  cout << fixed << setprecision(12) << ans << " " << a << endl;
}

Measured memory_bytes: 3844
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 10;
int a[maxn], b[maxn], n, k;
int main(void) {
    while(~scanf("%d%d", &n, &k)) {
        ll ans = 0;
        for(int i = 0; i < n; ++i) {
            scanf("%d%d", a + i, b + i);
            if((a[i] & k) == a[i]) ans += b[i];
        }
        for(int i = 30; i >= 0; --i) {
            int tmp = 1 << i;
            if(k & tmp) {
                int t = (k ^ tmp) | (tmp - 1);
                ll res = 0;
                for(int j = 0; j < n; ++j)
                    if((a[j] & t) == a[j]) res += b[j];
                ans = max(ans, res);
            }
        }
        printf("%lld\n", ans);
    }
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define DEBUG if(0)
#define lli long long int
#define ldouble long double
using namespace std;
 
const int maxN = 15; int n;
bool honest[maxN];
vector<pair<int, int>> testemonies[maxN];
 
bool valid(int bitmask)
{
  for (int i = 0; i < n; i ++)
    if (bitmask & (1 << i))
      for (auto &v: testemonies[i])
        if (v.second != ((bitmask >> v.first) & 1))
          return false;
  return true;
}
 
int main()
{
  while (scanf("%d", &n) != EOF)
  {
    for (int i = 0; i < n; i ++) honest[i] = true, testemonies[i].clear();
    for (int i = 0; i < n; i ++)
    {
      int a; scanf("%d", &a);
      for (int j = 0; j < a; j ++)
      {
        int u, is; scanf("%d %d", &u, &is); u --;
        testemonies[i].push_back({u, is});
      }
    }
 
    int ans = 0;
    for (int bitmask = 0, end = 1 << n; bitmask < end; bitmask ++)
    {
      if (valid(bitmask))
        ans = max(ans, __builtin_popcount(bitmask));
    }
    printf("%d\n", ans);
  }
  return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main()
{
    int n;
    int a[100001];
    bool used[100001];
    int ans,cnt = 0;

    cin >> n;
    for(int i = 1;i <= n;i++){
        cin >> a[i];
        used[i] = true;
    }
    ans = 1;
    used[1] = false;
    cnt++;

    while(true){
        ans = a[ans];
        if(!used[ans]){
            cout << -1 << endl;
            return 0;
        }
        used[ans] = false;
        if(ans == 2) break;
        else cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 768
#include<stdio.h>
int main(){
  long int n,m,k,i,a[200001]={0},b[200001]={0},x,r=0;
  scanf("%ld%ld%ld",&n,&m,&k);
  for(i=1;i<=n;i++){scanf("%ld",&a[i]);a[i]+=a[i-1];}
  for(i=1;i<=m;i++){scanf("%ld",&b[i]);b[i]+=b[i-1];}
  x=m;
  for(i=0;i<=n;i++){
    while(x>0&&a[i]+b[x]>k)x--;
    if(a[i]+b[x]<=k)r=i+x<r?r:i+x;
  }
  printf("%ld",r);
}


Measured memory_bytes: 4860
#include <bits/stdc++.h>
using namespace std;
int main(void){
    string s;
    cin >> s;
    
    int sum = 0;
    for(int i = 0;s[i] != '\0';i++){
        sum += (int)(s[i] - '0');
    }
    
    if(sum % 9 == 0){
        cout << "Yes";
    }
    else{
        cout << "No";
    }
    
    return 0;
}


Measured memory_bytes: 3748
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Edge = pair<int, int>;
using Graph = vector<vector<Edge>>;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const ll nmax = 8;
const ll INF = 1e9;
bool graph[nmax][nmax];
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}

class UnionFind
{
public:
    vector<ll> Parent;

    UnionFind(ll N)
    {
        Parent = vector<ll>(N, -1);
    }
    ll find(ll A)
    {
        if (Parent[A] < 0)
            return A;
        return Parent[A] = find(Parent[A]);
    }

    ll size(ll A)
    {
        return -Parent[find(A)];
    }

    bool Union(ll A, ll B)
    {
        A = find(A);
        B = find(B);
        if (A == B)
        {
            return false;
        }
        if (size(A) < size(B))
            swap(A, B);

        Parent[A] += Parent[B];
        Parent[B] = A;

        return true;
    }
};

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

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a / g * b;
}

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}

ll ceil(ll a, ll b)
{
    return (a + b - 1) / b;
}

void solve(long long a, long long b, long long x)
{
    if (a != 0)
    {
        cout << b / x - (a - 1) / x << endl;
    }
    else
    {
        cout << b / x + 1 << endl;
    }
}

int main()
{
    long long a;
    scanf("%lld", &a);
    long long b;
    scanf("%lld", &b);
    long long x;
    scanf("%lld", &x);
    solve(a, b, x);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(void){
  int n, k;
  int l;
  vector<int> v;
  cin >> n >> k;
  for(int i = 0; i < n; i++){
    cin >> l;
    v.push_back(l);
  }
  sort(v.begin(), v.end(), greater<int>());
  int ma = 0;
  for(int i = 0; i < k; i++) ma += v[i];
  cout << ma << endl;
  return 0;
}

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

#define rep(i,n) for(int i=0;i<(n);i++)
#define fr first
#define sc second
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};

using namespace std;
typedef pair<int,int> P;
int W,H;
string maze[100];
const int INF=1e9;

void solve() {
    int dp[100][100];
    rep(y,100) rep(x,100) dp[y][x]=INF;
    getchar();
    rep(y,2*H-1) getline(cin,maze[y]);

    queue<P> que;
    que.push(P(0,0));
    dp[0][0]=0;
    while(que.size()) {
        P p=que.front(); que.pop();
        rep(k,4) {
            int ny=p.fr+dy[k];
            int nx=p.sc+dx[k];
            int ny2=ny+dy[k];
            int nx2=nx+dx[k];
            if(!(0<=ny2&&ny2<2*H-1)) continue;
            if(!(0<=nx2&&nx2<2*W-1)) continue;
            if(dp[ny2][nx2]!=INF) continue;
            if(maze[ny][nx]=='1') continue;

            //printf("(%d, %d) -> (%d, %d)\n",p.fr,p.sc,ny2,nx2);
            dp[ny2][nx2]=dp[p.fr][p.sc]+1;
            que.push(P(ny2,nx2));
        }
    }

    int ans=dp[2*H-2][2*W-2];
    if(ans==INF) ans=0;
    else ans++;
    cout<<ans<<endl;
}

int main() {
    while(cin>>W>>H) {
        if(!W) break;
        solve();
    }
    return 0;
}

Measured memory_bytes: 1264
#include<stdio.h>

int Linear(int a[], int n, int key){
  int i = 0;
  a[n]  = key;
  while (a[i] != key)
    i++;
  if (i==n){
    return 0;
  } else {
    return 1;
  }
}

int main(){
  int i, n, a[10001], q, key;
  int sum = 0;

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

  scanf("%d", &q);
  for (i=0; i<q; i++) {
    scanf("%d", &key);
    if (Linear(a, n, key)==1)
      sum++;
  }
  printf("%d\n", sum);

  return 0;
}

Measured memory_bytes: 1856
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define REPR(i, n) for(int i = (n); i >= 0; i--)
#define FOR(i, m, n) for(int i = (m); i < (n); i++)
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << ": " << x << endl;

using namespace std;
typedef long long ll;

signed main() {
  int n, r;
  cin >> n >> r;
  if(n >= 10) {
    cout << r << endl;
  } else {
    cout << r + 100 * (10 - n) << endl;
  }
  return 0;
}


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

int main(){
    int S, W;
    cin >> S >> W;
    if(W >= S){
        cout << "unsafe" << endl;
    } else {
        cout << "safe" << endl;
    }

    return 0;
}


Measured memory_bytes: 3636
n,m = gets.chomp.split.map(&:to_i)
nums = gets.chomp.split.map(&:to_i)
num = nums.sort
if m<=n
  puts 0
else
  array = []
  (m-1).times do |i|
    array.unshift(num[i+1]-num[i])
  end
  ns = array.sort[0..m-n-1]
  puts ns.sum
end

Measured memory_bytes: 24008
# -*- coding: utf-8 -*-


def main():
    n = int(input())
    s = input()
    k = int(input())
    ans = ''
    kth_s = s[k - 1]

    for si in s:
        if si != kth_s:
            ans += '*'
        else:
            ans += si

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include <stdio.h>
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue> 
 
using namespace std;

typedef pair<int, pair<int, int> > p;

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

	int N, K, S;

	cin >> N >> K >> S;

	for(int i = 0; i < K; i++) {
		cout << S << " ";
	}
  
  	int x = pow(10, 9);

	for(int i = 0; i < N - K; i++) {
      if(S == x) cout << x - 1 << " "; 
      else cout << x << " ";
	}
}


Measured memory_bytes: 1280
#include "bits/stdc++.h"
using namespace std;
#define fastcin {\
    cin.tie(0);\
    ios::sync_with_stdio(false);\
}
#define rep(i, a, b) for(int i = a; i < b; i++)
#define rrep(i, a, b) for(int i = a; i >= b; i--)
#define fore(i, a) for(auto &i:a)
#define print(x) cout << x << "\n"
#define SORT(a, n) sort(a, a+n);
#define REVERSE(a,n) reverse(a,a+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VREVERSE(v) reverse(v.begin(), v.end());
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
const ll mod = 1000000007;
const int inf = 1e9+7;
const ll infl = 1e18+7;

int main() {
    fastcin;
    string s, t, ans = "No";
    cin >> s >> t;
    if(s.size()==t.size()) {
        rep(i, 0, s.size()) {
            if(s==t) {
                ans = "Yes";
                break;
            }
            char tmp = s.back();
            s.pop_back();
            s.insert(s.begin(), tmp);
        }
    }
    print(ans);
    return 0;
}

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

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt(), m = scanner.nextInt();
			Path[] paths = new Path[m];
			IntStream.range(0, m).forEach(
					// 最長距離を計算するため、距離をマイナスにする
					i -> paths[i] = new Path(scanner.nextInt() - 1, scanner.nextInt() - 1, -scanner.nextLong()));
			long[] distances = new long[n];
			if (bellmanFord(paths, 0, n, distances)) {
				System.out.println("inf");
			} else {
				System.out.println(-distances[n - 1]);
			}
		}
	}

	/**
	 * https://www.geeksforgeeks.org/bellman-ford-algorithm-dp-23/ を参考に作成
	 * 
	 * @param paths     ノード間の連結パス一覧の配列
	 * @param src       開始ノード
	 * @param n         ノードの数
	 * @param distances 開始ノードから各ノードへの最短距離の配列
	 * @return グラフにはループが含まれているかどうか
	 */
	private static boolean bellmanFord(final Path[] paths, final int src, final int n, final long[] distances) {
		Arrays.fill(distances, Long.MAX_VALUE);
		distances[src] = 0;

		IntStream.range(1, n).forEach(i -> IntStream.range(0, paths.length).forEach(j -> {
			int from = paths[j].from, to = paths[j].to;
			long cost = paths[j].cost;
			if (distances[from] != Long.MAX_VALUE && distances[from] + cost < distances[to]) {
				distances[to] = distances[from] + cost;
			}
		}));

		// マイナスのループが含まれているかどうかを判定
		// 解説に参考して作成
		boolean[] negative = new boolean[n];
		Arrays.fill(negative, false);
		IntStream.range(0, n).forEach(i -> IntStream.range(0, paths.length).forEach(j -> {
			int from = paths[j].from, to = paths[j].to;
			if (distances[from] != Long.MAX_VALUE && distances[from] + paths[j].cost < distances[to]) {
				distances[to] = distances[from] + paths[j].cost;
				negative[to] = true;
			}
			if (negative[from]) {
				negative[to] = true;
			}
		}));
		return negative[n - 1];
	}

	/**
	 * ノード間の一つのパスを表すクラス
	 */
	private static class Path implements Comparable<Path> {
		/** 開始ノード */
		int from;
		/** 終了ノード */
		int to;
		/** 移動コスト */
		long cost;

		Path(int from, int to, long cost) {
			super();
			this.from = from;
			this.to = to;
			this.cost = cost;
		}

		@Override
		public int compareTo(Path path) {
			long costDiff = this.cost - path.cost;
			return (costDiff > 0) ? 1 : (costDiff < 0) ? -1 : 0;
		}
	}
}


Measured memory_bytes: 43484
import java.util.Scanner;

public class Main
{

    public static void main(String[] args)
    {
        Scanner scan = new Scanner(System.in);
        int p = scan.nextInt();
        int m = scan.nextInt();
        int c = scan.nextInt();
        long A = p + m + c;

        System.out.println(A);
    }

}



Measured memory_bytes: 26004
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
typedef long long ll;
const ll MOD=1000000007;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }

int main(void){
    // Your code here!
    int h,w;
    cin >> h >> w;
    vector<vector<char>> s(h,vector<char>(w));
    rep(i,h) {
        rep(j,w) {
        cin >> s.at(i).at(j);
        }
    }
    bool can = true;
    const vector<int> dx = {1,0,-1,0};
    const vector<int> dy = {0,1,0,-1};
    rep(i,h) {
        rep(j,w) {
            if (s.at(i).at(j) == '.') continue;
            else {
                bool sharp = false;
                rep(d,4) {
                    int ni = i + dy[d];
                    int nj = j + dx[d];
                    if ( ni < 0 or ni >= h) continue;
                    if ( nj < 0 or nj >= w) continue;
                    if (s[ni][nj] == '#') {
                        sharp = true;
                    }
                }
                if (sharp == false) can = false;
                }
            }
        }
    
   
    if (can) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
hoge = input().split()
N = int(hoge[0])
M = int(hoge[1])
 
mi = 0
ma = N
 
for j in range(M):
    i = input().split(" ")
    l = int(i[0])
    r = int(i[1])
    if l >= mi:
        mi = l
    if r <= ma:
        ma = r
r = ma - mi + 1
if r > 0:
    print(r)
else:
    print(0)

Measured memory_bytes: 9180
#include <bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds;   
#define ll long long
#define ull unsigned long long
// #define ordered_set tree<pair<ll, ll>, null_type, less<pair<ll, ll>>, rb_tree_tag, tree_order_statistics_node_update> 
ll mod=1e9+7;
#define PI 3.1415926535897932385
#define inf 9e18
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
typedef pair<long long, long long> ii;
#define S second
#define F first
ll max(ll a,ll b){if(a>b){return a;}return b;}
ll min(ll a,ll b){if(a<b){return a;}return b;}
#define MAXN 200005
// Comment this out for interactice problem
// #define endl '\n'
// string to integer stoi() Remember: it takes string not character
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
 
// To compile--> g++ -std=c++0x -o output one.cpp
// To run--> ./output

int main()
{ 
    fastio;
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);

    ll n,k;
    cin>>n>>k;
    ll a[n];
    for (int i = 1; i < n+1; ++i)
    {
        cin>>a[i];
    }

    ll dp[n+1][k+1];

    for (int i = 0; i < n+1; ++i)
    {
        for (int j = 0; j < k+1; ++j)
        {
            dp[i][j]=0;
        }
    }

    dp[0][0]=1;

    for (int i = 1; i < n+1; ++i)
    {
        ll pref[k+1];
        for (int j = 0; j < k+1; ++j)
        {
            pref[j]=0;
        }

        pref[0]=(dp[i-1][0])%mod;
        for (int j = 1; j < k+1; ++j)
        {
            pref[j]=(pref[j-1]+dp[i-1][j])%mod;
        }

        for (int j = 0; j < k+1; ++j)
        {
            if(j<=a[i]){
                dp[i][j]=(pref[j])%mod;
            }
            else{
                dp[i][j]=(pref[j]-pref[j-a[i]-1] + mod)%mod;
            }
        }
    }
    cout<<(dp[n][k])%mod;

    return 0;
}


Measured memory_bytes: 83320
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
 
 
public class Main {
    public static void main(String args[]) throws IOException{
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder builder = new StringBuilder();
        int i=1;
        while(true){
            int data= Integer.parseInt(reader.readLine());
            if(data==0)
                break;
             
            builder.append("Case ").append(Integer.toString(i++)).append(": ").append(Integer.toString(data)).append("\n");
        }
        System.out.print(builder);
    }
}

Measured memory_bytes: 31136
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<int, int> P;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define Rep(i, r, n) for (ll i = r; i < n; i++)
#define debug(x) cout << #x << " =" << (x) << endl;
#define MOD 1000000007
#define EPS (1 >> 30)
#define INF (1 << 30)
//#define INFll (1LL << 60)

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    //---------------------------------------------

    int n;
    cin >> n;
    vector<string> s(n);
    rep(i, n)
    {
        cin >> s[i];
        sort(s[i].begin(), s[i].end());
    }
    sort(s.begin(), s.end());
    ll memo = 0;
    ll ans = 0;
    rep(i, n - 1)
    {
        if (s[i] == s[i + 1])
        {
            memo++;
        }
        else
        {
            ans += memo * (memo + 1) / 2;
            memo = 0;
        }
    }

    ans += memo * (memo + 1) / 2;

    cout << ans << endl;
}


Measured memory_bytes: 5760